Skip to content

Commit

Permalink
Ignore mouse mappings for UI
Browse files Browse the repository at this point in the history
  • Loading branch information
LunaMoo committed Jul 14, 2019
1 parent 179cafc commit b7a49be
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
24 changes: 13 additions & 11 deletions Common/KeyMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,15 @@ void UpdateNativeMenuKeys() {
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;

KeyFromPspButton(confirmKey, &confirmKeys);
KeyFromPspButton(cancelKey, &cancelKeys);
KeyFromPspButton(CTRL_LTRIGGER, &tabLeft);
KeyFromPspButton(CTRL_RTRIGGER, &tabRight);
KeyFromPspButton(CTRL_UP, &upKeys);
KeyFromPspButton(CTRL_DOWN, &downKeys);
KeyFromPspButton(CTRL_LEFT, &leftKeys);
KeyFromPspButton(CTRL_RIGHT, &rightKeys);
// Mouse mapping might be problematic in UI, so let's ignore mouse for UI
KeyFromPspButton(confirmKey, &confirmKeys, true);
KeyFromPspButton(cancelKey, &cancelKeys, true);
KeyFromPspButton(CTRL_LTRIGGER, &tabLeft, true);
KeyFromPspButton(CTRL_RTRIGGER, &tabRight, true);
KeyFromPspButton(CTRL_UP, &upKeys, true);
KeyFromPspButton(CTRL_DOWN, &downKeys, true);
KeyFromPspButton(CTRL_LEFT, &leftKeys, true);
KeyFromPspButton(CTRL_RIGHT, &rightKeys, true);

#ifdef __ANDROID__
// Hardcode DPAD on Android
Expand Down Expand Up @@ -786,11 +787,12 @@ bool KeyToPspButton(int deviceId, int key, std::vector<int> *pspKeys) {
}

// TODO: vector output
bool KeyFromPspButton(int btn, std::vector<KeyDef> *keys) {
bool KeyFromPspButton(int btn, std::vector<KeyDef> *keys, bool ignoreMouse) {
for (auto iter = g_controllerMap.begin(); iter != g_controllerMap.end(); ++iter) {
if (iter->first == btn) {
for (auto iter2 = iter->second.begin(); iter2 != iter->second.end(); ++iter2) {
keys->push_back(*iter2);
if (!ignoreMouse || iter2->deviceId != DEVICE_ID_MOUSE)
keys->push_back(*iter2);
}
}
}
Expand Down Expand Up @@ -911,7 +913,7 @@ void SaveToIni(IniFile &file) {

for (size_t i = 0; i < ARRAY_SIZE(psp_button_names); i++) {
std::vector<KeyDef> keys;
KeyFromPspButton(psp_button_names[i].key, &keys);
KeyFromPspButton(psp_button_names[i].key, &keys, false);

std::string value;
for (size_t j = 0; j < keys.size(); j++) {
Expand Down
2 changes: 1 addition & 1 deletion Common/KeyMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ namespace KeyMap {
// buttons. You should have already translated
// your platform's keys to KeyMap keys.
bool KeyToPspButton(int deviceId, int key, std::vector<int> *pspKeys);
bool KeyFromPspButton(int btn, std::vector<KeyDef> *keys);
bool KeyFromPspButton(int btn, std::vector<KeyDef> *keys, bool ignoreMouse);

int TranslateKeyCodeToAxis(int keyCode, int &direction);
int TranslateKeyCodeFromAxis(int axisId, int direction);
Expand Down
2 changes: 1 addition & 1 deletion UI/ControlMappingScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void ControlMapper::Refresh() {
LinearLayout *rightColumn = root->Add(new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT, 1.0f)));
rightColumn->SetSpacing(2.0f);
std::vector<KeyDef> mappings;
KeyMap::KeyFromPspButton(pspKey_, &mappings);
KeyMap::KeyFromPspButton(pspKey_, &mappings, false);

for (size_t i = 0; i < mappings.size(); i++) {
std::string deviceName = GetDeviceName(mappings[i].deviceId);
Expand Down

0 comments on commit b7a49be

Please sign in to comment.