ui/Panels/BossNametag.razor
@using Sandbox;
@using Sandbox.UI;
@namespace SS1
@inherits Panel
@attribute [StyleSheet("BossNametag.razor.scss")]

<root>
	@{
		var currHp = Manager.Instance.Difficulty >= 5
			? ( (Boss.IsValid() ? Math.Max(Boss.Health, 0f) : 0f) + (OtherBoss.IsValid() ? Math.Max(OtherBoss.Health, 0f) : 0f) )
			: Boss.Health;

		var maxHp = Manager.Instance.Difficulty >= 5
			? 14000f
			: Boss.MaxHealth;

		var hpPercent = currHp / maxHp;

		var bgColor = Lerp3(new Color(0f, 0.75f, 0f), new Color(0.75f, 0.75f, 0f), new Color(1f, 0f, 0f), 1f - hpPercent);
	}

	<div class="hpbar">
		<div class="hpbardelta" style="width:@(hpPercent * 100f)%;"></div>
		<div class="hpbaroverlay" style="width:@(hpPercent * 100f)%; background-color:@(bgColor.Rgba);"></div>

		<div class="name_label">@(Manager.Instance.Difficulty >= 5 ? "BOSSES" : "BOSS")</div>
			<div class="hp_label">
			<div class="label">@($"{(int)Math.Ceiling(currHp)}")</div>
			<div class="label">/</div>
			<div class="label">@($"{(int)maxHp}")</div>
		</div>
	</div>
</root>

@code
{
	public Boss Boss { get; set; }
	public Boss OtherBoss { get; set; }

	protected override int BuildHash()
	{
		var currHp = Manager.Instance.Difficulty >= 5
			? ( (Boss.IsValid() ? Math.Max(Boss.Health, 0f) : 0f) + (OtherBoss.IsValid() ? Math.Max(OtherBoss.Health, 0f) : 0f) )
			: Boss.Health;

		return HashCode.Combine(
			currHp
		);
	}

	Color Lerp3(Color a, Color b, Color c, float t)
	{
		if(t < 0.5f) // 0.0 to 0.5 goes to a -> b
			return Color.Lerp(a, b, t / 0.5f);
		else // 0.5 to 1.0 goes to b -> c
			return Color.Lerp(b, c, (t - 0.5f) / 0.5f);
	}
}