From cf107e7f905c55d7c4b2383cd86eb23e2d8dcc88 Mon Sep 17 00:00:00 2001 From: Cameron Cawley Date: Sun, 16 Jun 2019 23:29:12 +0100 Subject: [PATCH] PEGASUS: Implement joystick support --- engines/pegasus/detection.cpp | 3 ++- engines/pegasus/input.cpp | 39 +++++++++++++++++++++++++++++++++++ engines/pegasus/input.h | 2 ++ engines/pegasus/pegasus.cpp | 1 + 4 files changed, 44 insertions(+), 1 deletion(-) diff --git a/engines/pegasus/detection.cpp b/engines/pegasus/detection.cpp index 01a3113f2a8..74867c19771 100644 --- a/engines/pegasus/detection.cpp +++ b/engines/pegasus/detection.cpp @@ -43,7 +43,8 @@ bool PegasusEngine::hasFeature(EngineFeature f) const { return (f == kSupportsRTL) || (f == kSupportsLoadingDuringRuntime) - || (f == kSupportsSavingDuringRuntime); + || (f == kSupportsSavingDuringRuntime) + || (f == kSupportsJoystick); } bool PegasusEngine::isDemo() const { diff --git a/engines/pegasus/input.cpp b/engines/pegasus/input.cpp index 36a84dbd3c3..50267ae7675 100644 --- a/engines/pegasus/input.cpp +++ b/engines/pegasus/input.cpp @@ -175,6 +175,35 @@ void InputDeviceManager::waitInput(const InputBits filter) { } } +uint InputDeviceManager::convertJoystickToKey(uint joybutton) { + switch (joybutton) { + case Common::JOYSTICK_BUTTON_A: + return Common::KEYCODE_RETURN; // Action + case Common::JOYSTICK_BUTTON_B: + // nothing + break; + case Common::JOYSTICK_BUTTON_X: + return Common::KEYCODE_i; // Display Object Info + case Common::JOYSTICK_BUTTON_Y: + return Common::KEYCODE_t; // Toggle Data Display + case Common::JOYSTICK_BUTTON_LEFT_SHOULDER: + return Common::KEYCODE_TILDE; // Open Inventory Panel + case Common::JOYSTICK_BUTTON_RIGHT_SHOULDER: + return Common::KEYCODE_KP_MULTIPLY; // Open Biochip Panel + case Common::JOYSTICK_BUTTON_START: + return Common::KEYCODE_p; // Pause + case Common::JOYSTICK_BUTTON_DPAD_UP: + return Common::KEYCODE_UP; + case Common::JOYSTICK_BUTTON_DPAD_DOWN: + return Common::KEYCODE_DOWN; + case Common::JOYSTICK_BUTTON_DPAD_LEFT: + return Common::KEYCODE_LEFT; + case Common::JOYSTICK_BUTTON_DPAD_RIGHT: + return Common::KEYCODE_RIGHT; + } + return 0; +} + bool InputDeviceManager::notifyEvent(const Common::Event &event) { if (GUI::GuiManager::instance().isActive()) { // For some reason, the engine hooks in the event system using an EventObserver. @@ -215,6 +244,16 @@ bool InputDeviceManager::notifyEvent(const Common::Event &event) { if (_keyMap.contains(event.kbd.keycode)) _keyMap[event.kbd.keycode] = false; break; + case Common::EVENT_JOYAXIS_MOTION: + break; + case Common::EVENT_JOYBUTTON_DOWN: + if (_keyMap.contains(convertJoystickToKey(event.joystick.button))) + _keyMap[convertJoystickToKey(event.joystick.button)] = true; + break; + case Common::EVENT_JOYBUTTON_UP: + if (_keyMap.contains(convertJoystickToKey(event.joystick.button))) + _keyMap[convertJoystickToKey(event.joystick.button)] = false; + break; default: break; } diff --git a/engines/pegasus/input.h b/engines/pegasus/input.h index 42590769325..3b06b154efc 100644 --- a/engines/pegasus/input.h +++ b/engines/pegasus/input.h @@ -52,6 +52,8 @@ public: void pumpEvents(); + uint convertJoystickToKey(uint joybutton); + protected: friend class Common::Singleton; diff --git a/engines/pegasus/pegasus.cpp b/engines/pegasus/pegasus.cpp index f2c0afba5c6..043fddc03ce 100644 --- a/engines/pegasus/pegasus.cpp +++ b/engines/pegasus/pegasus.cpp @@ -1279,6 +1279,7 @@ void PegasusEngine::showTempScreen(const Common::String &fileName) { case Common::EVENT_LBUTTONUP: case Common::EVENT_RBUTTONUP: case Common::EVENT_KEYDOWN: + case Common::EVENT_JOYBUTTON_DOWN: done = true; break; default: