aboutsummaryrefslogtreecommitdiffstats
path: root/code/ui/spectator
diff options
context:
space:
mode:
authorLeonardo Bishop <me@leonardobishop.com>2023-07-28 13:37:17 +0100
committerLeonardo Bishop <me@leonardobishop.com>2023-07-28 13:37:17 +0100
commitf137095304f456b06229e4d17ee8249e974fceaf (patch)
tree23d4aa9d3c8b5ddfc432bfa68b5e4e761641f6e0 /code/ui/spectator
parent8b69e65e51507118b014a0426ae6f957b78a0707 (diff)
Add spectator mode
Diffstat (limited to 'code/ui/spectator')
-rw-r--r--code/ui/spectator/Spectator.razor63
1 files changed, 63 insertions, 0 deletions
diff --git a/code/ui/spectator/Spectator.razor b/code/ui/spectator/Spectator.razor
new file mode 100644
index 0000000..f6fe8af
--- /dev/null
+++ b/code/ui/spectator/Spectator.razor
@@ -0,0 +1,63 @@
+@using Sandbox;
+@using Sandbox.UI;
+@using System;
+
+@namespace MurderGame
+@inherits Panel
+
+<style>
+spectator {
+ top: 0;
+ left: 0;
+ width: 100vw;
+ height: 100vh;
+ position: absolute;
+ display: flex;
+ align-items: center;
+ justify-content: flex-end;
+ flex-direction: column;
+}
+.box {
+ backdrop-filter-blur: 8px;
+ background-color: rgba(0, 0, 0, 0.20);
+ padding: 10px;
+ color: white;
+ font-weight: 700;
+ font-size: 35px;
+ font-family: "Roboto";
+ margin: 30px;
+}
+</style>
+
+@if (Spectating) {
+<div class="box">
+ <div>Spectating @TargetName</div>
+</div>
+}
+
+@code
+{
+ public bool Spectating { get; set; }
+ public string TargetName { get; set; }
+
+ protected override int BuildHash()
+ {
+ var localPawn = Game.LocalPawn;
+ if (localPawn is Player player)
+ {
+ var spectator = player.Spectator;
+ if (spectator != null)
+ {
+ var target = spectator.Target;
+ Spectating = true;
+ TargetName = (target != null && target.IsValid() && target.LifeState == LifeState.Alive) ? target.Client.Name : "";
+ return HashCode.Combine(Spectating.GetHashCode(), TargetName.GetHashCode());
+ }
+ }
+ if (Spectating)
+ {
+ Spectating = false;
+ }
+ return Spectating.GetHashCode();
+ }
+}