A Razor UI PanelComponent for a boss health bar HUD. It shows the boss name, a filled health bar based on a shared HexPlatforms.BossBarFraction, static marks at 75/50/25%, and the boss phase. It only renders when HexPlatforms.BossBarShown is true and reduces rebuilds by hashing the percent (to a tenth) and phase.
@using Sandbox;
@using Sandbox.UI;
@using NZombies;
@inherits PanelComponent
@*
BOSS BAR — basalt's beast, top centre: his name, his health, a mark at each phase's line (75, 50, 25%), and the phase.
⚠️ ITS OWN PanelComponent, as the powerup banner is, and mounted the same way (`SurvivalHud.OnUpdate`): no scene edit, and
it draws whatever the survival HUD's `Visible` says — the fight can be played in creative too. It reads the fight as this
machine was told it (`HexPlatforms.BossBarShown`, `BossBarFraction`, `BossBarPhase`), so every player sees the same bar.
*@
<root class="@HudTheme.Class">
@if ( HexPlatforms.BossBarShown )
{
<div class="boss">
<div class="name">@HexPlatforms.BossBarName</div>
<div class="bar">
<div class="fill" style="width: @(Percent)%"></div>
<div class="mark" style="left: 75%"></div>
<div class="mark" style="left: 50%"></div>
<div class="mark" style="left: 25%"></div>
</div>
<div class="phase">@HexPlatforms.BossBarPhase</div>
</div>
}
</root>
@code
{
/// <summary>His health for the fill, in percent, to a tenth.</summary>
float Percent => System.MathF.Round( System.Math.Clamp( HexPlatforms.BossBarFraction, 0f, 1f ) * 1000f ) / 10f;
/// <summary>⚠️ REBUILDS ON THE FILL, TO A TENTH OF A PERCENT, AND ON THE PHASE — not every frame.</summary>
protected override int BuildHash() => System.HashCode.Combine(
HexPlatforms.BossBarShown, (int)(Percent * 10f), HexPlatforms.BossBarPhase, HudTheme.Class );
}