diff --git a/Common/Input/InputState.cpp b/Common/Input/InputState.cpp index 99bbd4ceea19..794ab788bdba 100644 --- a/Common/Input/InputState.cpp +++ b/Common/Input/InputState.cpp @@ -37,6 +37,7 @@ const char *GetDeviceName(int deviceId) { std::vector dpadKeys; std::vector confirmKeys; std::vector cancelKeys; +std::vector infoKeys; std::vector tabLeftKeys; std::vector tabRightKeys; static std::unordered_map uiFlipAnalogY; @@ -69,6 +70,10 @@ void SetTabLeftRightKeys(const std::vector &tabLeft, const std::ve tabRightKeys = tabRight; } +void SetInfoKeys(const std::vector &info) { + infoKeys = info; +} + void SetAnalogFlipY(std::unordered_map flipYByDeviceId) { uiFlipAnalogY = flipYByDeviceId; } diff --git a/Common/Input/InputState.h b/Common/Input/InputState.h index a94547443d23..2297d6bbf05b 100644 --- a/Common/Input/InputState.h +++ b/Common/Input/InputState.h @@ -191,12 +191,14 @@ struct AxisInput { extern std::vector dpadKeys; extern std::vector confirmKeys; extern std::vector cancelKeys; +extern std::vector infoKeys; extern std::vector tabLeftKeys; extern std::vector tabRightKeys; void SetDPadKeys(const std::vector &leftKey, const std::vector &rightKey, const std::vector &upKey, const std::vector &downKey); void SetConfirmCancelKeys(const std::vector &confirm, const std::vector &cancel); void SetTabLeftRightKeys(const std::vector &tabLeft, const std::vector &tabRight); +void SetInfoKeys(const std::vector &info); // 0 means unknown (attempt autodetect), -1 means flip, 1 means original direction. void SetAnalogFlipY(std::unordered_map flipYByDeviceId); diff --git a/Common/UI/View.cpp b/Common/UI/View.cpp index 9959c9b7b5cf..6ebac93d384f 100644 --- a/Common/UI/View.cpp +++ b/Common/UI/View.cpp @@ -307,6 +307,21 @@ bool IsEscapeKey(const KeyInput &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); + } +} + bool IsTabLeftKey(const KeyInput &key) { if (tabLeftKeys.empty()) { // This path is pretty much not used, tabLeftKeys should be set. diff --git a/Common/UI/View.h b/Common/UI/View.h index e1f1a8ecf4cb..0e0c5f7dccf5 100644 --- a/Common/UI/View.h +++ b/Common/UI/View.h @@ -1066,6 +1066,7 @@ void ApplyBoundsBySpec(Bounds &bounds, MeasureSpec horiz, MeasureSpec vert); bool IsDPadKey(const KeyInput &key); bool IsAcceptKey(const KeyInput &key); bool IsEscapeKey(const KeyInput &key); +bool IsInfoKey(const KeyInput &key); bool IsTabLeftKey(const KeyInput &key); bool IsTabRightKey(const KeyInput &key); diff --git a/Core/KeyMap.cpp b/Core/KeyMap.cpp index f906b4666a53..078f4dc4a83c 100644 --- a/Core/KeyMap.cpp +++ b/Core/KeyMap.cpp @@ -67,13 +67,16 @@ void UpdateNativeMenuKeys() { std::vector confirmKeys, cancelKeys; std::vector tabLeft, tabRight; std::vector upKeys, downKeys, leftKeys, rightKeys; + std::vector infoKeys; + + // Mouse mapping might be problematic in UI, so let's ignore mouse for UI 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; - // Mouse mapping might be problematic in UI, so let's ignore mouse for UI SingleInputMappingFromPspButton(confirmKey, &confirmKeys, true); SingleInputMappingFromPspButton(cancelKey, &cancelKeys, true); + SingleInputMappingFromPspButton(CTRL_TRIANGLE, &infoKeys, true); SingleInputMappingFromPspButton(CTRL_LTRIGGER, &tabLeft, true); SingleInputMappingFromPspButton(CTRL_RTRIGGER, &tabRight, true); SingleInputMappingFromPspButton(CTRL_UP, &upKeys, true); @@ -116,9 +119,21 @@ void UpdateNativeMenuKeys() { cancelKeys.push_back(hardcodedCancelKeys[i]); } + const InputMapping hardcodedInfoKeys[] = { + InputMapping(DEVICE_ID_KEYBOARD, NKCODE_S), + InputMapping(DEVICE_ID_KEYBOARD, NKCODE_NUMPAD_ADD), + InputMapping(DEVICE_ID_PAD_0, NKCODE_BUTTON_Y), // Also triangle + }; + + 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]); + } + SetDPadKeys(upKeys, downKeys, leftKeys, rightKeys); SetConfirmCancelKeys(confirmKeys, cancelKeys); SetTabLeftRightKeys(tabLeft, tabRight); + SetInfoKeys(infoKeys); std::unordered_map flipYByDeviceId; for (InputDeviceID deviceId : g_seenDeviceIds) { diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index 0ad55db3dfe3..f52d00698080 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -158,12 +158,10 @@ class GameButton : public UI::Clickable { std::vector pspKeys; bool showInfo = false; - if (HasFocus() && KeyMap::InputMappingToPspButton(InputMapping(key.deviceId, key.keyCode), &pspKeys)) { - for (auto it = pspKeys.begin(), end = pspKeys.end(); it != end; ++it) { - // If the button mapped to triangle, then show the info. - if ((key.flags & KEY_UP) && *it == CTRL_TRIANGLE) { - showInfo = true; - } + if (HasFocus() && UI::IsInfoKey(key)) { + // If the button mapped to triangle, then show the info. + if (key.flags & KEY_UP) { + showInfo = true; } } else if (hovering_ && key.deviceId == DEVICE_ID_MOUSE && key.keyCode == NKCODE_EXT_MOUSEBUTTON_2) { // If it's the right mouse button, and it's not otherwise mapped, show the info also.