aboutsummaryrefslogtreecommitdiffstats
path: root/code/ui/PlayerInfo.razor
blob: 9c235860cf06181adfb1e33cdaaca7ffefe0f4c0 (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
63
64
65
66
67
68
69
70
71
@using System
@using Sandbox;
@using Sandbox.UI;

@namespace MurderGame
@inherits Panel

<style>
playerinfo {
	position: absolute;
	width: 100vw;
	height: 100vh;
}
.box {
	background-color: rgba(0, 0, 0, 0.20);
	backdrop-filter-blur: 8px;
	display: flex;
	align-items: center;
	flex-direction: row;
	gap: 10px;
	padding: 10px;
}
.playerinfo {
	position: absolute;
	left: 30px;
	bottom: 30px;
}
.teaminfo {
	position: absolute;
	right: 30px;
	bottom: 30px;
}
</style>

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

@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());
    }
}