aboutsummaryrefslogtreecommitdiffstats
path: root/code/ui/health/Health.razor
blob: 4ec7f67adaf7ccdb603ac910ef02ee05c03b83f3 (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
@namespace MurderGame
@using Sandbox
@inherits Sandbox.UI.Panel

<style>
Health {
    width: 350px;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.90);
	box-shadow: 1px 1px 0 0 rgba(0,0,0,0.75);
}
.colour-bar {
    height: 100%;
}
.transition-bar {
    height: 100%;
    transition: width 1s ease-out 0.5s;
	position: absolute;
	top: 0;
	left: 0;
}
</style>
<div class="transition-bar" style="background-color: rgba(255, 255, 255, 0.8); width: @(GetHealth())%;"></div>
<div class="colour-bar" style="background-color: @(Colour); width: @(GetHealth())%;"></div>

@code
{
    public string Colour { get; set; }

    public int GetHealth()
    {
        var clientPawn = Game.LocalPawn;
        if (clientPawn is Player {Camera: not null } player)
        {
            return player.Camera.GetObservedHealth().CeilToInt();
        }
        return 0;
    }

    protected override int BuildHash()
    {
        return GetHealth().GetHashCode();
    }
}