Skip to content

Commit

Permalink
Merge pull request #3268 from thedax/master
Browse files Browse the repository at this point in the history
Set accept/escape buttons based on the bound CROSS/CIRCLE buttons.
  • Loading branch information
hrydgard committed Aug 22, 2013
2 parents 9bd020e + 59f878a commit cbb7f02
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
50 changes: 49 additions & 1 deletion Common/KeyMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
#include "../Core/Config.h"
#include "base/NativeApp.h"
#include "KeyMap.h"
#include "../Core/HLE/sceUtility.h"

#include <algorithm>


namespace KeyMap {

Expand Down Expand Up @@ -205,6 +209,45 @@ static const DefMappingStruct defaultXperiaPlay[] = {
{VIRTKEY_AXIS_Y_MAX, JOYSTICK_AXIS_Y, +1},
};

void UpdateConfirmCancelKeys() {
std::vector<keycode_t> confirmKeys, cancelKeys;

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;

for(auto i = g_controllerMap[confirmKey].begin(); i != g_controllerMap[confirmKey].end(); ++i) {
confirmKeys.push_back((keycode_t)i->keyCode);
}

for(auto i = g_controllerMap[cancelKey].begin(); i != g_controllerMap[cancelKey].end(); ++i) {
cancelKeys.push_back((keycode_t)i->keyCode);
}

// Push several hard-coded keys before submitting to native.
const keycode_t hardcodedConfirmKeys[] = {
NKCODE_SPACE,
NKCODE_ENTER,
};

// If they're not already bound, add them in.
for(int i = 0; i < ARRAY_SIZE(hardcodedConfirmKeys); i++) {
if(std::find(confirmKeys.begin(), confirmKeys.end(), hardcodedConfirmKeys[i]) == confirmKeys.end())
confirmKeys.push_back(hardcodedConfirmKeys[i]);
}

const keycode_t hardcodedCancelKeys[] = {
NKCODE_ESCAPE,
NKCODE_BACK,
};

for(int i = 0; i < ARRAY_SIZE(hardcodedCancelKeys); i++) {
if(std::find(cancelKeys.begin(), cancelKeys.end(), hardcodedCancelKeys[i]) == cancelKeys.end())
cancelKeys.push_back(hardcodedCancelKeys[i]);
}

SetConfirmCancelKeys(confirmKeys,cancelKeys);
}

static void SetDefaultKeyMap(int deviceId, const DefMappingStruct *array, int count, bool replace) {
for (size_t i = 0; i < count; i++) {
if (array[i].direction == 0)
Expand Down Expand Up @@ -235,6 +278,8 @@ void SetDefaultKeyMap(DefaultMaps dmap, bool replace) {
SetDefaultKeyMap(DEVICE_ID_DEFAULT, defaultXperiaPlay, ARRAY_SIZE(defaultXperiaPlay), replace);
break;
}

UpdateConfirmCancelKeys();
}

const KeyMap_IntStrPair key_names[] = {
Expand Down Expand Up @@ -613,6 +658,8 @@ void SetKeyMapping(int btn, KeyDef key, bool replace) {
}
g_controllerMap[btn].push_back(key);
}

UpdateConfirmCancelKeys();
}

void SetAxisMapping(int btn, int deviceId, int axisId, int direction, bool replace) {
Expand Down Expand Up @@ -674,7 +721,8 @@ void LoadFromIni(IniFile &file) {
SetKeyMapping(psp_button_names[i].key, KeyDef(deviceId, keyCode), false);
}
}
return;

UpdateConfirmCancelKeys();
}

void SaveToIni(IniFile &file) {
Expand Down
3 changes: 2 additions & 1 deletion Common/KeyMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,6 @@ namespace KeyMap {

void RestoreDefault();
void QuickMap(int device);
}

void UpdateConfirmCancelKeys();
}
3 changes: 3 additions & 0 deletions UI/GameSettingsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "math/curves.h"
#include "Core/HW/atrac3plus.h"
#include "Core/System.h"
#include "Common/KeyMap.h"

#ifdef _WIN32
#include "Core/Host.h"
Expand Down Expand Up @@ -455,6 +456,8 @@ UI::EventReturn GameSettingsScreen::OnBack(UI::EventParams &e) {
PostMessage(MainWindow::hwndMain, MainWindow::WM_USER_ATRAC_STATUS_CHANGED, 0, 0);
#endif

KeyMap::UpdateConfirmCancelKeys();

return UI::EVENT_DONE;
}

Expand Down
2 changes: 1 addition & 1 deletion native

0 comments on commit cbb7f02

Please sign in to comment.