From 25bdf0866aef97d36d06543da52e4fcc72e36960 Mon Sep 17 00:00:00 2001 From: Dav999 Date: Wed, 3 Jan 2024 23:13:51 +0100 Subject: [PATCH] Make left/right key input correct for RTL menus Instead of just up/down, you can also control menus with left/right. Which is illogical in Arabic... No big deal, I imagined this code to become much worse than it did. (And action sets is probably gonna refactor the whole thing anyway) --- desktop_version/src/Graphics.cpp | 4 +-- desktop_version/src/Input.cpp | 52 +++++++++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/desktop_version/src/Graphics.cpp b/desktop_version/src/Graphics.cpp index d45cbf1b..6b631503 100644 --- a/desktop_version/src/Graphics.cpp +++ b/desktop_version/src/Graphics.cpp @@ -249,11 +249,11 @@ void Graphics::map_tab(int opt, const char* text, bool selected /*= false*/) { char buffer[SCREEN_WIDTH_CHARS + 1]; vformat_buf(buffer, sizeof(buffer), loc::get_langmeta()->menu_select_tight.c_str(), "label:str", text); - font::print(PR_CEN | PR_CJK_LOW, x, 220, buffer, 196, 196, 255 - help.glow); + font::print(PR_CEN | PR_CJK_LOW | PR_RTL_XFLIP, x, 220, buffer, 196, 196, 255 - help.glow); } else { - font::print(PR_CEN | PR_CJK_LOW, x, 220, text, 64, 64, 64); + font::print(PR_CEN | PR_CJK_LOW | PR_RTL_XFLIP, x, 220, text, 64, 64, 64); } } diff --git a/desktop_version/src/Input.cpp b/desktop_version/src/Input.cpp index c68db440..904071c3 100644 --- a/desktop_version/src/Input.cpp +++ b/desktop_version/src/Input.cpp @@ -2289,11 +2289,33 @@ void titleinput(void) } else { - if (key.isDown(KEYBOARD_LEFT) || key.isDown(KEYBOARD_UP) || key.isDown(KEYBOARD_a) || key.isDown(KEYBOARD_w) || key.controllerWantsLeft(true)) + SDL_Keycode left, right, a, d; + bool controller_up = key.controllerWantsUp(); + bool controller_down = key.controllerWantsDown(); + if (!font::is_rtl(PR_FONT_INTERFACE)) + { + left = KEYBOARD_LEFT; + right = KEYBOARD_RIGHT; + a = KEYBOARD_a; + d = KEYBOARD_d; + controller_up |= key.controllerWantsLeft(false); + controller_down |= key.controllerWantsRight(false); + } + else + { + left = KEYBOARD_RIGHT; + right = KEYBOARD_LEFT; + a = KEYBOARD_d; + d = KEYBOARD_a; + controller_up |= key.controllerWantsRight(false); + controller_down |= key.controllerWantsLeft(false); + } + + if (key.isDown(left) || key.isDown(KEYBOARD_UP) || key.isDown(a) || key.isDown(KEYBOARD_w) || controller_up) { game.press_left = true; } - if (key.isDown(KEYBOARD_RIGHT) || key.isDown(KEYBOARD_DOWN) || key.isDown(KEYBOARD_d) || key.isDown(KEYBOARD_s) || key.controllerWantsRight(true)) + if (key.isDown(right) || key.isDown(KEYBOARD_DOWN) || key.isDown(d) || key.isDown(KEYBOARD_s) || controller_down) { game.press_right = true; } @@ -3019,11 +3041,33 @@ void mapinput(void) && ((!version2_2 && !game.fadetomenu && game.fadetomenudelay <= 0 && !game.fadetolab && game.fadetolabdelay <= 0) || graphics.fademode == FADE_NONE)) { - if (key.isDown(KEYBOARD_LEFT) || key.isDown(KEYBOARD_UP) || key.isDown(KEYBOARD_a) || key.isDown(KEYBOARD_w)|| key.controllerWantsLeft(true)) + SDL_Keycode left, right, a, d; + bool controller_up = key.controllerWantsUp(); + bool controller_down = key.controllerWantsDown(); + if (!font::is_rtl(PR_FONT_INTERFACE)) + { + left = KEYBOARD_LEFT; + right = KEYBOARD_RIGHT; + a = KEYBOARD_a; + d = KEYBOARD_d; + controller_up |= key.controllerWantsLeft(false); + controller_down |= key.controllerWantsRight(false); + } + else + { + left = KEYBOARD_RIGHT; + right = KEYBOARD_LEFT; + a = KEYBOARD_d; + d = KEYBOARD_a; + controller_up |= key.controllerWantsRight(false); + controller_down |= key.controllerWantsLeft(false); + } + + if (key.isDown(left) || key.isDown(KEYBOARD_UP) || key.isDown(a) || key.isDown(KEYBOARD_w)|| controller_up) { game.press_left = true; } - if (key.isDown(KEYBOARD_RIGHT) || key.isDown(KEYBOARD_DOWN) || key.isDown(KEYBOARD_d) || key.isDown(KEYBOARD_s)|| key.controllerWantsRight(true)) + if (key.isDown(right) || key.isDown(KEYBOARD_DOWN) || key.isDown(d) || key.isDown(KEYBOARD_s)|| controller_down) { game.press_right = true; }