React to Client changes and show them in Lobby.razor.
I tested this on Multiplayer and realized pretty much everything is broken and I haven't been thinking about networking enough. Will start fixing tomorrow.
This commit is contained in:
@@ -1,20 +1,49 @@
|
||||
@namespace LuckerParty.UI
|
||||
@using System
|
||||
@inherits PanelComponent
|
||||
@using System
|
||||
@using System.Collections.Immutable
|
||||
@implements NetworkManager.IClientEvent
|
||||
|
||||
<root>
|
||||
<div class="title">This is the Lobby</div>
|
||||
@foreach ( var client in _clients )
|
||||
{
|
||||
<div>@client.Name</div>
|
||||
}
|
||||
</root>
|
||||
|
||||
@code
|
||||
{
|
||||
public List<Client> Clients { get; set; }
|
||||
private ImmutableList<Client> _clients;
|
||||
private NetworkManager _networkManager;
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
base.OnStart();
|
||||
_networkManager = Scene.GetComponentInChildren<NetworkManager>();
|
||||
UpdateClients();
|
||||
}
|
||||
|
||||
void NetworkManager.IClientEvent.OnConnected( Client client )
|
||||
{
|
||||
UpdateClients();
|
||||
}
|
||||
|
||||
void NetworkManager.IClientEvent.OnDisconnected( Client client )
|
||||
{
|
||||
UpdateClients();
|
||||
}
|
||||
|
||||
private void UpdateClients()
|
||||
{
|
||||
_clients = _networkManager.Clients.Sort( ( clientA, clientB ) => DateTimeOffset.Compare( clientA.ConnectionTime, clientB.ConnectionTime ) );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// the hash determines if the system should be rebuilt. If it changes, it will be rebuilt
|
||||
/// </summary>
|
||||
protected override int BuildHash()
|
||||
{
|
||||
return HashCode.Combine( Clients );
|
||||
return HashCode.Combine( _clients );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user