From cc6b00a7119b8cd8018152a5557d5696d28398a5 Mon Sep 17 00:00:00 2001 From: Dav999-v Date: Fri, 20 Jan 2023 04:57:06 +0100 Subject: [PATCH] Add setfont scripting command The in the level file is basically the starting font, but it can be changed at any time via scripting. --- desktop_version/src/Font.cpp | 2 +- desktop_version/src/Font.h | 1 + desktop_version/src/Game.cpp | 3 +++ desktop_version/src/Script.cpp | 16 ++++++++++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/desktop_version/src/Font.cpp b/desktop_version/src/Font.cpp index 8a7ad421..b1f6a049 100644 --- a/desktop_version/src/Font.cpp +++ b/desktop_version/src/Font.cpp @@ -404,7 +404,7 @@ uint8_t get_font_idx_8x8(void) return font_idx_8x8; } -static void set_custom_font(const char* name) +void set_custom_font(const char* name) { /* Apply the choice for a certain level-specific font. */ diff --git a/desktop_version/src/Font.h b/desktop_version/src/Font.h index 66ecafc1..72072dd4 100644 --- a/desktop_version/src/Font.h +++ b/desktop_version/src/Font.h @@ -64,6 +64,7 @@ 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 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 4df093b3..fca7b922 100644 --- a/desktop_version/src/Game.cpp +++ b/desktop_version/src/Game.cpp @@ -7185,6 +7185,9 @@ void Game::returntoeditor(void) ed.notedelay = 0; ed.roomnamehide = 0; + // Might've been changed in a script + font::set_custom_font(cl.level_font_name.c_str()); + DEFER_CALLBACK(resetbg); music.fadeout(); //If warpdir() is used during playtesting, we need to set it back after! diff --git a/desktop_version/src/Script.cpp b/desktop_version/src/Script.cpp index 22b47f4e..51ec3c89 100644 --- a/desktop_version/src/Script.cpp +++ b/desktop_version/src/Script.cpp @@ -2424,6 +2424,19 @@ void scriptclass::run(void) position--; } } + else if (words[0] == "setfont") + { +#ifndef NO_CUSTOM_LEVELS + if (words[1] == "") + { + font::set_custom_font(cl.level_font_name.c_str()); + } + else + { + font::set_custom_font(words[1].c_str()); + } +#endif + } position++; } @@ -3433,6 +3446,9 @@ bool scriptclass::loadcustom(const std::string& t) }else if(words[0] == "loadtext"){ if(customtextmode==1){ add("endtext"); customtextmode=0;} add(lines[i]); + }else if(words[0] == "setfont"){ + if(customtextmode==1){ add("endtext"); customtextmode=0;} + add(lines[i]); }else if(words[0] == "destroy"){ if(customtextmode==1){ add("endtext"); customtextmode=0;} add(lines[i]);