]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Screen load event for GameplayState (#14316)
authorFlipp Syder <76629141+vulppine@users.noreply.github.com>
Sat, 11 Mar 2023 03:25:56 +0000 (19:25 -0800)
committerGitHub <noreply@github.com>
Sat, 11 Mar 2023 03:25:56 +0000 (14:25 +1100)
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
Content.Client/Gameplay/GameplayState.cs
Content.Client/UserInterface/Systems/Actions/ActionUIController.cs
Content.Client/UserInterface/Systems/Alerts/AlertsUIController.cs
Content.Client/UserInterface/Systems/Chat/ChatUIController.cs
Content.Client/UserInterface/Systems/Gameplay/GameplayStateLoadController.cs [new file with mode: 0644]
Content.Client/UserInterface/Systems/Ghost/GhostUIController.cs
Content.Client/UserInterface/Systems/Hotbar/HotbarUIController.cs
Content.Client/UserInterface/Systems/MenuBar/GameTopMenuBarUIController.cs
Content.Client/UserInterface/Systems/Viewport/ViewportUIController.cs

index f50c4934082ccb36888840f0e16cc646ae322ce7..3765753c6961059ca34225971d82096bf788b5b9 100644 (file)
@@ -1,29 +1,15 @@
-using Content.Client.Construction.UI;
 using Content.Client.Hands;
 using Content.Client.UserInterface.Controls;
 using Content.Client.UserInterface.Screens;
-using Content.Client.UserInterface.Systems.Actions;
-using Content.Client.UserInterface.Systems.Alerts;
-using Content.Client.UserInterface.Systems.Chat;
-using Content.Client.UserInterface.Systems.Chat.Widgets;
-using Content.Client.UserInterface.Systems.Ghost;
-using Content.Client.UserInterface.Systems.Hands;
-using Content.Client.UserInterface.Systems.Hotbar;
-using Content.Client.UserInterface.Systems.Hotbar.Widgets;
-using Content.Client.UserInterface.Systems.Inventory;
-using Content.Client.UserInterface.Systems.MenuBar;
-using Content.Client.UserInterface.Systems.Viewport;
+using Content.Client.UserInterface.Systems.Gameplay;
 using Content.Client.Viewport;
 using Content.Shared.CCVar;
 using Robust.Client.Graphics;
 using Robust.Client.Input;
 using Robust.Client.UserInterface;
-using Robust.Client.UserInterface.Controls;
 using Robust.Client.UserInterface.CustomControls;
 using Robust.Shared.Configuration;
 using Robust.Shared.Timing;
-using Robust.Client.Player;
-using Robust.Client.GameObjects;
 
 namespace Content.Client.Gameplay
 {
@@ -39,25 +25,13 @@ namespace Content.Client.Gameplay
 
         public MainViewport Viewport => _uiManager.ActiveScreen!.GetWidget<MainViewport>()!;
 
-        private readonly GhostUIController _ghostController;
-        private readonly ActionUIController _actionController;
-        private readonly AlertsUIController _alertsController;
-        private readonly HotbarUIController _hotbarController;
-        private readonly ChatUIController _chatController;
-        private readonly ViewportUIController _viewportController;
-        private readonly GameTopMenuBarUIController _menuController;
+        private readonly GameplayStateLoadController _loadController;
 
         public GameplayState()
         {
             IoCManager.InjectDependencies(this);
 
-            _ghostController = _uiManager.GetUIController<GhostUIController>();
-            _actionController = _uiManager.GetUIController<ActionUIController>();
-            _alertsController = _uiManager.GetUIController<AlertsUIController>();
-            _hotbarController = _uiManager.GetUIController<HotbarUIController>();
-            _chatController = _uiManager.GetUIController<ChatUIController>();
-            _viewportController = _uiManager.GetUIController<ViewportUIController>();
-            _menuController = _uiManager.GetUIController<GameTopMenuBarUIController>();
+            _loadController = _uiManager.GetUIController<GameplayStateLoadController>();
         }
 
         protected override void Startup()
@@ -109,10 +83,7 @@ namespace Content.Client.Gameplay
 
         private void UnloadMainScreen()
         {
-            _chatController.SetMainChat(false);
-            _menuController.UnloadButtons();
-            _ghostController.UnloadGui();
-            _actionController.UnloadGui();
+            _loadController.UnloadScreen();
             _uiManager.UnloadScreen();
         }
 
@@ -128,29 +99,15 @@ namespace Content.Client.Gameplay
             {
                 case ScreenType.Default:
                     _uiManager.LoadScreen<DefaultGameScreen>();
-
                     break;
                 case ScreenType.Separated:
                     _uiManager.LoadScreen<SeparatedChatGameScreen>();
                     break;
             }
 
-            _chatController.SetMainChat(true);
-            _viewportController.ReloadViewport();
-            _menuController.LoadButtons();
-
-            // TODO: This could just be like, the equivalent of an event or something
-            _ghostController.LoadGui();
-            _actionController.LoadGui();
-            _alertsController.SyncAlerts();
-            _hotbarController.ReloadHotbar();
-
-            var viewportContainer = _uiManager.ActiveScreen!.FindControl<LayoutContainer>("ViewportContainer");
-            _chatController.SetSpeechBubbleRoot(viewportContainer);
+            _loadController.LoadScreen();
         }
 
-
-
         protected override void OnKeyBindStateChanged(ViewportBoundKeyEventArgs args)
         {
             if (args.Viewport == null)
index c47fba16a28ab951f923a797f0802257e7536077..06a7792f3835ba068091bb5e7519a718bc887a02 100644 (file)
@@ -10,6 +10,7 @@ using Content.Client.UserInterface.Controls;
 using Content.Client.UserInterface.Systems.Actions.Controls;
 using Content.Client.UserInterface.Systems.Actions.Widgets;
 using Content.Client.UserInterface.Systems.Actions.Windows;
+using Content.Client.UserInterface.Systems.Gameplay;
 using Content.Shared.Actions;
 using Content.Shared.Actions.ActionTypes;
 using Content.Shared.Input;
@@ -87,6 +88,25 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
         }
     }
 
+    public override void Initialize()
+    {
+        base.Initialize();
+
+        var gameplayStateLoad = UIManager.GetUIController<GameplayStateLoadController>();
+        gameplayStateLoad.OnScreenLoad += OnScreenLoad;
+        gameplayStateLoad.OnScreenUnload += OnScreenUnload;
+    }
+
+    private void OnScreenLoad()
+    {
+       LoadGui();
+    }
+
+    private void OnScreenUnload()
+    {
+        UnloadGui();
+    }
+
     public void OnStateEntered(GameplayState state)
     {
         DebugTools.Assert(_window == null);
index 53963195a1d35a9868ace0d2ca2e684d25a9105c..5fe84b506c9dcf870659dc0cbb01bd18c6f17fe8 100644 (file)
@@ -1,6 +1,7 @@
 using Content.Client.Alerts;
 using Content.Client.Gameplay;
 using Content.Client.UserInterface.Systems.Alerts.Widgets;
+using Content.Client.UserInterface.Systems.Gameplay;
 using Content.Shared.Alert;
 using Robust.Client.UserInterface;
 using Robust.Client.UserInterface.Controllers;
@@ -13,6 +14,19 @@ public sealed class AlertsUIController : UIController, IOnStateEntered<GameplayS
 
     private AlertsUI? UI => UIManager.GetActiveUIWidgetOrNull<AlertsUI>();
 
+    public override void Initialize()
+    {
+        base.Initialize();
+
+        var gameplayStateLoad = UIManager.GetUIController<GameplayStateLoadController>();
+        gameplayStateLoad.OnScreenLoad += OnScreenLoad;
+    }
+
+    private void OnScreenLoad()
+    {
+        SyncAlerts();
+    }
+
     private void OnAlertPressed(object? sender, AlertType e)
     {
         _alertsSystem?.AlertClicked(e);
index 1097e7e851d2ad5457d53771389cb29b10945030..efc9929cc0e2651ffbaa61a0c38e544c96e22f40 100644 (file)
@@ -11,6 +11,7 @@ using Content.Client.Ghost;
 using Content.Client.Lobby.UI;
 using Content.Client.UserInterface.Screens;
 using Content.Client.UserInterface.Systems.Chat.Widgets;
+using Content.Client.UserInterface.Systems.Gameplay;
 using Content.Shared.Administration;
 using Content.Shared.CCVar;
 using Content.Shared.Chat;
@@ -183,6 +184,23 @@ public sealed class ChatUIController : UIController
 
         _input.SetInputCommand(ContentKeyFunctions.CycleChatChannelBackward,
             InputCmdHandler.FromDelegate(_ => CycleChatChannel(false)));
+
+        var gameplayStateLoad = UIManager.GetUIController<GameplayStateLoadController>();
+        gameplayStateLoad.OnScreenLoad += OnScreenLoad;
+        gameplayStateLoad.OnScreenUnload += OnScreenUnload;
+    }
+
+    public void OnScreenLoad()
+    {
+        SetMainChat(true);
+
+        var viewportContainer = UIManager.ActiveScreen!.FindControl<LayoutContainer>("ViewportContainer");
+        SetSpeechBubbleRoot(viewportContainer);
+    }
+
+    public void OnScreenUnload()
+    {
+        SetMainChat(false);
     }
 
     public void SetMainChat(bool setting)
diff --git a/Content.Client/UserInterface/Systems/Gameplay/GameplayStateLoadController.cs b/Content.Client/UserInterface/Systems/Gameplay/GameplayStateLoadController.cs
new file mode 100644 (file)
index 0000000..3290623
--- /dev/null
@@ -0,0 +1,30 @@
+using Content.Client.Gameplay;
+using Robust.Client.UserInterface.Controllers;
+
+namespace Content.Client.UserInterface.Systems.Gameplay;
+
+public sealed class GameplayStateLoadController : UIController, IOnStateChanged<GameplayState>
+{
+    public Action? OnScreenLoad;
+    public Action? OnScreenUnload;
+
+    public void OnStateEntered(GameplayState state)
+    {
+        LoadScreen();
+    }
+
+    public void OnStateExited(GameplayState state)
+    {
+        UnloadScreen();
+    }
+
+    public void UnloadScreen()
+    {
+        OnScreenUnload?.Invoke();
+    }
+
+    public void LoadScreen()
+    {
+        OnScreenLoad?.Invoke();
+    }
+}
index c379cbf643cbe29b918326e9291178818b2a82bc..d45ff4ee9e4dd1e11ef64132d9222c6263b735da 100644 (file)
@@ -1,5 +1,6 @@
 using Content.Client.Gameplay;
 using Content.Client.Ghost;
+using Content.Client.UserInterface.Systems.Gameplay;
 using Content.Client.UserInterface.Systems.Ghost.Widgets;
 using Content.Shared.Ghost;
 using Robust.Client.UserInterface;
@@ -16,6 +17,25 @@ public sealed class GhostUIController : UIController, IOnSystemChanged<GhostSyst
 
     private GhostGui? Gui => UIManager.GetActiveUIWidgetOrNull<GhostGui>();
 
+    public override void Initialize()
+    {
+        base.Initialize();
+
+        var gameplayStateLoad = UIManager.GetUIController<GameplayStateLoadController>();
+        gameplayStateLoad.OnScreenLoad += OnScreenLoad;
+        gameplayStateLoad.OnScreenUnload += OnScreenUnload;
+    }
+
+    private void OnScreenLoad()
+    {
+        LoadGui();
+    }
+
+    private void OnScreenUnload()
+    {
+        UnloadGui();
+    }
+
     public void OnSystemLoaded(GhostSystem system)
     {
         system.PlayerRemoved += OnPlayerRemoved;
index 4059803b7ab47a20d6352af3c00aacb978c9cf5b..17cc03c113105a9fbc8643d1fd5bf2544afe8a18 100644 (file)
@@ -1,4 +1,5 @@
-using Content.Client.UserInterface.Systems.Hands;
+using Content.Client.UserInterface.Systems.Gameplay;
+using Content.Client.UserInterface.Systems.Hands;
 using Content.Client.UserInterface.Systems.Hands.Controls;
 using Content.Client.UserInterface.Systems.Hotbar.Widgets;
 using Content.Client.UserInterface.Systems.Inventory;
@@ -13,6 +14,19 @@ public sealed class HotbarUIController : UIController
     private InventoryUIController? _inventory;
     private HandsUIController? _hands;
 
+    public override void Initialize()
+    {
+        base.Initialize();
+
+        var gameplayStateLoad = UIManager.GetUIController<GameplayStateLoadController>();
+        gameplayStateLoad.OnScreenLoad += OnScreenLoad;
+    }
+
+    private void OnScreenLoad()
+    {
+        ReloadHotbar();
+    }
+
     public void Setup(HandsContainer handsContainer, ItemSlotButtonContainer inventoryBar, ItemStatusPanel handStatus)
     {
         _inventory = UIManager.GetUIController<InventoryUIController>();
index 6f3c7344a4a509de62961ee32f7f338528d737e2..9779dbc582fb974ad2638950fbb28d3bee7b4ba3 100644 (file)
@@ -5,6 +5,7 @@ using Content.Client.UserInterface.Systems.Bwoink;
 using Content.Client.UserInterface.Systems.Character;
 using Content.Client.UserInterface.Systems.Crafting;
 using Content.Client.UserInterface.Systems.EscapeMenu;
+using Content.Client.UserInterface.Systems.Gameplay;
 using Content.Client.UserInterface.Systems.Inventory;
 using Content.Client.UserInterface.Systems.MenuBar.Widgets;
 using Content.Client.UserInterface.Systems.Sandbox;
@@ -25,6 +26,15 @@ public sealed class GameTopMenuBarUIController : UIController
 
     private GameTopMenuBar? GameTopMenuBar => UIManager.GetActiveUIWidgetOrNull<GameTopMenuBar>();
 
+    public override void Initialize()
+    {
+        base.Initialize();
+
+        var gameplayStateLoad = UIManager.GetUIController<GameplayStateLoadController>();
+        gameplayStateLoad.OnScreenLoad += LoadButtons;
+        gameplayStateLoad.OnScreenUnload += UnloadButtons;
+    }
+
     public void UnloadButtons()
     {
         _escape.UnloadButton();
index f0773b9a0d46c410bd9d0f033c7fff977ec9b678..d16b61317db3298c90e3a2fc3e78b5bbed5c2062 100644 (file)
@@ -1,4 +1,5 @@
 using Content.Client.UserInterface.Controls;
+using Content.Client.UserInterface.Systems.Gameplay;
 using Content.Shared.CCVar;
 using Robust.Client.GameObjects;
 using Robust.Client.Graphics;
@@ -25,6 +26,14 @@ public sealed class ViewportUIController : UIController
         _configurationManager.OnValueChanged(CCVars.ViewportMinimumWidth, _ => UpdateViewportRatio());
         _configurationManager.OnValueChanged(CCVars.ViewportMaximumWidth, _ => UpdateViewportRatio());
         _configurationManager.OnValueChanged(CCVars.ViewportWidth, _ => UpdateViewportRatio());
+
+        var gameplayStateLoad = UIManager.GetUIController<GameplayStateLoadController>();
+        gameplayStateLoad.OnScreenLoad += OnScreenLoad;
+    }
+
+    private void OnScreenLoad()
+    {
+        ReloadViewport();
     }
 
     private void UpdateViewportRatio()