Finish `MergeLAndRModifierKeys` UX (resolves #3184)
This commit is contained in:
parent
c490d8baa2
commit
ceb64cedb0
src
BizHawk.Client.Common/config
BizHawk.Client.EmuHawk
BizHawk.Common/Extensions
|
@ -1,5 +1,10 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using BizHawk.Common.StringExtensions;
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace BizHawk.Client.Common
|
||||
|
@ -136,6 +141,17 @@ namespace BizHawk.Client.Common
|
|||
config.PutCoreSyncSettings(o, typeof(TCore));
|
||||
}
|
||||
|
||||
public static void ReplaceKeysInBindings(this Config config, IReadOnlyDictionary<string, string> replMap)
|
||||
{
|
||||
string ReplMulti(string multiBind)
|
||||
=> multiBind.TransformFields(',', bind => bind.TransformFields('+', button => replMap.TryGetValue(button, out var repl) ? repl : button));
|
||||
foreach (var hotkeyBinding in config.HotkeyBindings.Bindings) hotkeyBinding.Bindings = ReplMulti(hotkeyBinding.Bindings);
|
||||
foreach (var bindCollection in new[] { config.AllTrollers, config.AllTrollersAutoFire }) // analog and feedback binds can only be bound to (host) gamepads, not keyboard
|
||||
{
|
||||
foreach (var k in bindCollection.Keys.ToArray()) bindCollection[k] = bindCollection[k].ToDictionary(static kvp => kvp.Key, kvp => ReplMulti(kvp.Value));
|
||||
}
|
||||
}
|
||||
|
||||
/// <param name="fileExt">file extension, including the leading period and in lowercase</param>
|
||||
/// <remarks><paramref name="systemID"/> will be <see langword="null"/> if returned value is <see langword="false"/></remarks>
|
||||
public static bool TryGetChosenSystemForFileExt(this Config config, string fileExt, out string systemID)
|
||||
|
|
|
@ -42,7 +42,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
_getConfigCallback = getConfigCallback;
|
||||
_currentConfig = _getConfigCallback();
|
||||
_currentConfig.MergeLAndRModifierKeys = true; // for debugging
|
||||
UpdateModifierKeysEffective();
|
||||
|
||||
MainFormInputAllowedCallback = mainFormInputAllowedCallback;
|
||||
|
@ -81,7 +80,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
.Concat(_currentConfig.ModifierKeys)
|
||||
.Take(32).ToArray();
|
||||
|
||||
private readonly IReadOnlyDictionary<string, string> _modifierKeyPreMap = new Dictionary<string, string>
|
||||
internal static readonly IReadOnlyDictionary<string, string> ModifierKeyPreMap = new Dictionary<string, string>
|
||||
{
|
||||
["LeftSuper"] = "Win",
|
||||
["RightSuper"] = "Win",
|
||||
|
@ -93,9 +92,17 @@ namespace BizHawk.Client.EmuHawk
|
|||
["RightShift"] = "Shift",
|
||||
};
|
||||
|
||||
internal static readonly IReadOnlyDictionary<string, string> ModifierKeyInvPreMap = new Dictionary<string, string>
|
||||
{
|
||||
["Super"] = "LeftWin",
|
||||
["Ctrl"] = "LeftCtrl",
|
||||
["Alt"] = "LeftAlt",
|
||||
["Shift"] = "LeftShift",
|
||||
};
|
||||
|
||||
private void HandleButton(string button, bool newState, ClientInputFocus source)
|
||||
{
|
||||
if (!(_currentConfig.MergeLAndRModifierKeys &&_modifierKeyPreMap.TryGetValue(button, out var button1))) button1 = button;
|
||||
if (!(_currentConfig.MergeLAndRModifierKeys && ModifierKeyPreMap.TryGetValue(button, out var button1))) button1 = button;
|
||||
var modIndex = _currentConfig.ModifierKeysEffective.IndexOf(button1);
|
||||
var currentModifier = modIndex is -1 ? 0U : 1U << modIndex;
|
||||
if (EnableIgnoreModifiers && currentModifier is not 0U) return;
|
||||
|
|
15
src/BizHawk.Client.EmuHawk/config/EmuHawkOptions.Designer.cs
generated
Normal file → Executable file
15
src/BizHawk.Client.EmuHawk/config/EmuHawkOptions.Designer.cs
generated
Normal file → Executable file
|
@ -78,6 +78,7 @@
|
|||
this.BackupSRamCheckbox = new System.Windows.Forms.CheckBox();
|
||||
this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
|
||||
this.locLabelEx1 = new BizHawk.WinForms.Controls.LocLabelEx();
|
||||
this.cbMergeLAndRModifierKeys = new System.Windows.Forms.CheckBox();
|
||||
this.tabControl1.SuspendLayout();
|
||||
this.tabPage1.SuspendLayout();
|
||||
this.groupBox3.SuspendLayout();
|
||||
|
@ -126,6 +127,7 @@
|
|||
//
|
||||
// tabPage1
|
||||
//
|
||||
this.tabPage1.Controls.Add(this.cbMergeLAndRModifierKeys);
|
||||
this.tabPage1.Controls.Add(this.HandleAlternateKeyboardLayoutsCheckBox);
|
||||
this.tabPage1.Controls.Add(this.NeverAskSaveCheckbox);
|
||||
this.tabPage1.Controls.Add(this.label2);
|
||||
|
@ -281,7 +283,7 @@
|
|||
this.groupBox1.Controls.Add(this.StartFullScreenCheckbox);
|
||||
this.groupBox1.Controls.Add(this.label3);
|
||||
this.groupBox1.Controls.Add(this.SingleInstanceModeCheckbox);
|
||||
this.groupBox1.Location = new System.Drawing.Point(6, 205);
|
||||
this.groupBox1.Location = new System.Drawing.Point(6, 221);
|
||||
this.groupBox1.Name = "groupBox1";
|
||||
this.groupBox1.Size = new System.Drawing.Size(369, 133);
|
||||
this.groupBox1.TabIndex = 15;
|
||||
|
@ -573,6 +575,16 @@
|
|||
this.locLabelEx1.Name = "locLabelEx1";
|
||||
this.locLabelEx1.Text = "Note: Only a tiny subset of commandline args work (incl. rom path)";
|
||||
//
|
||||
// cbMergeLAndRModifierKeys
|
||||
//
|
||||
this.cbMergeLAndRModifierKeys.AutoSize = true;
|
||||
this.cbMergeLAndRModifierKeys.Location = new System.Drawing.Point(7, 202);
|
||||
this.cbMergeLAndRModifierKeys.Name = "cbMergeLAndRModifierKeys";
|
||||
this.cbMergeLAndRModifierKeys.Size = new System.Drawing.Size(320, 17);
|
||||
this.cbMergeLAndRModifierKeys.TabIndex = 29;
|
||||
this.cbMergeLAndRModifierKeys.Text = "Merge L+R modifier keys e.g. Shift instead of LShift and RShift";
|
||||
this.cbMergeLAndRModifierKeys.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// EmuHawkOptions
|
||||
//
|
||||
this.AcceptButton = this.OkBtn;
|
||||
|
@ -657,5 +669,6 @@
|
|||
private System.Windows.Forms.CheckBox SingleInstanceModeCheckbox;
|
||||
private System.Windows.Forms.CheckBox NoMixedKeyPriorityCheckBox;
|
||||
private WinForms.Controls.LocLabelEx locLabelEx1;
|
||||
private System.Windows.Forms.CheckBox cbMergeLAndRModifierKeys;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,6 +70,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
AcceptBackgroundInputControllerOnlyCheckBox.Checked = _config.AcceptBackgroundInputControllerOnly;
|
||||
HandleAlternateKeyboardLayoutsCheckBox.Checked = _config.HandleAlternateKeyboardLayouts;
|
||||
NeverAskSaveCheckbox.Checked = _config.SuppressAskSave;
|
||||
cbMergeLAndRModifierKeys.Checked = _config.MergeLAndRModifierKeys;
|
||||
SingleInstanceModeCheckbox.Checked = _config.SingleInstanceMode;
|
||||
SingleInstanceModeCheckbox.Enabled = !OSTailoredCode.IsUnixHost;
|
||||
|
||||
|
@ -110,6 +111,19 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private void OkBtn_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (cbMergeLAndRModifierKeys.Checked != _config.MergeLAndRModifierKeys)
|
||||
{
|
||||
var merging = cbMergeLAndRModifierKeys.Checked;
|
||||
var result = MessageBox.Show(
|
||||
this,
|
||||
text: $"Would you like to replace {(merging ? "LShift and RShift with Shift" : "Shift with LShift")},\nand the same for the other modifier keys,\nin existing keybinds for hotkeys and all systems' gamepads?",
|
||||
caption: "Rewrite keybinds now?",
|
||||
MessageBoxButtons.YesNoCancel,
|
||||
MessageBoxIcon.Question);
|
||||
if (result is DialogResult.Cancel) return;
|
||||
if (result is DialogResult.Yes) _config.ReplaceKeysInBindings(merging ? Input.ModifierKeyPreMap : Input.ModifierKeyInvPreMap);
|
||||
}
|
||||
|
||||
_config.StartFullscreen = StartFullScreenCheckbox.Checked;
|
||||
_config.StartPaused = StartPausedCheckbox.Checked;
|
||||
_config.PauseWhenMenuActivated = PauseWhenMenuActivatedCheckbox.Checked;
|
||||
|
@ -120,6 +134,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
_config.AcceptBackgroundInputControllerOnly = AcceptBackgroundInputControllerOnlyCheckBox.Checked;
|
||||
_config.HandleAlternateKeyboardLayouts = HandleAlternateKeyboardLayoutsCheckBox.Checked;
|
||||
_config.SuppressAskSave = NeverAskSaveCheckbox.Checked;
|
||||
_config.MergeLAndRModifierKeys = cbMergeLAndRModifierKeys.Checked;
|
||||
_config.SingleInstanceMode = SingleInstanceModeCheckbox.Checked;
|
||||
if(rbInputMethodDirectInput.Checked) _config.HostInputMethod = EHostInputMethod.DirectInput;
|
||||
if(rbInputMethodOpenTK.Checked) _config.HostInputMethod = EHostInputMethod.OpenTK;
|
||||
|
|
|
@ -116,5 +116,13 @@ namespace BizHawk.Common.StringExtensions
|
|||
var index = str.IndexOf(delimiter);
|
||||
return index < 0 ? null : str.Substring(0, index);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// splits a given <paramref name="str"/> by <paramref name="delimiter"/>,
|
||||
/// applies <paramref name="transform"/> to each part, then rejoins them
|
||||
/// </summary>
|
||||
/// <remarks><c>"abc,def,ghi".TransformFields(',', s => s.Reverse()) == "cba,fed,ihg"</c></remarks>
|
||||
public static string TransformFields(this string str, char delimiter, Func<string, string> transform)
|
||||
=> string.Join(delimiter.ToString(), str.Split(delimiter).Select(transform));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue