From: Pieter-Jan Briers Date: Sat, 9 Dec 2023 02:15:06 +0000 (+0100) Subject: Fix being unable to open chat channel drop-down. (#22255) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=995f506aafd770dd6572dfc9e7bf9e18186e485a;p=space-station-14.git Fix being unable to open chat channel drop-down. (#22255) --- diff --git a/Content.Client/UserInterface/Systems/Chat/Controls/ChannelSelectorButton.cs b/Content.Client/UserInterface/Systems/Chat/Controls/ChannelSelectorButton.cs index 96a7594ff6..2431b575ef 100644 --- a/Content.Client/UserInterface/Systems/Chat/Controls/ChannelSelectorButton.cs +++ b/Content.Client/UserInterface/Systems/Chat/Controls/ChannelSelectorButton.cs @@ -2,16 +2,14 @@ using System.Numerics; using Content.Shared.Chat; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; -using Robust.Shared.Input; +using Robust.Shared.Timing; namespace Content.Client.UserInterface.Systems.Chat.Controls; -/// -/// Only needed to avoid the issue where right click on the button closes the popup -/// but leaves the button highlighted. -/// public sealed class ChannelSelectorButton : Button { + private readonly IGameTiming _gameTiming; + private readonly ChannelSelectorPopup _channelSelectorPopup; public event Action? OnChannelSelect; @@ -19,15 +17,16 @@ public sealed class ChannelSelectorButton : Button private const int SelectorDropdownOffset = 38; + private uint _frameLastPopupChanged; + public ChannelSelectorButton() { - // needed so the popup is untoggled regardless of which key is pressed when hovering this button. - // If we don't have this, then right clicking the button while it's toggled on will hide - // the popup but keep the button toggled on + _gameTiming = IoCManager.Resolve(); + Name = "ChannelSelector"; - Mode = ActionMode.Press; - EnableAllKeybinds = true; + ToggleMode = true; + OnToggled += OnSelectorButtonToggled; _channelSelectorPopup = UserInterfaceManager.CreatePopup(); _channelSelectorPopup.Selected += OnChannelSelected; @@ -46,13 +45,25 @@ public sealed class ChannelSelectorButton : Button 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) { - // needed since we need EnableAllKeybinds - don't double-send both UI click and Use - if (args.Function == EngineKeyFunctions.Use) return; + // 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); }