From f417bb93d43a7b323b7ed153f2e091472187d559 Mon Sep 17 00:00:00 2001 From: iota97 Date: Mon, 30 Aug 2021 13:13:09 +0200 Subject: [PATCH] Reuse translation --- Core/KeyMap.cpp | 7 +++++ Core/KeyMap.h | 1 + UI/GameSettingsScreen.cpp | 2 +- UI/GamepadEmu.cpp | 20 ++++++------ UI/GamepadEmu.h | 66 ++++++++++++++++++--------------------- 5 files changed, 50 insertions(+), 46 deletions(-) diff --git a/Core/KeyMap.cpp b/Core/KeyMap.cpp index 78efca5c41..76b173dab8 100644 --- a/Core/KeyMap.cpp +++ b/Core/KeyMap.cpp @@ -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 GetMappableKeys() { std::vector temp; for (size_t i = 0; i < ARRAY_SIZE(psp_button_names); i++) { diff --git a/Core/KeyMap.h b/Core/KeyMap.h index 01da7e9596..2126bcdc82 100644 --- a/Core/KeyMap.h +++ b/Core/KeyMap.h @@ -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 GetMappableKeys(); diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index e6618d486e..7c94269ff8 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -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"))); diff --git a/UI/GamepadEmu.cpp b/UI/GamepadEmu.cpp index b707882e8d..b38ec5505f 100644 --- a/UI/GamepadEmu.cpp +++ b/UI/GamepadEmu.cpp @@ -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; } } diff --git a/UI/GamepadEmu.h b/UI/GamepadEmu.h index cd7f2658e6..2eefabdc29 100644 --- a/UI/GamepadEmu.h +++ b/UI/GamepadEmu.h @@ -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 }; }