XAML PlayerTab (#5897)

* XAML PlayerTab entries

* Move command execution to PlayerTab

* Move command logic to the AdminSystem

* Clean up

* Add IClientConsoleHost dependency
This commit is contained in:
ShadowCommander
2021-12-25 20:10:55 -08:00
committed by GitHub
parent b675bdb789
commit 0bd24d1707
7 changed files with 134 additions and 145 deletions

View File

@@ -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<SS14Window> _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}");
}
}
}

View File

@@ -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">
<TabContainer Name="MasterTabContainer">
<adminTab:AdminTab />
<adminbusTab:AdminbusTab />
<atmosTab:AtmosTab />
<tabs:RoundTab />
<tabs:ServerTab />
<tabs:PlayerTab Name="PlayerTabControl" />
<playerTab:PlayerTab Name="PlayerTabControl" Access="Public" />
</TabContainer>
</SS14Window>

View File

@@ -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<AdminSystem>();
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<PlayerInfo> players)
{
PlayerList.RemoveAllChildren();
var playerManager = IoCManager.Resolve<IPlayerManager>();
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;
}
}
}
}

View File

@@ -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<BaseButton.ButtonEventArgs>? OnEntryPressed;
public PlayerTab()
{
_adminSystem = EntitySystem.Get<AdminSystem>();
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<PlayerInfo> players)
{
PlayerList.RemoveAllChildren();
var playerManager = IoCManager.Resolve<IPlayerManager>();
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;
}
}
}
}

View File

@@ -0,0 +1,22 @@
<ContainerButton xmlns="https://spacestation14.io"
xmlns:customControls="clr-namespace:Content.Client.Administration.UI.CustomControls">
<PanelContainer Name="BackgroundColorPanel"/>
<BoxContainer Orientation="Horizontal"
HorizontalExpand="True"
SeparationOverride="4">
<Label Name="UsernameLabel"
SizeFlagsStretchRatio="2"
HorizontalExpand="True"
ClipText="True"/>
<customControls:VSeparator/>
<Label Name="CharacterLabel"
SizeFlagsStretchRatio="2"
HorizontalExpand="True"
ClipText="True"/>
<customControls:VSeparator/>
<Label Name="AntagonistLabel"
SizeFlagsStretchRatio="2"
HorizontalExpand="True"
ClipText="True"/>
</BoxContainer>
</ContainerButton>

View File

@@ -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;
}
}