From 9b56a53d980dcf5101c2a7012e747e15427b7faa Mon Sep 17 00:00:00 2001 From: Misa Date: Sun, 21 Jan 2024 14:39:18 -0800 Subject: [PATCH] Add debug keybind CTRL+(SHIFT)+F8 to cycle lang This adds a debug keybind to cycle the current language forwards, CTRL+F8. It also adds a debug keybind to cycle it backwards, CTRL+SHIFT+F8. This is only active if the translator menu is active (and so if the regular F8 keybind is also active). This is useful for quickly catching errors in translations and/or inconsistencies between translations. In fact, I've already caught several translation mistakes using this keybind which made me mildly panic that I screwed something up in my own code, only to realize that no, actually, it was the translation that was at fault. For now, this is only meant to be used in-game, as text boxes get retranslated instantly, whereas things like menu options don't. But menu options will be retranslated on-the-fly in a later commit. --- desktop_version/src/Input.cpp | 5 +++- desktop_version/src/KeyPoll.cpp | 42 +++++++++++++++++++++++++++++---- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/desktop_version/src/Input.cpp b/desktop_version/src/Input.cpp index 102f028d..eeeab1cb 100644 --- a/desktop_version/src/Input.cpp +++ b/desktop_version/src/Input.cpp @@ -269,7 +269,8 @@ static void updatebuttonmappings(int bind) } } -static void recomputetextboxes(void) +/* Also used in KeyPoll.cpp. */ +void recomputetextboxes(void) { /* Retranslate and reposition all text boxes. * WARNING: Needs to update in linear order, starting from 0. */ @@ -1131,6 +1132,8 @@ static void menuactionpress(void) if (loc::languagelist.size() != 0 && (unsigned)game.currentmenuoption < loc::languagelist.size()) { + /* Update code also used in KeyPoll.cpp. */ + loc::languagelist_curlang = game.currentmenuoption; loc::lang = loc::languagelist[game.currentmenuoption].code; loc::loadtext(false); loc::lang_set = true; diff --git a/desktop_version/src/KeyPoll.cpp b/desktop_version/src/KeyPoll.cpp index 8f2c5bd2..b1771fc8 100644 --- a/desktop_version/src/KeyPoll.cpp +++ b/desktop_version/src/KeyPoll.cpp @@ -16,6 +16,7 @@ #include "Music.h" #include "Screen.h" #include "UTF8.h" +#include "UtilityClass.h" #include "Vlogging.h" bool SaveScreenshot(void); @@ -138,6 +139,9 @@ static int changemousestate( return timeout; } +/* Also used in Input.cpp. */ +void recomputetextboxes(void); + void KeyPoll::Poll(void) { static int raw_mousex = 0; @@ -178,10 +182,40 @@ void KeyPoll::Poll(void) if (loc::show_translator_menu && evt.key.keysym.sym == SDLK_F8 && !evt.key.repeat) { - /* Reload language files */ - loc::loadtext(false); - graphics.grphx.init_translations(); - music.playef(Sound_COIN); + if (keymap[SDLK_LCTRL]) + { + /* Debug keybind to cycle language. + * Not really meant to be used inside menus. */ + int i = loc::languagelist_curlang; + if (keymap[SDLK_LSHIFT]) + { + /* Backwards */ + i--; + } + else + { + /* Forwards */ + i++; + } + if (!loc::languagelist.empty()) + { + i = POS_MOD(i, (int) loc::languagelist.size()); + + loc::languagelist_curlang = i; + loc::lang = loc::languagelist[i].code; + loc::loadtext(false); + graphics.grphx.init_translations(); + + recomputetextboxes(); + } + } + else + { + /* Reload language files */ + loc::loadtext(false); + graphics.grphx.init_translations(); + music.playef(Sound_COIN); + } } if (evt.key.keysym.sym == SDLK_F6 && !evt.key.repeat)