From 8b6b89849352d3df7b1c7fc53a939337b4bf5e98 Mon Sep 17 00:00:00 2001 From: staphen Date: Thu, 20 Apr 2023 20:12:29 -0400 Subject: [PATCH] Defer d-pad inputs to movement handlers --- Source/controls/plrctrls.cpp | 5 +++++ Source/controls/plrctrls.h | 1 + Source/options.cpp | 24 ++++++++++++++++++++++++ Source/options.h | 1 + 4 files changed, 31 insertions(+) diff --git a/Source/controls/plrctrls.cpp b/Source/controls/plrctrls.cpp index 979ecc065..947dc1308 100644 --- a/Source/controls/plrctrls.cpp +++ b/Source/controls/plrctrls.cpp @@ -1741,6 +1741,11 @@ bool IsPointAndClick() return PointAndClickState; } +bool IsMovementHandlerActive() +{ + return GetLeftStickOrDPadGameUIHandler() != nullptr; +} + void plrctrls_after_check_curs_move() { // check for monsters first, then items, then towners. diff --git a/Source/controls/plrctrls.h b/Source/controls/plrctrls.h index 5327af706..b433d12d1 100644 --- a/Source/controls/plrctrls.h +++ b/Source/controls/plrctrls.h @@ -63,6 +63,7 @@ bool InGameMenu(); void SetPointAndClick(bool value); bool IsPointAndClick(); +bool IsMovementHandlerActive(); void DetectInputMethod(const SDL_Event &event, const ControllerButtonEvent &gamepadEvent); void ProcessGameAction(const GameAction &action); diff --git a/Source/options.cpp b/Source/options.cpp index b8a0a5dc4..250857621 100644 --- a/Source/options.cpp +++ b/Source/options.cpp @@ -1704,6 +1704,8 @@ void PadmapperOptions::ButtonPressed(ControllerButton button) const Action *action = FindAction(button); if (action == nullptr) return; + if (IsMovementHandlerActive() && CanDeferToMovementHandler(*action)) + return; if (action->actionPressed) action->actionPressed(); SuppressedButton = action->boundInput.modifier; @@ -1811,6 +1813,28 @@ const PadmapperOptions::Action *PadmapperOptions::FindAction(ControllerButton bu return nullptr; } +bool PadmapperOptions::CanDeferToMovementHandler(const Action &action) const +{ + if (action.boundInput.modifier != ControllerButton_NONE) + return false; + + if (spselflag) { + const string_view prefix { "QuickSpell" }; + const string_view key { action.key }; + if (key.size() >= prefix.size()) { + const string_view truncated { key.data(), prefix.size() }; + if (truncated == prefix) + return false; + } + } + + return IsAnyOf(action.boundInput.button, + ControllerButton_BUTTON_DPAD_UP, + ControllerButton_BUTTON_DPAD_DOWN, + ControllerButton_BUTTON_DPAD_LEFT, + ControllerButton_BUTTON_DPAD_RIGHT); +} + namespace { constexpr char ResamplerSpeex[] = "Speex"; constexpr char ResamplerSDL[] = "SDL"; diff --git a/Source/options.h b/Source/options.h index 55abc1c9f..48303bef3 100644 --- a/Source/options.h +++ b/Source/options.h @@ -778,6 +778,7 @@ private: bool committed = false; const Action *FindAction(ControllerButton button) const; + bool CanDeferToMovementHandler(const Action &action) const; }; struct Options {