Browse Source

Always remove release actions from padmapper regardless of whether the action can be invoked

pull/5453/head
staphen 3 years ago committed by Anders Jenbo
parent
commit
d7908d82f4
  1. 10
      Source/controls/game_controls.cpp
  2. 20
      Source/options.cpp
  3. 2
      Source/options.h

10
Source/controls/game_controls.cpp

@ -349,7 +349,17 @@ AxisDirection GetMoveDirection()
bool HandleControllerButtonEvent(const SDL_Event &event, GameAction &action)
{
struct ButtonReleaser {
~ButtonReleaser()
{
if (ctrlEvent.up)
sgOptions.Padmapper.ButtonReleased(ctrlEvent.button, false);
}
ControllerButtonEvent ctrlEvent;
};
const ControllerButtonEvent ctrlEvent = ToControllerButtonEvent(event);
const ButtonReleaser buttonReleaser { ctrlEvent };
bool isGamepadMotion = ProcessControllerMotion(event, ctrlEvent);
DetectInputMethod(event, ctrlEvent);
if (isGamepadMotion) {

20
Source/options.cpp

@ -1632,19 +1632,19 @@ void PadmapperOptions::ButtonPressed(ControllerButton button)
}
}
void PadmapperOptions::ButtonReleased(ControllerButton button)
void PadmapperOptions::ButtonReleased(ControllerButton button, bool invokeAction)
{
auto it = buttonToReleaseAction.find(button);
if (it == buttonToReleaseAction.end())
return; // Ignore unmapped buttons.
if (invokeAction) {
auto it = buttonToReleaseAction.find(button);
if (it == buttonToReleaseAction.end())
return; // Ignore unmapped buttons.
const Action &action = it->second.get();
// Check that the action can be triggered.
if (!action.actionReleased || (action.enable && !action.enable()))
return;
const Action &action = it->second.get();
action.actionReleased();
// Check that the action can be triggered.
if (action.actionReleased && (!action.enable || action.enable()))
action.actionReleased();
}
buttonToReleaseAction.erase(button);
}

2
Source/options.h

@ -737,7 +737,7 @@ struct PadmapperOptions : OptionCategoryBase {
unsigned index = 0);
void CommitActions();
void ButtonPressed(ControllerButton button);
void ButtonReleased(ControllerButton button);
void ButtonReleased(ControllerButton button, bool invokeAction = true);
string_view InputNameForAction(string_view actionName) const;
ControllerButtonCombo ButtonComboForAction(string_view actionName) const;

Loading…
Cancel
Save