]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix vote popup (#14940)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Wed, 29 Mar 2023 08:36:30 +0000 (19:36 +1100)
committerGitHub <noreply@github.com>
Wed, 29 Mar 2023 08:36:30 +0000 (19:36 +1100)
Content.Client/UserInterface/Screens/DefaultGameScreen.xaml
Content.Client/UserInterface/Screens/DefaultGameScreen.xaml.cs
Content.Client/UserInterface/Screens/SeparatedChatGameScreen.xaml
Content.Client/UserInterface/Screens/SeparatedChatGameScreen.xaml.cs
Content.Client/UserInterface/Systems/Vote/VoteUIController.cs [new file with mode: 0644]
Content.Client/Voting/VoteManager.cs

index a6d489147a1c7edf1097bffb610e83f595f359ba..703bf60e95fd627b3158c828a3fddbcfc80be3ec 100644 (file)
     <LayoutContainer Name="ViewportContainer" HorizontalExpand="True" VerticalExpand="True">
         <controls:MainViewport Name="MainViewport"/>
     </LayoutContainer>
-    <menuBar:GameTopMenuBar Name="TopBar" Access="Protected" />
+    <BoxContainer Name="TopLeft" Access="Protected" Orientation="Vertical">
+        <BoxContainer Orientation="Horizontal">
+            <menuBar:GameTopMenuBar Name="TopBar" Access="Protected" />
+            <!-- Buffer so big votes don't skew it -->
+            <Control/>
+        </BoxContainer>
+        <Control Name="VoteMenu" Access="Public" Margin="0 10 0 10"/>
+    </BoxContainer>
     <widgets:GhostGui Name="Ghost" Access="Protected" />
     <hotbar:HotbarGui Name="Hotbar" Access="Protected" />
     <actions:ActionsBar Name="Actions" Access="Protected" />
index ea69597ce2015e8135885ffcc6384601c9c9cac3..acaefeafa7a1a79865d0a91ec4b701da4d8906eb 100644 (file)
@@ -1,7 +1,5 @@
 using Content.Client.UserInterface.Systems.Chat.Widgets;
 using Robust.Client.AutoGenerated;
-using Robust.Client.UserInterface;
-using Robust.Client.UserInterface.Controls;
 using Robust.Client.UserInterface.XAML;
 
 namespace Content.Client.UserInterface.Screens;
@@ -17,7 +15,7 @@ public sealed partial class DefaultGameScreen : InGameScreen
 
         SetAnchorPreset(MainViewport, LayoutPreset.Wide);
         SetAnchorPreset(ViewportContainer, LayoutPreset.Wide);
-        SetAnchorAndMarginPreset(TopBar, LayoutPreset.TopLeft, margin: 10);
+        SetAnchorAndMarginPreset(TopLeft, LayoutPreset.TopLeft, margin: 10);
         SetAnchorAndMarginPreset(Actions, LayoutPreset.BottomLeft, margin: 10);
         SetAnchorAndMarginPreset(Ghost, LayoutPreset.BottomWide, margin: 80);
         SetAnchorAndMarginPreset(Hotbar, LayoutPreset.BottomWide, margin: 5);
index 80e56694f31a3ed5405d14f401c0889282cc8e8b..de3804edd584d6066a12267155cfea98a9abf7cd 100644 (file)
@@ -16,6 +16,7 @@
     <controls:RecordedSplitContainer Name="ScreenContainer" HorizontalExpand="True" VerticalExpand="True" SplitWidth="0" StretchDirection="TopLeft">
         <LayoutContainer Name="ViewportContainer" HorizontalExpand="True" VerticalExpand="True">
             <controls:MainViewport Name="MainViewport"/>
+            <Control Name="VoteMenu" Access="Public"/>
             <widgets:GhostGui Name="Ghost" Access="Protected" />
             <hotbar:HotbarGui Name="Hotbar" Access="Protected" />
             <actions:ActionsBar Name="Actions" Access="Protected" />
index da7903766feafc6dcb7baabc4bcfdd671c94e7ea..7ee01516ff4e98dbbeda9875678fd0e82276f6d3 100644 (file)
@@ -1,6 +1,5 @@
 using Content.Client.UserInterface.Systems.Chat.Widgets;
 using Robust.Client.AutoGenerated;
-using Robust.Client.UserInterface;
 using Robust.Client.UserInterface.Controls;
 using Robust.Client.UserInterface.XAML;
 
@@ -18,6 +17,7 @@ public sealed partial class SeparatedChatGameScreen : InGameScreen
         SetAnchorPreset(ScreenContainer, LayoutPreset.Wide);
         SetAnchorPreset(ViewportContainer, LayoutPreset.Wide);
         SetAnchorPreset(MainViewport, LayoutPreset.Wide);
+        SetAnchorAndMarginPreset(VoteMenu, LayoutPreset.TopLeft, margin: 10);
         SetAnchorAndMarginPreset(Actions, LayoutPreset.BottomLeft, margin: 10);
         SetAnchorAndMarginPreset(Ghost, LayoutPreset.BottomWide, margin: 80);
         SetAnchorAndMarginPreset(Hotbar, LayoutPreset.BottomWide, margin: 5);
diff --git a/Content.Client/UserInterface/Systems/Vote/VoteUIController.cs b/Content.Client/UserInterface/Systems/Vote/VoteUIController.cs
new file mode 100644 (file)
index 0000000..809134b
--- /dev/null
@@ -0,0 +1,37 @@
+using Content.Client.UserInterface.Screens;
+using Content.Client.UserInterface.Systems.Gameplay;
+using Content.Client.Voting;
+using Robust.Client.UserInterface.Controllers;
+
+namespace Content.Client.UserInterface.Systems.Vote;
+
+public sealed class VoteUIController : UIController
+{
+    [Dependency] private readonly IVoteManager _votes = default!;
+
+    public override void Initialize()
+    {
+        base.Initialize();
+        var gameplayStateLoad = UIManager.GetUIController<GameplayStateLoadController>();
+        gameplayStateLoad.OnScreenLoad += OnScreenLoad;
+        gameplayStateLoad.OnScreenUnload += OnScreenUnload;
+    }
+
+    private void OnScreenLoad()
+    {
+        switch (UIManager.ActiveScreen)
+        {
+            case DefaultGameScreen game:
+                _votes.SetPopupContainer(game.VoteMenu);
+                break;
+            case SeparatedChatGameScreen separated:
+                _votes.SetPopupContainer(separated.VoteMenu);
+                break;
+        }
+    }
+
+    private void OnScreenUnload()
+    {
+        _votes.ClearPopupContainer();
+    }
+}
index e379ca6803b347365fdefed7f31a501abe302b6a..a587ec7240d635d6b0c2523877f3a80fd7de9077 100644 (file)
@@ -95,6 +95,13 @@ namespace Content.Client.Voting
             }
 
             _popupContainer = container;
+            SetVoteData();
+        }
+
+        private void SetVoteData()
+        {
+            if (_popupContainer == null)
+                return;
 
             foreach (var (vId, vote) in _votes)
             {
@@ -121,9 +128,13 @@ namespace Content.Client.Voting
                 @new = true;
                 IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<AudioSystem>()
                     .PlayGlobal("/Audio/Effects/voteding.ogg", Filter.Local(), false);
-                // TODO: It would be better if this used a per-state container, i.e. a container
-                // for the lobby and each HUD layout.
-                SetPopupContainer(_userInterfaceManager.WindowRoot);
+
+                // Refresh
+                var container = _popupContainer;
+                ClearPopupContainer();
+
+                if (container != null)
+                    SetPopupContainer(container);
 
                 // New vote from the server.
                 var vote = new ActiveVote(voteId)
@@ -142,6 +153,7 @@ namespace Content.Client.Voting
                 _votes.Remove(voteId);
                 if (_votePopups.TryGetValue(voteId, out var toRemove))
                 {
+
                     toRemove.Orphan();
                     _votePopups.Remove(voteId);
                 }