aboutsummaryrefslogtreecommitdiffstats
path: root/code/ui/health/Health.razor
blob: 3da2c01519574cc1638b1d4f053576505857e615 (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
@using Sandbox;
@using Sandbox.UI;

@namespace MurderGame
@inherits Panel

<style>
Health {
    width: 400px;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.90);
}
.fill {
    height: 100%;
    transition: width 0.2s ease-out;
}
</style>
<div class="fill" style="background-color: @(Colour); width: @(GetHealth())%;"></div>

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

    public int GetHealth()
    {
        var ClientPawn = Game.LocalPawn;
        if (ClientPawn is Player)
        {
            return ClientPawn.Health.CeilToInt();
        }
        return 0;
    }

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