UI/PlayerHud/Components/PlayerInfo.razor

A Blazor/Razor UI panel component for the player HUD that shows info about the player the local player is looking at. It queries look-at information and, if the target is on the same team, renders a label with the target's description, name and health.

@namespace KOTH.UI
@inherits Panel
@attribute [StyleSheet]

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

<root>
	@if (GotLookAtInfo())
	{
		<label class="info">@(LookAtInfo.Description)@(LookAtInfo.Name) : @(LookAtInfo.Health)</label>
	}
</root>

@code
{
	FPlayerLookAtInfo LookAtInfo;

	bool GotLookAtInfo()
	{
		bool ManInfront = PlayerUtils.LookAtInfoQuery(PlayerState.Local.PlayerPawn, Scene, out LookAtInfo);
		return ManInfront && LookAtInfo.Team == PlayerState.Local.PlayerPawn.Team;
	}

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