From 19ca611f5ff125d2e5f65145c721dfb64a74e76a Mon Sep 17 00:00:00 2001 From: Leo Date: Fri, 19 Feb 2021 15:26:34 -0300 Subject: [PATCH] Improves kick, teleport and ban menus (#3312) --- .../CustomControls/PlayerListControl.xaml | 13 ++++ .../CustomControls/PlayerListControl.xaml.cs | 78 +++++++++++++++++++ .../AdminMenu/Tabs/AdminTab/BanWindow.xaml | 9 ++- .../AdminMenu/Tabs/AdminTab/BanWindow.xaml.cs | 23 ++---- .../AdminMenu/Tabs/AdminTab/KickWindow.xaml | 10 +-- .../Tabs/AdminTab/KickWindow.xaml.cs | 23 ++---- .../Tabs/AdminTab/TeleportWindow.xaml | 12 ++- .../Tabs/AdminTab/TeleportWindow.xaml.cs | 25 ++---- 8 files changed, 126 insertions(+), 67 deletions(-) create mode 100644 Content.Client/UserInterface/AdminMenu/CustomControls/PlayerListControl.xaml create mode 100644 Content.Client/UserInterface/AdminMenu/CustomControls/PlayerListControl.xaml.cs diff --git a/Content.Client/UserInterface/AdminMenu/CustomControls/PlayerListControl.xaml b/Content.Client/UserInterface/AdminMenu/CustomControls/PlayerListControl.xaml new file mode 100644 index 0000000000..33d5d6d535 --- /dev/null +++ b/Content.Client/UserInterface/AdminMenu/CustomControls/PlayerListControl.xaml @@ -0,0 +1,13 @@ + + + + + + + + + + diff --git a/Content.Client/UserInterface/AdminMenu/CustomControls/PlayerListControl.xaml.cs b/Content.Client/UserInterface/AdminMenu/CustomControls/PlayerListControl.xaml.cs new file mode 100644 index 0000000000..063a380a89 --- /dev/null +++ b/Content.Client/UserInterface/AdminMenu/CustomControls/PlayerListControl.xaml.cs @@ -0,0 +1,78 @@ +#nullable enable +using System; +using System.Collections.Generic; +using System.Linq; +using Robust.Client.AutoGenerated; +using Robust.Client.Player; +using Robust.Client.UserInterface.Controls; +using Robust.Shared.IoC; + +namespace Content.Client.UserInterface.AdminMenu.CustomControls +{ + [GenerateTypedNameReferences] + public partial class PlayerListControl : VBoxContainer + { + private List? _data; + + public event Action? OnSelectionChanged; + + protected override void EnteredTree() + { + // Fill the Option data + _data = IoCManager.Resolve().Sessions.ToList(); + PopulateList(); + PlayerItemList.OnItemSelected += PlayerItemListOnOnItemSelected; + PlayerItemList.OnItemDeselected += PlayerItemListOnOnItemDeselected; + FilterLineEdit.OnTextChanged += FilterLineEditOnOnTextEntered; + } + + private void FilterLineEditOnOnTextEntered(LineEdit.LineEditEventArgs obj) + { + PopulateList(FilterLineEdit.Text); + } + + private static string GetDisplayName(IPlayerSession session) + { + return $"{session.Name} ({session.AttachedEntity?.Name})"; + } + + private void PlayerItemListOnOnItemSelected(ItemList.ItemListSelectedEventArgs obj) + { + var selectedPlayer = (IPlayerSession) obj.ItemList[obj.ItemIndex].Metadata!; + OnSelectionChanged?.Invoke(selectedPlayer); + } + + private void PlayerItemListOnOnItemDeselected(ItemList.ItemListDeselectedEventArgs obj) + { + OnSelectionChanged?.Invoke(null); + } + + private void PopulateList(string? filter = null) + { + // _data should never be null here + if (_data == null) + return; + PlayerItemList.Clear(); + foreach (var session in _data) + { + var displayName = GetDisplayName(session); + if (!string.IsNullOrEmpty(filter) && + !displayName.ToLowerInvariant().Contains(filter.Trim().ToLowerInvariant())) + { + continue; + } + + PlayerItemList.Add(new ItemList.Item(PlayerItemList) + { + Metadata = session, + Text = displayName + }); + } + } + + public void ClearSelection() + { + PlayerItemList.ClearSelected(); + } + } +} diff --git a/Content.Client/UserInterface/AdminMenu/Tabs/AdminTab/BanWindow.xaml b/Content.Client/UserInterface/AdminMenu/Tabs/AdminTab/BanWindow.xaml index 913fca61fc..4d2d583b79 100644 --- a/Content.Client/UserInterface/AdminMenu/Tabs/AdminTab/BanWindow.xaml +++ b/Content.Client/UserInterface/AdminMenu/Tabs/AdminTab/BanWindow.xaml @@ -1,10 +1,12 @@  + xmlns="https://spacestation14.io" + xmlns:cc="clr-namespace:Content.Client.UserInterface.AdminMenu.CustomControls" + Title="{Loc Ban}" CustomMinimumSize="425 162">