Browse Source

Defer d-pad inputs to movement handlers

pull/6014/head
staphen 3 years ago committed by Anders Jenbo
parent
commit
8b6b898493
  1. 5
      Source/controls/plrctrls.cpp
  2. 1
      Source/controls/plrctrls.h
  3. 24
      Source/options.cpp
  4. 1
      Source/options.h

5
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.

1
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);

24
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";

1
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 {

Loading…
Cancel
Save