Re-organize all projects (#4166)
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
#nullable enable
|
||||
using Robust.Client.Console;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Client.Administration.UI.CustomControls
|
||||
{
|
||||
public class CommandButton : Button
|
||||
{
|
||||
public string? Command { get; set; }
|
||||
|
||||
public CommandButton() : base()
|
||||
{
|
||||
OnPressed += Execute;
|
||||
}
|
||||
|
||||
protected virtual bool CanPress()
|
||||
{
|
||||
return string.IsNullOrEmpty(Command) ||
|
||||
IoCManager.Resolve<IClientConGroupController>().CanCommand(Command);
|
||||
}
|
||||
|
||||
protected override void EnteredTree()
|
||||
{
|
||||
if (!CanPress())
|
||||
{
|
||||
Visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void Execute(ButtonEventArgs obj)
|
||||
{
|
||||
// Default is to execute command
|
||||
if (!string.IsNullOrEmpty(Command))
|
||||
IoCManager.Resolve<IClientConsoleHost>().ExecuteCommand(Command);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<VBoxContainer
|
||||
xmlns="https://spacestation14.io">
|
||||
<Control CustomMinimumSize="0 5" />
|
||||
<HBoxContainer>
|
||||
<!-- <Label Text="{Loc Search}" CustomMinimumSize="100 0" /> -->
|
||||
<!-- <Control CustomMinimumSize="50 0" /> -->
|
||||
<LineEdit Name="FilterLineEdit" CustomMinimumSize="100 0" SizeFlagsHorizontal="FillExpand" PlaceHolder="{Loc Filter}"/>
|
||||
</HBoxContainer>
|
||||
<!-- <Control CustomMinimumSize="0 5" /> -->
|
||||
<ItemList
|
||||
Name="PlayerItemList" SelectMode="Single" SizeFlagsVertical="FillExpand" SizeFlagsHorizontal="FillExpand"
|
||||
CustomMinimumSize="100 100" />
|
||||
</VBoxContainer>
|
||||
@@ -0,0 +1,79 @@
|
||||
#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;
|
||||
using Robust.Shared.Players;
|
||||
|
||||
namespace Content.Client.Administration.UI.CustomControls
|
||||
{
|
||||
[GenerateTypedNameReferences]
|
||||
public partial class PlayerListControl : VBoxContainer
|
||||
{
|
||||
private List<ICommonSession>? _data;
|
||||
|
||||
public event Action<ICommonSession?>? OnSelectionChanged;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
private void FilterLineEditOnOnTextEntered(LineEdit.LineEditEventArgs obj)
|
||||
{
|
||||
PopulateList(FilterLineEdit.Text);
|
||||
}
|
||||
|
||||
private static string GetDisplayName(ICommonSession session)
|
||||
{
|
||||
return $"{session.Name} ({session.AttachedEntity?.Name})";
|
||||
}
|
||||
|
||||
private void PlayerItemListOnOnItemSelected(ItemList.ItemListSelectedEventArgs obj)
|
||||
{
|
||||
var selectedPlayer = (ICommonSession) 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Client.Administration.UI.CustomControls
|
||||
{
|
||||
public class UICommandButton : CommandButton
|
||||
{
|
||||
public Type? WindowType { get; set; }
|
||||
private SS14Window? _window;
|
||||
|
||||
protected override void Execute(ButtonEventArgs obj)
|
||||
{
|
||||
if (WindowType == null)
|
||||
return;
|
||||
_window = (SS14Window) IoCManager.Resolve<IDynamicTypeFactory>().CreateInstance(WindowType);
|
||||
_window?.OpenCentered();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user