UI/PlayerHud/MainHUD.razor
@namespace KOTH.UI
@using KOTH.Notification
@using Sandbox.Events
@inherits PanelComponent
@implements Component.INetworkListener

@if (!IsHudEnabled)
	return;

@if (!PlayerState.Local.PlayerPawn.IsValid())
	return;

<root>
	<canvas>
		<Watermark />
		<DamageNumbers />
		<DamageIndicatorNew />
		<StickyOverlay />
		<SmallClassSelect />
		<XHair />
		<Health />
		<Ammo />
		<Topbar />
		<EngieOverlay />

		<PayloadIndicator />
		<MGEScore />
		<DMScore />
		
		<div class="right">
			<div class="flex-grow" />
			<Voices />
			<WeaponInfoComponent />
		</div>
	</canvas>

	<Scoreboard />
	<PauseMenu />
	<PlayerInfo />
	<Notifications />

	@* <div class="hud flex column justify-start bottom-left chat">
		@foreach (var VisableMessage in TextChat.Instance.GetVisableMessages())
		{
			@if (VisableMessage.AuthorSteamID > 0)
			{
				<div class="square rounded shrink-0"
				style="background-image: url( avatar:@VisableMessage.AuthorSteamID )"></div>
			}

			<label class="message no-shadow">@VisableMessage.GetChatMessage()</label>
		}
		<TextChatBox @ref="TextChat.Instance.InputBox" onsubmit="@TextChat.Instance.InputBox.SendMessage"></TextChatBox>
	</div> *@
</root>

@code
{

	[ConVar("cl_drawhud")] public static bool IsHudEnabled { get; set; } = true;

	protected override void OnEnabled()
	{
		base.OnEnabled();

		TextChat.Instance.InputBox = new();
	}

	protected override void OnUpdate()
	{
		base.OnUpdate();

		if (!PlayerState.Local.IsValid() || !PlayerState.Local.PlayerPawn.IsValid())
		{
			return;
		}

		if (Input.Pressed("chat"))
		{
			TextChat.Instance?.InputBox?.Focus();
		}
	}

	void Component.INetworkListener.OnConnected(Connection channel)
	{
		FTextChatMessage ChatMessage = new()
			{
				Message = "joined the game",
				AuthorName = channel.DisplayName,
				AuthorSteamID = channel.SteamId,
			};

		TextChat.Instance.ServerRequestMessage(ChatMessage);
	}

	void Component.INetworkListener.OnDisconnected(Connection channel)
	{
		FTextChatMessage ChatMessage = new()
			{
				Message = "left the game",
				AuthorName = channel.DisplayName,
				AuthorSteamID = channel.SteamId,
			};

		TextChat.Instance.ServerRequestMessage(ChatMessage);
	}

	protected override int BuildHash()
	{
		return HashCode.Combine(Time.Now);
	}
}