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.
This commit is contained in:
Misa 2024-01-21 14:39:18 -08:00 committed by Misa Elizabeth Kai
parent 84daa8fbc2
commit 9b56a53d98
2 changed files with 42 additions and 5 deletions

View File

@ -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;

View File

@ -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)