Browse Source

[gamepad] Fix using quick spells with rebound keys

pull/4272/head
Anders Jenbo 4 years ago
parent
commit
0f44da5487
  1. 16
      Source/controls/game_controls.cpp
  2. 10
      Source/options.cpp
  3. 1
      Source/options.h

16
Source/controls/game_controls.cpp

@ -232,25 +232,25 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrlEvent, Game
switch (ctrlEvent.button) {
case ControllerButton_BUTTON_DPAD_UP:
if (IsControllerButtonPressed(ControllerButton_BUTTON_BACK))
*action = GameActionSendKey { DVL_VK_F6, ctrlEvent.up };
*action = GameActionSendKey { sgOptions.Keymapper.KeyForAction("QuickSpell2"), ctrlEvent.up };
else
*action = GameActionSendKey { DVL_VK_ESCAPE, ctrlEvent.up };
return true;
case ControllerButton_BUTTON_DPAD_RIGHT:
if (IsControllerButtonPressed(ControllerButton_BUTTON_BACK))
*action = GameActionSendKey { DVL_VK_F8, ctrlEvent.up };
*action = GameActionSendKey { sgOptions.Keymapper.KeyForAction("QuickSpell4"), ctrlEvent.up };
else if (!ctrlEvent.up)
*action = GameAction(GameActionType_TOGGLE_INVENTORY);
return true;
case ControllerButton_BUTTON_DPAD_DOWN:
if (IsControllerButtonPressed(ControllerButton_BUTTON_BACK))
*action = GameActionSendKey { DVL_VK_F7, ctrlEvent.up };
*action = GameActionSendKey { sgOptions.Keymapper.KeyForAction("QuickSpell3"), ctrlEvent.up };
else
*action = GameActionSendKey { DVL_VK_TAB, ctrlEvent.up };
return true;
case ControllerButton_BUTTON_DPAD_LEFT:
if (IsControllerButtonPressed(ControllerButton_BUTTON_BACK))
*action = GameActionSendKey { DVL_VK_F5, ctrlEvent.up };
*action = GameActionSendKey { sgOptions.Keymapper.KeyForAction("QuickSpell1"), ctrlEvent.up };
else if (!ctrlEvent.up)
*action = GameAction(GameActionType_TOGGLE_CHARACTER_INFO);
return true;
@ -313,7 +313,7 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrlEvent, Game
if (ctrlEvent.up)
return true;
if (IsControllerButtonPressed(ControllerButton_BUTTON_BACK))
*action = GameActionSendKey { DVL_VK_F7, ctrlEvent.up };
*action = GameActionSendKey { sgOptions.Keymapper.KeyForAction("QuickSpell3"), ctrlEvent.up };
else if (DoomFlag)
*action = GameActionSendKey { DVL_VK_ESCAPE, ctrlEvent.up };
else if (invflag)
@ -336,7 +336,7 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrlEvent, Game
case ControllerButton_BUTTON_B: // Right button
if (!ctrlEvent.up) {
if (IsControllerButtonPressed(ControllerButton_BUTTON_BACK))
*action = GameActionSendKey { DVL_VK_F8, ctrlEvent.up };
*action = GameActionSendKey { sgOptions.Keymapper.KeyForAction("QuickSpell4"), ctrlEvent.up };
else
*action = GameAction(GameActionType_PRIMARY_ACTION);
}
@ -344,7 +344,7 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrlEvent, Game
case ControllerButton_BUTTON_Y: // Top button
if (!ctrlEvent.up) {
if (IsControllerButtonPressed(ControllerButton_BUTTON_BACK))
*action = GameActionSendKey { DVL_VK_F6, ctrlEvent.up };
*action = GameActionSendKey { sgOptions.Keymapper.KeyForAction("QuickSpell2"), ctrlEvent.up };
else
*action = GameAction(GameActionType_SECONDARY_ACTION);
}
@ -352,7 +352,7 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrlEvent, Game
case ControllerButton_BUTTON_X: // Left button
if (!ctrlEvent.up) {
if (IsControllerButtonPressed(ControllerButton_BUTTON_BACK))
*action = GameActionSendKey { DVL_VK_F5, ctrlEvent.up };
*action = GameActionSendKey { sgOptions.Keymapper.KeyForAction("QuickSpell1"), ctrlEvent.up };
else
*action = GameAction(GameActionType_CAST_SPELL);
}

10
Source/options.cpp

@ -1231,4 +1231,14 @@ string_view KeymapperOptions::KeyNameForAction(string_view actionName) const
return "";
}
uint32_t KeymapperOptions::KeyForAction(string_view actionName) const
{
for (const auto &action : actions) {
if (action->key == actionName && action->boundKey != DVL_VK_INVALID) {
return action->boundKey;
}
}
return DVL_VK_INVALID;
}
} // namespace devilution

1
Source/options.h

@ -577,6 +577,7 @@ struct KeymapperOptions : OptionCategoryBase {
void KeyPressed(int key) const;
void KeyReleased(int key) const;
string_view KeyNameForAction(string_view actionName) const;
uint32_t KeyForAction(string_view actionName) const;
private:
std::vector<std::unique_ptr<Action>> actions;

Loading…
Cancel
Save