Skip to content

Commit

Permalink
Merge pull request #18419 from hrydgard/gamelist-triangle-button-cleanup
Browse files Browse the repository at this point in the history
Clean up the checks for triangle-button-for-info on the main screen
  • Loading branch information
hrydgard committed Nov 13, 2023
2 parents cb9c6dc + 2910303 commit 70c7bb3
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 7 deletions.
5 changes: 5 additions & 0 deletions Common/Input/InputState.cpp
Expand Up @@ -37,6 +37,7 @@ const char *GetDeviceName(int deviceId) {
std::vector<InputMapping> dpadKeys;
std::vector<InputMapping> confirmKeys;
std::vector<InputMapping> cancelKeys;
std::vector<InputMapping> infoKeys;
std::vector<InputMapping> tabLeftKeys;
std::vector<InputMapping> tabRightKeys;
static std::unordered_map<InputDeviceID, int> uiFlipAnalogY;
Expand Down Expand Up @@ -69,6 +70,10 @@ void SetTabLeftRightKeys(const std::vector<InputMapping> &tabLeft, const std::ve
tabRightKeys = tabRight;
}

void SetInfoKeys(const std::vector<InputMapping> &info) {
infoKeys = info;
}

void SetAnalogFlipY(std::unordered_map<InputDeviceID, int> flipYByDeviceId) {
uiFlipAnalogY = flipYByDeviceId;
}
Expand Down
2 changes: 2 additions & 0 deletions Common/Input/InputState.h
Expand Up @@ -191,12 +191,14 @@ struct AxisInput {
extern std::vector<InputMapping> dpadKeys;
extern std::vector<InputMapping> confirmKeys;
extern std::vector<InputMapping> cancelKeys;
extern std::vector<InputMapping> infoKeys;
extern std::vector<InputMapping> tabLeftKeys;
extern std::vector<InputMapping> tabRightKeys;
void SetDPadKeys(const std::vector<InputMapping> &leftKey, const std::vector<InputMapping> &rightKey,
const std::vector<InputMapping> &upKey, const std::vector<InputMapping> &downKey);
void SetConfirmCancelKeys(const std::vector<InputMapping> &confirm, const std::vector<InputMapping> &cancel);
void SetTabLeftRightKeys(const std::vector<InputMapping> &tabLeft, const std::vector<InputMapping> &tabRight);
void SetInfoKeys(const std::vector<InputMapping> &info);

// 0 means unknown (attempt autodetect), -1 means flip, 1 means original direction.
void SetAnalogFlipY(std::unordered_map<InputDeviceID, int> flipYByDeviceId);
Expand Down
15 changes: 15 additions & 0 deletions Common/UI/View.cpp
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions Common/UI/View.h
Expand Up @@ -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);

Expand Down
17 changes: 16 additions & 1 deletion Core/KeyMap.cpp
Expand Up @@ -67,13 +67,16 @@ void UpdateNativeMenuKeys() {
std::vector<InputMapping> confirmKeys, cancelKeys;
std::vector<InputMapping> tabLeft, tabRight;
std::vector<InputMapping> upKeys, downKeys, leftKeys, rightKeys;
std::vector<InputMapping> 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);
Expand Down Expand Up @@ -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<InputDeviceID, int> flipYByDeviceId;
for (InputDeviceID deviceId : g_seenDeviceIds) {
Expand Down
10 changes: 4 additions & 6 deletions UI/MainScreen.cpp
Expand Up @@ -158,12 +158,10 @@ class GameButton : public UI::Clickable {
std::vector<int> 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.
Expand Down

0 comments on commit 70c7bb3

Please sign in to comment.