distribution/packages/games/emulators/duckstationsa/patches/RG503/005-add-hotkeys.patch
Brooksytech b1a006b21f
Add Duckstation Standalone Emulator. (#22)
* initial duckstation SA implementation
2022-07-13 12:47:58 -07:00

110 lines
4.6 KiB
Diff

diff --git a/src/frontend-common/sdl_controller_interface.cpp b/src/frontend-common/sdl_controller_interface.cpp
index 20e81daf..1deac2ce 100644
--- a/src/frontend-common/sdl_controller_interface.cpp
+++ b/src/frontend-common/sdl_controller_interface.cpp
@@ -6,6 +6,7 @@
#include "core/host_interface.h"
#include "core/system.h"
#include "sdl_initializer.h"
+#include "fullscreen_ui.h"
#include <SDL.h>
#include <cmath>
Log_SetChannel(SDLControllerInterface);
@@ -93,6 +94,8 @@ void SDLControllerInterface::PollEvents()
bool SDLControllerInterface::ProcessSDLEvent(const SDL_Event* event)
{
+ if (m_slots < 0) { m_host_interface->AddOSDMessage("State Slot set to #0", 5.f); m_slots = 0; }
+
switch (event->type)
{
case SDL_CONTROLLERDEVICEADDED:
@@ -204,6 +207,7 @@ bool SDLControllerInterface::OpenGameController(int index)
cd.joystick_id = joystick_id;
cd.haptic_left_right_effect = -1;
cd.game_controller = gcontroller;
+ cd.hotkey_down = false;
#if SDL_VERSION_ATLEAST(2, 0, 9)
cd.use_game_controller_rumble = (SDL_GameControllerRumble(gcontroller, 0, 0, 0) == 0);
@@ -712,15 +716,59 @@ bool SDLControllerInterface::HandleControllerButtonEvent(const SDL_ControllerBut
m_host_interface->SetControllerNavigationButtonState(nav_button_mapping[ev->button], pressed);
}
+ if (ev->button >= MAX_NUM_BUTTONS)
+ return false;
+
+ //------ Mimic Retroarch
+ if (ev->button == SDL_CONTROLLER_BUTTON_GUIDE || ev->button == SDL_CONTROLLER_BUTTON_BACK) it->hotkey_down = pressed;
+ else if (it->hotkey_down)
+ {
+ if (!pressed)
+ switch(ev->button)
+ {
+ case SDL_CONTROLLER_BUTTON_A : m_host_interface->SaveScreenshot(); break;
+ case SDL_CONTROLLER_BUTTON_B : m_host_interface->ResetSystem(); break;
+ case SDL_CONTROLLER_BUTTON_X : if (FullscreenUI::HasActiveWindow()) FullscreenUI::CloseQuickMenu(); else FullscreenUI::OpenQuickMenu(); break;
+ case SDL_CONTROLLER_BUTTON_Y : m_host_interface->ToggleWidescreen(); break;
+ case SDL_CONTROLLER_BUTTON_START :
+ case SDL_CONTROLLER_BUTTON_LEFTSTICK :
+ case SDL_CONTROLLER_BUTTON_RIGHTSTICK : break;
+ case SDL_CONTROLLER_BUTTON_LEFTSHOULDER : m_host_interface->LoadState(false, m_slots); break;
+ case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER: m_host_interface->SaveState(false, m_slots); break;
+ case SDL_CONTROLLER_BUTTON_DPAD_UP : m_slots = ++m_slots % 10; m_host_interface->AddOSDMessage(std::string("State Slot set to #") + (char)(0x30 + m_slots), 5.f); break;
+ case SDL_CONTROLLER_BUTTON_DPAD_DOWN : m_slots = (m_slots + 9) % 10; m_host_interface->AddOSDMessage(std::string("State Slot set to #") + (char)(0x30 + m_slots), 5.f); break;
+ case SDL_CONTROLLER_BUTTON_DPAD_LEFT : m_host_interface->SetRewindState(!System::IsRewinding()); break;
+ case SDL_CONTROLLER_BUTTON_DPAD_RIGHT : m_host_interface->SetFastForwardEnabled(!m_host_interface->IsFastForwardEnabled()); break;
+ default: break;
+ }
+ else
+ switch(ev->button)
+ {
+ case SDL_CONTROLLER_BUTTON_START : m_host_interface->RequestExit(); break;
+ case SDL_CONTROLLER_BUTTON_A :
+ case SDL_CONTROLLER_BUTTON_B :
+ case SDL_CONTROLLER_BUTTON_X :
+ case SDL_CONTROLLER_BUTTON_Y :
+ case SDL_CONTROLLER_BUTTON_LEFTSTICK :
+ case SDL_CONTROLLER_BUTTON_RIGHTSTICK :
+ case SDL_CONTROLLER_BUTTON_LEFTSHOULDER :
+ case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER:
+ case SDL_CONTROLLER_BUTTON_DPAD_UP :
+ case SDL_CONTROLLER_BUTTON_DPAD_DOWN :
+ case SDL_CONTROLLER_BUTTON_DPAD_LEFT :
+ case SDL_CONTROLLER_BUTTON_DPAD_RIGHT :
+ default: break;
+ }
+
+ return true;
+ }
+
if (m_host_interface->IsControllerNavigationActive())
{
// UI consumed the event
return true;
}
- if (ev->button >= MAX_NUM_BUTTONS)
- return false;
-
const ButtonCallback& cb = it->button_mapping[ev->button];
if (cb)
{
diff --git a/src/frontend-common/sdl_controller_interface.h b/src/frontend-common/sdl_controller_interface.h
index 06963a5c..ffc2ffac 100644
--- a/src/frontend-common/sdl_controller_interface.h
+++ b/src/frontend-common/sdl_controller_interface.h
@@ -57,6 +57,7 @@ private:
int joystick_id;
int player_id;
bool use_game_controller_rumble;
+ bool hotkey_down;
float deadzone = 0.25f;
@@ -93,4 +94,5 @@ private:
Hook::Callback m_event_intercept_callback;
bool m_sdl_subsystem_initialized = false;
+ int m_slots = -1;
};