diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index bad2cba24..f9f964643 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -43,7 +43,7 @@ END TEMPLATE--> ### Bugfixes -*None yet* +* Fixed keyboard events always propagating to the default viewport if `devwindow` is open. ### Other diff --git a/Robust.Client/Input/IInputManager.cs b/Robust.Client/Input/IInputManager.cs index 84e5742a6..9d0b21d1e 100644 --- a/Robust.Client/Input/IInputManager.cs +++ b/Robust.Client/Input/IInputManager.cs @@ -74,7 +74,7 @@ namespace Robust.Client.Input /// /// UIKeyBindStateChanged is called when a keybind is found. /// - event Func? UIKeyBindStateChanged; + event Func UIKeyBindStateChanged; /// /// If UIKeyBindStateChanged did not handle the BoundKeyEvent, KeyBindStateChanged is called. diff --git a/Robust.Client/Input/InputManager.cs b/Robust.Client/Input/InputManager.cs index 522cae844..dbe2cdca1 100644 --- a/Robust.Client/Input/InputManager.cs +++ b/Robust.Client/Input/InputManager.cs @@ -8,6 +8,7 @@ using System.Runtime.InteropServices; using System.Text; using JetBrains.Annotations; using Robust.Client.UserInterface; +using Robust.Shared.Collections; using Robust.Shared.Console; using Robust.Shared.ContentPack; using Robust.Shared.Input; @@ -63,6 +64,8 @@ namespace Robust.Client.Input [ViewVariables] private readonly List _bindings = new(); private readonly bool[] _keysPressed = new bool[256]; + private ValueList> _uiKeyBindStateChanged; + /// [ViewVariables] public BoundKeyMap NetworkBindMap { get; private set; } = default!; @@ -72,7 +75,11 @@ namespace Robust.Client.Input public IInputContextContainer Contexts { get; } = new InputContextContainer(); /// - public event Func? UIKeyBindStateChanged; + public event Func UIKeyBindStateChanged + { + add => _uiKeyBindStateChanged.Add(value); + remove => _uiKeyBindStateChanged.Remove(value); + } /// public event Action? KeyBindStateChanged; @@ -388,7 +395,14 @@ namespace Robust.Client.Input // UI returns true here into blockPass if it wants to prevent us from giving input events // to the viewport, but doesn't want it hard-handled so we keep processing possible key actions. - var blockPass = UIKeyBindStateChanged?.Invoke(eventArgs); + // + // I wouldn't normally use an unordered event subscription, but hey I'm fixing a bloody bug here ok. + var blockPass = false; + foreach (var stateChangedHandler in _uiKeyBindStateChanged) + { + blockPass |= stateChangedHandler(eventArgs); + } + if ((state == BoundKeyState.Up || (!(blockPass == true || eventArgs.Handled) && !uiOnly)) && _currentlyFindingViewport) {