From 968150cc778bdb1f4d2e377a5bc6558a0fff5760 Mon Sep 17 00:00:00 2001 From: The Dax Date: Thu, 22 Aug 2013 06:46:35 -0400 Subject: [PATCH 1/6] Rewrite the hard-coded removal of accept/cancel keys. It's much cleaner and simpler now. --- Common/KeyMap.cpp | 32 +++++++++++++++++++++++++++++++- native | 2 +- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Common/KeyMap.cpp b/Common/KeyMap.cpp index 096e326718..ae8fa4d07c 100644 --- a/Common/KeyMap.cpp +++ b/Common/KeyMap.cpp @@ -20,6 +20,7 @@ #include "../Core/Config.h" #include "base/NativeApp.h" #include "KeyMap.h" +#include "../Core/HLE/sceUtility.h" namespace KeyMap { @@ -205,6 +206,30 @@ static const DefMappingStruct defaultXperiaPlay[] = { {VIRTKEY_AXIS_Y_MAX, JOYSTICK_AXIS_Y, +1}, }; +void UpdateConfirmCancelKeys() { + std::vector confirm, cancel; + + int confirmBtns = g_Config.iButtonPreference == PSP_SYSTEMPARAM_BUTTON_CROSS ? CTRL_CROSS : CTRL_CIRCLE; + int cancelBtns = g_Config.iButtonPreference == PSP_SYSTEMPARAM_BUTTON_CROSS ? CTRL_CIRCLE : CTRL_CROSS; + + for(auto i = g_controllerMap[confirmBtns].begin(); i != g_controllerMap[confirmBtns].end(); ++i) + { + confirm.push_back((keycode_t)i->keyCode); + } + + for(auto i = g_controllerMap[cancelBtns].begin(); i != g_controllerMap[cancelBtns].end(); ++i) + { + cancel.push_back((keycode_t)i->keyCode); + } + + cancel.push_back(NKCODE_SPACE); + cancel.push_back(NKCODE_ESCAPE); + cancel.push_back(NKCODE_BACK); + cancel.push_back(NKCODE_EXT_MOUSEBUTTON_2); + + SetConfirmCancelKeys(confirm, cancel); +} + 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 +260,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 +640,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 +703,8 @@ void LoadFromIni(IniFile &file) { SetKeyMapping(psp_button_names[i].key, KeyDef(deviceId, keyCode), false); } } - return; + + UpdateConfirmCancelKeys(); } void SaveToIni(IniFile &file) { diff --git a/native b/native index 92dd9cd798..a8b45a68b9 160000 --- a/native +++ b/native @@ -1 +1 @@ -Subproject commit 92dd9cd7989394e1a5d69dceed0175519d3ffcd9 +Subproject commit a8b45a68b961d655b68c7166a798cb0b6447f039 From 20166c7f4f24516fb3c9475d8dc6c984e6d7f8f3 Mon Sep 17 00:00:00 2001 From: The Dax Date: Thu, 22 Aug 2013 07:10:06 -0400 Subject: [PATCH 2/6] Let the UI update the confirm cancel keys when the user presses back. They may have changed the O/X preference option. --- Common/KeyMap.h | 3 ++- UI/GameSettingsScreen.cpp | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) 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; } From 57ab8aa6113a7663c4729a43df7dc01de90d7272 Mon Sep 17 00:00:00 2001 From: The Dax Date: Thu, 22 Aug 2013 07:20:18 -0400 Subject: [PATCH 3/6] Only hard-code keys if they're not bound. --- Common/KeyMap.cpp | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/Common/KeyMap.cpp b/Common/KeyMap.cpp index ae8fa4d07c..e84e7d9cd4 100644 --- a/Common/KeyMap.cpp +++ b/Common/KeyMap.cpp @@ -21,6 +21,8 @@ #include "base/NativeApp.h" #include "KeyMap.h" #include "../Core/HLE/sceUtility.h" +#include + namespace KeyMap { @@ -207,27 +209,33 @@ static const DefMappingStruct defaultXperiaPlay[] = { }; void UpdateConfirmCancelKeys() { - std::vector confirm, cancel; + std::vector confirmKeys, cancelKeys; - int confirmBtns = g_Config.iButtonPreference == PSP_SYSTEMPARAM_BUTTON_CROSS ? CTRL_CROSS : CTRL_CIRCLE; - int cancelBtns = g_Config.iButtonPreference == PSP_SYSTEMPARAM_BUTTON_CROSS ? CTRL_CIRCLE : CTRL_CROSS; + 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[confirmBtns].begin(); i != g_controllerMap[confirmBtns].end(); ++i) - { - confirm.push_back((keycode_t)i->keyCode); + 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[cancelBtns].begin(); i != g_controllerMap[cancelBtns].end(); ++i) - { - cancel.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); } - cancel.push_back(NKCODE_SPACE); - cancel.push_back(NKCODE_ESCAPE); - cancel.push_back(NKCODE_BACK); - cancel.push_back(NKCODE_EXT_MOUSEBUTTON_2); + const keycode_t hardcodedCancelKeys[] = { + NKCODE_SPACE, + NKCODE_ESCAPE, + NKCODE_BACK, + NKCODE_EXT_MOUSEBUTTON_2 + }; - SetConfirmCancelKeys(confirm, cancel); + // If they're not already bound, add them in. + 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) { From 0c249f00844194de86ad795be2f842c36e8c9e2d Mon Sep 17 00:00:00 2001 From: The Dax Date: Thu, 22 Aug 2013 12:38:04 -0400 Subject: [PATCH 4/6] Remove RMB as a default cancel key. We'll let the user bind it to cancel manually. --- Common/KeyMap.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Common/KeyMap.cpp b/Common/KeyMap.cpp index e84e7d9cd4..f47f74be7a 100644 --- a/Common/KeyMap.cpp +++ b/Common/KeyMap.cpp @@ -222,11 +222,14 @@ void UpdateConfirmCancelKeys() { cancelKeys.push_back((keycode_t)i->keyCode); } + // Push several hard-coded keys before submitting to native. + if(std::find(cancelKeys.begin(), cancelKeys.end(), NKCODE_ENTER) == cancelKeys.end()) + confirmKeys.push_back(NKCODE_ENTER); + const keycode_t hardcodedCancelKeys[] = { NKCODE_SPACE, NKCODE_ESCAPE, NKCODE_BACK, - NKCODE_EXT_MOUSEBUTTON_2 }; // If they're not already bound, add them in. From 4beef2b8774e6957739587609d3c7840b7289f3b Mon Sep 17 00:00:00 2001 From: The Dax Date: Thu, 22 Aug 2013 12:49:39 -0400 Subject: [PATCH 5/6] Fix dumb copy and paste error. --- Common/KeyMap.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Common/KeyMap.cpp b/Common/KeyMap.cpp index f47f74be7a..e2ae8a3612 100644 --- a/Common/KeyMap.cpp +++ b/Common/KeyMap.cpp @@ -21,6 +21,7 @@ #include "base/NativeApp.h" #include "KeyMap.h" #include "../Core/HLE/sceUtility.h" + #include @@ -223,7 +224,7 @@ void UpdateConfirmCancelKeys() { } // Push several hard-coded keys before submitting to native. - if(std::find(cancelKeys.begin(), cancelKeys.end(), NKCODE_ENTER) == cancelKeys.end()) + if(std::find(confirmKeys.begin(), confirmKeys.end(), NKCODE_ENTER) == confirmKeys.end()) confirmKeys.push_back(NKCODE_ENTER); const keycode_t hardcodedCancelKeys[] = { From 59f878a3c4d1c44be6abe336a3fff7a4a2a37b6e Mon Sep 17 00:00:00 2001 From: The Dax Date: Thu, 22 Aug 2013 13:06:12 -0400 Subject: [PATCH 6/6] Add space as a confirm key, and use a loop for hard-coded confirm keys, too. --- Common/KeyMap.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Common/KeyMap.cpp b/Common/KeyMap.cpp index e2ae8a3612..98ca6f1b2d 100644 --- a/Common/KeyMap.cpp +++ b/Common/KeyMap.cpp @@ -224,16 +224,22 @@ void UpdateConfirmCancelKeys() { } // Push several hard-coded keys before submitting to native. - if(std::find(confirmKeys.begin(), confirmKeys.end(), NKCODE_ENTER) == confirmKeys.end()) - confirmKeys.push_back(NKCODE_ENTER); + 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_SPACE, NKCODE_ESCAPE, NKCODE_BACK, }; - // If they're not already bound, add them in. 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]);