From b030ce568fa9fb9aa5881edd9af5131d21f99259 Mon Sep 17 00:00:00 2001 From: Dav999-v Date: Sat, 21 Jan 2023 03:27:55 +0100 Subject: [PATCH] Make main game content use interface font instead of 8x8 font If a custom level doesn't specify a font, it should be the 8x8 font. But the main game can't specify a font, it's just the interface font because that's for the language that the game is in. --- desktop_version/src/Font.cpp | 55 +++++++++++++++++++++------------- desktop_version/src/Font.h | 3 +- desktop_version/src/Game.cpp | 2 +- desktop_version/src/Script.cpp | 15 ++++++++-- 4 files changed, 51 insertions(+), 24 deletions(-) diff --git a/desktop_version/src/Font.cpp b/desktop_version/src/Font.cpp index 664e0364..1c4173f8 100644 --- a/desktop_version/src/Font.cpp +++ b/desktop_version/src/Font.cpp @@ -70,8 +70,9 @@ static FontContainer fonts_custom = {}; static uint8_t font_idx_8x8 = 0; -static bool font_idx_custom_is_custom = false; -static uint8_t font_idx_custom = 0; +static bool font_level_is_interface = false; +static bool font_idx_level_is_custom = false; +static uint8_t font_idx_level = 0; static void codepoint_split( const uint32_t codepoint, @@ -404,31 +405,40 @@ uint8_t get_font_idx_8x8(void) return font_idx_8x8; } -void set_custom_font(const char* name) +void set_level_font(const char* name) { - /* Apply the choice for a certain level-specific font. */ + /* Apply the choice for a certain level-specific font. + * This function is for custom levels. */ + font_level_is_interface = false; - if (find_font_by_name(&fonts_custom, name, &font_idx_custom)) + if (find_font_by_name(&fonts_custom, name, &font_idx_level)) { - font_idx_custom_is_custom = true; + font_idx_level_is_custom = true; } else { - font_idx_custom_is_custom = false; - if (!find_font_by_name(&fonts_main, name, &font_idx_custom)) + font_idx_level_is_custom = false; + if (!find_font_by_name(&fonts_main, name, &font_idx_level)) { if (SDL_strcmp(name, "font") != 0) { - set_custom_font("font"); + set_level_font("font"); } else { - font_idx_custom = font_idx_8x8; + font_idx_level = font_idx_8x8; } } } } +void set_level_font_interface(void) +{ + /* Set the level font equal to the interface font. + * This function is for the main game. */ + font_level_is_interface = true; +} + static void load_font_filename(bool is_custom, const char* filename) { // Load font.png, and everything that matches *.fontmeta (but not font.fontmeta) @@ -467,6 +477,7 @@ void load_main(void) load_font_filename(false, item); } FILESYSTEM_freeEnumerate(&handle); + font_idx_level = font_idx_8x8; } void load_custom(const char* name) @@ -481,7 +492,7 @@ void load_custom(const char* name) } FILESYSTEM_freeEnumerate(&handle); - set_custom_font(name); + set_level_font(name); } void unload_font(Font* f) @@ -559,17 +570,21 @@ static Font* fontsel_to_font(int sel) switch (sel) { + case 1: + if (!font_level_is_interface) + { + if (font_idx_level_is_custom) + { + return container_get(&fonts_custom, font_idx_level); + } + else + { + return container_get(&fonts_main, font_idx_level); + } + } + SDL_FALLTHROUGH; case 0: return container_get(&fonts_main, loc::get_langmeta()->font_idx); - case 1: - if (font_idx_custom_is_custom) - { - return container_get(&fonts_custom, font_idx_custom); - } - else - { - return container_get(&fonts_main, font_idx_custom); - } case 2: return container_get(&fonts_main, font_idx_8x8); } diff --git a/desktop_version/src/Font.h b/desktop_version/src/Font.h index c56caf92..1faa603c 100644 --- a/desktop_version/src/Font.h +++ b/desktop_version/src/Font.h @@ -64,7 +64,8 @@ bool find_main_font_by_name(const char* name, uint8_t* idx); const char* get_main_font_name(uint8_t idx); uint8_t get_font_idx_8x8(void); -void set_custom_font(const char* name); +void set_level_font(const char* name); +void set_level_font_interface(void); void load_main(void); void load_custom(const char* name); void unload_custom(void); diff --git a/desktop_version/src/Game.cpp b/desktop_version/src/Game.cpp index 6f909f0a..506b20db 100644 --- a/desktop_version/src/Game.cpp +++ b/desktop_version/src/Game.cpp @@ -7186,7 +7186,7 @@ void Game::returntoeditor(void) ed.roomnamehide = 0; // Might've been changed in a script - font::set_custom_font(cl.level_font_name.c_str()); + font::set_level_font(cl.level_font_name.c_str()); DEFER_CALLBACK(resetbg); music.fadeout(); diff --git a/desktop_version/src/Script.cpp b/desktop_version/src/Script.cpp index 78929bca..7142d0b7 100644 --- a/desktop_version/src/Script.cpp +++ b/desktop_version/src/Script.cpp @@ -2429,11 +2429,11 @@ void scriptclass::run(void) #ifndef NO_CUSTOM_LEVELS if (words[1] == "") { - font::set_custom_font(cl.level_font_name.c_str()); + font::set_level_font(cl.level_font_name.c_str()); } else { - font::set_custom_font(words[1].c_str()); + font::set_level_font(words[1].c_str()); } #endif } @@ -2592,6 +2592,17 @@ void scriptclass::startgamemode(const enum StartMode mode) game.gamestate = GAMEMODE; } + switch (mode) + { + case Start_EDITOR: + case Start_EDITORPLAYTESTING: + case Start_CUSTOM: + case Start_CUSTOM_QUICKSAVE: + break; + default: + font::set_level_font_interface(); + } + game.jumpheld = true; switch (mode)