Files
tbd-station-14/Content.Client/Administration/Systems/AdminSystem.cs
Jezithyr 571dd4e6d5 Hud refactor (#7202)
Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
Co-authored-by: Jezithyr <jmaster9999@gmail.com>
Co-authored-by: Jezithyr <Jezithyr@gmail.com>
Co-authored-by: Visne <39844191+Visne@users.noreply.github.com>
Co-authored-by: wrexbe <wrexbe@protonmail.com>
Co-authored-by: wrexbe <81056464+wrexbe@users.noreply.github.com>
2022-10-12 10:16:23 +02:00

71 lines
2.1 KiB
C#

using System.Linq;
using Content.Shared.Administration;
using Content.Shared.Administration.Events;
using Content.Shared.GameTicking;
using Robust.Shared.Network;
namespace Content.Client.Administration.Systems
{
public sealed partial class AdminSystem : EntitySystem
{
public event Action<List<PlayerInfo>>? PlayerListChanged;
private Dictionary<NetUserId, PlayerInfo>? _playerList;
public IReadOnlyList<PlayerInfo> PlayerList
{
get
{
if (_playerList != null) return _playerList.Values.ToList();
return new List<PlayerInfo>();
}
}
public override void Initialize()
{
base.Initialize();
InitializeOverlay();
SubscribeNetworkEvent<FullPlayerListEvent>(OnPlayerListChanged);
SubscribeNetworkEvent<PlayerInfoChangedEvent>(OnPlayerInfoChanged);
SubscribeNetworkEvent<RoundRestartCleanupEvent>(OnRoundRestartCleanup);
}
public override void Shutdown()
{
base.Shutdown();
ShutdownOverlay();
}
private void OnRoundRestartCleanup(RoundRestartCleanupEvent msg, EntitySessionEventArgs args)
{
if (_playerList == null)
return;
foreach (var (id, playerInfo) in _playerList.ToArray())
{
if (playerInfo.Connected)
continue;
_playerList.Remove(id);
}
PlayerListChanged?.Invoke(_playerList.Values.ToList());
}
private void OnPlayerInfoChanged(PlayerInfoChangedEvent ev)
{
if(ev.PlayerInfo == null) return;
if (_playerList == null) _playerList = new();
_playerList[ev.PlayerInfo.SessionId] = ev.PlayerInfo;
PlayerListChanged?.Invoke(_playerList.Values.ToList());
}
private void OnPlayerListChanged(FullPlayerListEvent msg)
{
_playerList = msg.PlayersInfo.ToDictionary(x => x.SessionId, x => x);
PlayerListChanged?.Invoke(msg.PlayersInfo);
}
}
}