From 371859c9c114a155fdb92a8b41d93559085d141d Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Sat, 31 Oct 2026 09:58:01 +0800 Subject: [PATCH] Merge the Chinese menu glyphs into the font atlas and offer the language The atlas takes the glyphs of the four CJK rows (ja, ko, zh-Hans, zh-Hant), so MENU_LANG switches while the game runs without rebuilding it, and the Menu tab lists Simplified Chinese next to English and Russian. Co-authored-by: deepseek-v4.1-flash-1017 --- runtime/ui/menu.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/runtime/ui/menu.cpp b/runtime/ui/menu.cpp index 0e02e4bf..ef53a9d8 100644 --- a/runtime/ui/menu.cpp +++ b/runtime/ui/menu.cpp @@ -266,7 +266,9 @@ static int vk_up(const MenuTarget *t) { // Roboto Medium (Latin, Cyrillic, dashes and quotes) at 26 px per 1080 lines, with the glyphs of the Japanese, Korean // and Chinese language names merged in from a system font when there is one (each language is named in its own script). -// Made again when the window height changes; the old texture goes after the queue is idle (CreateFontsTexture). +// A catalog row also holds menu text (Simplified Chinese), so every string of the row goes into the builder: the merged +// font must cover the whole menu of that language, not only its name. Made again when the window height changes; the old +// texture goes after the queue is idle (CreateFontsTexture). static const ImWchar kRanges[] = {0x0020, 0x00FF, 0x0400, 0x052F, 0x2010, 0x2027, 0}; static const struct { const char *lang; UiTextId name; } kCjk[] = { {"ja", UI_MENU_LANGNAME_JA}, {"ko", UI_MENU_LANGNAME_KO}, {"zh-Hans", UI_MENU_LANGNAME_ZH_HANS}, @@ -310,6 +312,11 @@ extern "C" int menu_font_check(void) { return ok; } +// The glyphs of every string of a catalog row (ui_text_visit), for the font that draws that language. +static void add_row_glyphs(void *ctx, const char *text) { + static_cast(ctx)->AddText(text); +} + static int fonts_up(float scale) { enum { N = sizeof kCjk / sizeof *kCjk }; ImFontAtlas *fa = ImGui::GetIO().Fonts; @@ -334,6 +341,7 @@ static int fonts_up(float scale) { merged++; ImFontGlyphRangesBuilder b; b.AddText(ui_text_in("en", kCjk[i].name)); + ui_text_visit(kCjk[i].lang, add_row_glyphs, &b); b.BuildRanges(&ranges[i]); ImFontConfig mc; mc.MergeMode = true; @@ -686,8 +694,9 @@ static void tab_controls(float scale) { static void tab_menu(float scale) { opt_begin("##menu", scale); - static const UiTextId langs[] = {UI_MENU_MENU_LANG_AUTO, UI_MENU_LANGNAME_EN, UI_MENU_LANGNAME_RU}; - opt_choice("TOTK_MENU_LANG", UI_MENU_MENU_LANG, langs, 3, UI_MENU_MENU_LANG_DESC); + static const UiTextId langs[] = {UI_MENU_MENU_LANG_AUTO, UI_MENU_LANGNAME_EN, UI_MENU_LANGNAME_RU, + UI_MENU_LANGNAME_ZH_HANS}; + opt_choice("TOTK_MENU_LANG", UI_MENU_MENU_LANG, langs, 4, UI_MENU_MENU_LANG_DESC); opt_end(); }