From 5162d2ed1f1192e1a1f6601c728c5e1172ac4a8c Mon Sep 17 00:00:00 2001 From: Skipcast Date: Sat, 15 Jan 2022 19:45:41 +0100 Subject: [PATCH 1/7] Added a status panel that shows total players on server and in group (currently only shows placeholder data) --- .../Game/Entities/GameEntity.cs | 4 ++ .../Game/UI/Widgets/StatusPanel.cs | 61 +++++++++++++++++++ Resources/UI/Status/StatusPanel.xmmp | 15 +++++ 3 files changed, 80 insertions(+) create mode 100644 JKMP.Plugin.Multiplayer/Game/UI/Widgets/StatusPanel.cs create mode 100644 Resources/UI/Status/StatusPanel.xmmp diff --git a/JKMP.Plugin.Multiplayer/Game/Entities/GameEntity.cs b/JKMP.Plugin.Multiplayer/Game/Entities/GameEntity.cs index 4897a0a..7c566fc 100644 --- a/JKMP.Plugin.Multiplayer/Game/Entities/GameEntity.cs +++ b/JKMP.Plugin.Multiplayer/Game/Entities/GameEntity.cs @@ -28,6 +28,7 @@ public class GameEntity : BaseManagerEntity private LocalPlayerListener plrListener = null!; private Chat chatWidget = null!; + private StatusPanel statusPanel = null!; private float timeSincePositionUpdate; private const float PositionUpdateInterval = 30; // Send a position update every 30 seconds @@ -43,6 +44,7 @@ protected override void OnFirstUpdate() chatWidget = UIManager.AddWidget(new Chat()); localPlayer = EntityManager.instance.Find(); localPlayer.AddComponents(new PlayerStateTransmitter(P2P), new AudioListenerComponent()); + statusPanel = UIManager.AddWidget(new StatusPanel()); MatchmakingManager.Instance.Events.NearbyClientsReceived += OnNearbyClientsReceived; } @@ -55,6 +57,7 @@ protected override void OnDestroy() plrListener.Dispose(); P2P.Dispose(); UIManager.RemoveWidget(chatWidget); + UIManager.RemoveWidget(statusPanel); } private void OnNearbyClientsReceived(ICollection steamIds) @@ -78,6 +81,7 @@ protected override void Update(float delta) P2P.Update(delta); Sound.Update(delta); chatWidget.Update(delta); + statusPanel.Update(delta); } } } \ No newline at end of file diff --git a/JKMP.Plugin.Multiplayer/Game/UI/Widgets/StatusPanel.cs b/JKMP.Plugin.Multiplayer/Game/UI/Widgets/StatusPanel.cs new file mode 100644 index 0000000..bdb65df --- /dev/null +++ b/JKMP.Plugin.Multiplayer/Game/UI/Widgets/StatusPanel.cs @@ -0,0 +1,61 @@ +using JKMP.Plugin.Multiplayer.Matchmaking; +using JKMP.Plugin.Multiplayer.Networking; +using JumpKing.PauseMenu; +using Myra.Graphics2D.UI; + +namespace JKMP.Plugin.Multiplayer.Game.UI.Widgets +{ + public class StatusPanel : ResourceWidget + { + public string TotalPlayers + { + get => totalPlayers.Text; + set => totalPlayers.Text = value; + } + + public string GroupPlayers + { + get => groupPlayers.Text; + set => groupPlayers.Text = value; + } + + public bool Connected + { + get => connected; + set + { + if (value == connected) + return; + + connected = value; + + connectedContainer.Visible = connected; + disconnectedContainer.Visible = !connected; + } + } + + private readonly Label totalPlayers; + private readonly Label groupPlayers; + private readonly Widget connectedContainer; + private readonly Widget disconnectedContainer; + private bool connected; + + public StatusPanel() : base("UI/Status/StatusPanel.xmmp") + { + totalPlayers = EnsureWidgetById