Improves kick, teleport and ban menus (#3312)

This commit is contained in:
Leo
2021-02-19 15:26:34 -03:00
committed by GitHub
parent d1b5a31397
commit 19ca611f5f
8 changed files with 126 additions and 67 deletions

View File

@@ -1,6 +1,4 @@
#nullable enable
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using Robust.Client.AutoGenerated;
using Robust.Client.Console;
@@ -16,33 +14,26 @@ namespace Content.Client.UserInterface.AdminMenu.Tabs.AdminTab
[UsedImplicitly]
public partial class KickWindow : SS14Window
{
private IEnumerable<IPlayerSession>? _data;
private IPlayerSession? _selectedSession;
protected override void EnteredTree()
{
// Fill the Option data
_data = IoCManager.Resolve<IPlayerManager>().Sessions;
foreach (var session in _data)
{
PlayerOptions.AddItem(GetDisplayName(session));
}
PlayerOptions.OnItemSelected += eventArgs => PlayerOptions.SelectId(eventArgs.Id);
SubmitButton.OnPressed += SubmitButtonOnOnPressed;
PlayerList.OnSelectionChanged += OnListOnOnSelectionChanged;
}
private static string GetDisplayName(IPlayerSession session)
private void OnListOnOnSelectionChanged(IPlayerSession? obj)
{
return $"{session.Name} ({session.AttachedEntity?.Name})";
_selectedSession = obj;
SubmitButton.Disabled = _selectedSession == null;
}
private void SubmitButtonOnOnPressed(BaseButton.ButtonEventArgs obj)
{
if (_data == null)
if (_selectedSession == null)
return;
var dataList = _data.ToList();
var session = dataList[PlayerOptions.SelectedId];
IoCManager.Resolve<IClientConsoleHost>().ExecuteCommand(
$"kick \"{session.Name}\" \"{CommandParsing.Escape(ReasonLine.Text)}\"");
$"kick \"{_selectedSession.Name}\" \"{CommandParsing.Escape(ReasonLine.Text)}\"");
}
}
}