Fix keyboard events always propagating to default viewport if devwindow is open.

This commit is contained in:
Pieter-Jan Briers
2023-05-30 21:29:39 +02:00
parent 1ca68a89e7
commit 3164b58300
3 changed files with 18 additions and 4 deletions

View File

@@ -43,7 +43,7 @@ END TEMPLATE-->
### Bugfixes
*None yet*
* Fixed keyboard events always propagating to the default viewport if `devwindow` is open.
### Other

View File

@@ -74,7 +74,7 @@ namespace Robust.Client.Input
/// <summary>
/// UIKeyBindStateChanged is called when a keybind is found.
/// </summary>
event Func<BoundKeyEventArgs, bool>? UIKeyBindStateChanged;
event Func<BoundKeyEventArgs, bool> UIKeyBindStateChanged;
/// <summary>
/// If UIKeyBindStateChanged did not handle the BoundKeyEvent, KeyBindStateChanged is called.

View File

@@ -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<KeyBinding> _bindings = new();
private readonly bool[] _keysPressed = new bool[256];
private ValueList<Func<BoundKeyEventArgs, bool>> _uiKeyBindStateChanged;
/// <inheritdoc />
[ViewVariables]
public BoundKeyMap NetworkBindMap { get; private set; } = default!;
@@ -72,7 +75,11 @@ namespace Robust.Client.Input
public IInputContextContainer Contexts { get; } = new InputContextContainer();
/// <inheritdoc />
public event Func<BoundKeyEventArgs, bool>? UIKeyBindStateChanged;
public event Func<BoundKeyEventArgs, bool> UIKeyBindStateChanged
{
add => _uiKeyBindStateChanged.Add(value);
remove => _uiKeyBindStateChanged.Remove(value);
}
/// <inheritdoc />
public event Action<ViewportBoundKeyEventArgs>? 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)
{