Health.razor
@using Sandbox
@using Sandbox.UI
@inherits PanelComponent
<root>
@if ( Player is not null )
{
<div class="health-wrap">
<div class="name">@Player.Name</div>
<div class="health-box">
<div class="health-fill @HealthState" style="width:@(Player.HealthFraction * 100f)%"></div>
</div>
<div class="label">@Player.Health.ToString("0") / @Player.MaxHealth.ToString("0") HP</div>
</div>
}
else
{
<div class="health-wrap">
<div class="label">NO PLAYER</div>
</div>
}
</root>
@code {
[Property] public ButtonMasherPlayerController Player { get; set; }
string HealthState
{
get
{
if ( Player is null )
return "high";
if ( Player.HealthFraction <= 0.25f )
return "low";
if ( Player.HealthFraction <= 0.6f )
return "mid";
return "high";
}
}
protected override int BuildHash()
{
return System.HashCode.Combine(
Player?.Name,
Player?.Health,
Player?.MaxHealth,
Player?.HealthFraction
);
}
}