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,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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user