mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-08 03:56:24 +02:00
Use KeyDef for Confirm/Cancel/TabLeft/TabRight keys
This commit is contained in:
1 parent
e1d3a7421b
commit
32617ae17c
6 files changed
+43
-35
No files matched your search
@@ -51,17 +51,17 @@ int MapPadButtonFixed(int keycode) {
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<keycode_t> confirmKeys;
|
||||
std::vector<keycode_t> cancelKeys;
|
||||
std::vector<keycode_t> tabLeftKeys;
|
||||
std::vector<keycode_t> tabRightKeys;
|
||||
std::vector<KeyDef> confirmKeys;
|
||||
std::vector<KeyDef> cancelKeys;
|
||||
std::vector<KeyDef> tabLeftKeys;
|
||||
std::vector<KeyDef> tabRightKeys;
|
||||
|
||||
void SetConfirmCancelKeys(const std::vector<keycode_t> &confirm, const std::vector<keycode_t> &cancel) {
|
||||
void SetConfirmCancelKeys(const std::vector<KeyDef> &confirm, const std::vector<KeyDef> &cancel) {
|
||||
confirmKeys = confirm;
|
||||
cancelKeys = cancel;
|
||||
}
|
||||
|
||||
void SetTabLeftRightKeys(const std::vector<keycode_t> &tabLeft, const std::vector<keycode_t> &tabRight) {
|
||||
void SetTabLeftRightKeys(const std::vector<KeyDef> &tabLeft, const std::vector<KeyDef> &tabRight) {
|
||||
tabLeftKeys = tabLeft;
|
||||
tabRightKeys = tabRight;
|
||||
}
|
||||
|
||||
+6
-6
@@ -240,9 +240,9 @@ private:
|
||||
extern ButtonTracker g_buttonTracker;
|
||||
|
||||
// Is there a nicer place for this stuff? It's here to avoid dozens of linking errors in UnitTest..
|
||||
extern std::vector<keycode_t> confirmKeys;
|
||||
extern std::vector<keycode_t> cancelKeys;
|
||||
extern std::vector<keycode_t> tabLeftKeys;
|
||||
extern std::vector<keycode_t> tabRightKeys;
|
||||
void SetConfirmCancelKeys(const std::vector<keycode_t> &confirm, const std::vector<keycode_t> &cancel);
|
||||
void SetTabLeftRightKeys(const std::vector<keycode_t> &tabLeft, const std::vector<keycode_t> &tabRight);
|
||||
extern std::vector<KeyDef> confirmKeys;
|
||||
extern std::vector<KeyDef> cancelKeys;
|
||||
extern std::vector<KeyDef> tabLeftKeys;
|
||||
extern std::vector<KeyDef> tabRightKeys;
|
||||
void SetConfirmCancelKeys(const std::vector<KeyDef> &confirm, const std::vector<KeyDef> &cancel);
|
||||
void SetTabLeftRightKeys(const std::vector<KeyDef> &tabLeft, const std::vector<KeyDef> &tabRight);
|
||||
+1
-1
@@ -65,7 +65,7 @@ bool UIScreen::key(const KeyInput &key) {
|
||||
|
||||
bool UIDialogScreen::key(const KeyInput &key) {
|
||||
bool retval = UIScreen::key(key);
|
||||
if (!retval && (key.flags & KEY_DOWN) && UI::IsEscapeKeyCode(key.keyCode)) {
|
||||
if (!retval && (key.flags & KEY_DOWN) && UI::IsEscapeKey(key)) {
|
||||
if (finished_) {
|
||||
ELOG("Screen already finished");
|
||||
} else {
|
||||
|
||||
+24
-16
@@ -222,35 +222,43 @@ void Clickable::Touch(const TouchInput &input) {
|
||||
|
||||
// TODO: O/X confirm preference for xperia play?
|
||||
|
||||
bool IsAcceptKeyCode(int keyCode) {
|
||||
bool IsAcceptKey(const KeyInput &key) {
|
||||
if (confirmKeys.empty()) {
|
||||
return keyCode == NKCODE_SPACE || keyCode == NKCODE_ENTER || keyCode == NKCODE_Z || keyCode == NKCODE_BUTTON_A || keyCode == NKCODE_BUTTON_CROSS || keyCode == NKCODE_BUTTON_1;
|
||||
if (key.deviceId == DEVICE_ID_KEYBOARD) {
|
||||
return key.keyCode == NKCODE_SPACE || key.keyCode == NKCODE_ENTER || key.keyCode == NKCODE_Z;
|
||||
} else {
|
||||
return key.keyCode == NKCODE_BUTTON_A || key.keyCode == NKCODE_BUTTON_CROSS || key.keyCode == NKCODE_BUTTON_1;
|
||||
}
|
||||
} else {
|
||||
return std::find(confirmKeys.begin(), confirmKeys.end(), (keycode_t)keyCode) != confirmKeys.end();
|
||||
return std::find(confirmKeys.begin(), confirmKeys.end(), KeyDef(key.deviceId, key.keyCode)) != confirmKeys.end();
|
||||
}
|
||||
}
|
||||
|
||||
bool IsEscapeKeyCode(int keyCode) {
|
||||
bool IsEscapeKey(const KeyInput &key) {
|
||||
if (cancelKeys.empty()) {
|
||||
return keyCode == NKCODE_ESCAPE || keyCode == NKCODE_BACK || keyCode == NKCODE_BUTTON_CIRCLE || keyCode == NKCODE_BUTTON_B || keyCode == NKCODE_BUTTON_2;
|
||||
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 std::find(cancelKeys.begin(), cancelKeys.end(), (keycode_t)keyCode) != cancelKeys.end();
|
||||
return std::find(cancelKeys.begin(), cancelKeys.end(), KeyDef(key.deviceId, key.keyCode)) != cancelKeys.end();
|
||||
}
|
||||
}
|
||||
|
||||
bool IsTabLeftKeyCode(int keyCode) {
|
||||
bool IsTabLeftKey(const KeyInput &key) {
|
||||
if (tabLeftKeys.empty()) {
|
||||
return keyCode == NKCODE_BUTTON_L1;
|
||||
return key.keyCode == NKCODE_BUTTON_L1;
|
||||
} else {
|
||||
return std::find(tabLeftKeys.begin(), tabLeftKeys.end(), (keycode_t)keyCode) != tabLeftKeys.end();
|
||||
return std::find(tabLeftKeys.begin(), tabLeftKeys.end(), KeyDef(key.deviceId, key.keyCode)) != tabLeftKeys.end();
|
||||
}
|
||||
}
|
||||
|
||||
bool IsTabRightKeyCode(int keyCode) {
|
||||
bool IsTabRightKey(const KeyInput &key) {
|
||||
if (tabRightKeys.empty()) {
|
||||
return keyCode == NKCODE_BUTTON_R1;
|
||||
return key.keyCode == NKCODE_BUTTON_R1;
|
||||
} else {
|
||||
return std::find(tabRightKeys.begin(), tabRightKeys.end(), (keycode_t)keyCode) != tabRightKeys.end();
|
||||
return std::find(tabRightKeys.begin(), tabRightKeys.end(), KeyDef(key.deviceId, key.keyCode)) != tabRightKeys.end();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,19 +270,19 @@ bool Clickable::Key(const KeyInput &key) {
|
||||
// TODO: Replace most of Update with this.
|
||||
bool ret = false;
|
||||
if (key.flags & KEY_DOWN) {
|
||||
if (IsAcceptKeyCode(key.keyCode)) {
|
||||
if (IsAcceptKey(key)) {
|
||||
down_ = true;
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
if (key.flags & KEY_UP) {
|
||||
if (IsAcceptKeyCode(key.keyCode)) {
|
||||
if (IsAcceptKey(key)) {
|
||||
if (down_) {
|
||||
Click();
|
||||
down_ = false;
|
||||
ret = true;
|
||||
}
|
||||
} else if (IsEscapeKeyCode(key.keyCode)) {
|
||||
} else if (IsEscapeKey(key)) {
|
||||
down_ = false;
|
||||
}
|
||||
}
|
||||
@@ -305,7 +313,7 @@ bool StickyChoice::Key(const KeyInput &key) {
|
||||
|
||||
// TODO: Replace most of Update with this.
|
||||
if (key.flags & KEY_DOWN) {
|
||||
if (IsAcceptKeyCode(key.keyCode)) {
|
||||
if (IsAcceptKey(key)) {
|
||||
down_ = true;
|
||||
Click();
|
||||
return true;
|
||||
|
||||
@@ -801,9 +801,9 @@ void MeasureBySpec(Size sz, float contentWidth, MeasureSpec spec, float *measure
|
||||
|
||||
void EventTriggered(Event *e, EventParams params);
|
||||
void DispatchEvents();
|
||||
bool IsAcceptKeyCode(int keyCode);
|
||||
bool IsEscapeKeyCode(int keyCode);
|
||||
bool IsTabLeftKeyCode(int keyCode);
|
||||
bool IsTabRightKeyCode(int keyCode);
|
||||
bool IsAcceptKey(const KeyInput &key);
|
||||
bool IsEscapeKey(const KeyInput &key);
|
||||
bool IsTabLeftKey(const KeyInput &key);
|
||||
bool IsTabRightKey(const KeyInput &key);
|
||||
|
||||
} // namespace
|
||||
+2
-2
@@ -1064,10 +1064,10 @@ void ChoiceStrip::HighlightChoice(unsigned int choice){
|
||||
bool ChoiceStrip::Key(const KeyInput &input) {
|
||||
bool ret = false;
|
||||
if (input.flags & KEY_DOWN) {
|
||||
if (IsTabLeftKeyCode(input.keyCode) && selected_ > 0) {
|
||||
if (IsTabLeftKey(input) && selected_ > 0) {
|
||||
SetSelection(selected_ - 1);
|
||||
ret = true;
|
||||
} else if (IsTabRightKeyCode(input.keyCode) && selected_ < (int)views_.size() - 1) {
|
||||
} else if (IsTabRightKey(input) && selected_ < (int)views_.size() - 1) {
|
||||
SetSelection(selected_ + 1);
|
||||
ret = true;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user