From 8418098dd8e95fa07b8ec05eda35f9f345debf21 Mon Sep 17 00:00:00 2001 From: Jesse Rougeau Date: Sun, 13 Mar 2022 19:33:19 -0700 Subject: [PATCH] Lobby Refactor (#7077) --- .../GameTicking/Managers/ClientGameTicker.cs | 4 +- Content.Client/Info/DevInfoBanner.cs | 32 ++++++ Content.Client/Info/LinkBanner.cs | 43 ++++++++ Content.Client/Info/ServerInfo.cs | 41 ------- Content.Client/Lobby/LobbyState.cs | 43 ++------ .../Lobby/UI/LobbyCharacterPreviewPanel.cs | 36 +++--- Content.Client/Lobby/UI/LobbyGui.xaml | 103 ++++++++---------- Content.Client/Lobby/UI/LobbyGui.xaml.cs | 96 ---------------- .../UserInterface/Controls/HLine.cs | 46 ++++++++ .../UserInterface/Controls/HSpacer.cs | 21 ++++ .../UserInterface/Controls/VSpacer.cs | 20 ++++ .../GameTicking/GameTicker.Lobby.cs | 2 +- .../GameTicking/GameTicker.LobbyBackground.cs | 33 ++++++ Content.Server/GameTicking/GameTicker.cs | 1 + .../GameTicking/SharedGameTicker.cs | 4 +- Resources/Locale/en-US/lobby/lobby-gui.ftl | 1 + .../LobbyScreens/PutLobbyScreensHere.txt | 2 + 17 files changed, 278 insertions(+), 250 deletions(-) create mode 100644 Content.Client/Info/DevInfoBanner.cs create mode 100644 Content.Client/Info/LinkBanner.cs create mode 100644 Content.Client/UserInterface/Controls/HLine.cs create mode 100644 Content.Client/UserInterface/Controls/HSpacer.cs create mode 100644 Content.Client/UserInterface/Controls/VSpacer.cs create mode 100644 Content.Server/GameTicking/GameTicker.LobbyBackground.cs create mode 100644 Resources/Textures/LobbyScreens/PutLobbyScreensHere.txt diff --git a/Content.Client/GameTicking/Managers/ClientGameTicker.cs b/Content.Client/GameTicking/Managers/ClientGameTicker.cs index bc37a6e4d6..b1451b73e8 100644 --- a/Content.Client/GameTicking/Managers/ClientGameTicker.cs +++ b/Content.Client/GameTicking/Managers/ClientGameTicker.cs @@ -9,6 +9,7 @@ using Content.Shared.Station; using JetBrains.Annotations; using Robust.Client.Graphics; using Robust.Client.State; +using Robust.Shared.ContentPack; using Robust.Shared.IoC; using Robust.Shared.Log; using Robust.Shared.Network; @@ -21,7 +22,6 @@ namespace Content.Client.GameTicking.Managers public sealed class ClientGameTicker : SharedGameTicker { [Dependency] private readonly IStateManager _stateManager = default!; - [ViewVariables] private bool _initialized; private Dictionary> _jobsAvailable = new(); private Dictionary _stationNames = new(); @@ -29,6 +29,7 @@ namespace Content.Client.GameTicking.Managers [ViewVariables] public bool AreWeReady { get; private set; } [ViewVariables] public bool IsGameStarted { get; private set; } [ViewVariables] public string? LobbySong { get; private set; } + [ViewVariables] public string? LobbyBackground { get; private set; } [ViewVariables] public bool DisallowedLateJoin { get; private set; } [ViewVariables] public string? ServerInfoBlob { get; private set; } [ViewVariables] public TimeSpan StartTime { get; private set; } @@ -89,6 +90,7 @@ namespace Content.Client.GameTicking.Managers IsGameStarted = message.IsRoundStarted; AreWeReady = message.YouAreReady; LobbySong = message.LobbySong; + LobbyBackground = message.LobbyBackground; Paused = message.Paused; if (IsGameStarted) Status.Clear(); diff --git a/Content.Client/Info/DevInfoBanner.cs b/Content.Client/Info/DevInfoBanner.cs new file mode 100644 index 0000000000..9898b60f83 --- /dev/null +++ b/Content.Client/Info/DevInfoBanner.cs @@ -0,0 +1,32 @@ +using Content.Client.Changelog; +using Content.Client.Credits; +using Content.Client.Links; +using Robust.Client.UserInterface; +using Robust.Client.UserInterface.Controls; +using Robust.Shared.IoC; +using Robust.Shared.Localization; +using Robust.Shared.Utility; + +namespace Content.Client.Info +{ + public sealed class DevInfoBanner : BoxContainer + { + public DevInfoBanner() { + var buttons = new BoxContainer + { + Orientation = LayoutOrientation.Horizontal + }; + AddChild(buttons); + + var uriOpener = IoCManager.Resolve(); + + var reportButton = new Button {Text = Loc.GetString("server-info-report-button")}; + reportButton.OnPressed += args => uriOpener.OpenUri(UILinks.BugReport); + + var creditsButton = new Button {Text = Loc.GetString("server-info-credits-button")}; + creditsButton.OnPressed += args => new CreditsWindow().Open(); + buttons.AddChild(reportButton); + buttons.AddChild(creditsButton); + } + } +} diff --git a/Content.Client/Info/LinkBanner.cs b/Content.Client/Info/LinkBanner.cs new file mode 100644 index 0000000000..b79293bd37 --- /dev/null +++ b/Content.Client/Info/LinkBanner.cs @@ -0,0 +1,43 @@ +using Content.Client.Changelog; +using Content.Client.Credits; +using Content.Client.Links; +using Robust.Client.UserInterface; +using Robust.Client.UserInterface.Controls; +using Robust.Shared.IoC; +using Robust.Shared.Localization; +using Robust.Shared.Utility; + +namespace Content.Client.Info +{ + public sealed class LinkBanner : BoxContainer + { + public LinkBanner() + { + var buttons = new BoxContainer + { + Orientation = LayoutOrientation.Horizontal + }; + AddChild(buttons); + + var uriOpener = IoCManager.Resolve(); + + var rulesButton = new Button() {Text = Loc.GetString("server-info-rules-button")}; + rulesButton.OnPressed += args => new RulesAndInfoWindow().Open(); + + var discordButton = new Button {Text = Loc.GetString("server-info-discord-button")}; + discordButton.OnPressed += args => uriOpener.OpenUri(UILinks.Discord); + + var websiteButton = new Button {Text = Loc.GetString("server-info-website-button")}; + websiteButton.OnPressed += args => uriOpener.OpenUri(UILinks.Website); + + var wikiButton = new Button {Text = Loc.GetString("server-info-wiki-button")}; + wikiButton.OnPressed += args => uriOpener.OpenUri(UILinks.Wiki); + var changelogButton = new ChangelogButton(); + buttons.AddChild(changelogButton); + buttons.AddChild(rulesButton); + buttons.AddChild(discordButton); + buttons.AddChild(websiteButton); + buttons.AddChild(wikiButton); + } + } +} diff --git a/Content.Client/Info/ServerInfo.cs b/Content.Client/Info/ServerInfo.cs index 455950d929..f072c50397 100644 --- a/Content.Client/Info/ServerInfo.cs +++ b/Content.Client/Info/ServerInfo.cs @@ -22,48 +22,7 @@ namespace Content.Client.Info VerticalExpand = true }; AddChild(_richTextLabel); - - var buttons = new BoxContainer - { - Orientation = LayoutOrientation.Horizontal - }; - AddChild(buttons); - - var uriOpener = IoCManager.Resolve(); - - var rulesButton = new Button() { Text = Loc.GetString("server-info-rules-button") }; - rulesButton.OnPressed += args => new RulesAndInfoWindow().Open(); - - var discordButton = new Button {Text = Loc.GetString("server-info-discord-button") }; - discordButton.OnPressed += args => uriOpener.OpenUri(UILinks.Discord); - - var websiteButton = new Button {Text = Loc.GetString("server-info-website-button") }; - websiteButton.OnPressed += args => uriOpener.OpenUri(UILinks.Website); - - var wikiButton = new Button {Text = Loc.GetString("server-info-wiki-button") }; - wikiButton.OnPressed += args => uriOpener.OpenUri(UILinks.Wiki); - - var reportButton = new Button { Text = Loc.GetString("server-info-report-button") }; - reportButton.OnPressed += args => uriOpener.OpenUri(UILinks.BugReport); - - var creditsButton = new Button { Text = Loc.GetString("server-info-credits-button") }; - creditsButton.OnPressed += args => new CreditsWindow().Open(); - - var changelogButton = new ChangelogButton - { - HorizontalExpand = true, - HorizontalAlignment = HAlignment.Right - }; - - buttons.AddChild(rulesButton); - buttons.AddChild(discordButton); - buttons.AddChild(websiteButton); - buttons.AddChild(wikiButton); - buttons.AddChild(reportButton); - buttons.AddChild(creditsButton); - buttons.AddChild(changelogButton); } - public void SetInfoBlob(string markup) { _richTextLabel.SetMessage(FormattedMessage.FromMarkup(markup)); diff --git a/Content.Client/Lobby/LobbyState.cs b/Content.Client/Lobby/LobbyState.cs index f9a88a778b..5d128c32b8 100644 --- a/Content.Client/Lobby/LobbyState.cs +++ b/Content.Client/Lobby/LobbyState.cs @@ -8,6 +8,7 @@ using Content.Client.LateJoin; using Content.Client.Lobby.UI; using Content.Client.Preferences; using Content.Client.Preferences.UI; +using Content.Client.Resources; using Content.Client.Voting; using Content.Shared.GameTicking; using Robust.Client; @@ -22,6 +23,7 @@ using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Prototypes; using Robust.Shared.Timing; +using Robust.Shared.Utility; using Robust.Shared.ViewVariables; namespace Content.Client.Lobby @@ -104,12 +106,10 @@ namespace Content.Client.Lobby _lobby.LeaveButton.OnPressed += _ => _consoleHost.ExecuteCommand("disconnect"); _lobby.OptionsButton.OnPressed += _ => new OptionsMenu().Open(); - UpdatePlayerList(); _playerManager.PlayerListUpdated += PlayerManagerOnPlayerListUpdated; _gameTicker.InfoBlobUpdated += UpdateLobbyUi; _gameTicker.LobbyStatusUpdated += LobbyStatusUpdated; - _gameTicker.LobbyReadyUpdated += LobbyReadyUpdated; _gameTicker.LobbyLateJoinStatusUpdated += LobbyLateJoinStatusUpdated; } @@ -118,7 +118,6 @@ namespace Content.Client.Lobby _playerManager.PlayerListUpdated -= PlayerManagerOnPlayerListUpdated; _gameTicker.InfoBlobUpdated -= UpdateLobbyUi; _gameTicker.LobbyStatusUpdated -= LobbyStatusUpdated; - _gameTicker.LobbyReadyUpdated -= LobbyReadyUpdated; _gameTicker.LobbyLateJoinStatusUpdated -= LobbyLateJoinStatusUpdated; _lobby?.Dispose(); @@ -176,14 +175,12 @@ namespace Content.Client.Lobby } } - UpdatePlayerList(); } - private void LobbyReadyUpdated() => UpdatePlayerList(); private void LobbyStatusUpdated() { - UpdatePlayerList(); + UpdateLobbyBackground(); UpdateLobbyUi(); } @@ -222,35 +219,18 @@ namespace Content.Client.Lobby } } - private void UpdatePlayerList() + private void UpdateLobbyBackground() { if (_lobby == null) return; - _lobby.OnlinePlayerList.Clear(); - var gameTicker = EntitySystem.Get(); - - foreach (var session in _playerManager.Sessions.OrderBy(s => s.Name)) + if (_gameTicker.LobbyBackground != null) { - var readyState = string.Empty; - // Don't show ready state if we're ingame - if (!gameTicker.IsGameStarted) - { - LobbyPlayerStatus status; - if (session.UserId == _playerManager.LocalPlayer?.UserId) - status = gameTicker.AreWeReady ? LobbyPlayerStatus.Ready : LobbyPlayerStatus.NotReady; - else - gameTicker.Status.TryGetValue(session.UserId, out status); - - readyState = status switch - { - LobbyPlayerStatus.NotReady => Loc.GetString("lobby-state-player-status-not-ready"), - LobbyPlayerStatus.Ready => Loc.GetString("lobby-state-player-status-ready"), - LobbyPlayerStatus.Observer => Loc.GetString("lobby-state-player-status-observer"), - _ => string.Empty, - }; - } - - _lobby.OnlinePlayerList.AddItem(session.Name, readyState); + _lobby.Background.Texture = _resourceCache.GetResource(_gameTicker.LobbyBackground ); } + else + { + _lobby.Background.Texture = null; + } + } private void SetReady(bool newReady) @@ -261,7 +241,6 @@ namespace Content.Client.Lobby } _consoleHost.ExecuteCommand($"toggleready {newReady}"); - UpdatePlayerList(); } } } diff --git a/Content.Client/Lobby/UI/LobbyCharacterPreviewPanel.cs b/Content.Client/Lobby/UI/LobbyCharacterPreviewPanel.cs index 4937ea34f8..7370a43546 100644 --- a/Content.Client/Lobby/UI/LobbyCharacterPreviewPanel.cs +++ b/Content.Client/Lobby/UI/LobbyCharacterPreviewPanel.cs @@ -2,6 +2,7 @@ using System.Linq; using Content.Client.HUD.UI; using Content.Client.Inventory; using Content.Client.Preferences; +using Content.Client.UserInterface.Controls; using Content.Shared.CharacterAppearance.Systems; using Content.Shared.GameTicking; using Content.Shared.Inventory; @@ -23,23 +24,20 @@ namespace Content.Client.Lobby.UI { public sealed class LobbyCharacterPreviewPanel : Control { - private readonly IEntityManager _entMan; - private readonly IClientPreferencesManager _preferencesManager; - private readonly IPrototypeManager _prototypeManager; + [Dependency] private readonly IEntityManager _entityManager = default!; + [Dependency] private readonly IClientPreferencesManager _preferencesManager = default!; + [Dependency] private readonly IPrototypeManager _prototypeManager = default!; + + private EntityUid? _previewDummy; private readonly Label _summaryLabel; private readonly BoxContainer _loaded; private readonly BoxContainer _viewBox; private readonly Label _unloaded; - public LobbyCharacterPreviewPanel(IEntityManager entityManager, - IClientPreferencesManager preferencesManager, - IPrototypeManager prototypeManager) + public LobbyCharacterPreviewPanel() { - _entMan = entityManager; - _preferencesManager = preferencesManager; - _prototypeManager = prototypeManager; - + IoCManager.InjectDependencies(this); var header = new NanoHeading { Text = Loc.GetString("lobby-character-preview-panel-header") @@ -57,9 +55,6 @@ namespace Content.Client.Lobby.UI { Orientation = LayoutOrientation.Vertical }; - - vBox.AddChild(header); - _unloaded = new Label { Text = Loc.GetString("lobby-character-preview-panel-unloaded-preferences-label") }; _loaded = new BoxContainer @@ -67,17 +62,18 @@ namespace Content.Client.Lobby.UI Orientation = LayoutOrientation.Vertical, Visible = false }; - - _loaded.AddChild(CharacterSetupButton); - _loaded.AddChild(_summaryLabel); - _viewBox = new BoxContainer { Orientation = LayoutOrientation.Horizontal }; + var _vSpacer = new VSpacer(); + _loaded.AddChild(_summaryLabel); _loaded.AddChild(_viewBox); + _loaded.AddChild(_vSpacer); + _loaded.AddChild(CharacterSetupButton); + vBox.AddChild(header); vBox.AddChild(_loaded); vBox.AddChild(_unloaded); AddChild(vBox); @@ -95,7 +91,7 @@ namespace Content.Client.Lobby.UI _preferencesManager.OnServerDataLoaded -= UpdateUI; if (!disposing) return; - if (_previewDummy != null) _entMan.DeleteEntity(_previewDummy.Value); + if (_previewDummy != null) _entityManager.DeleteEntity(_previewDummy.Value); _previewDummy = default; } @@ -103,7 +99,7 @@ namespace Content.Client.Lobby.UI { return new() { - Sprite = _entMan.GetComponent(entity), + Sprite = _entityManager.GetComponent(entity), OverrideDirection = direction, Scale = (2, 2) }; @@ -126,7 +122,7 @@ namespace Content.Client.Lobby.UI } else { - _previewDummy = _entMan.SpawnEntity(_prototypeManager.Index(selectedCharacter.Species).DollPrototype, MapCoordinates.Nullspace); + _previewDummy = _entityManager.SpawnEntity(_prototypeManager.Index(selectedCharacter.Species).DollPrototype, MapCoordinates.Nullspace); var viewSouth = MakeSpriteView(_previewDummy.Value, Direction.South); var viewNorth = MakeSpriteView(_previewDummy.Value, Direction.North); var viewWest = MakeSpriteView(_previewDummy.Value, Direction.West); diff --git a/Content.Client/Lobby/UI/LobbyGui.xaml b/Content.Client/Lobby/UI/LobbyGui.xaml index 8bc9797a13..038c03b3db 100644 --- a/Content.Client/Lobby/UI/LobbyGui.xaml +++ b/Content.Client/Lobby/UI/LobbyGui.xaml @@ -1,10 +1,10 @@  - - - - - - -