From 87d74b50bf443bf199be05bd03afdca6ece082ff Mon Sep 17 00:00:00 2001 From: Leonardo Bishop Date: Wed, 2 Aug 2023 17:36:42 +0100 Subject: Add temporary tablist --- code/ui/Hud.razor | 1 + code/ui/overlay/RoleOverlay.Network.cs | 20 +++++ code/ui/overlay/RoleOverlay.cs | 20 ----- code/ui/overlay/TabListEntry.cs | 54 +++++++++++++ code/ui/overlay/TabListOverlay.razor | 142 +++++++++++++++++++++++++++++++++ 5 files changed, 217 insertions(+), 20 deletions(-) create mode 100644 code/ui/overlay/RoleOverlay.Network.cs delete mode 100644 code/ui/overlay/RoleOverlay.cs create mode 100644 code/ui/overlay/TabListEntry.cs create mode 100644 code/ui/overlay/TabListOverlay.razor diff --git a/code/ui/Hud.razor b/code/ui/Hud.razor index d6fe5b6..d5e3a40 100644 --- a/code/ui/Hud.razor +++ b/code/ui/Hud.razor @@ -14,6 +14,7 @@ + diff --git a/code/ui/overlay/RoleOverlay.Network.cs b/code/ui/overlay/RoleOverlay.Network.cs new file mode 100644 index 0000000..300d0bf --- /dev/null +++ b/code/ui/overlay/RoleOverlay.Network.cs @@ -0,0 +1,20 @@ +using Sandbox; + +namespace MurderGame; + +public partial class RoleOverlay +{ + [ClientRpc] + public static void Show( ) + { + Instance.SetClass( "hidden", false ); + Instance.ShowOverlay = true; + } + + [ClientRpc] + public static void Hide() + { + Instance.SetClass( "hidden", true ); + Instance.ShowOverlay = false; + } +} diff --git a/code/ui/overlay/RoleOverlay.cs b/code/ui/overlay/RoleOverlay.cs deleted file mode 100644 index 300d0bf..0000000 --- a/code/ui/overlay/RoleOverlay.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Sandbox; - -namespace MurderGame; - -public partial class RoleOverlay -{ - [ClientRpc] - public static void Show( ) - { - Instance.SetClass( "hidden", false ); - Instance.ShowOverlay = true; - } - - [ClientRpc] - public static void Hide() - { - Instance.SetClass( "hidden", true ); - Instance.ShowOverlay = false; - } -} diff --git a/code/ui/overlay/TabListEntry.cs b/code/ui/overlay/TabListEntry.cs new file mode 100644 index 0000000..b4d7769 --- /dev/null +++ b/code/ui/overlay/TabListEntry.cs @@ -0,0 +1,54 @@ +using Sandbox; +using Sandbox.UI; +using Sandbox.UI.Construct; + +namespace MurderGame; + +public class TabListEntry : Panel +{ + + public IClient Client; + + public Label PlayerName; + public Label Ping; + + RealTimeSince TimeSinceUpdate = 0; + + public TabListEntry() + { + AddClass( "entry" ); + + PlayerName = Add.Label( "PlayerName", "name" ); + Ping = Add.Label( "", "ping" ); + } + + public override void Tick() + { + base.Tick(); + + if ( !IsVisible ) + return; + + if ( !Client.IsValid() ) + return; + + if ( TimeSinceUpdate < 0.1f ) + return; + + TimeSinceUpdate = 0; + UpdateData(); + } + + public virtual void UpdateData() + { + PlayerName.Text = Client.Name; + Ping.Text = Client.Ping.ToString(); + } + + public virtual void UpdateFrom( IClient client ) + { + Client = client; + UpdateData(); + } + +} diff --git a/code/ui/overlay/TabListOverlay.razor b/code/ui/overlay/TabListOverlay.razor new file mode 100644 index 0000000..d240c9e --- /dev/null +++ b/code/ui/overlay/TabListOverlay.razor @@ -0,0 +1,142 @@ + + +@using System.Collections.Generic +@using System.Linq +@using Sandbox; +@using Sandbox.UI; + +@namespace MurderGame +@inherits Panel + + + +
+
+ Murder + This game mode is still a work in progress. Source code available at https://github.com/LMBishop/murder. +
+ +
+
+ Name + Ping +
+ +
+ +
+
+
+ +@code +{ + Dictionary Entries = new(); + + public Panel List { get; set; } + + public static TabListOverlay Instance { get; private set; } + + public TabListOverlay() + { + Instance = this; + } + + public bool IsOpen => Input.Down( "score" ); + + public override void Tick() + { + base.Tick(); + + SetClass( "hidden", !IsOpen ); + + if ( !IsVisible ) + return; + + foreach ( IClient cl in Game.Clients.Except( Entries.Keys ) ) + { + TabListEntry entry = new(); + Entries.Add(cl, entry); + entry.UpdateFrom(cl); + entry.Parent = List; + } + + foreach ( IClient cl in Entries.Keys.Except( Game.Clients ) ) + { + if( Entries.TryGetValue( cl, out var entry ) ) + { + entry.Delete(); + Entries.Remove( cl ); + } + } + + // foreach ( var entry in Entries ) + // { + // entry.Value.Parent = List; + // } + } + +} \ No newline at end of file -- cgit v1.2.3-70-g09d2