From 915fffb6357002f549a18400e2d1d736e1a65cf7 Mon Sep 17 00:00:00 2001 From: ike709 Date: Fri, 10 Jul 2020 08:27:55 -0500 Subject: [PATCH] Latejoin Job Selection (#1284) * UI version 1 * Latejoining * cleanup * missed a line * Various fixes * comment --- Content.Client/State/GameScreen.cs | 1 - Content.Client/State/LobbyState.cs | 4 +- Content.Client/UserInterface/LateJoinGui.cs | 116 ++++++++++++++++++ Content.IntegrationTests/DummyGameTicker.cs | 7 +- .../GameTicking/GameTicker.JobController.cs | 2 +- Content.Server/GameTicking/GameTicker.cs | 4 +- .../GameTicking/GameTickerCommands.cs | 30 ++++- .../Interfaces/GameTicking/IGameTicker.cs | 4 +- 8 files changed, 159 insertions(+), 9 deletions(-) create mode 100644 Content.Client/UserInterface/LateJoinGui.cs diff --git a/Content.Client/State/GameScreen.cs b/Content.Client/State/GameScreen.cs index 7e36c9cca0..5449ed7e3b 100644 --- a/Content.Client/State/GameScreen.cs +++ b/Content.Client/State/GameScreen.cs @@ -26,7 +26,6 @@ namespace Content.Client.State [Dependency] private readonly IGameHud _gameHud; [Dependency] private readonly IInputManager _inputManager; [Dependency] private readonly IChatManager _chatManager; - [Dependency] private readonly IClientConGroupController _groupController = default!; #pragma warning restore 649 [ViewVariables] private ChatBox _gameChat; diff --git a/Content.Client/State/LobbyState.cs b/Content.Client/State/LobbyState.cs index 440509796c..9f09c1373d 100644 --- a/Content.Client/State/LobbyState.cs +++ b/Content.Client/State/LobbyState.cs @@ -9,6 +9,7 @@ using Robust.Client.Interfaces; using Robust.Client.Interfaces.Input; using Robust.Client.Interfaces.ResourceManagement; using Robust.Client.Interfaces.UserInterface; +using Robust.Client.UserInterface.CustomControls; using Robust.Client.Player; using Robust.Client.UserInterface.Controls; using Robust.Shared.Input; @@ -87,7 +88,8 @@ namespace Content.Client.State return; } - _console.ProcessCommand("joingame"); + new LateJoinGui().OpenCentered(); + return; }; _lobby.ReadyButton.OnToggled += args => diff --git a/Content.Client/UserInterface/LateJoinGui.cs b/Content.Client/UserInterface/LateJoinGui.cs new file mode 100644 index 0000000000..02edca1d92 --- /dev/null +++ b/Content.Client/UserInterface/LateJoinGui.cs @@ -0,0 +1,116 @@ +using Robust.Client.Console; +using Robust.Client.UserInterface.Controls; +using Robust.Client.Utility; +using Content.Shared.Jobs; +using Robust.Shared.IoC; +using Robust.Shared.Localization; +using Robust.Shared.Log; +using Robust.Shared.Maths; +using Robust.Shared.Prototypes; +using Robust.Shared.Utility; +using System; +using System.Collections.Generic; +using System.Linq; + + +namespace Robust.Client.UserInterface.CustomControls +{ + public sealed class LateJoinGui : SS14Window + { +#pragma warning disable 649 + [Dependency] private readonly IPrototypeManager _prototypeManager; + [Dependency] private readonly IClientConsole _console; +#pragma warning restore 649 + + protected override Vector2? CustomSize => (360, 560); + + public event Action SelectedId; + + public LateJoinGui() + { + IoCManager.InjectDependencies(this); + + Title = Loc.GetString("Late Join"); + + var jobList = new VBoxContainer(); + var vBox = new VBoxContainer + { + Children = + { + new ScrollContainer + { + SizeFlagsVertical = SizeFlags.FillExpand, + Children = + { + jobList + } + } + } + }; + Contents.AddChild(vBox); + + foreach (var job in _prototypeManager.EnumeratePrototypes().OrderBy(j => j.Name)) + { + var jobButton = new JobButton + { + JobId = job.ID + }; + + var jobSelector = new HBoxContainer + { + SizeFlagsHorizontal = SizeFlags.FillExpand + }; + + var icon = new TextureRect + { + TextureScale = (2, 2), + Stretch = TextureRect.StretchMode.KeepCentered + }; + + if (job.Icon != null) + { + var specifier = new SpriteSpecifier.Rsi(new ResourcePath("/Textures/Interface/Misc/job_icons.rsi"), job.Icon); + icon.Texture = specifier.Frame0(); + } + jobSelector.AddChild(icon); + + var jobLabel = new Label + { + Text = job.Name + }; + + jobSelector.AddChild(jobLabel); + + jobButton.AddChild(jobSelector); + jobList.AddChild(jobButton); + jobButton.OnPressed += args => + { + SelectedId?.Invoke(jobButton.JobId); + }; + } + + SelectedId += jobId => + { + Logger.InfoS("latejoin", $"Late joining as ID: {jobId}"); + _console.ProcessCommand($"joingame {CommandParsing.Escape(jobId)}"); + Close(); + }; + + + } + + public string ReturnId() + { + return SelectedId.ToString(); + } + + } + class JobButton : ContainerButton + { + public string JobId { get; set; } + public JobButton() + { + AddStyleClass(StyleClassButton); + } + } +} diff --git a/Content.IntegrationTests/DummyGameTicker.cs b/Content.IntegrationTests/DummyGameTicker.cs index 5a5b5e6425..f135339c75 100644 --- a/Content.IntegrationTests/DummyGameTicker.cs +++ b/Content.IntegrationTests/DummyGameTicker.cs @@ -53,7 +53,7 @@ namespace Content.IntegrationTests { } - public void MakeJoinGame(IPlayerSession player) + public void MakeJoinGame(IPlayerSession player, string jobId) { } @@ -109,5 +109,10 @@ namespace Content.IntegrationTests { return false; } + + public Dictionary GetAvailablePositions() + { + return new Dictionary(); + } } } diff --git a/Content.Server/GameTicking/GameTicker.JobController.cs b/Content.Server/GameTicking/GameTicker.JobController.cs index f5e7eb7c46..fd72fe545a 100644 --- a/Content.Server/GameTicking/GameTicker.JobController.cs +++ b/Content.Server/GameTicking/GameTicker.JobController.cs @@ -124,7 +124,7 @@ namespace Content.Server.GameTicking /// /// Gets the remaining available job positions in the current round. /// - private Dictionary GetAvailablePositions() + public Dictionary GetAvailablePositions() { var basePositions = GetBasePositions(false); diff --git a/Content.Server/GameTicking/GameTicker.cs b/Content.Server/GameTicking/GameTicker.cs index 4373fd9e51..72238cdd88 100644 --- a/Content.Server/GameTicking/GameTicker.cs +++ b/Content.Server/GameTicking/GameTicker.cs @@ -352,11 +352,11 @@ namespace Content.Server.GameTicking _spawnObserver(player); } - public void MakeJoinGame(IPlayerSession player) + public void MakeJoinGame(IPlayerSession player, string jobId = null) { if (!_playersInLobby.ContainsKey(player)) return; - SpawnPlayer(player); + SpawnPlayer(player, jobId); } public void ToggleReady(IPlayerSession player, bool ready) diff --git a/Content.Server/GameTicking/GameTickerCommands.cs b/Content.Server/GameTicking/GameTickerCommands.cs index 0c12e593c5..cb15158cf9 100644 --- a/Content.Server/GameTicking/GameTickerCommands.cs +++ b/Content.Server/GameTicking/GameTickerCommands.cs @@ -1,11 +1,15 @@ using System; -using Content.Server.GameTicking.GamePresets; +using System.Collections.Generic; +using Content.Server.GameTicking; using Content.Server.Interfaces.GameTicking; using Content.Server.Players; +using Content.Shared.Jobs; using Robust.Server.Interfaces.Console; using Robust.Server.Interfaces.Player; using Robust.Shared.IoC; using Robust.Shared.Network; +using Robust.Shared.Prototypes; +using Robust.Shared.Log; namespace Content.Server.GameTicking { @@ -175,12 +179,20 @@ namespace Content.Server.GameTicking class JoinGameCommand : IClientCommand { +#pragma warning disable 649 + [Dependency] private IPrototypeManager _prototypeManager; +#pragma warning restore 649 public string Command => "joingame"; public string Description => ""; public string Help => ""; + public JoinGameCommand() + { + IoCManager.InjectDependencies(this); + } public void Execute(IConsoleShell shell, IPlayerSession player, string[] args) { + var output = string.Join(".", args); if (player == null) { return; @@ -192,8 +204,22 @@ namespace Content.Server.GameTicking shell.SendText(player, "Round has not started."); return; } + else if(ticker.RunLevel == GameRunLevel.InRound) + { + string ID = args[0]; + var positions = ticker.GetAvailablePositions(); - ticker.MakeJoinGame(player); + if(positions.GetValueOrDefault(ID, 0) == 0) //n < 0 is treated as infinite + { + var jobPrototype = _prototypeManager.Index(ID); + shell.SendText(player, $"{jobPrototype.Name} has no available slots."); + return; + } + ticker.MakeJoinGame(player, args[0].ToString()); + return; + } + + ticker.MakeJoinGame(player, null); } } diff --git a/Content.Server/Interfaces/GameTicking/IGameTicker.cs b/Content.Server/Interfaces/GameTicking/IGameTicker.cs index b0eadb8094..6ec11e8421 100644 --- a/Content.Server/Interfaces/GameTicking/IGameTicker.cs +++ b/Content.Server/Interfaces/GameTicking/IGameTicker.cs @@ -26,7 +26,7 @@ namespace Content.Server.Interfaces.GameTicking void Respawn(IPlayerSession targetPlayer); void MakeObserve(IPlayerSession player); - void MakeJoinGame(IPlayerSession player); + void MakeJoinGame(IPlayerSession player, string jobId); void ToggleReady(IPlayerSession player, bool ready); GridCoordinates GetLateJoinSpawnPoint(); @@ -50,5 +50,7 @@ namespace Content.Server.Interfaces.GameTicking bool TogglePause(); bool DelayStart(TimeSpan time); + + Dictionary GetAvailablePositions(); } }