summaryrefslogtreecommitdiff
path: root/src/input/inputmanager.cpp
diff options
context:
space:
mode:
authorasuratva <asuratva@proton.me>2024-05-18 10:58:37 +0000
committerasuratva <asuratva@proton.me>2024-05-18 10:58:37 +0000
commit1d7ee3161693ed016264a4940778a6e4b2258e38 (patch)
tree059f68cc39a725a0bc64538e5771ef3525aa6ec6 /src/input/inputmanager.cpp
parent9294f5a1ba84c7a4e947ab94a2645625e8a6171d (diff)
parent5570d9d1c2b1b5fba50283ec443088430332bb86 (diff)
downloadplus-master.tar.gz
plus-master.tar.bz2
plus-master.tar.xz
plus-master.zip
Merge branch plus:master into masterHEADmaster
Diffstat (limited to 'src/input/inputmanager.cpp')
-rw-r--r--src/input/inputmanager.cpp125
1 files changed, 103 insertions, 22 deletions
diff --git a/src/input/inputmanager.cpp b/src/input/inputmanager.cpp
index a379e0e86..8cb10041e 100644
--- a/src/input/inputmanager.cpp
+++ b/src/input/inputmanager.cpp
@@ -416,8 +416,45 @@ std::string InputManager::getKeyStringLong(const InputActionT index) const
}
else if (key.type == InputType::JOYSTICK)
{
- // TRANSLATORS: long joystick button name. must be short.
- str = strprintf(_("JButton%d"), key.value + 1);
+ if (key.value < Joystick::MAX_BUTTONS)
+ {
+ // TRANSLATORS: joystick button name. must be short.
+ str = strprintf(_("JButton%d"), key.value + 1);
+ }
+ else if (key.value == Joystick::KEY_UP)
+ {
+ // TRANSLATORS: joystick up button. must be short.
+ str = _("JUp");
+ }
+ else if (key.value == Joystick::KEY_DOWN)
+ {
+ // TRANSLATORS: joystick down button. must be short.
+ str = _("JDown");
+ }
+ else if (key.value == Joystick::KEY_LEFT)
+ {
+ // TRANSLATORS: joystick left button. must be short.
+ str = _("JLeft");
+ }
+ else if (key.value == Joystick::KEY_RIGHT)
+ {
+ // TRANSLATORS: joystick right button. must be short.
+ str = _("JRight");
+ }
+ else if (key.value >= Joystick::KEY_NEGATIVE_AXIS_FIRST
+ && key.value < Joystick::KEY_POSITIVE_AXIS_FIRST)
+ {
+ // TRANSLATORS: joystick negative axis. must be short.
+ str = strprintf(_("JAxis%dMinus"),
+ key.value - Joystick::KEY_NEGATIVE_AXIS_FIRST);
+ }
+ else if (key.value >= Joystick::KEY_POSITIVE_AXIS_FIRST
+ && key.value < Joystick::KEY_END)
+ {
+ // TRANSLATORS: joystick positive axis. must be short.
+ str = strprintf(_("JAxis%dPlus"),
+ key.value - Joystick::KEY_POSITIVE_AXIS_FIRST);
+ }
}
if (!str.empty())
{
@@ -459,8 +496,45 @@ void InputManager::updateKeyString(const InputFunction &ki,
}
else if (key.type == InputType::JOYSTICK)
{
- // TRANSLATORS: short joystick button name. muse be very short
- str = strprintf(_("JB%d"), key.value + 1);
+ if (key.value < Joystick::MAX_BUTTONS)
+ {
+ // TRANSLATORS: joystick button name. must be very short
+ str = strprintf(_("JB%d"), key.value + 1);
+ }
+ else if (key.value == Joystick::KEY_UP)
+ {
+ // TRANSLATORS: joystick up button. must be very short
+ str = _("JUp");
+ }
+ else if (key.value == Joystick::KEY_DOWN)
+ {
+ // TRANSLATORS: joystick down button. must be very short
+ str = _("JDn");
+ }
+ else if (key.value == Joystick::KEY_LEFT)
+ {
+ // TRANSLATORS: joystick left button. must be very short
+ str = _("JLt");
+ }
+ else if (key.value == Joystick::KEY_RIGHT)
+ {
+ // TRANSLATORS: joystick right button. must be very short
+ str = _("JRt");
+ }
+ else if (key.value >= Joystick::KEY_NEGATIVE_AXIS_FIRST
+ && key.value < Joystick::KEY_POSITIVE_AXIS_FIRST)
+ {
+ // TRANSLATORS: joystick negative axis. must be very short.
+ str = strprintf(_("JA%d-"),
+ key.value - Joystick::KEY_NEGATIVE_AXIS_FIRST);
+ }
+ else if (key.value >= Joystick::KEY_POSITIVE_AXIS_FIRST
+ && key.value < Joystick::KEY_END)
+ {
+ // TRANSLATORS: joystick positive axis. must be very short.
+ str = strprintf(_("JA%d+"),
+ key.value - Joystick::KEY_POSITIVE_AXIS_FIRST);
+ }
}
if (!str.empty())
{
@@ -617,21 +691,7 @@ bool InputManager::handleEvent(const SDL_Event &restrict event) restrict2
BLOCK_END("InputManager::handleEvent")
return true;
}
-
keyboard.handleActivateKey(event);
- // send straight to gui for certain windows
-#ifndef DYECMD
- if ((quitDialog != nullptr) || TextDialog::isActive())
- {
- if (guiInput != nullptr)
- guiInput->pushInput(event);
- if (gui != nullptr)
- gui->handleInput();
- BLOCK_END("InputManager::handleEvent")
- return true;
- }
-#endif // DYECMD
-
break;
}
case SDL_KEYUP:
@@ -650,10 +710,13 @@ bool InputManager::handleEvent(const SDL_Event &restrict event) restrict2
break;
}
case SDL_JOYBUTTONDOWN:
+ case SDL_JOYHATMOTION:
+ case SDL_JOYAXISMOTION:
{
updateConditionMask(true);
// joystick.handleActicateButton(event);
- if (handleAssignKey(event, InputType::JOYSTICK))
+ if (joystick != nullptr && joystick->isActionEvent(event)
+ && handleAssignKey(event, InputType::JOYSTICK))
{
BLOCK_END("InputManager::handleEvent")
return true;
@@ -690,8 +753,16 @@ bool InputManager::handleEvent(const SDL_Event &restrict event) restrict2
guiInput->pushInput(event);
if (gui != nullptr)
{
- const bool res = gui->handleInput();
- if (res && event.type == SDL_KEYDOWN)
+ bool res = gui->handleInput();
+#ifndef DYECMD
+ // always treat keyboard input as handled if a text dialog is active
+ if (event.type == SDL_KEYDOWN && TextDialog::isActive())
+ res = true;
+#endif // DYECMD
+ const bool joystickActionEvent =
+ joystick != nullptr && joystick->isActionEvent(event);
+ // stop processing input if event is consumed by the gui
+ if (res && (event.type == SDL_KEYDOWN || joystickActionEvent))
{
BLOCK_END("InputManager::handleEvent")
return true;
@@ -724,6 +795,8 @@ bool InputManager::handleEvent(const SDL_Event &restrict event) restrict2
// break;
case SDL_JOYBUTTONDOWN:
+ case SDL_JOYHATMOTION:
+ case SDL_JOYAXISMOTION:
if ((joystick != nullptr) && joystick->validate())
{
if (triggerAction(joystick->getActionVector(event)))
@@ -1055,7 +1128,6 @@ InputActionT InputManager::getKeyIndex(const int value,
InputActionT InputManager::getActionByKey(const SDL_Event &restrict event)
const restrict2
{
- // for now support only keyboard events
if (event.type == SDL_KEYDOWN || event.type == SDL_KEYUP)
{
const InputActionT idx = keyboard.getActionId(event);
@@ -1065,6 +1137,15 @@ InputActionT InputManager::getActionByKey(const SDL_Event &restrict event)
return idx;
}
}
+ if (joystick != nullptr && joystick->isActionEvent(event))
+ {
+ const InputActionT idx = joystick->getActionId(event);
+ if (CAST_S32(idx) >= 0 &&
+ checkKey(&inputActionData[CAST_SIZE(idx)]))
+ {
+ return idx;
+ }
+ }
return InputAction::NO_VALUE;
}