From 0bd24d170705e9631b42019b4def7742ce367157 Mon Sep 17 00:00:00 2001
From: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com>
Date: Sat, 25 Dec 2021 20:10:55 -0800
Subject: [PATCH] XAML PlayerTab (#5897)
* XAML PlayerTab entries
* Move command execution to PlayerTab
* Move command logic to the AdminSystem
* Clean up
* Add IClientConsoleHost dependency
---
.../Administration/AdminSystem.Menu.cs | 13 ++
.../Administration/UI/AdminMenuWindow.xaml | 5 +-
.../Administration/UI/Tabs/PlayerTab.xaml.cs | 143 ------------------
.../UI/Tabs/{ => PlayerTab}/PlayerTab.xaml | 0
.../UI/Tabs/PlayerTab/PlayerTab.xaml.cs | 73 +++++++++
.../UI/Tabs/PlayerTab/PlayerTabEntry.xaml | 22 +++
.../UI/Tabs/PlayerTab/PlayerTabEntry.xaml.cs | 23 +++
7 files changed, 134 insertions(+), 145 deletions(-)
delete mode 100644 Content.Client/Administration/UI/Tabs/PlayerTab.xaml.cs
rename Content.Client/Administration/UI/Tabs/{ => PlayerTab}/PlayerTab.xaml (100%)
create mode 100644 Content.Client/Administration/UI/Tabs/PlayerTab/PlayerTab.xaml.cs
create mode 100644 Content.Client/Administration/UI/Tabs/PlayerTab/PlayerTabEntry.xaml
create mode 100644 Content.Client/Administration/UI/Tabs/PlayerTab/PlayerTabEntry.xaml.cs
diff --git a/Content.Client/Administration/AdminSystem.Menu.cs b/Content.Client/Administration/AdminSystem.Menu.cs
index 9fb4d3082f..947bb3f62e 100644
--- a/Content.Client/Administration/AdminSystem.Menu.cs
+++ b/Content.Client/Administration/AdminSystem.Menu.cs
@@ -1,12 +1,14 @@
using System.Collections.Generic;
using Content.Client.Administration.Managers;
using Content.Client.Administration.UI;
+using Content.Client.Administration.UI.Tabs.PlayerTab;
using Content.Client.HUD;
using Content.Shared.Input;
using Robust.Client.Console;
using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Client.ResourceManagement;
+using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.GameObjects;
using Robust.Shared.Input.Binding;
@@ -26,6 +28,7 @@ namespace Content.Client.Administration
[Dependency] private readonly IResourceCache _resourceCache = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IEntityLookup _entityLookup = default!;
+ [Dependency] private readonly IClientConsoleHost _clientConsoleHost = default!;
private AdminMenuWindow? _window;
private readonly List _commandWindows = new();
@@ -88,6 +91,7 @@ namespace Content.Client.Administration
public void Open()
{
_window ??= new AdminMenuWindow();
+ _window.PlayerTabControl.OnEntryPressed += PlayerTabEntryPressed;
_window.OpenCentered();
}
@@ -129,5 +133,14 @@ namespace Content.Client.Administration
TryOpen();
}
}
+
+ private void PlayerTabEntryPressed(BaseButton.ButtonEventArgs args)
+ {
+ if (args.Button is not PlayerTabEntry button
+ || button.PlayerUid == null)
+ return;
+
+ _clientConsoleHost.ExecuteCommand($"vv {button.PlayerUid}");
+ }
}
}
diff --git a/Content.Client/Administration/UI/AdminMenuWindow.xaml b/Content.Client/Administration/UI/AdminMenuWindow.xaml
index 7153dfb5a7..4c5077cb95 100644
--- a/Content.Client/Administration/UI/AdminMenuWindow.xaml
+++ b/Content.Client/Administration/UI/AdminMenuWindow.xaml
@@ -3,13 +3,14 @@
xmlns:adminTab="clr-namespace:Content.Client.Administration.UI.Tabs.AdminTab"
xmlns:adminbusTab="clr-namespace:Content.Client.Administration.UI.Tabs.AdminbusTab"
xmlns:atmosTab="clr-namespace:Content.Client.Administration.UI.Tabs.AtmosTab"
- xmlns:tabs="clr-namespace:Content.Client.Administration.UI.Tabs">
+ xmlns:tabs="clr-namespace:Content.Client.Administration.UI.Tabs"
+ xmlns:playerTab="clr-namespace:Content.Client.Administration.UI.Tabs.PlayerTab">
-
+
diff --git a/Content.Client/Administration/UI/Tabs/PlayerTab.xaml.cs b/Content.Client/Administration/UI/Tabs/PlayerTab.xaml.cs
deleted file mode 100644
index c8ed5d084f..0000000000
--- a/Content.Client/Administration/UI/Tabs/PlayerTab.xaml.cs
+++ /dev/null
@@ -1,143 +0,0 @@
-using System.Collections.Generic;
-using Content.Client.Administration.UI.CustomControls;
-using Content.Shared.Administration;
-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;
-
-namespace Content.Client.Administration.UI.Tabs
-{
- [GenerateTypedNameReferences]
- public partial class PlayerTab : Control
- {
- private readonly AdminSystem _adminSystem;
-
- public PlayerTab()
- {
- _adminSystem = EntitySystem.Get();
- RobustXamlLoader.Load(this);
- RefreshPlayerList(_adminSystem.PlayerList);
- _adminSystem.PlayerListChanged += RefreshPlayerList;
- OverlayButtonOn.OnPressed += _adminSystem.AdminOverlayOn;
- OverlayButtonOff.OnPressed += _adminSystem.AdminOverlayOff;
- }
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
-
- _adminSystem.PlayerListChanged -= RefreshPlayerList;
- OverlayButtonOn.OnPressed -= _adminSystem.AdminOverlayOn;
- OverlayButtonOff.OnPressed -= _adminSystem.AdminOverlayOff;
- }
-
- private void RefreshPlayerList(IReadOnlyList players)
- {
- PlayerList.RemoveAllChildren();
- var playerManager = IoCManager.Resolve();
- PlayerCount.Text = $"Players: {playerManager.PlayerCount}";
-
- var altColor = Color.FromHex("#292B38");
- var defaultColor = Color.FromHex("#2F2F3B");
-
- var header = new BoxContainer
- {
- Orientation = LayoutOrientation.Horizontal,
- HorizontalExpand = true,
- SeparationOverride = 4,
- Children =
- {
- new Label
- {
- Text = "Username",
- SizeFlagsStretchRatio = 2f,
- HorizontalExpand = true
- },
- new VSeparator(),
- new Label
- {
- Text = "Character",
- SizeFlagsStretchRatio = 2f,
- HorizontalExpand = true
- },
- new VSeparator(),
- new Label()
- {
- Text = "Antagonist",
- SizeFlagsStretchRatio = 2f,
- HorizontalExpand = true,
- }
- }
- };
- PlayerList.AddChild(new PanelContainer
- {
- PanelOverride = new StyleBoxFlat
- {
- BackgroundColor = altColor,
- },
- Children =
- {
- header
- }
- });
- PlayerList.AddChild(new HSeparator());
-
- var useAltColor = false;
- foreach (var player in players)
- {
- var hBox = new BoxContainer
- {
- Orientation = LayoutOrientation.Horizontal,
- HorizontalExpand = true,
- SeparationOverride = 4,
- Children =
- {
- new Label
- {
- Text = player.Username,
- SizeFlagsStretchRatio = 2f,
- HorizontalExpand = true,
- ClipText = true
- },
- new VSeparator(),
- new CommandButton()
- {
- Command = $"vv {player.EntityUid}",
- Text = player.CharacterName,
- SizeFlagsStretchRatio = 2f,
- HorizontalExpand = true,
- ClipText = true
- },
- new VSeparator(),
- new Label()
- {
- Text = player.Antag ? "YES" : "NO",
- SizeFlagsStretchRatio = 2f,
- HorizontalExpand = true,
- ClipText = true,
- }
- }
- };
- PlayerList.AddChild(new PanelContainer
- {
- PanelOverride = new StyleBoxFlat
- {
- BackgroundColor = useAltColor ? altColor : defaultColor,
- },
- Children =
- {
- hBox
- }
- });
- useAltColor ^= true;
- }
- }
- }
-}
diff --git a/Content.Client/Administration/UI/Tabs/PlayerTab.xaml b/Content.Client/Administration/UI/Tabs/PlayerTab/PlayerTab.xaml
similarity index 100%
rename from Content.Client/Administration/UI/Tabs/PlayerTab.xaml
rename to Content.Client/Administration/UI/Tabs/PlayerTab/PlayerTab.xaml
diff --git a/Content.Client/Administration/UI/Tabs/PlayerTab/PlayerTab.xaml.cs b/Content.Client/Administration/UI/Tabs/PlayerTab/PlayerTab.xaml.cs
new file mode 100644
index 0000000000..3c77c5b5fe
--- /dev/null
+++ b/Content.Client/Administration/UI/Tabs/PlayerTab/PlayerTab.xaml.cs
@@ -0,0 +1,73 @@
+using System;
+using System.Collections.Generic;
+using Content.Client.Administration.UI.CustomControls;
+using Content.Shared.Administration;
+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;
+
+namespace Content.Client.Administration.UI.Tabs.PlayerTab
+{
+ [GenerateTypedNameReferences]
+ public partial class PlayerTab : Control
+ {
+ private readonly AdminSystem _adminSystem;
+
+ public event Action? OnEntryPressed;
+
+ public PlayerTab()
+ {
+ _adminSystem = EntitySystem.Get();
+ RobustXamlLoader.Load(this);
+ RefreshPlayerList(_adminSystem.PlayerList);
+ _adminSystem.PlayerListChanged += RefreshPlayerList;
+ OverlayButtonOn.OnPressed += _adminSystem.AdminOverlayOn;
+ OverlayButtonOff.OnPressed += _adminSystem.AdminOverlayOff;
+ }
+
+ protected override void Dispose(bool disposing)
+ {
+ base.Dispose(disposing);
+
+ _adminSystem.PlayerListChanged -= RefreshPlayerList;
+ OverlayButtonOn.OnPressed -= _adminSystem.AdminOverlayOn;
+ OverlayButtonOff.OnPressed -= _adminSystem.AdminOverlayOff;
+ }
+
+ private void RefreshPlayerList(IReadOnlyList players)
+ {
+ PlayerList.RemoveAllChildren();
+ var playerManager = IoCManager.Resolve();
+ PlayerCount.Text = $"Players: {playerManager.PlayerCount}";
+
+ var altColor = Color.FromHex("#292B38");
+ var defaultColor = Color.FromHex("#2F2F3B");
+
+ PlayerList.AddChild(new PlayerTabEntry("Username",
+ "Character",
+ "Antagonist",
+ new StyleBoxFlat(altColor)));
+ PlayerList.AddChild(new HSeparator());
+
+ var useAltColor = false;
+ foreach (var player in players)
+ {
+ var entry = new PlayerTabEntry(player.Username,
+ player.CharacterName,
+ player.Antag ? "YES" : "NO",
+ new StyleBoxFlat(useAltColor ? altColor : defaultColor));
+ entry.PlayerUid = player.EntityUid;
+ entry.OnPressed += args => OnEntryPressed?.Invoke(args);
+ PlayerList.AddChild(entry);
+
+ useAltColor ^= true;
+ }
+ }
+ }
+}
diff --git a/Content.Client/Administration/UI/Tabs/PlayerTab/PlayerTabEntry.xaml b/Content.Client/Administration/UI/Tabs/PlayerTab/PlayerTabEntry.xaml
new file mode 100644
index 0000000000..6a0702be62
--- /dev/null
+++ b/Content.Client/Administration/UI/Tabs/PlayerTab/PlayerTabEntry.xaml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/Content.Client/Administration/UI/Tabs/PlayerTab/PlayerTabEntry.xaml.cs b/Content.Client/Administration/UI/Tabs/PlayerTab/PlayerTabEntry.xaml.cs
new file mode 100644
index 0000000000..c333bc9609
--- /dev/null
+++ b/Content.Client/Administration/UI/Tabs/PlayerTab/PlayerTabEntry.xaml.cs
@@ -0,0 +1,23 @@
+using Robust.Client.AutoGenerated;
+using Robust.Client.Graphics;
+using Robust.Client.UserInterface.Controls;
+using Robust.Client.UserInterface.XAML;
+using Robust.Shared.GameObjects;
+
+namespace Content.Client.Administration.UI.Tabs.PlayerTab;
+
+[GenerateTypedNameReferences]
+public partial class PlayerTabEntry : ContainerButton
+{
+ public EntityUid? PlayerUid;
+
+ public PlayerTabEntry(string username, string character, string antagonist, StyleBox styleBox)
+ {
+ RobustXamlLoader.Load(this);
+
+ UsernameLabel.Text = username;
+ CharacterLabel.Text = character;
+ AntagonistLabel.Text = antagonist;
+ BackgroundColorPanel.PanelOverride = styleBox;
+ }
+}