diff --git a/Content.Client/Administration/AdminNameOverlay.cs b/Content.Client/Administration/AdminNameOverlay.cs index 4b605c4ad0..7b84e17d5d 100644 --- a/Content.Client/Administration/AdminNameOverlay.cs +++ b/Content.Client/Administration/AdminNameOverlay.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; -using Content.Client.Administration.Managers; -using Content.Shared.Administration.Menu; +using Content.Shared.Administration.Events; using Robust.Client.Graphics; using Robust.Client.ResourceManagement; using Robust.Shared.Enums; @@ -11,16 +10,15 @@ namespace Content.Client.Administration { internal class AdminNameOverlay : Overlay { - private readonly AdminMenuManager _manager; + private readonly AdminSystem _system; private readonly IEntityManager _entityManager; private readonly IEyeManager _eyeManager; private readonly IEntityLookup _entityLookup; - private IReadOnlyList? _playerInfos; private readonly Font _font; - public AdminNameOverlay(AdminMenuManager manager, IEntityManager entityManager, IEyeManager eyeManager, IResourceCache resourceCache, IEntityLookup entityLookup) + public AdminNameOverlay(AdminSystem system, IEntityManager entityManager, IEyeManager eyeManager, IResourceCache resourceCache, IEntityLookup entityLookup) { - _manager = manager; + _system = system; _entityManager = entityManager; _eyeManager = eyeManager; _entityLookup = entityLookup; @@ -30,21 +28,11 @@ namespace Content.Client.Administration public override OverlaySpace Space => OverlaySpace.ScreenSpace; - public void UpdatePlayerInfo(List playerInfos) - { - _playerInfos = playerInfos; - } - protected override void Draw(in OverlayDrawArgs args) { - if (_playerInfos == null) - { - return; - } - var viewport = _eyeManager.GetWorldViewport(); - foreach (var playerInfo in _playerInfos) + foreach (var playerInfo in _system.PlayerList) { // Otherwise the entity can not exist yet if (!_entityManager.TryGetEntity(playerInfo.EntityUid, out var entity)) diff --git a/Content.Client/Administration/Managers/AdminMenuManager.cs b/Content.Client/Administration/AdminSystem.Menu.cs similarity index 66% rename from Content.Client/Administration/Managers/AdminMenuManager.cs rename to Content.Client/Administration/AdminSystem.Menu.cs index dd1a7f5789..a2cc51b9a3 100644 --- a/Content.Client/Administration/Managers/AdminMenuManager.cs +++ b/Content.Client/Administration/AdminSystem.Menu.cs @@ -1,7 +1,7 @@ -using System.Collections.Generic; +using System.Collections.Generic; +using Content.Client.Administration.Managers; using Content.Client.Administration.UI; using Content.Client.HUD; -using Content.Shared.Administration.Menu; using Content.Shared.Input; using Robust.Client.Console; using Robust.Client.Graphics; @@ -13,9 +13,9 @@ using Robust.Shared.Input.Binding; using Robust.Shared.IoC; using Robust.Shared.Network; -namespace Content.Client.Administration.Managers +namespace Content.Client.Administration { - internal class AdminMenuManager : IAdminMenuManager + public partial class AdminSystem { [Dependency] private readonly INetManager _netManager = default!; [Dependency] private readonly IInputManager _inputManager = default!; @@ -29,16 +29,10 @@ namespace Content.Client.Administration.Managers [Dependency] private readonly IEntityLookup _entityLookup = default!; private AdminMenuWindow? _window; - private List _commandWindows = new(); - private AdminNameOverlay _adminNameOverlay = default!; + private readonly List _commandWindows = new(); - public void Initialize() + private void InitializeMenu() { - _netManager.RegisterNetMessage(); - _netManager.RegisterNetMessage(HandlePlayerListMessage); - - _commandWindows = new List(); - _adminNameOverlay = new AdminNameOverlay(this, _entityManager, _eyeManager, _resourceCache, _entityLookup); // Reset the AdminMenu Window on disconnect _netManager.Disconnect += (_, _) => ResetWindow(); @@ -70,37 +64,19 @@ namespace Content.Client.Administration.Managers _gameHud.AdminButtonDown = false; } - private void RequestPlayerList() - { - var message = _netManager.CreateNetMessage(); - - _netManager.ClientSendMessage(message); - } - - private void HandlePlayerListMessage(AdminMenuPlayerListMessage msg) - { - _window?.RefreshPlayerList(msg.PlayersInfo); - _adminNameOverlay.UpdatePlayerInfo(msg.PlayersInfo); - } - - private void AdminNameOverlayOn() - { - if (!_overlayManager.HasOverlay()) - _overlayManager.AddOverlay(_adminNameOverlay); - } - - private void AdminNameOverlayOff() - { - _overlayManager.RemoveOverlay(); - } public void ResetWindow() { _window?.Close(); + _window?.Dispose(); _window = null; foreach (var window in _commandWindows) - window?.Dispose(); + { + window.Close(); + window.Dispose(); + } + _commandWindows.Clear(); } @@ -113,9 +89,6 @@ namespace Content.Client.Administration.Managers public void Open() { _window ??= new AdminMenuWindow(); - _window.OnPlayerListRefresh += RequestPlayerList; - _window.OnAdminNameOverlayOn += AdminNameOverlayOn; - _window.OnAdminNameOverlayOff += AdminNameOverlayOff; _window.OpenCentered(); } @@ -158,14 +131,4 @@ namespace Content.Client.Administration.Managers } } } - - internal interface IAdminMenuManager - { - void Initialize(); - void Open(); - void OpenCommand(SS14Window window); - bool CanOpen(); - void TryOpen(); - void Toggle(); - } } diff --git a/Content.Client/Administration/AdminSystem.Overlay.cs b/Content.Client/Administration/AdminSystem.Overlay.cs new file mode 100644 index 0000000000..b2d442db45 --- /dev/null +++ b/Content.Client/Administration/AdminSystem.Overlay.cs @@ -0,0 +1,25 @@ +using Robust.Client.UserInterface.Controls; + +namespace Content.Client.Administration +{ + public partial class AdminSystem + { + private AdminNameOverlay _adminNameOverlay = default!; + + private void InitializeOverlay() + { + _adminNameOverlay = new AdminNameOverlay(this, _entityManager, _eyeManager, _resourceCache, _entityLookup); + } + + public void AdminOverlayOn(BaseButton.ButtonEventArgs? _ = null) + { + if (!_overlayManager.HasOverlay()) + _overlayManager.AddOverlay(_adminNameOverlay); + } + + public void AdminOverlayOff(BaseButton.ButtonEventArgs? _ = null) + { + _overlayManager.RemoveOverlay(); + } + } +} diff --git a/Content.Client/Administration/AdminSystem.cs b/Content.Client/Administration/AdminSystem.cs new file mode 100644 index 0000000000..6e72234a92 --- /dev/null +++ b/Content.Client/Administration/AdminSystem.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Content.Shared.Administration; +using Content.Shared.Administration.Events; +using Robust.Client.Player; +using Robust.Shared.GameObjects; +using Robust.Shared.IoC; +using Robust.Shared.Log; +using Robust.Shared.Network; +using Robust.Shared.Players; + +namespace Content.Client.Administration +{ + public partial class AdminSystem : EntitySystem + { + [Dependency] private readonly IPlayerManager _playerManager = default!; + + public event Action>? PlayerListChanged; + + private Dictionary? _playerList; + public IReadOnlyList PlayerList + { + get + { + if (_playerList != null) return _playerList.Values.ToList(); + + return new List(); + } + } + + public override void Initialize() + { + base.Initialize(); + + InitializeOverlay(); + InitializeMenu(); + SubscribeNetworkEvent(OnPlayerListChanged); + SubscribeNetworkEvent(OnPlayerInfoChanged); + SubscribeNetworkEvent(OnPlayerInfoRemoval); + } + + private void OnPlayerInfoRemoval(PlayerInfoRemovalMessage ev) + { + if (_playerList == null) _playerList = new(); + + _playerList.Remove(ev.NetUserId); + 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); + } + } +} diff --git a/Content.Client/Administration/UI/AdminMenuWindow.xaml.cs b/Content.Client/Administration/UI/AdminMenuWindow.xaml.cs index 908a4a3cd1..c84794b47e 100644 --- a/Content.Client/Administration/UI/AdminMenuWindow.xaml.cs +++ b/Content.Client/Administration/UI/AdminMenuWindow.xaml.cs @@ -1,7 +1,5 @@ -using System.Collections.Generic; using Content.Client.Administration.UI.Tabs; using Content.Client.HUD; -using Content.Shared.Administration.Menu; using Robust.Client.AutoGenerated; using Robust.Client.UserInterface.CustomControls; using Robust.Client.UserInterface.XAML; @@ -15,24 +13,6 @@ namespace Content.Client.Administration.UI { [Dependency] private readonly IGameHud? _gameHud = default!; - public event PlayerTab.PlayerListRefresh? OnPlayerListRefresh - { - add => PlayerTabControl.OnPlayerListRefresh += value; - remove => PlayerTabControl.OnPlayerListRefresh -= value; - } - - public event PlayerTab.AdminNameOverlayToggle? OnAdminNameOverlayOn - { - add => PlayerTabControl.OnAdminNameOverlayOn += value; - remove => PlayerTabControl.OnAdminNameOverlayOn -= value; - } - - public event PlayerTab.AdminNameOverlayToggle? OnAdminNameOverlayOff - { - add => PlayerTabControl.OnAdminNameOverlayOff += value; - remove => PlayerTabControl.OnAdminNameOverlayOff -= value; - } - public AdminMenuWindow() { MinSize = SetSize = (500, 250); @@ -60,10 +40,5 @@ namespace Content.Client.Administration.UI if (_gameHud != null) _gameHud.AdminButtonDown = false; } - - public void RefreshPlayerList(IEnumerable players) - { - PlayerTabControl.RefreshPlayerList(players); - } } } diff --git a/Content.Client/Administration/UI/CustomControls/PlayerListControl.xaml.cs b/Content.Client/Administration/UI/CustomControls/PlayerListControl.xaml.cs index 9877433289..282bd29b59 100644 --- a/Content.Client/Administration/UI/CustomControls/PlayerListControl.xaml.cs +++ b/Content.Client/Administration/UI/CustomControls/PlayerListControl.xaml.cs @@ -1,9 +1,13 @@ using System; using System.Collections.Generic; using System.Linq; +using Content.Shared.Administration; +using Content.Shared.Administration.Events; using Robust.Client.AutoGenerated; using Robust.Client.Player; using Robust.Client.UserInterface.Controls; +using Robust.Client.UserInterface.XAML; +using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Players; @@ -12,28 +16,31 @@ namespace Content.Client.Administration.UI.CustomControls [GenerateTypedNameReferences] public partial class PlayerListControl : BoxContainer { - private List? _data; + [Dependency] private readonly IPlayerManager _playerManager = default!; + private readonly AdminSystem _adminSystem; public event Action? OnSelectionChanged; + public PlayerListControl() + { + _adminSystem = EntitySystem.Get(); + IoCManager.InjectDependencies(this); + RobustXamlLoader.Load(this); + } + protected override void EnteredTree() { // Fill the Option data - _data = IoCManager.Resolve().Sessions.OfType().ToList(); PopulateList(); PlayerItemList.OnItemSelected += PlayerItemListOnOnItemSelected; PlayerItemList.OnItemDeselected += PlayerItemListOnOnItemDeselected; FilterLineEdit.OnTextChanged += FilterLineEditOnOnTextEntered; + _adminSystem.PlayerListChanged += PopulateList; } private void FilterLineEditOnOnTextEntered(LineEdit.LineEditEventArgs obj) { - PopulateList(FilterLineEdit.Text); - } - - private static string GetDisplayName(ICommonSession session) - { - return $"{session.Name} ({session.AttachedEntity?.Name})"; + PopulateList(); } private void PlayerItemListOnOnItemSelected(ItemList.ItemListSelectedEventArgs obj) @@ -47,32 +54,24 @@ namespace Content.Client.Administration.UI.CustomControls OnSelectionChanged?.Invoke(null); } - private void PopulateList(string? filter = null) + private void PopulateList(IReadOnlyList _ = null!) { - // _data should never be null here - if (_data == null) - return; PlayerItemList.Clear(); - foreach (var session in _data) + foreach (var info in _adminSystem.PlayerList) { - var displayName = GetDisplayName(session); - if (!string.IsNullOrEmpty(filter) && - !displayName.ToLowerInvariant().Contains(filter.Trim().ToLowerInvariant())) + var displayName = $"{info.CharacterName} ({info.Username})"; + if (!string.IsNullOrEmpty(FilterLineEdit.Text) && + !displayName.ToLowerInvariant().Contains(FilterLineEdit.Text.Trim().ToLowerInvariant())) { continue; } PlayerItemList.Add(new ItemList.Item(PlayerItemList) { - Metadata = session, + Metadata = _playerManager.SessionsDict[info.SessionId], Text = displayName }); } } - - public void ClearSelection() - { - PlayerItemList.ClearSelected(); - } } } diff --git a/Content.Client/Administration/UI/Tabs/AdminbusTab/AdminbusTab.xaml.cs b/Content.Client/Administration/UI/Tabs/AdminbusTab/AdminbusTab.xaml.cs index 698880b754..5ac9d16ef0 100644 --- a/Content.Client/Administration/UI/Tabs/AdminbusTab/AdminbusTab.xaml.cs +++ b/Content.Client/Administration/UI/Tabs/AdminbusTab/AdminbusTab.xaml.cs @@ -5,6 +5,7 @@ using Robust.Client.ResourceManagement; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.CustomControls; +using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Map; using Robust.Shared.Prototypes; @@ -27,20 +28,18 @@ namespace Content.Client.Administration.UI.Tabs.AdminbusTab private void SpawnEntitiesButtonOnOnPressed(BaseButton.ButtonEventArgs obj) { - var manager = IoCManager.Resolve(); _entitySpawnWindow ??= new EntitySpawnWindow(IoCManager.Resolve(), IoCManager.Resolve(), IoCManager.Resolve()); - manager.OpenCommand(_entitySpawnWindow); + EntitySystem.Get().OpenCommand(_entitySpawnWindow); } private void SpawnTilesButtonOnOnPressed(BaseButton.ButtonEventArgs obj) { - var manager = IoCManager.Resolve(); _tileSpawnWindow ??= new TileSpawnWindow(IoCManager.Resolve(), IoCManager.Resolve(), IoCManager.Resolve()); - manager.OpenCommand(_tileSpawnWindow); + EntitySystem.Get().OpenCommand(_tileSpawnWindow); } } } diff --git a/Content.Client/Administration/UI/Tabs/PlayerTab.xaml b/Content.Client/Administration/UI/Tabs/PlayerTab.xaml index 4e133e5d06..502d7ca515 100644 --- a/Content.Client/Administration/UI/Tabs/PlayerTab.xaml +++ b/Content.Client/Administration/UI/Tabs/PlayerTab.xaml @@ -1,10 +1,8 @@  -