]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
More UI fixes (#22431)
authorPieter-Jan Briers <pieterjan.briers+git@gmail.com>
Wed, 13 Dec 2023 02:02:19 +0000 (03:02 +0100)
committerGitHub <noreply@github.com>
Wed, 13 Dec 2023 02:02:19 +0000 (19:02 -0700)
* Fix chat filter button

Oh look, the popup code was copy pasted between chat filter and channel selector.

Hilarious.

Anyways same stuff as 995f506aafd770dd6572dfc9e7bf9e18186e485a. I pulled it all out into a base class so NO MORE COPY PASTE.

Fixes #22360

* Remove all further EnableAllKeybinds buttons.

Fixes #22346

Yeah none of these are valid use cases, why is this set...

12 files changed:
Content.Client/Administration/UI/CustomControls/PlayerListControl.xaml.cs
Content.Client/Administration/UI/Tabs/ObjectsTab/ObjectsTabEntry.xaml
Content.Client/Administration/UI/Tabs/PlayerTab/PlayerTabEntry.xaml
Content.Client/Administration/UI/Tabs/PlayerTab/PlayerTabHeader.xaml
Content.Client/Administration/UI/Tabs/PlayerTab/PlayerTabHeader.xaml.cs
Content.Client/Info/PlaytimeStats/PlaytimeStatsEntry.xaml
Content.Client/Info/PlaytimeStats/PlaytimeStatsHeader.cs
Content.Client/Info/PlaytimeStats/PlaytimeStatsHeader.xaml
Content.Client/UserInterface/Systems/Chat/Controls/ChannelFilterButton.cs
Content.Client/UserInterface/Systems/Chat/Controls/ChannelSelectorButton.cs
Content.Client/UserInterface/Systems/Chat/Controls/ChatPopupButton.cs [new file with mode: 0644]
Content.Client/UserInterface/Systems/Chat/Widgets/ChatBox.xaml.cs

index 39749f8ac6f60a21fb9cea45438d638f0a8789c0..050262cc991d6346c868f928037e372ef464e93b 100644 (file)
@@ -122,7 +122,7 @@ namespace Content.Client.Administration.UI.CustomControls
                     }
                 }
             });
-            button.EnableAllKeybinds = true;
+
             button.AddStyleClass(ListContainer.StyleClassListContainerButton);
         }
     }
index 92d5278ab5cf4970f3ff467d37ac8f2e0d8c38b8..0f6975e3656d94176260abaef25526e4cdfa51e6 100644 (file)
@@ -1,6 +1,5 @@
 <ContainerButton xmlns="https://spacestation14.io"
-                 xmlns:customControls="clr-namespace:Content.Client.Administration.UI.CustomControls"
-                 EnableAllKeybinds="True">
+                 xmlns:customControls="clr-namespace:Content.Client.Administration.UI.CustomControls">
     <PanelContainer Name="BackgroundColorPanel"/>
     <BoxContainer Orientation="Horizontal"
                   HorizontalExpand="True"
index 883681a28a954d67b627c6fa57eebe7b72cd13b4..8ac90305ca91a6a08f275c13170957ff1943cbea 100644 (file)
@@ -1,6 +1,5 @@
 <ContainerButton xmlns="https://spacestation14.io"
-                 xmlns:customControls="clr-namespace:Content.Client.Administration.UI.CustomControls"
-                 EnableAllKeybinds="True">
+                 xmlns:customControls="clr-namespace:Content.Client.Administration.UI.CustomControls">
     <PanelContainer Name="BackgroundColorPanel"/>
     <BoxContainer Orientation="Horizontal"
                   HorizontalExpand="True"
index 001d56efcb28f65c992d5f02d736965c2dab00be..2fd3f31b90329f4e62855a746180747d6668f946 100644 (file)
@@ -1,6 +1,5 @@
-<ContainerButton xmlns="https://spacestation14.io"
-                 xmlns:cc="clr-namespace:Content.Client.Administration.UI.CustomControls"
-                 EnableAllKeybinds="True">
+<Control xmlns="https://spacestation14.io"
+                 xmlns:cc="clr-namespace:Content.Client.Administration.UI.CustomControls">
     <PanelContainer Name="BackgroundColorPanel" Access="Public"/>
     <BoxContainer Orientation="Horizontal"
                   HorizontalExpand="True"
@@ -39,4 +38,4 @@
                Text="{Loc player-tab-playtime}"
                MouseFilter="Pass"/>
     </BoxContainer>
-</ContainerButton>
+</Control>
index 98de6dafa98dfa05e3e6ea9754a6d2dfa535bec1..cf7ceff23c40190b55719c0d4374f51a44d9621a 100644 (file)
@@ -7,7 +7,7 @@ using Robust.Shared.Input;
 namespace Content.Client.Administration.UI.Tabs.PlayerTab;
 
 [GenerateTypedNameReferences]
-public sealed partial class PlayerTabHeader : ContainerButton
+public sealed partial class PlayerTabHeader : Control
 {
     public event Action<Header>? OnHeaderClicked;
 
index 97a66e5cc24744a91b6c7866d1f65421e78ccaab..0f973b768900f698ca8ffbe06bff2ba6f903f87d 100644 (file)
@@ -1,6 +1,5 @@
 <ContainerButton xmlns="https://spacestation14.io"
-                 xmlns:customControls1="clr-namespace:Content.Client.Administration.UI.CustomControls"
-                 EnableAllKeybinds="True">
+                 xmlns:customControls1="clr-namespace:Content.Client.Administration.UI.CustomControls">
     <PanelContainer Name="BackgroundColorPanel"/>
     <BoxContainer Orientation="Horizontal"
                   HorizontalExpand="True"
index b005c641f7c2b5c27bbf92ad65e8af1d937cdcbc..8bab3231c25d0b1f941c51d66b546660751a2c52 100644 (file)
@@ -7,7 +7,7 @@ using Robust.Shared.Input;
 namespace Content.Client.Info.PlaytimeStats;
 
 [GenerateTypedNameReferences]
-public sealed partial class PlaytimeStatsHeader : ContainerButton
+public sealed partial class PlaytimeStatsHeader : Control
 {
     public event Action<Header, SortDirection>? OnHeaderClicked;
     private SortDirection _roleDirection = SortDirection.Ascending;
index 4cf4d8e2ccc4ef64a543b02cbc2729461906e224..d83e794472c16a93b18fe4242c5efacf53b7dc71 100644 (file)
@@ -1,6 +1,5 @@
-<ContainerButton xmlns="https://spacestation14.io"
-                 xmlns:customControls="clr-namespace:Content.Client.Administration.UI.CustomControls"
-                 EnableAllKeybinds="True">
+<Control xmlns="https://spacestation14.io"
+                 xmlns:customControls="clr-namespace:Content.Client.Administration.UI.CustomControls">
     <PanelContainer Name="BackgroundColorPlaytimePanel" Access="Public"/>
     <BoxContainer Orientation="Vertical"
                   HorizontalExpand="True">
@@ -26,4 +25,4 @@
         <!-- Horizontal Separator -->
         <customControls:HSeparator/>
     </BoxContainer>
-</ContainerButton>
+</Control>
index d19f167587fc2ed2e7daa2b839dabfb88e882b72..c5b810ced318164b962251815974d09fbf37eb34 100644 (file)
@@ -1,20 +1,18 @@
 using System.Numerics;
 using Content.Client.Resources;
 using Robust.Client.ResourceManagement;
-using Robust.Client.UserInterface;
 using Robust.Client.UserInterface.Controls;
-using Robust.Shared.Input;
 
 namespace Content.Client.UserInterface.Systems.Chat.Controls;
 
-public sealed class ChannelFilterButton : ContainerButton
+public sealed class ChannelFilterButton : ChatPopupButton<ChannelFilterPopup>
 {
     private static readonly Color ColorNormal = Color.FromHex("#7b7e9e");
     private static readonly Color ColorHovered = Color.FromHex("#9699bb");
     private static readonly Color ColorPressed = Color.FromHex("#789B8C");
     private readonly TextureRect? _textureRect;
-    public readonly ChannelFilterPopup ChatFilterPopup;
     private readonly ChatUIController _chatUIController;
+
     private const int FilterDropdownOffset = 120;
 
     public ChannelFilterButton()
@@ -23,10 +21,6 @@ public sealed class ChannelFilterButton : ContainerButton
         var filterTexture = IoCManager.Resolve<IResourceCache>()
             .GetTexture("/Textures/Interface/Nano/filter.svg.96dpi.png");
 
-        // needed for same reason as ChannelSelectorButton
-        Mode = ActionMode.Press;
-        EnableAllKeybinds = true;
-
         AddChild(
             (_textureRect = new TextureRect
             {
@@ -35,42 +29,19 @@ public sealed class ChannelFilterButton : ContainerButton
                 VerticalAlignment = VAlignment.Center
             })
         );
-        ToggleMode = true;
-        OnToggled += OnFilterButtonToggled;
-        ChatFilterPopup = UserInterfaceManager.CreatePopup<ChannelFilterPopup>();
-        ChatFilterPopup.OnVisibilityChanged += PopupVisibilityChanged;
-
-        _chatUIController.FilterableChannelsChanged += ChatFilterPopup.SetChannels;
-        _chatUIController.UnreadMessageCountsUpdated += ChatFilterPopup.UpdateUnread;
-        ChatFilterPopup.SetChannels(_chatUIController.FilterableChannels);
-    }
-
-    private void PopupVisibilityChanged(Control control)
-    {
-        Pressed = control.Visible;
-    }
 
-    private void OnFilterButtonToggled(ButtonToggledEventArgs args)
-    {
-        if (args.Pressed)
-        {
-            var globalPos = GlobalPosition;
-            var (minX, minY) = ChatFilterPopup.MinSize;
-            var box = UIBox2.FromDimensions(globalPos - new Vector2(FilterDropdownOffset, 0),
-                new Vector2(Math.Max(minX, ChatFilterPopup.MinWidth), minY));
-            ChatFilterPopup.Open(box);
-        }
-        else
-        {
-            ChatFilterPopup.Close();
-        }
+        _chatUIController.FilterableChannelsChanged += Popup.SetChannels;
+        _chatUIController.UnreadMessageCountsUpdated += Popup.UpdateUnread;
+        Popup.SetChannels(_chatUIController.FilterableChannels);
     }
 
-    protected override void KeyBindDown(GUIBoundKeyEventArgs args)
+    protected override UIBox2 GetPopupPosition()
     {
-        // needed since we need EnableAllKeybinds - don't double-send both UI click and Use
-        if (args.Function == EngineKeyFunctions.Use) return;
-        base.KeyBindDown(args);
+        var globalPos = GlobalPosition;
+        var (minX, minY) = Popup.MinSize;
+        return UIBox2.FromDimensions(
+            globalPos - new Vector2(FilterDropdownOffset, 0),
+            new Vector2(Math.Max(minX, Popup.MinWidth), minY));
     }
 
     private void UpdateChildColors()
@@ -114,7 +85,7 @@ public sealed class ChannelFilterButton : ContainerButton
         if (!disposing)
             return;
 
-        _chatUIController.FilterableChannelsChanged -= ChatFilterPopup.SetChannels;
-        _chatUIController.UnreadMessageCountsUpdated -= ChatFilterPopup.UpdateUnread;
+        _chatUIController.FilterableChannelsChanged -= Popup.SetChannels;
+        _chatUIController.UnreadMessageCountsUpdated -= Popup.UpdateUnread;
     }
 }
index 2431b575ef27f53b07b92c839bb00c445ab6512f..25cf851c7bb0c588d4a7d2cafdc6cb5811542478 100644 (file)
@@ -1,80 +1,51 @@
 using System.Numerics;
 using Content.Shared.Chat;
-using Robust.Client.UserInterface;
-using Robust.Client.UserInterface.Controls;
-using Robust.Shared.Timing;
 
 namespace Content.Client.UserInterface.Systems.Chat.Controls;
 
-public sealed class ChannelSelectorButton : Button
+public sealed class ChannelSelectorButton : ChatPopupButton<ChannelSelectorPopup>
 {
-    private readonly IGameTiming _gameTiming;
-
-    private readonly ChannelSelectorPopup _channelSelectorPopup;
     public event Action<ChatSelectChannel>? OnChannelSelect;
 
     public ChatSelectChannel SelectedChannel { get; private set; }
 
     private const int SelectorDropdownOffset = 38;
 
-    private uint _frameLastPopupChanged;
-
     public ChannelSelectorButton()
     {
-        _gameTiming = IoCManager.Resolve<IGameTiming>();
-
         Name = "ChannelSelector";
 
-        ToggleMode = true;
+        Popup.Selected += OnChannelSelected;
 
-        OnToggled += OnSelectorButtonToggled;
-        _channelSelectorPopup = UserInterfaceManager.CreatePopup<ChannelSelectorPopup>();
-        _channelSelectorPopup.Selected += OnChannelSelected;
-        _channelSelectorPopup.OnVisibilityChanged += OnPopupVisibilityChanged;
-
-        if (_channelSelectorPopup.FirstChannel is { } firstSelector)
+        if (Popup.FirstChannel is { } firstSelector)
         {
             Select(firstSelector);
         }
     }
 
-    private void OnChannelSelected(ChatSelectChannel channel)
+    protected override UIBox2 GetPopupPosition()
     {
-        Select(channel);
+        var globalLeft = GlobalPosition.X;
+        var globalBot = GlobalPosition.Y + Height;
+        return UIBox2.FromDimensions(
+            new Vector2(globalLeft, globalBot),
+            new Vector2(SizeBox.Width, SelectorDropdownOffset));
     }
 
-    private void OnPopupVisibilityChanged(Control control)
-    {
-        // If the popup gets closed (e.g. by clicking anywhere else on the screen)
-        // We clear the button pressed state.
-
-        Pressed = control.Visible;
-        _frameLastPopupChanged = _gameTiming.CurFrame;
-    }
-
-    protected override void KeyBindDown(GUIBoundKeyEventArgs args)
+    private void OnChannelSelected(ChatSelectChannel channel)
     {
-        // If you try to close the popup by clicking on the button again the following would happen:
-        // The UI system would see that you clicked outside a popup, and would close it.
-        // Because of the above logic, that sets the button to UNPRESSED.
-        // THEN, it would propagate the keyboard event to us, the chat selector...
-        // And we would become pressed again.
-        // As a workaround, we check the frame the popup was last dismissed (above)
-        // and don't allow changing it again this frame.
-        if (_frameLastPopupChanged == _gameTiming.CurFrame)
-            return;
-
-        base.KeyBindDown(args);
+        Select(channel);
     }
 
     public void Select(ChatSelectChannel channel)
     {
-        if (_channelSelectorPopup.Visible)
+        if (Popup.Visible)
         {
-            _channelSelectorPopup.Close();
+            Popup.Close();
         }
 
-        if (SelectedChannel == channel) return;
+        if (SelectedChannel == channel)
+            return;
         SelectedChannel = channel;
         OnChannelSelect?.Invoke(channel);
     }
@@ -102,19 +73,4 @@ public sealed class ChannelSelectorButton : Button
         Text = radio != null ? Loc.GetString(radio.Name) : ChannelSelectorName(channel);
         Modulate = radio?.Color ?? ChannelSelectColor(channel);
     }
-
-    private void OnSelectorButtonToggled(ButtonToggledEventArgs args)
-    {
-        if (args.Pressed)
-        {
-            var globalLeft = GlobalPosition.X;
-            var globalBot = GlobalPosition.Y + Height;
-            var box = UIBox2.FromDimensions(new Vector2(globalLeft, globalBot), new Vector2(SizeBox.Width, SelectorDropdownOffset));
-            _channelSelectorPopup.Open(box);
-        }
-        else
-        {
-            _channelSelectorPopup.Close();
-        }
-    }
 }
diff --git a/Content.Client/UserInterface/Systems/Chat/Controls/ChatPopupButton.cs b/Content.Client/UserInterface/Systems/Chat/Controls/ChatPopupButton.cs
new file mode 100644 (file)
index 0000000..e284eda
--- /dev/null
@@ -0,0 +1,70 @@
+using Robust.Client.UserInterface;
+using Robust.Client.UserInterface.Controls;
+using Robust.Shared.Timing;
+
+namespace Content.Client.UserInterface.Systems.Chat.Controls;
+
+// NO MORE FUCKING COPY PASTING THIS SHIT
+
+/// <summary>
+/// Base class for button that toggles a popup-window.
+/// Base type of <see cref="ChannelFilterButton"/> and <see cref="ChannelSelectorButton"/>.
+/// </summary>
+public abstract class ChatPopupButton<TPopup> : Button
+    where TPopup : Popup, new()
+{
+    private readonly IGameTiming _gameTiming;
+
+    public readonly TPopup Popup;
+
+    private uint _frameLastPopupChanged;
+
+    protected ChatPopupButton()
+    {
+        _gameTiming = IoCManager.Resolve<IGameTiming>();
+
+        ToggleMode = true;
+        OnToggled += OnButtonToggled;
+
+        Popup = UserInterfaceManager.CreatePopup<TPopup>();
+        Popup.OnVisibilityChanged += OnPopupVisibilityChanged;
+    }
+
+    protected override void KeyBindDown(GUIBoundKeyEventArgs args)
+    {
+        // If you try to close the popup by clicking on the button again the following would happen:
+        // The UI system would see that you clicked outside a popup, and would close it.
+        // Because of the above logic, that sets the button to UNPRESSED.
+        // THEN, it would propagate the keyboard event to us, the chat selector...
+        // And we would become pressed again.
+        // As a workaround, we check the frame the popup was last dismissed (above)
+        // and don't allow changing it again this frame.
+        if (_frameLastPopupChanged == _gameTiming.CurFrame)
+            return;
+
+        base.KeyBindDown(args);
+    }
+
+    protected abstract UIBox2 GetPopupPosition();
+
+    private void OnButtonToggled(ButtonToggledEventArgs args)
+    {
+        if (args.Pressed)
+        {
+            Popup.Open(GetPopupPosition());
+        }
+        else
+        {
+            Popup.Close();
+        }
+    }
+
+    private void OnPopupVisibilityChanged(Control control)
+    {
+        // If the popup gets closed (e.g. by clicking anywhere else on the screen)
+        // We clear the button pressed state.
+
+        Pressed = control.Visible;
+        _frameLastPopupChanged = _gameTiming.CurFrame;
+    }
+}
index 79d23a94beeb87cf363fff8b4c32fc16b52454ef..936e7cdecd4b6113b0ff82b1b99f8f267817201f 100644 (file)
@@ -36,7 +36,7 @@ public partial class ChatBox : UIWidget
         ChatInput.Input.OnKeyBindDown += OnKeyBindDown;
         ChatInput.Input.OnTextChanged += OnTextChanged;
         ChatInput.ChannelSelector.OnChannelSelect += OnChannelSelect;
-        ChatInput.FilterButton.ChatFilterPopup.OnChannelFilter += OnChannelFilter;
+        ChatInput.FilterButton.Popup.OnChannelFilter += OnChannelFilter;
 
         _controller = UserInterfaceManager.GetUIController<ChatUIController>();
         _controller.MessageAdded += OnMessageAdded;
@@ -51,7 +51,7 @@ public partial class ChatBox : UIWidget
     private void OnMessageAdded(ChatMessage msg)
     {
         Logger.DebugS("chat", $"{msg.Channel}: {msg.Message}");
-        if (!ChatInput.FilterButton.ChatFilterPopup.IsActive(msg.Channel))
+        if (!ChatInput.FilterButton.Popup.IsActive(msg.Channel))
         {
             return;
         }