Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Robust.Client/Input/IKeyBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public interface IKeyBinding
bool CanRepeat { get; }
bool AllowSubCombs { get; }

bool StrictModifiers { get; }

/// <summary>
/// For a <see cref="KeyBindingType.Command"/>-type binding,
/// whether the binding should activate if UI is focused.
Expand Down
35 changes: 29 additions & 6 deletions Robust.Client/Input/InputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ public void SaveToUserData()
Type = p.BindingType,
CanFocus = p.CanFocus,
CanRepeat = p.CanRepeat,
AllowSubCombs = p.AllowSubCombs
AllowSubCombs = p.AllowSubCombs,
StrictModifiers = p.StrictModifiers
}).ToArray();

var leaveEmpty = _modifiedKeyFunctions
Expand Down Expand Up @@ -252,7 +253,22 @@ public void KeyDown(KeyEventArgs args)
PackedContainsKey(binding.PackedKeyCombo, args.Key))
{
matchedCombo = binding.PackedKeyCombo;

if (binding.StrictModifiers)
{
var isStrict = true;
for (Key i=Key.Control; i<Key.LSystem; i++)
{
if (i != binding.Mod1 &&
i != binding.Mod2 &&
i != binding.Mod3 && _keysPressed[(byte)i] == true)
{
isStrict = false;
break;
}
}
if (!isStrict)
continue;
}
bindsDown.Add(binding);

hasCanFocus |= binding.CanFocus;
Expand Down Expand Up @@ -597,7 +613,7 @@ public IKeyBinding RegisterBinding(BoundKeyFunction function, KeyBindingType bin
Key baseKey, Key? mod1, Key? mod2, Key? mod3)
{
var binding = new KeyBinding(this, function.FunctionName, bindingType, baseKey, false, false, false,
0, true, mod1 ?? Key.Unknown, mod2 ?? Key.Unknown, mod3 ?? Key.Unknown);
0, true, false, mod1 ?? Key.Unknown, mod2 ?? Key.Unknown, mod3 ?? Key.Unknown);

RegisterBinding(binding);

Expand All @@ -608,7 +624,7 @@ public IKeyBinding RegisterBinding(string function, KeyBindingType bindingType,
Key baseKey, Key? mod1, Key? mod2, Key? mod3)
{
var binding = new KeyBinding(this, function, bindingType, baseKey, false, false, false,
0, true, mod1 ?? Key.Unknown, mod2 ?? Key.Unknown, mod3 ?? Key.Unknown);
0, true, false, mod1 ?? Key.Unknown, mod2 ?? Key.Unknown, mod3 ?? Key.Unknown);

RegisterBinding(binding);

Expand All @@ -618,7 +634,7 @@ public IKeyBinding RegisterBinding(string function, KeyBindingType bindingType,
public IKeyBinding RegisterBinding(in KeyBindingRegistration reg, bool markModified = true, bool invalid = false)
{
var binding = new KeyBinding(this, reg.Function.FunctionName, reg.Type, reg.BaseKey, reg.CanFocus, reg.CanRepeat,
reg.AllowSubCombs, reg.Priority, reg.CommandWhenUIFocused, reg.Mod1, reg.Mod2, reg.Mod3);
reg.AllowSubCombs, reg.Priority, reg.CommandWhenUIFocused, reg.StrictModifiers, reg.Mod1, reg.Mod2, reg.Mod3);

RegisterBinding(binding, markModified);

Expand Down Expand Up @@ -792,13 +808,19 @@ private sealed class KeyBinding : IKeyBinding

[ViewVariables] public int Priority { get; internal set; }

/// <summary>
/// Whether the Bound Key Combination works when ONLY the specified modifier keys are pressed (prevents altgr clashes).
/// </summary>
[ViewVariables]
public bool StrictModifiers {get; internal set; }

public KeyBinding(
InputManager inputManager,
string function,
KeyBindingType bindingType,
Key baseKey,
bool canFocus, bool canRepeat, bool allowSubCombs, int priority,
bool commandWhenUIFocused,
bool commandWhenUIFocused, bool strictModifiers,
Key mod1 = Key.Unknown,
Key mod2 = Key.Unknown,
Key mod3 = Key.Unknown)
Expand All @@ -810,6 +832,7 @@ public KeyBinding(
AllowSubCombs = allowSubCombs;
Priority = priority;
CommandWhenUIFocused = commandWhenUIFocused;
StrictModifiers = strictModifiers;
_inputManager = inputManager;

PackedKeyCombo = new PackedKeyCombo(baseKey, mod1, mod2, mod3);
Expand Down
6 changes: 6 additions & 0 deletions Robust.Client/Input/KeyBindingRegistration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,11 @@ public sealed partial class KeyBindingRegistration
/// </summary>
[DataField]
public bool CommandWhenUIFocused { get; set; } = true;

/// <summary>
/// See <see cref="KeyBinding.StrictModifiers"/>
/// </summary>
[DataField]
public bool StrictModifiers = false;
}
}
Loading