summaryrefslogtreecommitdiff
path: root/src/input/inputmanager.cpp
diff options
context:
space:
mode:
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;
}