diff --git a/backends/events/sdl/sdl-events.cpp b/backends/events/sdl/sdl-events.cpp index 98cb5eb01fd..c7fcefa36d6 100644 --- a/backends/events/sdl/sdl-events.cpp +++ b/backends/events/sdl/sdl-events.cpp @@ -89,7 +89,7 @@ void SdlEventSource::loadGameControllerMappingFile() { SdlEventSource::SdlEventSource() : EventSource(), _scrollLock(false), _joystick(0), _lastScreenID(0), _graphicsManager(0), _queuedFakeMouseMove(false), _lastHatPosition(SDL_HAT_CENTERED) #if SDL_VERSION_ATLEAST(2, 0, 0) - , _queuedFakeKeyUp(false), _fakeKeyUp(), _controller(nullptr) + , _queuedFakeKeyUp(false), _fakeKeyUp(), _controller(nullptr), _leftTriggerDown(false), _rightTriggerDown(false) #endif { // Reset mouse state @@ -1064,6 +1064,48 @@ bool SdlEventSource::handleControllerAxisMotion(const SDL_Event &ev, Common::Eve return handleAxisToMouseMotion(_km.joy_x, _km.joy_y); } + // Left trigger is treated as axis in SDL + if (ev.caxis.axis == SDL_CONTROLLER_AXIS_TRIGGERLEFT) { + if (ev.caxis.value < 8192) { // 25% pressed + if (_leftTriggerDown) { + _leftTriggerDown = false; + event.type = Common::EVENT_JOYBUTTON_UP; + event.joystick.button = Common::JOYSTICK_BUTTON_LEFT_TRIGGER; + return true; + } else + return false; + } else if (ev.caxis.value > 16384) { // 50% pressed + if (!_leftTriggerDown) { + _leftTriggerDown = true; + event.type = Common::EVENT_JOYBUTTON_DOWN; + event.joystick.button = Common::JOYSTICK_BUTTON_LEFT_TRIGGER; + return true; + } else + return false; + } + } + + // Right trigger is treated as axis in SDL + if (ev.caxis.axis == SDL_CONTROLLER_AXIS_TRIGGERRIGHT) { + if (ev.caxis.value < 8192) { // 25% pressed + if (_rightTriggerDown) { + _rightTriggerDown = false; + event.type = Common::EVENT_JOYBUTTON_UP; + event.joystick.button = Common::JOYSTICK_BUTTON_RIGHT_TRIGGER; + return true; + } else + return false; + } else if (ev.caxis.value > 16384) { // 50% pressed + if (!_rightTriggerDown) { + _rightTriggerDown = true; + event.type = Common::EVENT_JOYBUTTON_DOWN; + event.joystick.button = Common::JOYSTICK_BUTTON_RIGHT_TRIGGER; + return true; + } else + return false; + } + } + return false; } #endif diff --git a/backends/events/sdl/sdl-events.h b/backends/events/sdl/sdl-events.h index f1f2bdd645a..a7a2db4524b 100644 --- a/backends/events/sdl/sdl-events.h +++ b/backends/events/sdl/sdl-events.h @@ -84,6 +84,10 @@ protected: #if SDL_VERSION_ATLEAST(2, 0, 0) /** Game controller */ SDL_GameController *_controller; + + /** keep memory of current trigger status */ + bool _leftTriggerDown; + bool _rightTriggerDown; #endif /** Last screen id for checking if it was modified */ diff --git a/backends/keymapper/hardware-input.cpp b/backends/keymapper/hardware-input.cpp index 0b4c0f5e00d..d3a2d02e15f 100644 --- a/backends/keymapper/hardware-input.cpp +++ b/backends/keymapper/hardware-input.cpp @@ -236,6 +236,8 @@ const HardwareInputTableEntry defaultJoystickButtons[] = { { "JOY_RIGHT_STICK", JOYSTICK_BUTTON_RIGHT_STICK, _s("Right Stick") }, { "JOY_LEFT_SHOULDER", JOYSTICK_BUTTON_LEFT_SHOULDER, _s("Left Shoulder") }, { "JOY_RIGHT_SHOULDER", JOYSTICK_BUTTON_RIGHT_SHOULDER, _s("Right Shoulder") }, + { "JOY_LEFT_TRIGGER", JOYSTICK_BUTTON_LEFT_TRIGGER, _s("Left Trigger") }, + { "JOY_RIGHT_TRIGGER", JOYSTICK_BUTTON_RIGHT_TRIGGER, _s("Right Trigger") }, { "JOY_UP", JOYSTICK_BUTTON_DPAD_UP, _s("D-pad Up") }, { "JOY_DOWN", JOYSTICK_BUTTON_DPAD_DOWN, _s("D-pad Down") }, { "JOY_LEFT", JOYSTICK_BUTTON_DPAD_LEFT, _s("D-pad Left") }, diff --git a/backends/platform/sdl/psp2/psp2.cpp b/backends/platform/sdl/psp2/psp2.cpp index f87d8f809fc..ab535b96342 100644 --- a/backends/platform/sdl/psp2/psp2.cpp +++ b/backends/platform/sdl/psp2/psp2.cpp @@ -26,6 +26,7 @@ #include "common/scummsys.h" #include "common/config-manager.h" #include "common/debug-channels.h" +#include "common/translation.h" #include "backends/platform/sdl/psp2/psp2.h" #include "backends/graphics/psp2sdl/psp2sdl-graphics.h" #include "backends/saves/default/default-saves.h" @@ -33,12 +34,30 @@ #include "backends/fs/psp2/psp2-fs-factory.h" #include "backends/events/psp2sdl/psp2sdl-events.h" #include "backends/fs/psp2/psp2-dirent.h" +#include "backends/keymapper/hardware-input.h" #include #ifdef __PSP2_DEBUG__ #include #endif +static const Common::HardwareInputTableEntry psp2JoystickButtons[] = { + { "JOY_A", Common::JOYSTICK_BUTTON_A, _s("Cross") }, + { "JOY_B", Common::JOYSTICK_BUTTON_B, _s("Circle") }, + { "JOY_X", Common::JOYSTICK_BUTTON_X, _s("Square") }, + { "JOY_Y", Common::JOYSTICK_BUTTON_Y, _s("Triangle") }, + { "JOY_BACK", Common::JOYSTICK_BUTTON_BACK, _s("Select") }, + { "JOY_START", Common::JOYSTICK_BUTTON_START, _s("Start") }, + { "JOY_LEFT_SHOULDER", Common::JOYSTICK_BUTTON_LEFT_SHOULDER, _s("L") }, + { "JOY_RIGHT_SHOULDER", Common::JOYSTICK_BUTTON_RIGHT_SHOULDER, _s("R") }, + { "JOY_UP", Common::JOYSTICK_BUTTON_DPAD_UP, _s("D-pad Up") }, + { "JOY_DOWN", Common::JOYSTICK_BUTTON_DPAD_DOWN, _s("D-pad Down") }, + { "JOY_LEFT", Common::JOYSTICK_BUTTON_DPAD_LEFT, _s("D-pad Left") }, + { "JOY_RIGHT", Common::JOYSTICK_BUTTON_DPAD_RIGHT, _s("D-pad Right") }, + { nullptr, 0, nullptr } +}; + + int access(const char *pathname, int mode) { struct stat sb; @@ -174,3 +193,16 @@ Common::String OSystem_PSP2::getDefaultConfigFileName() { Common::String OSystem_PSP2::getDefaultLogFileName() { return "ux0:data/scummvm/scummvm.log"; } + +Common::HardwareInputSet *OSystem_PSP2::getHardwareInputSet() { + using namespace Common; + + CompositeHardwareInputSet *inputSet = new CompositeHardwareInputSet(); + + // Users may use USB / bluetooth mice and keyboards + inputSet->addHardwareInputSet(new MouseHardwareInputSet(defaultMouseButtons)); + inputSet->addHardwareInputSet(new KeyboardHardwareInputSet(defaultKeys, defaultModifiers)); + inputSet->addHardwareInputSet(new JoystickHardwareInputSet(psp2JoystickButtons)); + + return inputSet; +} \ No newline at end of file diff --git a/backends/platform/sdl/psp2/psp2.h b/backends/platform/sdl/psp2/psp2.h index 0b3be259501..72422d8da88 100644 --- a/backends/platform/sdl/psp2/psp2.h +++ b/backends/platform/sdl/psp2/psp2.h @@ -36,6 +36,7 @@ public: virtual void setFeatureState(Feature f, bool enable) override; virtual bool getFeatureState(Feature f) override; virtual void logMessage(LogMessageType::Type type, const char *message) override; + virtual Common::HardwareInputSet *getHardwareInputSet() override; protected: virtual Common::String getDefaultConfigFileName() override; diff --git a/backends/platform/sdl/switch/switch.cpp b/backends/platform/sdl/switch/switch.cpp index 120fb955fb5..270e398a33e 100644 --- a/backends/platform/sdl/switch/switch.cpp +++ b/backends/platform/sdl/switch/switch.cpp @@ -24,11 +24,34 @@ #include "common/scummsys.h" #include "common/config-manager.h" +#include "common/translation.h" #include "backends/platform/sdl/switch/switch.h" #include "backends/events/switchsdl/switchsdl-events.h" #include "backends/saves/posix/posix-saves.h" #include "backends/fs/posix/posix-fs-factory.h" #include "backends/fs/posix/posix-fs.h" +#include "backends/keymapper/hardware-input.h" + +static const Common::HardwareInputTableEntry switchJoystickButtons[] = { + { "JOY_A", Common::JOYSTICK_BUTTON_A, _s("B") }, + { "JOY_B", Common::JOYSTICK_BUTTON_B, _s("A") }, + { "JOY_X", Common::JOYSTICK_BUTTON_X, _s("Y") }, + { "JOY_Y", Common::JOYSTICK_BUTTON_Y, _s("X") }, + { "JOY_BACK", Common::JOYSTICK_BUTTON_BACK, _s("Minus") }, + { "JOY_START", Common::JOYSTICK_BUTTON_START, _s("Plus") }, + { "JOY_LEFT_STICK", Common::JOYSTICK_BUTTON_LEFT_STICK, _s("L3") }, + { "JOY_RIGHT_STICK", Common::JOYSTICK_BUTTON_RIGHT_STICK, _s("R3") }, + { "JOY_LEFT_SHOULDER", Common::JOYSTICK_BUTTON_LEFT_SHOULDER, _s("L") }, + { "JOY_RIGHT_SHOULDER", Common::JOYSTICK_BUTTON_RIGHT_SHOULDER, _s("R") }, + { "JOY_LEFT_TRIGGER", Common::JOYSTICK_BUTTON_LEFT_TRIGGER, _s("ZL") }, + { "JOY_RIGHT_TRIGGER", Common::JOYSTICK_BUTTON_RIGHT_TRIGGER, _s("ZR") }, + { "JOY_UP", Common::JOYSTICK_BUTTON_DPAD_UP, _s("D-pad Up") }, + { "JOY_DOWN", Common::JOYSTICK_BUTTON_DPAD_DOWN, _s("D-pad Down") }, + { "JOY_LEFT", Common::JOYSTICK_BUTTON_DPAD_LEFT, _s("D-pad Left") }, + { "JOY_RIGHT", Common::JOYSTICK_BUTTON_DPAD_RIGHT, _s("D-pad Right") }, + { nullptr, 0, nullptr } +}; + void OSystem_Switch::init() { @@ -125,3 +148,16 @@ void OSystem_Switch::logMessage(LogMessageType::Type type, const char *message) Common::String OSystem_Switch::getDefaultLogFileName() { return "scummvm.log"; } + +Common::HardwareInputSet *OSystem_Switch::getHardwareInputSet() { + using namespace Common; + + CompositeHardwareInputSet *inputSet = new CompositeHardwareInputSet(); + + // Users may use USB / bluetooth mice and keyboards + inputSet->addHardwareInputSet(new MouseHardwareInputSet(defaultMouseButtons)); + inputSet->addHardwareInputSet(new KeyboardHardwareInputSet(defaultKeys, defaultModifiers)); + inputSet->addHardwareInputSet(new JoystickHardwareInputSet(switchJoystickButtons)); + + return inputSet; +} \ No newline at end of file diff --git a/backends/platform/sdl/switch/switch.h b/backends/platform/sdl/switch/switch.h index 2bdea6fe098..ea2a21f6527 100644 --- a/backends/platform/sdl/switch/switch.h +++ b/backends/platform/sdl/switch/switch.h @@ -33,6 +33,7 @@ public: virtual void setFeatureState(Feature f, bool enable) override; virtual bool getFeatureState(Feature f) override; virtual void logMessage(LogMessageType::Type type, const char *message) override; + virtual Common::HardwareInputSet *getHardwareInputSet() override; protected: virtual Common::String getDefaultLogFileName() override; diff --git a/common/events.h b/common/events.h index 11bfc797da5..0221a98d367 100644 --- a/common/events.h +++ b/common/events.h @@ -131,6 +131,8 @@ enum JoystickButton { JOYSTICK_BUTTON_RIGHT_STICK, JOYSTICK_BUTTON_LEFT_SHOULDER, JOYSTICK_BUTTON_RIGHT_SHOULDER, + JOYSTICK_BUTTON_LEFT_TRIGGER, + JOYSTICK_BUTTON_RIGHT_TRIGGER, JOYSTICK_BUTTON_DPAD_UP, JOYSTICK_BUTTON_DPAD_DOWN, JOYSTICK_BUTTON_DPAD_LEFT,