From 531b151d12f71280991fe8ce6e96ea8ec04cde76 Mon Sep 17 00:00:00 2001 From: Misa Date: Sun, 21 Jan 2024 17:26:55 -0800 Subject: [PATCH] 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). --- desktop_version/src/KeyPoll.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/desktop_version/src/KeyPoll.cpp b/desktop_version/src/KeyPoll.cpp index d6f400ab..92be5ba0 100644 --- a/desktop_version/src/KeyPoll.cpp +++ b/desktop_version/src/KeyPoll.cpp @@ -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 {