UI/Hud.razor

Razor UI component for the game's HUD root. It chooses which child panel to show: community browser or launcher when no Game exists on the host, game setup while the game is in Waiting state, and the in-game HUD otherwise. It resolves a GameDirector from the scene and exposes the active CardGame for view logic.

Networking
@namespace CardGames
@using Sandbox
@using Sandbox.UI
@using System
@using System.Linq
@inherits PanelComponent

<root class="cgui">
	@if ( Game is null && Networking.IsHost )
	{
		@if ( Director?.Screen == MenuScreen.Community )
		{
			<CommunityBrowser />
		}
		else
		{
			<GameLauncher />
		}
	}
	else if ( Game is not null && Game.State == GameState.Waiting )
	{
		<GameSetup />
	}
	else
	{
		<GameHud />
	}
</root>

@code
{
	// The one screen panel on the camera. It only decides which sub-panel to show; the launcher and
	// the in-game HUD own their own markup, styles and state.
	private GameDirector _director;
	private GameDirector Director => _director ??= Scene.Get<GameDirector>();
	private CardGame Game => Director?.ActiveGame;

	// Include State so we swap setup ↔ in-game HUD when the round begins (the Game object reference is unchanged).
	protected override int BuildHash() => HashCode.Combine( Game, Game?.State, Networking.IsHost, Director?.Screen );
}