From 7fa52a091692a271c2ddf1cc052f80c38c510c1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 13 Feb 2026 22:08:28 +0100 Subject: [PATCH] Fix problem with confirm button set to O. Fixes #21042 --- Common/Input/InputState.cpp | 2 ++ Common/UI/View.cpp | 57 +++++++------------------------------ Core/KeyMap.cpp | 36 +++++++++++++++-------- UI/GameSettingsScreen.cpp | 7 +++-- 4 files changed, 40 insertions(+), 62 deletions(-) diff --git a/Common/Input/InputState.cpp b/Common/Input/InputState.cpp index 9e7ad463ca..50e82665e2 100644 --- a/Common/Input/InputState.cpp +++ b/Common/Input/InputState.cpp @@ -35,12 +35,14 @@ const char *GetDeviceName(int deviceId) { bool g_IsMappingMouseInput; +// TODO: Replace these with using the ControlMapper system. std::vector dpadKeys; std::vector confirmKeys; std::vector cancelKeys; std::vector infoKeys; std::vector tabLeftKeys; std::vector tabRightKeys; + static std::unordered_map uiFlipAnalogY; static void AppendKeys(std::vector &keys, const std::vector &newKeys) { diff --git a/Common/UI/View.cpp b/Common/UI/View.cpp index f9f6d483d6..0e1ce10b92 100644 --- a/Common/UI/View.cpp +++ b/Common/UI/View.cpp @@ -289,66 +289,29 @@ bool IsDPadKey(const KeyInput &key) { } bool IsAcceptKey(const KeyInput &key) { - if (confirmKeys.empty()) { - // This path is pretty much not used, confirmKeys should be set. - // TODO: Get rid of this stuff? - if (key.deviceId == DEVICE_ID_KEYBOARD) { - return key.keyCode == NKCODE_SPACE || key.keyCode == NKCODE_ENTER || key.keyCode == NKCODE_Z || key.keyCode == NKCODE_NUMPAD_ENTER; - } else { - return key.keyCode == NKCODE_BUTTON_A || key.keyCode == NKCODE_BUTTON_CROSS || key.keyCode == NKCODE_BUTTON_1 || key.keyCode == NKCODE_DPAD_CENTER; - } - } else { - return MatchesKeyDef(confirmKeys, key); - } + _dbg_assert_(!confirmKeys.empty()); + return MatchesKeyDef(confirmKeys, key); } bool IsEscapeKey(const KeyInput &key) { - if (cancelKeys.empty()) { - // This path is pretty much not used, cancelKeys should be set. - // TODO: Get rid of this stuff? - if (key.deviceId == DEVICE_ID_KEYBOARD) { - return key.keyCode == NKCODE_ESCAPE || key.keyCode == NKCODE_BACK; - } else { - return key.keyCode == NKCODE_BUTTON_CIRCLE || key.keyCode == NKCODE_BUTTON_B || key.keyCode == NKCODE_BUTTON_2; - } - } else { - return MatchesKeyDef(cancelKeys, key); - } + _dbg_assert_(!cancelKeys.empty()); + return MatchesKeyDef(cancelKeys, key); } // Corresponds to Triangle bool IsInfoKey(const KeyInput &key) { - if (infoKeys.empty()) { - // This path is pretty much not used, infoKeys should be set. - // TODO: Get rid of this stuff? - if (key.deviceId == DEVICE_ID_KEYBOARD) { - return key.keyCode == NKCODE_S || key.keyCode == NKCODE_NUMPAD_ADD; - } else { - return key.keyCode == NKCODE_BUTTON_Y || key.keyCode == NKCODE_BUTTON_3; - } - } else { - return MatchesKeyDef(infoKeys, key); - } + _dbg_assert_(!infoKeys.empty()); + return MatchesKeyDef(infoKeys, key); } bool IsTabLeftKey(const KeyInput &key) { - if (tabLeftKeys.empty()) { - // This path is pretty much not used, tabLeftKeys should be set. - // TODO: Get rid of this stuff? - return key.keyCode == NKCODE_BUTTON_L1; - } else { - return MatchesKeyDef(tabLeftKeys, key); - } + _dbg_assert_(!tabLeftKeys.empty()); + return MatchesKeyDef(tabLeftKeys, key); } bool IsTabRightKey(const KeyInput &key) { - if (tabRightKeys.empty()) { - // This path is pretty much not used, tabRightKeys should be set. - // TODO: Get rid of this stuff? - return key.keyCode == NKCODE_BUTTON_R1; - } else { - return MatchesKeyDef(tabRightKeys, key); - } + _dbg_assert_(!tabRightKeys.empty()); + return MatchesKeyDef(tabRightKeys, key); } bool Clickable::Key(const KeyInput &key) { diff --git a/Core/KeyMap.cpp b/Core/KeyMap.cpp index 83313a8543..6b65690337 100644 --- a/Core/KeyMap.cpp +++ b/Core/KeyMap.cpp @@ -84,6 +84,11 @@ void SingleInputMappingFromPspButton(int btn, std::vector *mapping } } +static void InsertIntoVector(std::vector *vec, const InputMapping &mapping) { + if (std::find(vec->begin(), vec->end(), mapping) == vec->end()) + vec->push_back(mapping); +} + // TODO: This is such a mess... void UpdateNativeMenuKeys() { std::vector confirmKeys, cancelKeys; @@ -92,9 +97,10 @@ void UpdateNativeMenuKeys() { std::vector infoKeys; // Mouse mapping might be problematic in UI, so let's ignore mouse for UI + const bool confirmWithCross = g_Config.iButtonPreference == PSP_SYSTEMPARAM_BUTTON_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; + const int confirmKey = confirmWithCross ? CTRL_CROSS : CTRL_CIRCLE; + const int cancelKey = confirmWithCross ? CTRL_CIRCLE : CTRL_CROSS; SingleInputMappingFromPspButton(confirmKey, &confirmKeys, true); SingleInputMappingFromPspButton(cancelKey, &cancelKeys, true); @@ -106,7 +112,7 @@ void UpdateNativeMenuKeys() { SingleInputMappingFromPspButton(CTRL_LEFT, &leftKeys, true); SingleInputMappingFromPspButton(CTRL_RIGHT, &rightKeys, true); -#ifdef __ANDROID__ +#if PPSSPP_PLATFORM(ANDROID) // Hardcode DPAD on Android upKeys.push_back(InputMapping(DEVICE_ID_ANY, NKCODE_DPAD_UP)); downKeys.push_back(InputMapping(DEVICE_ID_ANY, NKCODE_DPAD_DOWN)); @@ -119,26 +125,24 @@ void UpdateNativeMenuKeys() { InputMapping(DEVICE_ID_KEYBOARD, NKCODE_SPACE), InputMapping(DEVICE_ID_KEYBOARD, NKCODE_ENTER), InputMapping(DEVICE_ID_KEYBOARD, NKCODE_NUMPAD_ENTER), - InputMapping(DEVICE_ID_ANY, NKCODE_BUTTON_A), - InputMapping(DEVICE_ID_PAD_0, NKCODE_DPAD_CENTER), // A number of Android devices. + InputMapping(DEVICE_ID_ANY, confirmWithCross ? NKCODE_BUTTON_A : NKCODE_BUTTON_B), + InputMapping(DEVICE_ID_PAD_0, NKCODE_DPAD_CENTER), // A number of old obscure Android devices need this. }; // If they're not already bound, add them in. for (size_t i = 0; i < ARRAY_SIZE(hardcodedConfirmKeys); i++) { - if (std::find(confirmKeys.begin(), confirmKeys.end(), hardcodedConfirmKeys[i]) == confirmKeys.end()) - confirmKeys.push_back(hardcodedConfirmKeys[i]); + InsertIntoVector(&confirmKeys, hardcodedConfirmKeys[i]); } const InputMapping hardcodedCancelKeys[] = { InputMapping(DEVICE_ID_KEYBOARD, NKCODE_ESCAPE), InputMapping(DEVICE_ID_ANY, NKCODE_BACK), - InputMapping(DEVICE_ID_ANY, NKCODE_BUTTON_B), + InputMapping(DEVICE_ID_ANY, confirmWithCross ? NKCODE_BUTTON_B : NKCODE_BUTTON_A), InputMapping(DEVICE_ID_MOUSE, NKCODE_EXT_MOUSEBUTTON_4), }; for (size_t i = 0; i < ARRAY_SIZE(hardcodedCancelKeys); i++) { - if (std::find(cancelKeys.begin(), cancelKeys.end(), hardcodedCancelKeys[i]) == cancelKeys.end()) - cancelKeys.push_back(hardcodedCancelKeys[i]); + InsertIntoVector(&cancelKeys, hardcodedCancelKeys[i]); } const InputMapping hardcodedInfoKeys[] = { @@ -148,10 +152,18 @@ void UpdateNativeMenuKeys() { }; for (size_t i = 0; i < ARRAY_SIZE(hardcodedInfoKeys); i++) { - if (std::find(infoKeys.begin(), infoKeys.end(), hardcodedInfoKeys[i]) == infoKeys.end()) - infoKeys.push_back(hardcodedInfoKeys[i]); + InsertIntoVector(&infoKeys, hardcodedInfoKeys[i]); } + /* + for (size_t i = 0; i < confirmKeys.size(); i++) { + INFO_LOG(Log::System, "Confirm key: %s", MultiInputMapping(confirmKeys[i]).ToVisualString().c_str()); + } + for (size_t i = 0; i < cancelKeys.size(); i++) { + INFO_LOG(Log::System, "Cancel key: %s", MultiInputMapping(cancelKeys[i]).ToVisualString().c_str()); + } + */ + SetDPadKeys(upKeys, downKeys, leftKeys, rightKeys); SetConfirmCancelKeys(confirmKeys, cancelKeys); SetTabLeftRightKeys(tabLeft, tabRight); diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 99d41e31d8..41844963fb 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -164,8 +164,6 @@ GameSettingsScreen::~GameSettingsScreen() { System_Notify(SystemNotification::UI); - KeyMap::UpdateNativeMenuKeys(); - // Wipe some caches after potentially changing settings. // Let's not send resize messages here, handled elsewhere. System_PostUIMessage(UIMessage::GPU_CONFIG_CHANGED); @@ -1466,7 +1464,10 @@ void GameSettingsScreen::CreateSystemSettings(UI::ViewGroup *systemSettings) { static const char *timeFormat[] = { "24HR", "12HR" }; systemSettings->Add(new PopupMultiChoice(&g_Config.iTimeFormat, sy->T("Time Format"), timeFormat, 0, ARRAY_SIZE(timeFormat), I18NCat::SYSTEM, screenManager())); static const char *buttonPref[] = { "Use O to confirm", "Use X to confirm" }; - systemSettings->Add(new PopupMultiChoice(&g_Config.iButtonPreference, sy->T("Confirmation Button"), buttonPref, 0, ARRAY_SIZE(buttonPref), I18NCat::SYSTEM, screenManager())); + PopupMultiChoice *buttonPrefChoice = systemSettings->Add(new PopupMultiChoice(&g_Config.iButtonPreference, sy->T("Confirmation Button"), buttonPref, 0, ARRAY_SIZE(buttonPref), I18NCat::SYSTEM, screenManager())); + buttonPrefChoice->OnChoice.Add([](UI::EventParams &e) { + KeyMap::UpdateNativeMenuKeys(); + }); #if defined(_WIN32) || (defined(USING_QT_UI) && !defined(MOBILE_DEVICE)) systemSettings->Add(new ItemHeader(sy->T("Recording")));