Browse Source

Hotkeys: Support more keybindings (#6719)

* Extend F keys with F13-F24 range
* Add more possible keybindings
* Removed hardcoded keys that are used elsewhere
* Put PAUSE back where it was before
* Remove hardcoded logic for PAUSE key
* Hotkeys: Support more keybindings

This patch adds more keybindings, so we can map multiple keys.

It also adds a possibility to bind an alternate key to pause game
(currently mapped to P and Pause key by default).

Co-authored-by: n <neube.github@gmail.com>
Co-authored-by: staphen <staphen@gmail.com>
pull/6742/head
lithraal 2 years ago committed by GitHub
parent
commit
9123f01a96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      Source/diablo.cpp
  2. 31
      Source/options.cpp

10
Source/diablo.cpp

@ -484,10 +484,6 @@ void PressKey(SDL_Keycode vkey, uint16_t modState)
if (vkey == SDLK_UNKNOWN)
return;
if (vkey == SDLK_PAUSE) {
diablo_pause_game();
return;
}
if (gmenu_presskeys(vkey) || control_presskeys(vkey)) {
return;
}
@ -1821,6 +1817,12 @@ void InitKeymapActions()
N_("Pauses the game."),
'P',
diablo_pause_game);
sgOptions.Keymapper.AddAction(
"Pause Game (Alternate)",
N_("Pause Game (Alternate)"),
N_("Pauses the game."),
SDLK_PAUSE,
diablo_pause_game);
sgOptions.Keymapper.AddAction(
"DecreaseGamma",
N_("Decrease Gamma"),

31
Source/options.cpp

@ -1292,7 +1292,7 @@ std::vector<OptionEntryBase *> LanguageOptions::GetEntries()
KeymapperOptions::KeymapperOptions()
: OptionCategoryBase("Keymapping", N_("Keymapping"), N_("Keymapping Settings"))
{
// Insert all supported keys: a-z, 0-9 and F1-F12.
// Insert all supported keys: a-z, 0-9 and F1-F24.
keyIDToKeyName.reserve(('Z' - 'A' + 1) + ('9' - '0' + 1) + 12);
for (char c = 'A'; c <= 'Z'; ++c) {
keyIDToKeyName.emplace(c, std::string(1, c));
@ -1303,6 +1303,9 @@ KeymapperOptions::KeymapperOptions()
for (int i = 0; i < 12; ++i) {
keyIDToKeyName.emplace(SDLK_F1 + i, StrCat("F", i + 1));
}
for (int i = 0; i < 12; ++i) {
keyIDToKeyName.emplace(SDLK_F13 + i, StrCat("F", i + 13));
}
keyIDToKeyName.emplace(SDLK_KP_0, "KEYPADNUM 0");
for (int i = 0; i < 9; i++) {
@ -1311,9 +1314,12 @@ KeymapperOptions::KeymapperOptions()
keyIDToKeyName.emplace(SDLK_LALT, "LALT");
keyIDToKeyName.emplace(SDLK_RALT, "RALT");
keyIDToKeyName.emplace(SDLK_SPACE, "SPACE");
keyIDToKeyName.emplace(SDLK_RCTRL, "RCONTROL");
keyIDToKeyName.emplace(SDLK_LCTRL, "LCONTROL");
keyIDToKeyName.emplace(SDLK_PRINTSCREEN, "PRINT");
keyIDToKeyName.emplace(SDLK_PAUSE, "PAUSE");
keyIDToKeyName.emplace(SDLK_TAB, "TAB");
@ -1321,6 +1327,29 @@ KeymapperOptions::KeymapperOptions()
keyIDToKeyName.emplace(SDL_BUTTON_X1 | KeymapperMouseButtonMask, "X1MOUSE");
keyIDToKeyName.emplace(SDL_BUTTON_X2 | KeymapperMouseButtonMask, "X2MOUSE");
keyIDToKeyName.emplace(SDLK_BACKQUOTE, "`");
keyIDToKeyName.emplace(SDLK_LEFTBRACKET, "[");
keyIDToKeyName.emplace(SDLK_RIGHTBRACKET, "]");
keyIDToKeyName.emplace(SDLK_BACKSLASH, "\\");
keyIDToKeyName.emplace(SDLK_SEMICOLON, ";");
keyIDToKeyName.emplace(SDLK_QUOTE, "'");
keyIDToKeyName.emplace(SDLK_COMMA, ",");
keyIDToKeyName.emplace(SDLK_PERIOD, ".");
keyIDToKeyName.emplace(SDLK_SLASH, "/");
keyIDToKeyName.emplace(SDLK_BACKSPACE, "BACKSPACE");
keyIDToKeyName.emplace(SDLK_CAPSLOCK, "CAPSLOCK");
keyIDToKeyName.emplace(SDLK_SCROLLLOCK, "SCROLLLOCK");
keyIDToKeyName.emplace(SDLK_INSERT, "INSERT");
keyIDToKeyName.emplace(SDLK_DELETE, "DELETE");
keyIDToKeyName.emplace(SDLK_HOME, "HOME");
keyIDToKeyName.emplace(SDLK_END, "END");
keyIDToKeyName.emplace(SDLK_KP_DIVIDE, "KEYPAD /");
keyIDToKeyName.emplace(SDLK_KP_MULTIPLY, "KEYPAD *");
keyIDToKeyName.emplace(SDLK_KP_ENTER, "KEYPAD ENTER");
keyIDToKeyName.emplace(SDLK_KP_PERIOD, "KEYPAD DECIMAL");
keyNameToKeyID.reserve(keyIDToKeyName.size());
for (const auto &[key, value] : keyIDToKeyName) {
keyNameToKeyID.emplace(value, key);

Loading…
Cancel
Save