aboutsummaryrefslogtreecommitdiffstats
path: root/code/ui/PlayerInfo.razor
blob: 131b278c402a0eb415f6d39fdfa60944884a8e87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
@using System
@using Sandbox;
@using Sandbox.UI;

@namespace MurderGame
@inherits Panel

<style>
playerinfo {
	position: absolute;
	width: 100vw;
	height: 100vh;
}
.playerinfo {
	position: absolute;
	left: 30px;
	bottom: 30px;
}
.teaminfo {
	position: absolute;
	right: 30px;
	bottom: 30px;
}
</style>

<box class="playerinfo">
	<Health Colour="@GetCharacterColour()"></Health>
	<NameInfo Colour="@GetCharacterColour()"></NameInfo>
</box>
<box class="teaminfo">
	<TeamInfo Colour="@GetTeamColour()"></TeamInfo>
</box>

@code
{
    public string GetCharacterColour()
    {
        var clientPawn = Game.LocalPawn;
        if (clientPawn is Player {Camera: not null } player)
        {
	        var colour = player.Camera.GetObservedColour();
	        return string.IsNullOrWhiteSpace(colour) ? "white" : colour;
        }
        return "white";
    }
	
	public string GetTeamColour()
	{
		var clientPawn = Game.LocalPawn;
		if (clientPawn is Player {Camera: not null } player)
		{
			var colour = TeamOperations.GetTeamColour(player.Camera.GetObservedTeam());
			return string.IsNullOrWhiteSpace(colour) ? "white" : colour;
		}
		return "white";
	}

    protected override int BuildHash()
    {
	    return HashCode.Combine(GetTeamColour().GetHashCode(), GetTeamColour().GetHashCode());
    }
}