From aa4a33e6dbbd903c60f61506eb4882f88ea39849 Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Thu, 17 Sep 2015 22:07:22 +0200 Subject: [PATCH] Fix "ANY" device keydefs (used for ui nav). --- ext/native/input/input_state.h | 1 + ext/native/ui/view.cpp | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/ext/native/input/input_state.h b/ext/native/input/input_state.h index bf4cd7b5b5..e404cfceb9 100644 --- a/ext/native/input/input_state.h +++ b/ext/native/input/input_state.h @@ -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; diff --git a/ext/native/ui/view.cpp b/ext/native/ui/view.cpp index 1992953007..5f24490958 100644 --- a/ext/native/ui/view.cpp +++ b/ext/native/ui/view.cpp @@ -220,13 +220,20 @@ void Clickable::Touch(const TouchInput &input) { } } +static bool MatchesKeyDef(const std::vector &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); } }