Fancy up the lobby GUI.
This commit is contained in:
@@ -14,12 +14,10 @@ using Robust.Client.Interfaces.ResourceManagement;
|
||||
using Robust.Client.Interfaces.UserInterface;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.Input;
|
||||
using Robust.Shared.Interfaces.Network;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
@@ -48,6 +46,7 @@ namespace Content.Client.GameTicking
|
||||
[ViewVariables] private LobbyGui _lobby;
|
||||
[ViewVariables] private bool _gameStarted;
|
||||
[ViewVariables] private DateTime _startTime;
|
||||
[ViewVariables] private string _serverInfoBlob;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
@@ -56,6 +55,7 @@ namespace Content.Client.GameTicking
|
||||
_netManager.RegisterNetMessage<MsgTickerJoinLobby>(nameof(MsgTickerJoinLobby), _joinLobby);
|
||||
_netManager.RegisterNetMessage<MsgTickerJoinGame>(nameof(MsgTickerJoinGame), _joinGame);
|
||||
_netManager.RegisterNetMessage<MsgTickerLobbyStatus>(nameof(MsgTickerLobbyStatus), _lobbyStatus);
|
||||
_netManager.RegisterNetMessage<MsgTickerLobbyInfo>(nameof(MsgTickerLobbyInfo), _lobbyInfo);
|
||||
|
||||
_baseClient.RunLevelChanged += BaseClientOnRunLevelChanged;
|
||||
_playerManager.PlayerListUpdated += PlayerManagerOnPlayerListUpdated;
|
||||
@@ -97,7 +97,7 @@ namespace Content.Client.GameTicking
|
||||
_gameHud.RootControl.Orphan();
|
||||
}
|
||||
|
||||
public void FrameUpdate(FrameEventArgs FrameEventArgs)
|
||||
public void FrameUpdate(FrameEventArgs frameEventArgs)
|
||||
{
|
||||
if (_lobby == null)
|
||||
{
|
||||
@@ -140,6 +140,13 @@ namespace Content.Client.GameTicking
|
||||
_updateLobbyUi();
|
||||
}
|
||||
|
||||
private void _lobbyInfo(MsgTickerLobbyInfo message)
|
||||
{
|
||||
_serverInfoBlob = message.TextBlob;
|
||||
|
||||
_updateLobbyUi();
|
||||
}
|
||||
|
||||
private void _updateLobbyUi()
|
||||
{
|
||||
if (_lobby == null)
|
||||
@@ -160,6 +167,8 @@ namespace Content.Client.GameTicking
|
||||
_lobby.ReadyButton.ToggleMode = true;
|
||||
_lobby.ReadyButton.Pressed = _areWeReady;
|
||||
}
|
||||
|
||||
_lobby.ServerInfo.SetInfoBlob(_serverInfoBlob);
|
||||
}
|
||||
|
||||
private void _joinLobby(MsgTickerJoinLobby message)
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
using Content.Client.Chat;
|
||||
using Content.Client.Utility;
|
||||
using Robust.Client.Graphics.Drawing;
|
||||
using Robust.Client.Interfaces.ResourceManagement;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Content.Client.UserInterface
|
||||
{
|
||||
internal sealed class LobbyGui : PanelContainer
|
||||
internal sealed class LobbyGui : Control
|
||||
{
|
||||
public Label ServerName { get; }
|
||||
public Label StartTime { get; }
|
||||
@@ -16,97 +18,195 @@ namespace Content.Client.UserInterface
|
||||
public Button LeaveButton { get; }
|
||||
public ChatBox Chat { get; }
|
||||
public ItemList OnlinePlayerItemList { get; }
|
||||
public ServerInfo ServerInfo { get; }
|
||||
|
||||
public LobbyGui(ILocalizationManager localization, IResourceCache resourceCache)
|
||||
{
|
||||
PanelOverride = new StyleBoxFlat {BackgroundColor = new Color(37, 37, 45)};
|
||||
PanelOverride.SetContentMarginOverride(StyleBox.Margin.All, 4);
|
||||
var panelTex = resourceCache.GetTexture("/Nano/button.svg.96dpi.png");
|
||||
var back = new StyleBoxTexture
|
||||
{
|
||||
Texture = panelTex,
|
||||
Modulate = new Color(37, 37, 42),
|
||||
};
|
||||
back.SetPatchMargin(StyleBox.Margin.All, 10);
|
||||
|
||||
var panel = new Panel
|
||||
{
|
||||
PanelOverride = back
|
||||
};
|
||||
|
||||
AddChild(panel);
|
||||
|
||||
panel.SetAnchorAndMarginPreset(LayoutPreset.Wide);
|
||||
|
||||
var vBox = new VBoxContainer {SeparationOverride = 0};
|
||||
|
||||
vBox.SetAnchorAndMarginPreset(LayoutPreset.Wide);
|
||||
|
||||
vBox.MarginTop = 40;
|
||||
|
||||
var vBox = new VBoxContainer();
|
||||
AddChild(vBox);
|
||||
|
||||
{
|
||||
// Title bar.
|
||||
var titleContainer = new HBoxContainer();
|
||||
vBox.AddChild(titleContainer);
|
||||
|
||||
var lobbyTitle = new Label
|
||||
AddChild(new Label
|
||||
{
|
||||
Text = localization.GetString("Lobby"),
|
||||
SizeFlagsHorizontal = SizeFlags.None
|
||||
};
|
||||
lobbyTitle.AddStyleClass(NanoStyle.StyleClassLabelHeading);
|
||||
titleContainer.AddChild(lobbyTitle);
|
||||
|
||||
titleContainer.AddChild(ServerName = new Label
|
||||
{
|
||||
SizeFlagsHorizontal = SizeFlags.ShrinkCenter | SizeFlags.Expand
|
||||
StyleClasses = {NanoStyle.StyleClassLabelHeadingBigger},
|
||||
MarginBottom = 40,
|
||||
MarginLeft = 8,
|
||||
VAlign = Label.VAlignMode.Center
|
||||
});
|
||||
ServerName.AddStyleClass(NanoStyle.StyleClassLabelHeading);
|
||||
|
||||
titleContainer.AddChild(LeaveButton = new Button
|
||||
AddChild(ServerName = new Label
|
||||
{
|
||||
StyleClasses = {NanoStyle.StyleClassLabelHeadingBigger},
|
||||
MarginBottom = 40,
|
||||
GrowHorizontal = GrowDirection.Both,
|
||||
VAlign = Label.VAlignMode.Center
|
||||
});
|
||||
|
||||
ServerName.SetAnchorAndMarginPreset(LayoutPreset.CenterTop);
|
||||
|
||||
AddChild(LeaveButton = new Button
|
||||
{
|
||||
SizeFlagsHorizontal = SizeFlags.ShrinkEnd,
|
||||
Text = localization.GetString("Leave")
|
||||
Text = localization.GetString("Leave"),
|
||||
StyleClasses = {NanoStyle.StyleClassButtonBig}
|
||||
});
|
||||
LeaveButton.AddStyleClass(NanoStyle.StyleClassButtonBig);
|
||||
}
|
||||
|
||||
var hBox = new HBoxContainer {SizeFlagsVertical = SizeFlags.FillExpand};
|
||||
LeaveButton.SetAnchorAndMarginPreset(LayoutPreset.TopRight);
|
||||
|
||||
vBox.AddChild(new Panel
|
||||
{
|
||||
PanelOverride = new StyleBoxFlat
|
||||
{
|
||||
BackgroundColor = NanoStyle.NanoGold,
|
||||
ContentMarginTopOverride = 2
|
||||
},
|
||||
});
|
||||
|
||||
var hBox = new HBoxContainer
|
||||
{
|
||||
SizeFlagsVertical = SizeFlags.FillExpand,
|
||||
SeparationOverride = 0
|
||||
};
|
||||
vBox.AddChild(hBox);
|
||||
|
||||
hBox.AddChild(new VBoxContainer
|
||||
{
|
||||
var leftVBox = new VBoxContainer {SizeFlagsHorizontal = SizeFlags.FillExpand};
|
||||
hBox.AddChild(leftVBox);
|
||||
|
||||
leftVBox.AddChild(new Placeholder(resourceCache)
|
||||
SizeFlagsHorizontal = SizeFlags.FillExpand,
|
||||
SeparationOverride = 0,
|
||||
Children =
|
||||
{
|
||||
new Placeholder(resourceCache)
|
||||
{
|
||||
SizeFlagsVertical = SizeFlags.FillExpand,
|
||||
PlaceholderText = localization.GetString("Character UI\nPlaceholder")
|
||||
});
|
||||
},
|
||||
|
||||
var readyButtons = new HBoxContainer();
|
||||
|
||||
leftVBox.AddChild(readyButtons);
|
||||
readyButtons.AddChild(ObserveButton = new Button
|
||||
new StripeBack
|
||||
{
|
||||
Text = localization.GetString("Observe")
|
||||
});
|
||||
ObserveButton.AddStyleClass(NanoStyle.StyleClassButtonBig);
|
||||
|
||||
readyButtons.AddChild(StartTime = new Label
|
||||
Children =
|
||||
{
|
||||
new MarginContainer
|
||||
{
|
||||
MarginRightOverride = 3,
|
||||
MarginLeftOverride = 3,
|
||||
MarginTopOverride = 3,
|
||||
MarginBottomOverride = 3,
|
||||
Children =
|
||||
{
|
||||
new HBoxContainer
|
||||
{
|
||||
SeparationOverride = 6,
|
||||
Children =
|
||||
{
|
||||
(ObserveButton = new Button
|
||||
{
|
||||
Text = localization.GetString("Observe"),
|
||||
StyleClasses = {NanoStyle.StyleClassButtonBig}
|
||||
}),
|
||||
(StartTime = new Label
|
||||
{
|
||||
SizeFlagsHorizontal = SizeFlags.FillExpand,
|
||||
Align = Label.AlignMode.Right
|
||||
});
|
||||
|
||||
readyButtons.AddChild(ReadyButton = new Button
|
||||
Align = Label.AlignMode.Right,
|
||||
FontColorOverride = Color.DarkGray,
|
||||
StyleClasses = { NanoStyle.StyleClassLabelBig }
|
||||
}),
|
||||
(ReadyButton = new Button
|
||||
{
|
||||
ToggleMode = true,
|
||||
Text = localization.GetString("Ready Up")
|
||||
});
|
||||
ReadyButton.AddStyleClass(NanoStyle.StyleClassButtonBig);
|
||||
|
||||
leftVBox.AddChild(Chat = new ChatBox {SizeFlagsVertical = SizeFlags.FillExpand});
|
||||
Chat.Input.PlaceHolder = localization.GetString("Say something!");
|
||||
Text = localization.GetString("Ready Up"),
|
||||
StyleClasses = {NanoStyle.StyleClassButtonBig}
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
new MarginContainer
|
||||
{
|
||||
MarginRightOverride = 3,
|
||||
MarginLeftOverride = 3,
|
||||
MarginTopOverride = 3,
|
||||
MarginBottomOverride = 3,
|
||||
SizeFlagsVertical = SizeFlags.FillExpand,
|
||||
Children =
|
||||
{
|
||||
(Chat = new ChatBox
|
||||
{
|
||||
Input = {PlaceHolder = localization.GetString("Say something!")}
|
||||
})
|
||||
}
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
hBox.AddChild(new Panel
|
||||
{
|
||||
PanelOverride = new StyleBoxFlat {BackgroundColor = NanoStyle.NanoGold}, CustomMinimumSize = (2, 0)
|
||||
});
|
||||
|
||||
{
|
||||
var rightVBox = new VBoxContainer {SizeFlagsHorizontal = SizeFlags.FillExpand};
|
||||
hBox.AddChild(rightVBox);
|
||||
rightVBox.AddChild(new Label
|
||||
hBox.AddChild(new VBoxContainer
|
||||
{
|
||||
Text = localization.GetString("Online Players:")
|
||||
});
|
||||
rightVBox.AddChild(OnlinePlayerItemList = new ItemList
|
||||
SizeFlagsHorizontal = SizeFlags.FillExpand,
|
||||
Children =
|
||||
{
|
||||
new NanoHeading
|
||||
{
|
||||
Text = localization.GetString("Online Players"),
|
||||
},
|
||||
new MarginContainer
|
||||
{
|
||||
SizeFlagsVertical = SizeFlags.FillExpand,
|
||||
//SelectMode = ItemList.ItemListSelectMode.None
|
||||
});
|
||||
rightVBox.AddChild(new Placeholder(resourceCache)
|
||||
MarginRightOverride = 3,
|
||||
MarginLeftOverride = 3,
|
||||
MarginTopOverride = 3,
|
||||
MarginBottomOverride = 3,
|
||||
Children =
|
||||
{
|
||||
(OnlinePlayerItemList = new ItemList())
|
||||
}
|
||||
},
|
||||
new NanoHeading
|
||||
{
|
||||
Text = localization.GetString("Server Info"),
|
||||
},
|
||||
new MarginContainer
|
||||
{
|
||||
SizeFlagsVertical = SizeFlags.FillExpand,
|
||||
PlaceholderText = localization.GetString("Server Info\nPlaceholder")
|
||||
MarginRightOverride = 3,
|
||||
MarginLeftOverride = 3,
|
||||
MarginTopOverride = 3,
|
||||
MarginBottomOverride = 2,
|
||||
Children =
|
||||
{
|
||||
(ServerInfo = new ServerInfo(localization))
|
||||
}
|
||||
},
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
44
Content.Client/UserInterface/ServerInfo.cs
Normal file
44
Content.Client/UserInterface/ServerInfo.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Client.UserInterface
|
||||
{
|
||||
public class ServerInfo : VBoxContainer
|
||||
{
|
||||
private const string DiscordUrl = "https://discordapp.com/invite/t2jac3p";
|
||||
private const string WebsiteUrl = "https://spacestation14.io";
|
||||
|
||||
private readonly RichTextLabel _richTextLabel;
|
||||
|
||||
public ServerInfo(ILocalizationManager localization)
|
||||
{
|
||||
_richTextLabel = new RichTextLabel
|
||||
{
|
||||
SizeFlagsVertical = SizeFlags.FillExpand
|
||||
};
|
||||
AddChild(_richTextLabel);
|
||||
|
||||
var buttons = new HBoxContainer();
|
||||
AddChild(buttons);
|
||||
|
||||
var uriOpener = IoCManager.Resolve<IUriOpener>();
|
||||
|
||||
var discordButton = new Button {Text = localization.GetString("Join us on Discord!")};
|
||||
discordButton.OnPressed += args => uriOpener.OpenUri(DiscordUrl);
|
||||
|
||||
var websiteButton = new Button {Text = localization.GetString("Website")};
|
||||
websiteButton.OnPressed += args => uriOpener.OpenUri(WebsiteUrl);
|
||||
|
||||
buttons.AddChild(discordButton);
|
||||
buttons.AddChild(websiteButton);
|
||||
}
|
||||
|
||||
public void SetInfoBlob(string markup)
|
||||
{
|
||||
_richTextLabel.SetMessage(FormattedMessage.FromMarkup(markup));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,5 +6,6 @@ namespace Content.Server.GameTicking
|
||||
public abstract class GamePreset
|
||||
{
|
||||
public abstract void Start();
|
||||
public virtual string Description => "Secret!";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,5 +14,7 @@ namespace Content.Server.GameTicking.GamePresets
|
||||
{
|
||||
_gameTicker.AddGameRule<RuleDeathMatch>();
|
||||
}
|
||||
|
||||
public override string Description => "Deathmatch, go and kill everybody else to win!";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,5 +14,7 @@ namespace Content.Server.GameTicking.GamePresets
|
||||
{
|
||||
_sandboxManager.IsSandboxEnabled = true;
|
||||
}
|
||||
|
||||
public override string Description => "Sandbox, go and build something!";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Server.GameObjects;
|
||||
@@ -10,7 +10,6 @@ using Content.Server.Mobs;
|
||||
using Content.Server.Players;
|
||||
using Content.Shared;
|
||||
using Content.Shared.GameObjects.Components.Inventory;
|
||||
using Robust.Server.Interfaces.Console;
|
||||
using Robust.Server.Interfaces.Maps;
|
||||
using Robust.Server.Interfaces.Player;
|
||||
using Robust.Server.Player;
|
||||
@@ -24,10 +23,10 @@ using Robust.Shared.Interfaces.Network;
|
||||
using Robust.Shared.Interfaces.Random;
|
||||
using Robust.Shared.Interfaces.Timing;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Timers;
|
||||
using Robust.Shared.Timing;
|
||||
@@ -92,6 +91,7 @@ namespace Content.Server.GameTicking
|
||||
[Dependency] private IChatManager _chatManager;
|
||||
[Dependency] private IServerNetManager _netManager;
|
||||
[Dependency] private IDynamicTypeFactory _dynamicTypeFactory;
|
||||
[Dependency] private readonly ILocalizationManager _localization;
|
||||
[Dependency] private readonly IRobustRandom _robustRandom;
|
||||
#pragma warning restore 649
|
||||
|
||||
@@ -105,6 +105,7 @@ namespace Content.Server.GameTicking
|
||||
_netManager.RegisterNetMessage<MsgTickerJoinLobby>(nameof(MsgTickerJoinLobby));
|
||||
_netManager.RegisterNetMessage<MsgTickerJoinGame>(nameof(MsgTickerJoinGame));
|
||||
_netManager.RegisterNetMessage<MsgTickerLobbyStatus>(nameof(MsgTickerLobbyStatus));
|
||||
_netManager.RegisterNetMessage<MsgTickerLobbyInfo>(nameof(MsgTickerLobbyInfo));
|
||||
|
||||
RestartRound();
|
||||
|
||||
@@ -156,7 +157,7 @@ namespace Content.Server.GameTicking
|
||||
|
||||
RunLevel = GameRunLevel.InRound;
|
||||
|
||||
var preset = _dynamicTypeFactory.CreateInstance<GamePreset>(_presetType ?? typeof(PresetSandbox));
|
||||
var preset = MakeGamePreset();
|
||||
preset.Start();
|
||||
|
||||
foreach (var (playerSession, ready) in _playersInLobby.ToList())
|
||||
@@ -256,6 +257,7 @@ namespace Content.Server.GameTicking
|
||||
throw new ArgumentException("type must inherit GamePreset");
|
||||
}
|
||||
_presetType = type;
|
||||
UpdateInfoText();
|
||||
}
|
||||
|
||||
private IEntity _spawnPlayerMob()
|
||||
@@ -461,6 +463,7 @@ namespace Content.Server.GameTicking
|
||||
|
||||
_netManager.ServerSendMessage(_netManager.CreateNetMessage<MsgTickerJoinLobby>(), session.ConnectedClient);
|
||||
_netManager.ServerSendMessage(_getStatusMsg(session), session.ConnectedClient);
|
||||
_netManager.ServerSendMessage(GetInfoMsg(), session.ConnectedClient);
|
||||
}
|
||||
|
||||
private void _playerJoinGame(IPlayerSession session)
|
||||
@@ -484,6 +487,13 @@ namespace Content.Server.GameTicking
|
||||
return msg;
|
||||
}
|
||||
|
||||
private MsgTickerLobbyInfo GetInfoMsg()
|
||||
{
|
||||
var msg = _netManager.CreateNetMessage<MsgTickerLobbyInfo>();
|
||||
msg.TextBlob = GetInfoText();
|
||||
return msg;
|
||||
}
|
||||
|
||||
private void _sendStatusToAll()
|
||||
{
|
||||
foreach (var player in _playersInLobby.Keys)
|
||||
@@ -491,6 +501,26 @@ namespace Content.Server.GameTicking
|
||||
_netManager.ServerSendMessage(_getStatusMsg(player), player.ConnectedClient);
|
||||
}
|
||||
}
|
||||
|
||||
private string GetInfoText()
|
||||
{
|
||||
var gameMode = MakeGamePreset().Description;
|
||||
return _localization.GetString(@"Hi and welcome to [color=white]Space Station 14![/color]
|
||||
|
||||
The current game mode is [color=white]{0}[/color]", gameMode);
|
||||
}
|
||||
|
||||
private void UpdateInfoText()
|
||||
{
|
||||
var infoMsg = GetInfoMsg();
|
||||
|
||||
_netManager.ServerSendToMany(infoMsg, _playersInLobby.Keys.Select(p => p.ConnectedClient).ToList());
|
||||
}
|
||||
|
||||
private GamePreset MakeGamePreset()
|
||||
{
|
||||
return _dynamicTypeFactory.CreateInstance<GamePreset>(_presetType ?? typeof(PresetSandbox));
|
||||
}
|
||||
}
|
||||
|
||||
public enum GameRunLevel
|
||||
|
||||
@@ -90,5 +90,28 @@ namespace Content.Shared
|
||||
buffer.Write(StartTime.Ticks);
|
||||
}
|
||||
}
|
||||
|
||||
protected class MsgTickerLobbyInfo : NetMessage
|
||||
{
|
||||
#region REQUIRED
|
||||
|
||||
public const MsgGroups GROUP = MsgGroups.Command;
|
||||
public const string NAME = nameof(MsgTickerLobbyInfo);
|
||||
public MsgTickerLobbyInfo(INetChannel channel) : base(NAME, GROUP) { }
|
||||
|
||||
#endregion
|
||||
|
||||
public string TextBlob { get; set; }
|
||||
|
||||
public override void ReadFromBuffer(NetIncomingMessage buffer)
|
||||
{
|
||||
TextBlob = buffer.ReadString();
|
||||
}
|
||||
|
||||
public override void WriteToBuffer(NetOutgoingMessage buffer)
|
||||
{
|
||||
buffer.Write(TextBlob);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user