ui/RunTimerLabel.razor

A Razor UI panel that displays the current run timer. It reads the elapsed time from Manager, or FinalRunTime once the run ends in victory or failure, and formats it as mm:ss or hh:mm:ss. It also shifts its right offset based on whether the player is muted and dims itself outside the buy phase.

@using Sandbox;
@using Sandbox.UI;
@inherits Panel
@attribute [StyleSheet("RunTimerLabel.razor.scss")]

<root style="opacity: @(Manager.Instance.GameState == GameState.BuyPhase ? 1f : 0.4f); right: @(Manager.Instance.IsMuted ? 112 : 60)px;">
	@{
		TimeSpan time = (Manager.Instance.GameState == GameState.Victory || Manager.Instance.GameState == GameState.Failure)
			? TimeSpan.FromSeconds(Manager.Instance.FinalRunTime)
			: TimeSpan.FromSeconds(Manager.Instance.TimeSinceRunStart.Relative);
	}
	
	<div class="message">
		@(time.TotalSeconds > 3600 ? time.ToString(@"hh\:mm\:ss") : time.ToString(@"mm\:ss"))
	</div>
</root>

@code
{
	protected override int BuildHash()
	{
		var seconds = MathX.FloorToInt(Manager.Instance.TimeSinceRunStart.Relative);

		return HashCode.Combine(
			seconds,
			Manager.Instance.GameState,
			Manager.Instance.IsMuted
		);
	}
}