A UI Razor component that draws an Active Reload bar above a player's head using a WorldPanel. It positions and sizes the world panel each update and renders section and bar elements driven by a PerkActiveReload instance.
@namespace Sandbox
@using Sandbox;
@using Sandbox.UI;
@using System;
@inherits PanelComponent
@attribute [StyleSheet("ActiveReloadBar.razor.scss")]
@{
if (!Player.IsValid() || Player.IsDead)
return;
}
<root style="opacity:@(Perk.IsVisible ? 1f : 0f);">
<div class="container @(Perk.IsBarInSection ? "in-section" : "")">
<div class="section" style="left: @(Perk.SectionStart * 1000f)px; width:@(Perk.SectionWidth * 1000f)px;"></div>
<div class="bar" style="left: @(Perk.BarProgress * 1000f - 4)px;"></div>
</div>
</root>
@code {
[Property] public Sandbox.WorldPanel WorldPanel { get; set; }
public Player Player { get; set; }
public PerkActiveReload Perk { get; set; }
protected override void OnStart()
{
base.OnStart();
}
protected override void OnUpdate()
{
base.OnUpdate();
// if (!Unit.IsValid())
// Unit = GetComponentInParent<Unit>();
// if (!Unit.IsValid())
// return;
WorldPanel.PanelSize = new Vector2(3000, 200);
WorldPanel.LocalPosition = Vector3.Up * (Player.HealthbarOffset + 20f);
WorldPanel.WorldRotation = Rotation.From(-55f, -90f, 0f);
}
protected override int BuildHash()
{
// if (!Unit.IsValid())
// return 0;
// var player = Unit as Player;
// var armor = player.IsValid() ? player.Armor : 0;
// var sinceArmorChange = player.IsValid() ? (player.TimeSinceArmorChanged < 0.5f ? player.TimeSinceArmorChanged : 0f) : 0f;
return HashCode.Combine( Time.Now );
}
}