Translate menu options on-the-fly

I saw that the only problem with cycling languages in a title screen
menu is that the menu options don't get updated. So I was like, we can
just recreate the menu, and then I was like "Sure, why not." So that's
what I did.

To accommodate the CTRL+F8 keybind in the language menu, it
automatically updates the menu option when you cycle it. This is because
otherwise using the keybind in the language menu wouldn't visibly update
the language, but it still actually does change your language, and that
can be seen by pressing Escape.

Also, the menucountdown needs to be preserved because otherwise
createmenu() resets it, even if it's the "same" menu (this behavior is
needed so that the menu that is shown during the countdown isn't added
as a stack frame which would make it a menu that could be returned to).
This commit is contained in:
Misa 2024-01-21 17:26:55 -08:00
parent 8189e6cfbf
commit 7d66da242b
1 changed files with 13 additions and 2 deletions

View File

@ -187,8 +187,7 @@ void KeyPoll::Poll(void)
{
if (keymap[SDLK_LCTRL])
{
/* Debug keybind to cycle language.
* Not really meant to be used inside menus. */
/* Debug keybind to cycle language. */
int i = loc::languagelist_curlang;
if (keymap[SDLK_LSHIFT])
{
@ -211,6 +210,18 @@ void KeyPoll::Poll(void)
should_recompute_textboxes = true;
}
if (game.gamestate == TITLEMODE)
{
int temp = game.menucountdown;
game.createmenu(game.currentmenuname, true);
game.menucountdown = temp;
if (game.currentmenuname == Menu::language)
{
game.currentmenuoption = i;
}
}
}
else
{