Reuse translation

This commit is contained in:
iota97 2021-08-30 13:13:09 +02:00
parent 2821035b1d
commit f417bb93d4
5 changed files with 50 additions and 46 deletions

View File

@ -446,6 +446,13 @@ std::string GetPspButtonName(int btn) {
return FindName(btn, psp_button_names, ARRAY_SIZE(psp_button_names));
}
const char* GetPspButtonNameCharPointer(int btn) {
for (size_t i = 0; i < ARRAY_SIZE(psp_button_names); i++)
if (psp_button_names[i].key == btn)
return psp_button_names[i].name;
return nullptr;
}
std::vector<KeyMap_IntStrPair> GetMappableKeys() {
std::vector<KeyMap_IntStrPair> temp;
for (size_t i = 0; i < ARRAY_SIZE(psp_button_names); i++) {

View File

@ -112,6 +112,7 @@ namespace KeyMap {
std::string GetKeyOrAxisName(int keyCode);
std::string GetAxisName(int axisId);
std::string GetPspButtonName(int btn);
const char* GetPspButtonNameCharPointer(int btn);
std::vector<KeyMap_IntStrPair> GetMappableKeys();

View File

@ -2012,7 +2012,7 @@ void GestureMappingScreen::CreateViews() {
static const char *gestureButton[ARRAY_SIZE(GestureKey::keyList)+1];
gestureButton[0] = "None";
for (int i = 1; i < ARRAY_SIZE(gestureButton); ++i) {
gestureButton[i] = GestureKey::keyList[i-1].n;
gestureButton[i] = KeyMap::GetPspButtonNameCharPointer(GestureKey::keyList[i-1]);
}
vert->Add(new CheckBox(&g_Config.bGestureControlEnabled, co->T("Enable gesture control")));

View File

@ -854,7 +854,7 @@ void GestureGamepad::Touch(const TouchInput &input) {
const float now = time_now_d();
if (now - lastTapRelease_ < 0.3f && !haveDoubleTapped_) {
if (g_Config.iDoubleTapGesture != 0 )
controllMapper_->pspKey(GestureKey::keyList[g_Config.iDoubleTapGesture-1].c, KEY_DOWN);
controllMapper_->pspKey(GestureKey::keyList[g_Config.iDoubleTapGesture-1], KEY_DOWN);
haveDoubleTapped_ = true;
}
@ -877,7 +877,7 @@ void GestureGamepad::Touch(const TouchInput &input) {
if (haveDoubleTapped_) {
if (g_Config.iDoubleTapGesture != 0)
controllMapper_->pspKey(GestureKey::keyList[g_Config.iDoubleTapGesture-1].c, KEY_UP);
controllMapper_->pspKey(GestureKey::keyList[g_Config.iDoubleTapGesture-1], KEY_UP);
haveDoubleTapped_ = false;
}
}
@ -890,37 +890,37 @@ void GestureGamepad::Update() {
float dy = deltaY_ * g_dpi_scale_y * g_Config.fSwipeSensitivity;
if (g_Config.iSwipeRight != 0) {
if (dx > th) {
controllMapper_->pspKey(GestureKey::keyList[g_Config.iSwipeRight-1].c, KEY_DOWN);
controllMapper_->pspKey(GestureKey::keyList[g_Config.iSwipeRight-1], KEY_DOWN);
swipeRightReleased_ = false;
} else if (!swipeRightReleased_) {
controllMapper_->pspKey(GestureKey::keyList[g_Config.iSwipeRight-1].c, KEY_UP);
controllMapper_->pspKey(GestureKey::keyList[g_Config.iSwipeRight-1], KEY_UP);
swipeRightReleased_ = true;
}
}
if (g_Config.iSwipeLeft != 0) {
if (dx < -th) {
controllMapper_->pspKey(GestureKey::keyList[g_Config.iSwipeLeft-1].c, KEY_DOWN);
controllMapper_->pspKey(GestureKey::keyList[g_Config.iSwipeLeft-1], KEY_DOWN);
swipeLeftReleased_ = false;
} else if (!swipeLeftReleased_) {
controllMapper_->pspKey(GestureKey::keyList[g_Config.iSwipeLeft-1].c, KEY_UP);
controllMapper_->pspKey(GestureKey::keyList[g_Config.iSwipeLeft-1], KEY_UP);
swipeLeftReleased_ = true;
}
}
if (g_Config.iSwipeUp != 0) {
if (dy < -th) {
controllMapper_->pspKey(GestureKey::keyList[g_Config.iSwipeUp-1].c, KEY_DOWN);
controllMapper_->pspKey(GestureKey::keyList[g_Config.iSwipeUp-1], KEY_DOWN);
swipeUpReleased_ = false;
} else if (!swipeUpReleased_) {
controllMapper_->pspKey(GestureKey::keyList[g_Config.iSwipeUp-1].c, KEY_UP);
controllMapper_->pspKey(GestureKey::keyList[g_Config.iSwipeUp-1], KEY_UP);
swipeUpReleased_ = true;
}
}
if (g_Config.iSwipeDown != 0) {
if (dy > th) {
controllMapper_->pspKey(GestureKey::keyList[g_Config.iSwipeDown-1].c, KEY_DOWN);
controllMapper_->pspKey(GestureKey::keyList[g_Config.iSwipeDown-1], KEY_DOWN);
swipeDownReleased_ = false;
} else if (!swipeDownReleased_) {
controllMapper_->pspKey(GestureKey::keyList[g_Config.iSwipeDown-1].c, KEY_UP);
controllMapper_->pspKey(GestureKey::keyList[g_Config.iSwipeDown-1], KEY_UP);
swipeDownReleased_ = true;
}
}

View File

@ -315,42 +315,38 @@ namespace CustomKey {
// Gesture key only have virtual button that can work without constant press
namespace GestureKey {
struct key {
const char* n; // UI name
uint32_t c; // Key code
};
static const key keyList[] = {
{ "Square", CTRL_SQUARE },
{ "Triangle", CTRL_TRIANGLE },
{ "Circle", CTRL_CIRCLE },
{ "Cross", CTRL_CROSS },
{ "Up", CTRL_UP },
{ "Down", CTRL_DOWN },
{ "Left", CTRL_LEFT },
{ "Right", CTRL_RIGHT },
{ "Start", CTRL_START },
{ "Select", CTRL_SELECT },
{ "L", CTRL_LTRIGGER },
{ "R", CTRL_RTRIGGER },
{ "An.Up", VIRTKEY_AXIS_Y_MAX },
{ "An.Down", VIRTKEY_AXIS_Y_MIN },
{ "An.Left", VIRTKEY_AXIS_X_MIN },
{ "An.Right", VIRTKEY_AXIS_X_MAX },
{ "SpeedToggle", VIRTKEY_SPEED_TOGGLE },
{ "Rewind", VIRTKEY_REWIND },
{ "Save State", VIRTKEY_SAVE_STATE },
{ "Load State", VIRTKEY_LOAD_STATE },
{ "Next Slot", VIRTKEY_NEXT_SLOT },
{ "Toggle Fullscreen", VIRTKEY_TOGGLE_FULLSCREEN },
{ "Texture Dumping", VIRTKEY_TEXTURE_DUMP },
{ "Texture Replacement", VIRTKEY_TEXTURE_REPLACE },
{ "Screenshot", VIRTKEY_SCREENSHOT },
{ "Mute toggle", VIRTKEY_MUTE_TOGGLE },
{ "OpenChat", VIRTKEY_OPENCHAT },
{ "Pause", VIRTKEY_PAUSE },
{ "DevMenu", VIRTKEY_DEVMENU },
static const uint32_t keyList[] = {
CTRL_SQUARE,
CTRL_TRIANGLE,
CTRL_CIRCLE,
CTRL_CROSS,
CTRL_UP,
CTRL_DOWN,
CTRL_LEFT,
CTRL_RIGHT,
CTRL_START,
CTRL_SELECT,
CTRL_LTRIGGER,
CTRL_RTRIGGER,
VIRTKEY_AXIS_Y_MAX,
VIRTKEY_AXIS_Y_MIN,
VIRTKEY_AXIS_X_MIN,
VIRTKEY_AXIS_X_MAX,
VIRTKEY_SPEED_TOGGLE,
VIRTKEY_REWIND,
VIRTKEY_SAVE_STATE,
VIRTKEY_LOAD_STATE,
VIRTKEY_NEXT_SLOT,
VIRTKEY_TOGGLE_FULLSCREEN,
VIRTKEY_TEXTURE_DUMP,
VIRTKEY_TEXTURE_REPLACE,
VIRTKEY_SCREENSHOT,
VIRTKEY_MUTE_TOGGLE,
VIRTKEY_OPENCHAT,
VIRTKEY_PAUSE,
VIRTKEY_DEVMENU,
#ifndef MOBILE_DEVICE
{ "Record", VIRTKEY_RECORD },
VIRTKEY_RECORD,
#endif
};
}