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

@@ -0,0 +1,16 @@
<Control xmlns="https://spacestation14.io">
<BoxContainer Orientation="Vertical">
<BoxContainer Orientation="Horizontal">
<Label Name="PlayerCount" HorizontalExpand="True" SizeFlagsStretchRatio="0.50"
Text="{Loc Player Count}" />
<Button Name="OverlayButtonOn" HorizontalExpand="True" SizeFlagsStretchRatio="0.25"
Text="{Loc Overlay On}"/>
<Button Name="OverlayButtonOff" HorizontalExpand="True" SizeFlagsStretchRatio="0.25"
Text="{Loc Overlay Off}"/>
</BoxContainer>
<Control MinSize="0 5" />
<ScrollContainer HorizontalExpand="True" VerticalExpand="True">
<BoxContainer Orientation="Vertical" Name="PlayerList" />
</ScrollContainer>
</BoxContainer>
</Control>

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