2020-10-01 09:36:43 +02:00
|
|
|
#include "Common/Input/InputState.h"
|
|
|
|
|
#include "Common/Input/KeyCodes.h"
|
2013-08-22 06:45:45 -04:00
|
|
|
#include <vector>
|
2013-06-24 21:47:29 -07:00
|
|
|
|
2013-07-06 19:07:48 +02:00
|
|
|
const char *GetDeviceName(int deviceId) {
|
|
|
|
|
switch (deviceId) {
|
2015-08-29 21:52:53 +02:00
|
|
|
case DEVICE_ID_ANY: return "any";
|
2013-07-06 19:07:48 +02:00
|
|
|
case DEVICE_ID_DEFAULT: return "built-in";
|
|
|
|
|
case DEVICE_ID_KEYBOARD: return "kbd";
|
2014-06-01 11:35:57 +02:00
|
|
|
case DEVICE_ID_PAD_0: return "pad1";
|
|
|
|
|
case DEVICE_ID_PAD_1: return "pad2";
|
|
|
|
|
case DEVICE_ID_PAD_2: return "pad3";
|
|
|
|
|
case DEVICE_ID_PAD_3: return "pad4";
|
|
|
|
|
case DEVICE_ID_PAD_4: return "pad5";
|
|
|
|
|
case DEVICE_ID_PAD_5: return "pad6";
|
|
|
|
|
case DEVICE_ID_PAD_6: return "pad7";
|
|
|
|
|
case DEVICE_ID_PAD_7: return "pad8";
|
|
|
|
|
case DEVICE_ID_PAD_8: return "pad9";
|
|
|
|
|
case DEVICE_ID_PAD_9: return "pad10";
|
2013-07-06 19:07:48 +02:00
|
|
|
case DEVICE_ID_X360_0: return "x360";
|
2017-02-19 15:02:17 +01:00
|
|
|
case DEVICE_ID_X360_1: return "x360_2";
|
|
|
|
|
case DEVICE_ID_X360_2: return "x360_3";
|
|
|
|
|
case DEVICE_ID_X360_3: return "x360_4";
|
2013-07-06 19:07:48 +02:00
|
|
|
case DEVICE_ID_ACCELEROMETER: return "accelerometer";
|
2013-08-17 10:33:49 +02:00
|
|
|
case DEVICE_ID_MOUSE: return "mouse";
|
2013-07-06 19:07:48 +02:00
|
|
|
default:
|
|
|
|
|
return "unknown";
|
2013-06-24 21:47:29 -07:00
|
|
|
}
|
2013-06-29 19:15:55 -07:00
|
|
|
}
|
2013-07-15 17:37:16 +02:00
|
|
|
|
2015-08-28 20:51:33 +02:00
|
|
|
std::vector<KeyDef> dpadKeys;
|
2015-08-28 17:05:11 +02:00
|
|
|
std::vector<KeyDef> confirmKeys;
|
|
|
|
|
std::vector<KeyDef> cancelKeys;
|
|
|
|
|
std::vector<KeyDef> tabLeftKeys;
|
|
|
|
|
std::vector<KeyDef> tabRightKeys;
|
2021-04-04 08:39:49 -07:00
|
|
|
static std::unordered_map<int, int> uiFlipAnalogY;
|
2013-08-22 06:45:45 -04:00
|
|
|
|
2015-08-28 20:51:33 +02:00
|
|
|
static void AppendKeys(std::vector<KeyDef> &keys, const std::vector<KeyDef> &newKeys) {
|
|
|
|
|
for (auto iter = newKeys.begin(); iter != newKeys.end(); ++iter) {
|
|
|
|
|
keys.push_back(*iter);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SetDPadKeys(const std::vector<KeyDef> &leftKey, const std::vector<KeyDef> &rightKey,
|
|
|
|
|
const std::vector<KeyDef> &upKey, const std::vector<KeyDef> &downKey) {
|
|
|
|
|
dpadKeys.clear();
|
|
|
|
|
|
|
|
|
|
// Store all directions into one vector for now. In the future it might be
|
|
|
|
|
// useful to keep track of the different directions separately.
|
|
|
|
|
AppendKeys(dpadKeys, leftKey);
|
|
|
|
|
AppendKeys(dpadKeys, rightKey);
|
|
|
|
|
AppendKeys(dpadKeys, upKey);
|
|
|
|
|
AppendKeys(dpadKeys, downKey);
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-28 17:05:11 +02:00
|
|
|
void SetConfirmCancelKeys(const std::vector<KeyDef> &confirm, const std::vector<KeyDef> &cancel) {
|
2013-08-22 06:45:45 -04:00
|
|
|
confirmKeys = confirm;
|
|
|
|
|
cancelKeys = cancel;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-28 17:05:11 +02:00
|
|
|
void SetTabLeftRightKeys(const std::vector<KeyDef> &tabLeft, const std::vector<KeyDef> &tabRight) {
|
2014-01-25 11:58:49 -08:00
|
|
|
tabLeftKeys = tabLeft;
|
|
|
|
|
tabRightKeys = tabRight;
|
|
|
|
|
}
|
2021-04-04 08:39:49 -07:00
|
|
|
|
|
|
|
|
void SetAnalogFlipY(std::unordered_map<int, int> flipYByDeviceId) {
|
|
|
|
|
uiFlipAnalogY = flipYByDeviceId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int GetAnalogYDirection(int deviceId) {
|
|
|
|
|
auto configured = uiFlipAnalogY.find(deviceId);
|
|
|
|
|
if (configured != uiFlipAnalogY.end())
|
|
|
|
|
return configured->second;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|