Improves the Admin PlayerList (#1989)

* -Makes PlayerList scrollable
-Player names clip when they are too long
-Shows Player count

* Add padding to make columns more noticeable

* -Added Separators between the columns
-Pushed List a bit down

* Add alternating row colors
This commit is contained in:
Exp
2020-09-02 18:47:13 +02:00
committed by GitHub
parent 9944dc70d0
commit fd21ceb0cf

View File

@@ -1,11 +1,9 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using Content.Client.GameObjects.EntitySystems;
using Content.Client.StationEvents;
using Content.Shared.Atmos;
using Robust.Client.Console;
using Robust.Client.Graphics.Drawing;
using Robust.Client.Interfaces.Placement;
using Robust.Client.Interfaces.ResourceManagement;
using Robust.Client.Player;
@@ -17,8 +15,12 @@ using Robust.Shared.Interfaces.Map;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using static Robust.Client.UserInterface.Controls.BaseButton;
namespace Content.Client.UserInterface.AdminMenu
@@ -27,6 +29,9 @@ namespace Content.Client.UserInterface.AdminMenu
{
public TabContainer MasterTabContainer;
public VBoxContainer PlayerList;
public Label PlayerCount;
protected override Vector2? CustomSize => (500, 250);
private List<CommandButton> _adminButtons = new List<CommandButton>
{
@@ -57,51 +62,107 @@ namespace Content.Client.UserInterface.AdminMenu
new DirectCommandButton("Shutdown", "shutdown"),
};
private static readonly Color SeparatorColor = Color.FromHex("#3D4059");
private class HSeperator : Control
{
public HSeperator()
{
AddChild(new PanelContainer {
PanelOverride = new StyleBoxFlat
{
BackgroundColor = SeparatorColor,
ContentMarginBottomOverride = 2, ContentMarginLeftOverride = 2
}
});
}
}
private class VSeperator : PanelContainer
{
public VSeperator()
{
CustomMinimumSize = (2, 5);
AddChild(new PanelContainer {
PanelOverride = new StyleBoxFlat {
BackgroundColor = SeparatorColor
}
});
}
}
private void RefreshPlayerList(ButtonEventArgs args)
{
PlayerList.RemoveAllChildren();
var sessions = IoCManager.Resolve<IPlayerManager>().Sessions;
var playerManager = IoCManager.Resolve<IPlayerManager>();
var sessions = playerManager.Sessions;
PlayerCount.Text = $"Players: {playerManager.PlayerCount}";
Color altColor = Color.FromHex("#292B38");
Color defaultColor = Color.FromHex("#2F2F3B");
var header = new HBoxContainer
{
SizeFlagsHorizontal = SizeFlags.FillExpand,
SeparationOverride = 4,
Children =
{
new Label { Text = "Name",
SizeFlagsStretchRatio = 2f,
SizeFlagsHorizontal = SizeFlags.FillExpand },
new VSeperator(),
new Label { Text = "Player",
SizeFlagsStretchRatio = 2f,
SizeFlagsHorizontal = SizeFlags.FillExpand },
new VSeperator(),
new Label { Text = "Status",
SizeFlagsStretchRatio = 1f,
SizeFlagsHorizontal = SizeFlags.FillExpand },
new VSeperator(),
new Label { Text = "Ping",
SizeFlagsStretchRatio = 1f,
SizeFlagsHorizontal = SizeFlags.FillExpand,
Align = Label.AlignMode.Right },
}
};
PlayerList.AddChild(header);
PlayerList.AddChild(new Controls.HighDivider());
PlayerList.AddChild(new PanelContainer
{
PanelOverride = new StyleBoxFlat
{
BackgroundColor = altColor,
},
Children =
{
header
}
});
PlayerList.AddChild(new HSeperator());
var useAltColor = false;
foreach (var player in sessions)
{
var hbox = new HBoxContainer
{
SizeFlagsHorizontal = SizeFlags.FillExpand,
SeparationOverride = 4,
Children =
{
new Label {
Text = player.Name,
SizeFlagsStretchRatio = 2f,
SizeFlagsHorizontal = SizeFlags.FillExpand },
SizeFlagsHorizontal = SizeFlags.FillExpand,
ClipText = true },
new VSeperator(),
new Label {
Text = player.AttachedEntity?.Name,
SizeFlagsStretchRatio = 2f,
SizeFlagsHorizontal = SizeFlags.FillExpand },
SizeFlagsHorizontal = SizeFlags.FillExpand,
ClipText = true },
new VSeperator(),
new Label {
Text = player.Status.ToString(),
SizeFlagsStretchRatio = 1f,
SizeFlagsHorizontal = SizeFlags.FillExpand },
new VSeperator(),
new Label {
Text = player.Ping.ToString(),
SizeFlagsStretchRatio = 1f,
@@ -109,7 +170,18 @@ namespace Content.Client.UserInterface.AdminMenu
Align = Label.AlignMode.Right },
}
};
PlayerList.AddChild(hbox);
PlayerList.AddChild(new PanelContainer
{
PanelOverride = new StyleBoxFlat
{
BackgroundColor = useAltColor ? altColor : defaultColor,
},
Children =
{
hbox
}
});
useAltColor ^= true;
}
}
@@ -133,7 +205,6 @@ namespace Content.Client.UserInterface.AdminMenu
public AdminMenuWindow() //TODO: search for buttons?
{
CustomMinimumSize = (415,0);
Title = Loc.GetString("Admin Menu");
#region PlayerList
@@ -146,22 +217,50 @@ namespace Content.Client.UserInterface.AdminMenu
MarginBottomOverride = 4,
CustomMinimumSize = (50, 50),
};
PlayerList = new VBoxContainer();
PlayerCount = new Label
{
SizeFlagsHorizontal = SizeFlags.FillExpand,
SizeFlagsStretchRatio = 0.7f,
};
var refreshButton = new Button
{
Text = "Refresh"
SizeFlagsHorizontal = SizeFlags.FillExpand,
SizeFlagsStretchRatio = 0.3f,
Text = "Refresh",
};
refreshButton.OnPressed += RefreshPlayerList;
RefreshPlayerList(null!);
PlayerList = new VBoxContainer();
var playerVBox = new VBoxContainer
{
SizeFlagsVertical = SizeFlags.FillExpand,
Children =
{
new HBoxContainer
{
SizeFlagsHorizontal = SizeFlags.FillExpand,
Children =
{
PlayerCount,
refreshButton,
}
},
new Control { CustomMinimumSize = (0, 5) },
new ScrollContainer
{
SizeFlagsHorizontal = SizeFlags.FillExpand,
SizeFlagsVertical = SizeFlags.FillExpand,
Children =
{
PlayerList
},
},
}
};
playerTabContainer.AddChild(playerVBox);
RefreshPlayerList(null!);
#endregion PlayerList
#region Admin Tab