Fix "ANY" device keydefs (used for ui nav).

This commit is contained in:
Henrik Rydgard 2015-09-17 22:07:22 +02:00
parent 3232e46c36
commit aa4a33e6db
2 changed files with 13 additions and 5 deletions

View File

@ -88,6 +88,7 @@ public:
int deviceId;
int keyCode;
// If you want to use std::find and match ANY, you need to perform an explicit search for that.
bool operator < (const KeyDef &other) const {
if (deviceId < other.deviceId) return true;
if (deviceId > other.deviceId) return false;

View File

@ -220,13 +220,20 @@ void Clickable::Touch(const TouchInput &input) {
}
}
static bool MatchesKeyDef(const std::vector<KeyDef> &defs, const KeyInput &key) {
// In addition to the actual search, we need to do another search where we replace the device ID with "ANY".
return
std::find(defs.begin(), defs.end(), KeyDef(key.deviceId, key.keyCode)) != defs.end() ||
std::find(defs.begin(), defs.end(), KeyDef(DEVICE_ID_ANY, key.keyCode)) != defs.end();
}
// TODO: O/X confirm preference for xperia play?
bool IsDPadKey(const KeyInput &key) {
if (dpadKeys.empty()) {
return key.keyCode >= NKCODE_DPAD_UP && key.keyCode <= NKCODE_DPAD_RIGHT;
} else {
return std::find(dpadKeys.begin(), dpadKeys.end(), KeyDef(key.deviceId, key.keyCode)) != dpadKeys.end();
return MatchesKeyDef(dpadKeys, key);
}
}
@ -238,7 +245,7 @@ bool IsAcceptKey(const KeyInput &key) {
return key.keyCode == NKCODE_BUTTON_A || key.keyCode == NKCODE_BUTTON_CROSS || key.keyCode == NKCODE_BUTTON_1;
}
} else {
return std::find(confirmKeys.begin(), confirmKeys.end(), KeyDef(key.deviceId, key.keyCode)) != confirmKeys.end();
return MatchesKeyDef(confirmKeys, key);
}
}
@ -250,7 +257,7 @@ bool IsEscapeKey(const KeyInput &key) {
return key.keyCode == NKCODE_BUTTON_CIRCLE || key.keyCode == NKCODE_BUTTON_B || key.keyCode == NKCODE_BUTTON_2;
}
} else {
return std::find(cancelKeys.begin(), cancelKeys.end(), KeyDef(key.deviceId, key.keyCode)) != cancelKeys.end();
return MatchesKeyDef(cancelKeys, key);
}
}
@ -258,7 +265,7 @@ bool IsTabLeftKey(const KeyInput &key) {
if (tabLeftKeys.empty()) {
return key.keyCode == NKCODE_BUTTON_L1;
} else {
return std::find(tabLeftKeys.begin(), tabLeftKeys.end(), KeyDef(key.deviceId, key.keyCode)) != tabLeftKeys.end();
return MatchesKeyDef(tabLeftKeys, key);
}
}
@ -266,7 +273,7 @@ bool IsTabRightKey(const KeyInput &key) {
if (tabRightKeys.empty()) {
return key.keyCode == NKCODE_BUTTON_R1;
} else {
return std::find(tabRightKeys.begin(), tabRightKeys.end(), KeyDef(key.deviceId, key.keyCode)) != tabRightKeys.end();
return MatchesKeyDef(tabRightKeys, key);
}
}