Skip to content

Commit 4cc9dbe

Browse files
committed
Create enum for input/hotkey priority settings.
1 parent 18bf16c commit 4cc9dbe

File tree

5 files changed

+39
-34
lines changed

5 files changed

+39
-34
lines changed

src/BizHawk.Client.Common/config/Config.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,14 @@ public void ResolveDefaults()
106106
public Dictionary<string, string> FirmwareUserSpecifications { get; set; } = new Dictionary<string, string>();
107107

108108
// General Client Settings
109-
public int InputHotkeyOverrideOptions { get; set; }
109+
public enum InputPriority
110+
{
111+
BOTH,
112+
INPUT,
113+
HOTKEY,
114+
}
115+
116+
public InputPriority InputHotkeyOverrideOptions { get; set; }
110117
public bool NoMixedInputHokeyOverride { get; set; }
111118

112119
public bool StackOSDMessages { get; set; } = true;

src/BizHawk.Client.Common/inputAdapters/InputManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ public void ProcessInput(IPhysicalInputSource source, Func<string, bool> process
161161
var hotkeyTriggers = ClientControls.SearchBindings(ie.LogicalButton.ToString());
162162
bool isEmuInput = ActiveController.HasBinding(ie.LogicalButton.ToString());
163163

164-
bool shouldDoHotkey = config.InputHotkeyOverrideOptions != 1;
165-
bool shouldDoEmuInput = config.InputHotkeyOverrideOptions != 2;
164+
bool shouldDoHotkey = config.InputHotkeyOverrideOptions != Config.InputPriority.INPUT;
165+
bool shouldDoEmuInput = config.InputHotkeyOverrideOptions != Config.InputPriority.HOTKEY;
166166
if (shouldDoEmuInput && !isEmuInput) shouldDoHotkey = true;
167167

168168
bool didHotkey = false;

src/BizHawk.Client.EmuHawk/MainForm.Events.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -726,13 +726,13 @@ private void KeyPriorityMenuItem_DropDownOpened(object sender, EventArgs e)
726726
switch (Config.InputHotkeyOverrideOptions)
727727
{
728728
default:
729-
case 0:
729+
case Config.InputPriority.BOTH:
730730
BothHkAndControllerMenuItem.Checked = true;
731731
break;
732-
case 1:
732+
case Config.InputPriority.INPUT:
733733
InputOverHkMenuItem.Checked = true;
734734
break;
735-
case 2:
735+
case Config.InputPriority.HOTKEY:
736736
HkOverInputMenuItem.Checked = true;
737737
break;
738738
}
@@ -961,19 +961,19 @@ private void MinimizeSkippingMenuItem_Click(object sender, EventArgs e)
961961

962962
private void BothHkAndControllerMenuItem_Click(object sender, EventArgs e)
963963
{
964-
Config.InputHotkeyOverrideOptions = 0;
964+
Config.InputHotkeyOverrideOptions = Config.InputPriority.BOTH;
965965
UpdateKeyPriorityIcon();
966966
}
967967

968968
private void InputOverHkMenuItem_Click(object sender, EventArgs e)
969969
{
970-
Config.InputHotkeyOverrideOptions = 1;
970+
Config.InputHotkeyOverrideOptions = Config.InputPriority.INPUT;
971971
UpdateKeyPriorityIcon();
972972
}
973973

974974
private void HkOverInputMenuItem_Click(object sender, EventArgs e)
975975
{
976-
Config.InputHotkeyOverrideOptions = 2;
976+
Config.InputHotkeyOverrideOptions = Config.InputPriority.HOTKEY;
977977
UpdateKeyPriorityIcon();
978978
}
979979

@@ -1457,9 +1457,9 @@ private void KeyPriorityStatusLabel_Click(object sender, EventArgs e)
14571457
{
14581458
Config.InputHotkeyOverrideOptions = Config.InputHotkeyOverrideOptions switch
14591459
{
1460-
1 => 2,
1461-
2 => Config.NoMixedInputHokeyOverride ? 1 : 0,
1462-
_ => 1,
1460+
Config.InputPriority.INPUT => Config.InputPriority.HOTKEY,
1461+
Config.InputPriority.HOTKEY => Config.NoMixedInputHokeyOverride ? Config.InputPriority.INPUT : Config.InputPriority.BOTH,
1462+
_ => Config.InputPriority.INPUT,
14631463
};
14641464
UpdateKeyPriorityIcon();
14651465
}

src/BizHawk.Client.EmuHawk/MainForm.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2751,15 +2751,15 @@ private void UpdateKeyPriorityIcon()
27512751
switch (Config.InputHotkeyOverrideOptions)
27522752
{
27532753
default:
2754-
case 0:
2754+
case Config.InputPriority.BOTH:
27552755
KeyPriorityStatusLabel.Image = Properties.Resources.Both;
27562756
KeyPriorityStatusLabel.ToolTipText = "Key priority: Allow both hotkeys and controller buttons";
27572757
break;
2758-
case 1:
2758+
case Config.InputPriority.INPUT:
27592759
KeyPriorityStatusLabel.Image = Properties.Resources.GameController;
27602760
KeyPriorityStatusLabel.ToolTipText = "Key priority: Controller buttons will override hotkeys";
27612761
break;
2762-
case 2:
2762+
case Config.InputPriority.HOTKEY:
27632763
KeyPriorityStatusLabel.Image = Properties.Resources.HotKeys;
27642764
KeyPriorityStatusLabel.ToolTipText = "Key priority: Hotkeys will override controller buttons";
27652765
break;
@@ -2859,28 +2859,30 @@ private void UpdateCoreStatusBarButton()
28592859

28602860
private void ToggleKeyPriority()
28612861
{
2862-
Config.InputHotkeyOverrideOptions++;
2863-
if (Config.InputHotkeyOverrideOptions > 2)
2862+
int priority = (int)Config.InputHotkeyOverrideOptions;
2863+
priority++;
2864+
if (priority > 2)
28642865
{
2865-
Config.InputHotkeyOverrideOptions = 0;
2866+
priority = 0;
28662867
}
28672868

2868-
if (Config.NoMixedInputHokeyOverride && Config.InputHotkeyOverrideOptions == 0)
2869+
if (Config.NoMixedInputHokeyOverride && priority == 0)
28692870
{
2870-
Config.InputHotkeyOverrideOptions = 1;
2871+
priority = 1;
28712872
}
28722873

2874+
Config.InputHotkeyOverrideOptions = (Config.InputPriority)priority;
28732875
UpdateKeyPriorityIcon();
28742876
switch (Config.InputHotkeyOverrideOptions)
28752877
{
2876-
case 0:
2878+
case Config.InputPriority.BOTH:
28772879
AddOnScreenMessage("Key priority set to Both Hotkey and Input");
28782880
break;
2879-
case 1:
2881+
case Config.InputPriority.INPUT:
28802882
AddOnScreenMessage("Key priority set to Input over Hotkey");
28812883
break;
2882-
case 2:
2883-
AddOnScreenMessage("Key priority set to Input");
2884+
case Config.InputPriority.HOTKEY:
2885+
AddOnScreenMessage("Key priority set to Hotkey over Input");
28842886
break;
28852887
}
28862888
}

src/BizHawk.Tests.Client.Common/InputManagerTests.cs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ public void BasicInputProcessing()
4040

4141
private static readonly IReadOnlyList<string> _modifierKeys = new[] { "Super", "Ctrl", "Alt", "Shift" };
4242

43-
private static readonly int PRIORITY_BOTH = 0;
44-
private static readonly int PRIORITY_INPUT = 1;
45-
private static readonly int PRIORITY_HOTKEY = 2;
46-
4743
private InputEvent MakePressEvent(string keyboardButton, uint modifiers = 0)
4844
{
4945
return new()
@@ -284,7 +280,7 @@ public void SinglePressCanDoControllerAndHotkeyInput()
284280
Context context = MakeContext();
285281
InputManager manager = context.manager;
286282
FakeInputSource source = context.source;
287-
context.config.InputHotkeyOverrideOptions = PRIORITY_BOTH;
283+
context.config.InputHotkeyOverrideOptions = Config.InputPriority.BOTH;
288284

289285
manager.ClientControls.BindMulti(_hotkeys[0], "Z");
290286
manager.ActiveController.BindMulti("A", "Z");
@@ -303,7 +299,7 @@ public void HotkeyPriority()
303299
Context context = MakeContext();
304300
InputManager manager = context.manager;
305301
FakeInputSource source = context.source;
306-
context.config.InputHotkeyOverrideOptions = PRIORITY_HOTKEY;
302+
context.config.InputHotkeyOverrideOptions = Config.InputPriority.HOTKEY;
307303

308304
manager.ClientControls.BindMulti(_hotkeys[0], "Z");
309305
manager.ActiveController.BindMulti("A", "Z");
@@ -322,7 +318,7 @@ public void ControllerPriority()
322318
Context context = MakeContext();
323319
InputManager manager = context.manager;
324320
FakeInputSource source = context.source;
325-
context.config.InputHotkeyOverrideOptions = PRIORITY_INPUT;
321+
context.config.InputHotkeyOverrideOptions = Config.InputPriority.INPUT;
326322

327323
manager.ClientControls.BindMulti(_hotkeys[0], "Z");
328324
manager.ActiveController.BindMulti("A", "Z");
@@ -340,7 +336,7 @@ public void HotkeyPriorityWithModifier()
340336
Context context = MakeContext();
341337
InputManager manager = context.manager;
342338
FakeInputSource source = context.source;
343-
context.config.InputHotkeyOverrideOptions = PRIORITY_HOTKEY;
339+
context.config.InputHotkeyOverrideOptions = Config.InputPriority.HOTKEY;
344340

345341
manager.ClientControls.BindMulti(_hotkeys[0], "Shift+Z");
346342
manager.ActiveController.BindMulti("A", "Shift+Z");
@@ -360,7 +356,7 @@ public void ControllerPriorityWithModifier()
360356
Context context = MakeContext();
361357
InputManager manager = context.manager;
362358
FakeInputSource source = context.source;
363-
context.config.InputHotkeyOverrideOptions = PRIORITY_INPUT;
359+
context.config.InputHotkeyOverrideOptions = Config.InputPriority.INPUT;
364360

365361
manager.ClientControls.BindMulti(_hotkeys[0], "Shift+Z");
366362
manager.ActiveController.BindMulti("A", "Shift+Z");
@@ -379,7 +375,7 @@ public void HotkeyOverrideDoesNotEatReleaseEvents()
379375
Context context = MakeContext();
380376
InputManager manager = context.manager;
381377
FakeInputSource source = context.source;
382-
context.config.InputHotkeyOverrideOptions = PRIORITY_HOTKEY;
378+
context.config.InputHotkeyOverrideOptions = Config.InputPriority.HOTKEY;
383379

384380
manager.ClientControls.BindMulti(_hotkeys[0], "Z");
385381
manager.ActiveController.BindMulti("A", "Shift+Z");

0 commit comments

Comments
 (0)