-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from Jump-King-Multiplayer/feature/status-panel
Implemented server status panel that shows total players in server and your group
- Loading branch information
Showing
11 changed files
with
161 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<StatusPanel> | ||
{ | ||
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<Label>("TotalPlayers"); | ||
groupPlayers = EnsureWidgetById<Label>("GroupPlayers"); | ||
connectedContainer = EnsureWidgetById<Widget>("ConnectedContainer"); | ||
disconnectedContainer = EnsureWidgetById<Widget>("DisconnectedContainer"); | ||
|
||
connectedContainer.Visible = false; | ||
|
||
AcceptsKeyboardFocus = false; | ||
|
||
MatchmakingManager.Instance.Events.ServerStatusUpdateReceived += OnServerStatusReceived; | ||
} | ||
|
||
private void OnServerStatusReceived(ServerStatus status) | ||
{ | ||
TotalPlayers = status.TotalPlayers.ToString(); | ||
GroupPlayers = status.GroupPlayers.ToString(); | ||
} | ||
|
||
public void Update(float delta) | ||
{ | ||
Visible = PauseManager.instance.IsPaused; | ||
Connected = MatchmakingManager.Instance.IsConnected; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace Matchmaking.Client.EventData | ||
{ | ||
public class ServerStatus | ||
{ | ||
public uint TotalPlayers { get; set; } | ||
public uint GroupPlayers { get; set; } | ||
|
||
public ServerStatus(uint totalPlayers, uint groupPlayers) | ||
{ | ||
TotalPlayers = totalPlayers; | ||
GroupPlayers = groupPlayers; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
Matchmaking.Client/Messages/Handlers/ServerStatusUpdateHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System.Threading.Tasks; | ||
using Matchmaking.Client.EventData; | ||
using Matchmaking.Client.Messages.Processing; | ||
using Serilog; | ||
|
||
namespace Matchmaking.Client.Messages.Handlers | ||
{ | ||
internal class ServerStatusUpdateHandler : IMessageHandler<ServerStatusUpdate, Context> | ||
{ | ||
private static readonly ILogger Logger = Log.ForContext<ServerStatusUpdateHandler>(); | ||
|
||
public Task HandleMessage(ServerStatusUpdate message, Context context) | ||
{ | ||
Logger.Information("Received server status. Total players: {totalPlayers}, group players: {groupPlayers}", message.TotalPlayers, message.GroupPlayers); | ||
context.MatchmakingClient.Events.OnServerStatusUpdateReceived(new ServerStatus(message.TotalPlayers, message.GroupPlayers)); | ||
|
||
return Task.CompletedTask; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
using System.IO; | ||
|
||
namespace Matchmaking.Client.Messages | ||
{ | ||
internal class ServerStatusUpdate : Message | ||
{ | ||
public uint TotalPlayers { get; set; } | ||
public uint GroupPlayers { get; set; } | ||
|
||
public override void Serialize(BinaryWriter writer) | ||
{ | ||
throw new NotSupportedException(); | ||
} | ||
|
||
public override void Deserialize(BinaryReader reader) | ||
{ | ||
TotalPlayers = (uint)reader.ReadVarInt(); | ||
GroupPlayers = (uint)reader.ReadVarInt(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Panel Padding="20" Margin="10, 10, 0, 0" HorizontalAlignment="Left" VerticalAlignment="Top" Background="#00000096"> | ||
<VerticalStackPanel Id="ConnectedContainer"> | ||
<HorizontalStackPanel> | ||
<Label Text="Players online: " Font="Fonts/OpenSans-Bold.ttf:22" /> | ||
<Label Id="TotalPlayers" Text="..." Font="Fonts/OpenSans-Bold.ttf:22" /> | ||
</HorizontalStackPanel> | ||
<HorizontalStackPanel> | ||
<Label Text="Players in your group: " Font="Fonts/OpenSans-Bold.ttf:22" /> | ||
<Label Id="GroupPlayers" Text="..." Font="Fonts/OpenSans-Bold.ttf:22" /> | ||
</HorizontalStackPanel> | ||
</VerticalStackPanel> | ||
<VerticalStackPanel Id="DisconnectedContainer"> | ||
<Label Text="Reconnecting..." Font="Fonts/OpenSans-Bold.ttf:22" /> | ||
</VerticalStackPanel> | ||
</Panel> |