From b537f677f9da3e960d59222191d81dff6ba42eeb Mon Sep 17 00:00:00 2001 From: staphen Date: Sun, 16 Apr 2023 11:21:46 -0400 Subject: [PATCH] Improve d-pad handling for in-game menus --- Source/controls/controller_motion.cpp | 37 ++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/Source/controls/controller_motion.cpp b/Source/controls/controller_motion.cpp index 5bae3914c..315944a52 100644 --- a/Source/controls/controller_motion.cpp +++ b/Source/controls/controller_motion.cpp @@ -2,6 +2,7 @@ #include +#include "control.h" #include "controls/controller.h" #ifndef USE_SDL1 #include "controls/devices/game_controller.h" @@ -65,6 +66,34 @@ void ScaleJoystickAxes(float *x, float *y, float deadzone) } } +bool IsMovementOverriddenByPadmapper(ControllerButton button) +{ + ControllerButtonEvent releaseEvent { button, true }; + string_view actionName = sgOptions.Padmapper.ActionNameTriggeredByButtonEvent(releaseEvent); + ControllerButtonCombo buttonCombo = sgOptions.Padmapper.ButtonComboForAction(actionName); + return buttonCombo.modifier != ControllerButton_NONE; +} + +bool TriggersQuickSpellAction(ControllerButton button) +{ + ControllerButtonEvent releaseEvent { button, true }; + string_view actionName = sgOptions.Padmapper.ActionNameTriggeredByButtonEvent(releaseEvent); + + string_view prefix { "QuickSpell" }; + if (actionName.size() < prefix.size()) + return false; + string_view truncatedActionName { actionName.data(), prefix.size() }; + return truncatedActionName == prefix; +} + +bool IsPressedForMovement(ControllerButton button) +{ + return !PadMenuNavigatorActive + && IsControllerButtonPressed(button) + && !IsMovementOverriddenByPadmapper(button) + && !(spselflag && TriggersQuickSpellAction(button)); +} + void SetSimulatingMouseWithPadmapper(bool value) { if (SimulatingMouseWithPadmapper == value) @@ -181,10 +210,10 @@ AxisDirection GetLeftStickOrDpadDirection(bool usePadmapper) isLeftPressed |= sgOptions.Padmapper.IsActive("MoveLeft"); isRightPressed |= sgOptions.Padmapper.IsActive("MoveRight"); } else if (!SimulatingMouseWithPadmapper) { - isUpPressed |= IsControllerButtonPressed(ControllerButton_BUTTON_DPAD_UP); - isDownPressed |= IsControllerButtonPressed(ControllerButton_BUTTON_DPAD_DOWN); - isLeftPressed |= IsControllerButtonPressed(ControllerButton_BUTTON_DPAD_LEFT); - isRightPressed |= IsControllerButtonPressed(ControllerButton_BUTTON_DPAD_RIGHT); + isUpPressed |= IsPressedForMovement(ControllerButton_BUTTON_DPAD_UP); + isDownPressed |= IsPressedForMovement(ControllerButton_BUTTON_DPAD_DOWN); + isLeftPressed |= IsPressedForMovement(ControllerButton_BUTTON_DPAD_LEFT); + isRightPressed |= IsPressedForMovement(ControllerButton_BUTTON_DPAD_RIGHT); } #ifndef USE_SDL1