refactors adminmenu a timid amount (#5095)
Co-authored-by: Paul <ritter.paul1+git@googlemail.com> Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
@@ -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<AdminMenuPlayerListMessage.PlayerInfo> players)
|
||||
{
|
||||
PlayerTabControl.RefreshPlayerList(players);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<ICommonSession>? _data;
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
private readonly AdminSystem _adminSystem;
|
||||
|
||||
public event Action<ICommonSession?>? OnSelectionChanged;
|
||||
|
||||
public PlayerListControl()
|
||||
{
|
||||
_adminSystem = EntitySystem.Get<AdminSystem>();
|
||||
IoCManager.InjectDependencies(this);
|
||||
RobustXamlLoader.Load(this);
|
||||
}
|
||||
|
||||
protected override void EnteredTree()
|
||||
{
|
||||
// Fill the Option data
|
||||
_data = IoCManager.Resolve<IPlayerManager>().Sessions.OfType<ICommonSession>().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<PlayerInfo> _ = 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<IAdminMenuManager>();
|
||||
_entitySpawnWindow ??= new EntitySpawnWindow(IoCManager.Resolve<IPlacementManager>(),
|
||||
IoCManager.Resolve<IPrototypeManager>(),
|
||||
IoCManager.Resolve<IResourceCache>());
|
||||
manager.OpenCommand(_entitySpawnWindow);
|
||||
EntitySystem.Get<AdminSystem>().OpenCommand(_entitySpawnWindow);
|
||||
}
|
||||
|
||||
private void SpawnTilesButtonOnOnPressed(BaseButton.ButtonEventArgs obj)
|
||||
{
|
||||
var manager = IoCManager.Resolve<IAdminMenuManager>();
|
||||
_tileSpawnWindow ??= new TileSpawnWindow(IoCManager.Resolve<ITileDefinitionManager>(),
|
||||
IoCManager.Resolve<IPlacementManager>(),
|
||||
IoCManager.Resolve<IResourceCache>());
|
||||
manager.OpenCommand(_tileSpawnWindow);
|
||||
EntitySystem.Get<AdminSystem>().OpenCommand(_tileSpawnWindow);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
<Control xmlns="https://spacestation14.io">
|
||||
<BoxContainer Orientation="Vertical">
|
||||
<BoxContainer Orientation="Horizontal">
|
||||
<Label Name="PlayerCount" HorizontalExpand="True" SizeFlagsStretchRatio="0.25"
|
||||
<Label Name="PlayerCount" HorizontalExpand="True" SizeFlagsStretchRatio="0.50"
|
||||
Text="{Loc Player Count}" />
|
||||
<Button Name="RefreshButton" HorizontalExpand="True" SizeFlagsStretchRatio="0.25"
|
||||
Text="{Loc Refresh}" />
|
||||
<Button Name="OverlayButtonOn" HorizontalExpand="True" SizeFlagsStretchRatio="0.25"
|
||||
Text="{Loc Overlay On}"/>
|
||||
<Button Name="OverlayButtonOff" HorizontalExpand="True" SizeFlagsStretchRatio="0.25"
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.Administration.Menu;
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Administration.Events;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Maths;
|
||||
using static Robust.Client.UserInterface.Controls.BoxContainer;
|
||||
@@ -16,30 +17,28 @@ namespace Content.Client.Administration.UI.Tabs
|
||||
[GenerateTypedNameReferences]
|
||||
public partial class PlayerTab : Control
|
||||
{
|
||||
public delegate void PlayerListRefresh();
|
||||
|
||||
public delegate void AdminNameOverlayToggle();
|
||||
|
||||
public event PlayerListRefresh? OnPlayerListRefresh;
|
||||
public event AdminNameOverlayToggle? OnAdminNameOverlayOn;
|
||||
public event AdminNameOverlayToggle? OnAdminNameOverlayOff;
|
||||
|
||||
private readonly AdminSystem _adminSystem;
|
||||
|
||||
public PlayerTab()
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
_adminSystem = EntitySystem.Get<AdminSystem>();
|
||||
RobustXamlLoader.Load(this);
|
||||
RefreshButton.OnPressed += (_) => OnPlayerListRefresh?.Invoke();
|
||||
OverlayButtonOn.OnPressed += (_) => OnAdminNameOverlayOn?.Invoke();
|
||||
OverlayButtonOff.OnPressed += (_) => OnAdminNameOverlayOff?.Invoke();
|
||||
RefreshPlayerList(_adminSystem.PlayerList);
|
||||
_adminSystem.PlayerListChanged += RefreshPlayerList;
|
||||
OverlayButtonOn.OnPressed += _adminSystem.AdminOverlayOn;
|
||||
OverlayButtonOff.OnPressed += _adminSystem.AdminOverlayOff;
|
||||
}
|
||||
|
||||
protected override void EnteredTree()
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
OnPlayerListRefresh?.Invoke();
|
||||
base.Dispose(disposing);
|
||||
|
||||
_adminSystem.PlayerListChanged -= RefreshPlayerList;
|
||||
OverlayButtonOn.OnPressed -= _adminSystem.AdminOverlayOn;
|
||||
OverlayButtonOff.OnPressed -= _adminSystem.AdminOverlayOff;
|
||||
}
|
||||
|
||||
public void RefreshPlayerList(IEnumerable<AdminMenuPlayerListMessage.PlayerInfo> players)
|
||||
private void RefreshPlayerList(IReadOnlyList<PlayerInfo> players)
|
||||
{
|
||||
PlayerList.RemoveAllChildren();
|
||||
var playerManager = IoCManager.Resolve<IPlayerManager>();
|
||||
|
||||
Reference in New Issue
Block a user