From d7908d82f4e76c0dd2ac1de2bc0be4f8848aab25 Mon Sep 17 00:00:00 2001 From: staphen Date: Sun, 30 Oct 2022 20:28:06 -0400 Subject: [PATCH] Always remove release actions from padmapper regardless of whether the action can be invoked --- Source/controls/game_controls.cpp | 10 ++++++++++ Source/options.cpp | 20 ++++++++++---------- Source/options.h | 2 +- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/Source/controls/game_controls.cpp b/Source/controls/game_controls.cpp index 1b7fecec5..a82d6af13 100644 --- a/Source/controls/game_controls.cpp +++ b/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) { diff --git a/Source/options.cpp b/Source/options.cpp index 4346ec476..9e7a93b56 100644 --- a/Source/options.cpp +++ b/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); } diff --git a/Source/options.h b/Source/options.h index a312d0c39..68ccd4b32 100644 --- a/Source/options.h +++ b/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;