summaryrefslogtreecommitdiff
path: root/src/input/joystick.cpp
diff options
context:
space:
mode:
authorewewukek <ewewukek@gmail.com>2024-01-11 13:03:53 +0300
committerewewukek <ewewukek@gmail.com>2024-03-27 13:18:30 +0300
commit9728279062a74c4e80c7ed1c714571ae6fda2016 (patch)
treecdf9c4f81effd3e5d1a672bb85147b46290779c8 /src/input/joystick.cpp
parent9ccb4f7cc71443f9ed43171d4d825ba08b61943c (diff)
downloadmanaverse-9728279062a74c4e80c7ed1c714571ae6fda2016.tar.gz
manaverse-9728279062a74c4e80c7ed1c714571ae6fda2016.tar.bz2
manaverse-9728279062a74c4e80c7ed1c714571ae6fda2016.tar.xz
manaverse-9728279062a74c4e80c7ed1c714571ae6fda2016.zip
Add a checkbox for d-pad to switch between movement and button behavior
Diffstat (limited to 'src/input/joystick.cpp')
-rw-r--r--src/input/joystick.cpp44
1 files changed, 27 insertions, 17 deletions
diff --git a/src/input/joystick.cpp b/src/input/joystick.cpp
index 59087c2c7..01414b4dc 100644
--- a/src/input/joystick.cpp
+++ b/src/input/joystick.cpp
@@ -52,6 +52,7 @@ Joystick::Joystick(const int no) :
mTolerance(0),
mNumber(no >= joystickCount ? joystickCount : no),
mButtonsNumber(MAX_BUTTONS),
+ mUseHatForMovement(true),
mUseInactive(false),
mHaveHats(false),
mKeyToAction(),
@@ -199,6 +200,7 @@ bool Joystick::open()
config.setValue("joystickTolerance", 0.1F);
#endif
mTolerance = config.getFloatValue("joystickTolerance");
+ mUseHatForMovement = config.getBoolValue("useHatForMovement");
mUseInactive = config.getBoolValue("useInactiveJoystick");
return true;
@@ -278,6 +280,8 @@ void Joystick::logic()
mHatPosition |= UP;
else if ((hat & SDL_HAT_DOWN) != 0)
mHatPosition |= DOWN;
+ if ((mDirection == 0U) && mUseHatForMovement)
+ mDirection = mHatPosition;
}
// Buttons
@@ -310,14 +314,17 @@ bool Joystick::buttonPressed(const int no) const
return false;
if (no < MAX_BUTTONS)
return mActiveButtons[no];
- if (no == KEY_UP)
- return (mHatPosition & UP) != 0;
- if (no == KEY_DOWN)
- return (mHatPosition & DOWN) != 0;
- if (no == KEY_LEFT)
- return (mHatPosition & LEFT) != 0;
- if (no == KEY_RIGHT)
- return (mHatPosition & RIGHT) != 0;
+ if (!mUseHatForMovement)
+ {
+ if (no == KEY_UP)
+ return (mHatPosition & UP) != 0;
+ if (no == KEY_DOWN)
+ return (mHatPosition & DOWN) != 0;
+ if (no == KEY_LEFT)
+ return (mHatPosition & LEFT) != 0;
+ if (no == KEY_RIGHT)
+ return (mHatPosition & RIGHT) != 0;
+ }
return false;
}
@@ -358,7 +365,7 @@ int Joystick::getButtonFromEvent(const SDL_Event &event) const
return -1;
return event.jbutton.button;
}
- if (event.type == SDL_JOYHATMOTION)
+ if (!mUseHatForMovement && event.type == SDL_JOYHATMOTION)
{
// reading only hat 0
if (event.jhat.which != mNumber || event.jhat.hat != 0)
@@ -415,14 +422,17 @@ void Joystick::handleRepeat(const int time)
if (mActiveButtons[key])
repeat = true;
}
- if (key == KEY_UP && (mHatPosition & UP) != 0)
- repeat = true;
- if (key == KEY_DOWN && (mHatPosition & DOWN) != 0)
- repeat = true;
- if (key == KEY_LEFT && (mHatPosition & LEFT) != 0)
- repeat = true;
- if (key == KEY_RIGHT && (mHatPosition & RIGHT) != 0)
- repeat = true;
+ if (!mUseHatForMovement)
+ {
+ if (key == KEY_UP && (mHatPosition & UP) != 0)
+ repeat = true;
+ if (key == KEY_DOWN && (mHatPosition & DOWN) != 0)
+ repeat = true;
+ if (key == KEY_LEFT && (mHatPosition & LEFT) != 0)
+ repeat = true;
+ if (key == KEY_RIGHT && (mHatPosition & RIGHT) != 0)
+ repeat = true;
+ }
if (repeat)
{
int &keyTime = (*it).second;