Cancel hotkey rebind on Esc key press

This commit is contained in:
Ivaylo Draganov
2020-01-30 21:24:25 +02:00
committed by teinarss
parent 889e2152a4
commit 47f6e407d9
2 changed files with 19 additions and 3 deletions

View File

@@ -24,6 +24,7 @@ namespace OpenRA.Mods.Common.Widgets
public int LeftMargin = 5; public int LeftMargin = 5;
public int RightMargin = 5; public int RightMargin = 5;
public Action OnEscKey = () => { };
public Action OnLoseFocus = () => { }; public Action OnLoseFocus = () => { };
public Func<bool> IsDisabled = () => false; public Func<bool> IsDisabled = () => false;
@@ -86,7 +87,8 @@ namespace OpenRA.Mods.Common.Widgets
Keycode.RSHIFT, Keycode.LSHIFT, Keycode.RSHIFT, Keycode.LSHIFT,
Keycode.RCTRL, Keycode.LCTRL, Keycode.RCTRL, Keycode.LCTRL,
Keycode.RALT, Keycode.LALT, Keycode.RALT, Keycode.LALT,
Keycode.RGUI, Keycode.LGUI Keycode.RGUI, Keycode.LGUI,
Keycode.RETURN, Keycode.KP_ENTER
}; };
public override bool HandleKeyPress(KeyInput e) public override bool HandleKeyPress(KeyInput e)
@@ -97,8 +99,16 @@ namespace OpenRA.Mods.Common.Widgets
if (!HasKeyboardFocus || IgnoreKeys.Contains(e.Key)) if (!HasKeyboardFocus || IgnoreKeys.Contains(e.Key))
return false; return false;
if (e.Key != Keycode.ESCAPE && e.Key != Keycode.RETURN && e.Key != Keycode.KP_ENTER) switch (e.Key)
Key = Hotkey.FromKeyInput(e); {
case Keycode.ESCAPE:
OnEscKey();
break;
default:
Key = Hotkey.FromKeyInput(e);
break;
}
YieldKeyboardFocus(); YieldKeyboardFocus();

View File

@@ -1060,6 +1060,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
hotkeyEntryWidget = panel.Get<HotkeyEntryWidget>("HOTKEY_ENTRY"); hotkeyEntryWidget = panel.Get<HotkeyEntryWidget>("HOTKEY_ENTRY");
hotkeyEntryWidget.IsValid = () => isHotkeyValid; hotkeyEntryWidget.IsValid = () => isHotkeyValid;
hotkeyEntryWidget.OnLoseFocus = ValidateHotkey; hotkeyEntryWidget.OnLoseFocus = ValidateHotkey;
hotkeyEntryWidget.OnEscKey = () =>
{
hotkeyEntryWidget.Key = modData.Hotkeys[selectedHotkeyDefinition.Name].GetValue();
};
} }
void ValidateHotkey() void ValidateHotkey()
@@ -1070,6 +1074,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (isHotkeyValid) if (isHotkeyValid)
SaveHotkey(); SaveHotkey();
else
hotkeyEntryWidget.TakeKeyboardFocus();
} }
void SaveHotkey() void SaveHotkey()