diff --git a/Common/KeyMap.cpp b/Common/KeyMap.cpp index 096e326718..98ca6f1b2d 100644 --- a/Common/KeyMap.cpp +++ b/Common/KeyMap.cpp @@ -20,6 +20,10 @@ #include "../Core/Config.h" #include "base/NativeApp.h" #include "KeyMap.h" +#include "../Core/HLE/sceUtility.h" + +#include + namespace KeyMap { @@ -205,6 +209,45 @@ static const DefMappingStruct defaultXperiaPlay[] = { {VIRTKEY_AXIS_Y_MAX, JOYSTICK_AXIS_Y, +1}, }; +void UpdateConfirmCancelKeys() { + std::vector confirmKeys, cancelKeys; + + int confirmKey = g_Config.iButtonPreference == PSP_SYSTEMPARAM_BUTTON_CROSS ? CTRL_CROSS : CTRL_CIRCLE; + int cancelKey = g_Config.iButtonPreference == PSP_SYSTEMPARAM_BUTTON_CROSS ? CTRL_CIRCLE : CTRL_CROSS; + + for(auto i = g_controllerMap[confirmKey].begin(); i != g_controllerMap[confirmKey].end(); ++i) { + confirmKeys.push_back((keycode_t)i->keyCode); + } + + for(auto i = g_controllerMap[cancelKey].begin(); i != g_controllerMap[cancelKey].end(); ++i) { + cancelKeys.push_back((keycode_t)i->keyCode); + } + + // Push several hard-coded keys before submitting to native. + const keycode_t hardcodedConfirmKeys[] = { + NKCODE_SPACE, + NKCODE_ENTER, + }; + + // If they're not already bound, add them in. + for(int i = 0; i < ARRAY_SIZE(hardcodedConfirmKeys); i++) { + if(std::find(confirmKeys.begin(), confirmKeys.end(), hardcodedConfirmKeys[i]) == confirmKeys.end()) + confirmKeys.push_back(hardcodedConfirmKeys[i]); + } + + const keycode_t hardcodedCancelKeys[] = { + NKCODE_ESCAPE, + NKCODE_BACK, + }; + + for(int i = 0; i < ARRAY_SIZE(hardcodedCancelKeys); i++) { + if(std::find(cancelKeys.begin(), cancelKeys.end(), hardcodedCancelKeys[i]) == cancelKeys.end()) + cancelKeys.push_back(hardcodedCancelKeys[i]); + } + + SetConfirmCancelKeys(confirmKeys,cancelKeys); +} + static void SetDefaultKeyMap(int deviceId, const DefMappingStruct *array, int count, bool replace) { for (size_t i = 0; i < count; i++) { if (array[i].direction == 0) @@ -235,6 +278,8 @@ void SetDefaultKeyMap(DefaultMaps dmap, bool replace) { SetDefaultKeyMap(DEVICE_ID_DEFAULT, defaultXperiaPlay, ARRAY_SIZE(defaultXperiaPlay), replace); break; } + + UpdateConfirmCancelKeys(); } const KeyMap_IntStrPair key_names[] = { @@ -613,6 +658,8 @@ void SetKeyMapping(int btn, KeyDef key, bool replace) { } g_controllerMap[btn].push_back(key); } + + UpdateConfirmCancelKeys(); } void SetAxisMapping(int btn, int deviceId, int axisId, int direction, bool replace) { @@ -674,7 +721,8 @@ void LoadFromIni(IniFile &file) { SetKeyMapping(psp_button_names[i].key, KeyDef(deviceId, keyCode), false); } } - return; + + UpdateConfirmCancelKeys(); } void SaveToIni(IniFile &file) { diff --git a/Common/KeyMap.h b/Common/KeyMap.h index 3ccdf7bcb9..9b577cbf01 100644 --- a/Common/KeyMap.h +++ b/Common/KeyMap.h @@ -151,5 +151,6 @@ namespace KeyMap { void RestoreDefault(); void QuickMap(int device); -} + void UpdateConfirmCancelKeys(); +} diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index a0ddcf7efc..28da8c857e 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -34,6 +34,7 @@ #include "math/curves.h" #include "Core/HW/atrac3plus.h" #include "Core/System.h" +#include "Common/KeyMap.h" #ifdef _WIN32 #include "Core/Host.h" @@ -455,6 +456,8 @@ UI::EventReturn GameSettingsScreen::OnBack(UI::EventParams &e) { PostMessage(MainWindow::hwndMain, MainWindow::WM_USER_ATRAC_STATUS_CHANGED, 0, 0); #endif + KeyMap::UpdateConfirmCancelKeys(); + return UI::EVENT_DONE; } diff --git a/native b/native index 92dd9cd798..a8b45a68b9 160000 --- a/native +++ b/native @@ -1 +1 @@ -Subproject commit 92dd9cd7989394e1a5d69dceed0175519d3ffcd9 +Subproject commit a8b45a68b961d655b68c7166a798cb0b6447f039