Files
tbd-station-14/Content.Client/Administration/UI/Tabs/PlayerTab.xaml.cs
DrSmugleaf c3fe5909ad THE RETURN OF THE KING
This reverts commit c18d07538a.
2021-11-22 19:08:27 +01:00

143 lines
4.9 KiB
C#

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