diff --git a/JKMP.Plugin.Multiplayer/Game/Components/PlayerStateTransmitter.cs b/JKMP.Plugin.Multiplayer/Game/Components/PlayerStateTransmitter.cs index fb7569c..27689a1 100644 --- a/JKMP.Plugin.Multiplayer/Game/Components/PlayerStateTransmitter.cs +++ b/JKMP.Plugin.Multiplayer/Game/Components/PlayerStateTransmitter.cs @@ -77,12 +77,7 @@ protected override void LateUpdate(float delta) private void SendState() { if (body == null || listener == null) - throw new InvalidOperationException("SendTranmission was called before component was initialized"); - - // Only send message if the connected players mutex isn't locked (prevents potential lag spikes) - // Note that there's still a chance it will be locked after this check and before the broadcast happens, but it should (hopefully) lower lag spikes significantly - if (p2p.ConnectedPlayersMtx.IsLocked) - return; + throw new InvalidOperationException("SendState was called before component was initialized"); var surfaceType = listener.CurrentSurfaceType; bool wearingShoes = SkinManager.IsWearingSkin(Items.Shoes); 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..b762c22 --- /dev/null +++ b/JKMP.Plugin.Multiplayer/Game/UI/Widgets/StatusPanel.cs @@ -0,0 +1,70 @@ +using JKMP.Plugin.Multiplayer.Matchmaking; +using JKMP.Plugin.Multiplayer.Networking; +using JumpKing.PauseMenu; +using Matchmaking.Client.EventData; +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