Add online player list to lobby UI.

This commit is contained in:
Pieter-Jan Briers
2019-05-14 12:54:47 +02:00
parent a78a07d0c4
commit cbca48ebbb
3 changed files with 51 additions and 10 deletions

View File

@@ -1,4 +1,5 @@
using System; using System;
using System.Linq;
using Content.Client.Chat; using Content.Client.Chat;
using Content.Client.Interfaces; using Content.Client.Interfaces;
using Content.Client.Interfaces.Chat; using Content.Client.Interfaces.Chat;
@@ -11,6 +12,7 @@ using Robust.Client.Interfaces;
using Robust.Client.Interfaces.Input; using Robust.Client.Interfaces.Input;
using Robust.Client.Interfaces.ResourceManagement; using Robust.Client.Interfaces.ResourceManagement;
using Robust.Client.Interfaces.UserInterface; using Robust.Client.Interfaces.UserInterface;
using Robust.Client.Player;
using Robust.Client.UserInterface; using Robust.Client.UserInterface;
using Robust.Shared.Input; using Robust.Shared.Input;
using Robust.Shared.Interfaces.Network; using Robust.Shared.Interfaces.Network;
@@ -32,6 +34,7 @@ namespace Content.Client.GameTicking
[Dependency] private IClientConsole _console; [Dependency] private IClientConsole _console;
[Dependency] private ILocalizationManager _localization; [Dependency] private ILocalizationManager _localization;
[Dependency] private IResourceCache _resourceCache; [Dependency] private IResourceCache _resourceCache;
[Dependency] private IPlayerManager _playerManager;
#pragma warning restore 649 #pragma warning restore 649
[ViewVariables] private bool _areWeReady; [ViewVariables] private bool _areWeReady;
@@ -51,10 +54,25 @@ namespace Content.Client.GameTicking
_netManager.RegisterNetMessage<MsgTickerLobbyStatus>(nameof(MsgTickerLobbyStatus), _lobbyStatus); _netManager.RegisterNetMessage<MsgTickerLobbyStatus>(nameof(MsgTickerLobbyStatus), _lobbyStatus);
_baseClient.RunLevelChanged += BaseClientOnRunLevelChanged; _baseClient.RunLevelChanged += BaseClientOnRunLevelChanged;
_playerManager.PlayerListUpdated += PlayerManagerOnPlayerListUpdated;
_initialized = true; _initialized = true;
} }
private void PlayerManagerOnPlayerListUpdated(object sender, EventArgs e)
{
if (_lobby == null)
{
return;
}
_lobby.OnlinePlayerItemList.Clear();
foreach (var session in _playerManager.Sessions.OrderBy(s => s.Name))
{
_lobby.OnlinePlayerItemList.AddItem(session.Name);
}
}
private void BaseClientOnRunLevelChanged(object sender, RunLevelChangedEventArgs e) private void BaseClientOnRunLevelChanged(object sender, RunLevelChangedEventArgs e)
{ {
if (e.NewLevel != ClientRunLevel.Initialize) if (e.NewLevel != ClientRunLevel.Initialize)

View File

@@ -14,7 +14,8 @@ namespace Content.Client.UserInterface
public Button ReadyButton { get; } public Button ReadyButton { get; }
public Button ObserveButton { get; } public Button ObserveButton { get; }
public Button LeaveButton { get; } public Button LeaveButton { get; }
public ChatBox Chat { get; set; } public ChatBox Chat { get; }
public ItemList OnlinePlayerItemList { get; }
public LobbyGui(ILocalizationManager localization, IResourceCache resourceCache) public LobbyGui(ILocalizationManager localization, IResourceCache resourceCache)
{ {
@@ -90,12 +91,24 @@ namespace Content.Client.UserInterface
Chat.Input.PlaceHolder = localization.GetString("Talk!"); Chat.Input.PlaceHolder = localization.GetString("Talk!");
} }
// Placeholder.
hBox.AddChild(new Placeholder(resourceCache)
{ {
SizeFlagsHorizontal = SizeFlags.FillExpand, var rightVBox = new VBoxContainer {SizeFlagsHorizontal = SizeFlags.FillExpand};
hBox.AddChild(rightVBox);
rightVBox.AddChild(new Label
{
Text = localization.GetString("Online Players:")
});
rightVBox.AddChild(OnlinePlayerItemList = new ItemList
{
SizeFlagsVertical = SizeFlags.FillExpand,
//SelectMode = ItemList.ItemListSelectMode.None
});
rightVBox.AddChild(new Placeholder(resourceCache)
{
SizeFlagsVertical = SizeFlags.FillExpand,
PlaceholderText = localization.GetString("Server Info\nPlaceholder") PlaceholderText = localization.GetString("Server Info\nPlaceholder")
}); });
} }
} }
} }
}

View File

@@ -149,6 +149,16 @@ namespace Content.Client.UserInterface
placeholder.SetPatchMargin(StyleBox.Margin.All, 24); placeholder.SetPatchMargin(StyleBox.Margin.All, 24);
placeholder.SetExpandMargin(StyleBox.Margin.All, -5); placeholder.SetExpandMargin(StyleBox.Margin.All, -5);
var itemListBackgroundSelected = new StyleBoxFlat {BackgroundColor = new Color(75, 75, 86)};
itemListBackgroundSelected.SetContentMarginOverride(StyleBox.Margin.Vertical, 2);
itemListBackgroundSelected.SetContentMarginOverride(StyleBox.Margin.Horizontal, 4);
var itemListItemBackgroundDisabled = new StyleBoxFlat {BackgroundColor = new Color(10, 10, 12)};
itemListItemBackgroundDisabled.SetContentMarginOverride(StyleBox.Margin.Vertical, 2);
itemListItemBackgroundDisabled.SetContentMarginOverride(StyleBox.Margin.Horizontal, 4);
var itemListItemBackground = new StyleBoxFlat {BackgroundColor = new Color(55, 55, 68)};
itemListItemBackground.SetContentMarginOverride(StyleBox.Margin.Vertical, 2);
itemListItemBackground.SetContentMarginOverride(StyleBox.Margin.Horizontal, 4);
Stylesheet = new Stylesheet(new[] Stylesheet = new Stylesheet(new[]
{ {
// Default font. // Default font.
@@ -367,11 +377,11 @@ namespace Content.Client.UserInterface
new StyleProperty(ItemList.StylePropertyBackground, new StyleProperty(ItemList.StylePropertyBackground,
new StyleBoxFlat {BackgroundColor = new Color(32, 32, 40)}), new StyleBoxFlat {BackgroundColor = new Color(32, 32, 40)}),
new StyleProperty(ItemList.StylePropertyItemBackground, new StyleProperty(ItemList.StylePropertyItemBackground,
new StyleBoxFlat {BackgroundColor = new Color(55, 55, 68)}), itemListItemBackground),
new StyleProperty(ItemList.StylePropertyDisabledItemBackground, new StyleProperty(ItemList.StylePropertyDisabledItemBackground,
new StyleBoxFlat {BackgroundColor = new Color(10, 10, 12)}), itemListItemBackgroundDisabled),
new StyleProperty(ItemList.StylePropertySelectedItemBackground, new StyleProperty(ItemList.StylePropertySelectedItemBackground,
new StyleBoxFlat {BackgroundColor = new Color(75, 75, 86)}) itemListBackgroundSelected)
}), }),
// Tree // Tree