From 9ca2c2eddc3e0edfc6ba909765075a348dca44d0 Mon Sep 17 00:00:00 2001 From: QwertyChouskie Date: Thu, 28 Oct 2021 21:24:25 -0700 Subject: [PATCH] Remove ugly font/skin loading hack font_manager->loadFonts() needs data from the GUI skin. Move this initialization to after we naturally have the data, instead of doing an extra dummy initialization just to get this data. --- src/graphics/irr_driver.cpp | 3 +-- src/guiengine/engine.cpp | 2 ++ src/guiengine/skin.cpp | 23 ++++++++----------- src/main.cpp | 8 +------ .../options/options_screen_ui.cpp | 3 +-- 5 files changed, 14 insertions(+), 25 deletions(-) diff --git a/src/graphics/irr_driver.cpp b/src/graphics/irr_driver.cpp index b470290f5..c5e6a62f3 100644 --- a/src/graphics/irr_driver.cpp +++ b/src/graphics/irr_driver.cpp @@ -1055,8 +1055,7 @@ void IrrDriver::applyResolutionSettings(bool recreate_device) SP::loadShaders(); #endif - font_manager = new FontManager(); - font_manager->loadFonts(); + font_manager = new FontManager(); // Fonts are loaded in GUIEngine::init input_manager = new InputManager(); input_manager->setMode(InputManager::MENU); diff --git a/src/guiengine/engine.cpp b/src/guiengine/engine.cpp index 5434366a0..b2dc88a92 100644 --- a/src/guiengine/engine.cpp +++ b/src/guiengine/engine.cpp @@ -1137,6 +1137,8 @@ namespace GUIEngine } } + font_manager->loadFonts(); + RegularFace* regular = font_manager->getFont(); BoldFace* bold = font_manager->getFont(); DigitFace* digit = font_manager->getFont(); diff --git a/src/guiengine/skin.cpp b/src/guiengine/skin.cpp index 48783bb70..897a0368b 100644 --- a/src/guiengine/skin.cpp +++ b/src/guiengine/skin.cpp @@ -172,7 +172,7 @@ namespace SkinConfig * \brief loads skin information from a STK skin file * \throw std::runtime_error if file cannot be read */ - static void loadFromFile(std::string file, bool load_advanced_only) + static void loadFromFile(std::string file) { // Clear global variables for android m_render_params.clear(); @@ -208,11 +208,11 @@ namespace SkinConfig { const XMLNode* node = root->getNode(i); - if (node->getName() == "element" && !load_advanced_only) + if (node->getName() == "element") { parseElement(node); } - else if (node->getName() == "color" && !load_advanced_only) + else if (node->getName() == "color") { parseColor(node); } @@ -271,7 +271,7 @@ namespace SkinConfig list_ttf_path.begin(), list_ttf_path.end()); } } - else if (!load_advanced_only) + else { Log::error("skin", "Unknown node in XML file '%s'.", node->getName().c_str()); @@ -507,7 +507,6 @@ X##_yflip.LowerRightCorner.Y = y1;} Skin::Skin(IGUISkin* fallback_skin) { - // fallback_skin will be null if load only basic theming data std::string skin_id = UserConfigParams::m_skin_file; std::string skin_name = skin_id.find("addon_") != std::string::npos ? file_manager->getAddonsFile( @@ -516,7 +515,7 @@ Skin::Skin(IGUISkin* fallback_skin) try { - SkinConfig::loadFromFile(skin_name, /*load_advanced_only*/fallback_skin == NULL); + SkinConfig::loadFromFile(skin_name); } catch (std::runtime_error& e) { @@ -526,18 +525,14 @@ Skin::Skin(IGUISkin* fallback_skin) std::string default_skin_id = UserConfigParams::m_skin_file; skin_name = file_manager->getAsset(FileManager::SKIN, default_skin_id + "/stkskin.xml"); - SkinConfig::loadFromFile(skin_name, /*load_advanced_only*/fallback_skin == NULL); + SkinConfig::loadFromFile(skin_name); } m_bg_image = NULL; - m_fallback_skin = NULL; - if (fallback_skin) - { - m_fallback_skin = fallback_skin; - m_fallback_skin->grab(); - assert(fallback_skin != NULL); - } + assert(fallback_skin != NULL); + m_fallback_skin = fallback_skin; + m_fallback_skin->grab(); m_dialog = false; m_dialog_size = 0.0f; diff --git a/src/main.cpp b/src/main.cpp index af34520cb..caf9f5b59 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1863,13 +1863,7 @@ void initRest() exit(0); } - // We need a temporary skin to load the font list from skin (if any) - GUIEngine::Skin* tmp_skin = new GUIEngine::Skin(NULL); - GUIEngine::setSkin(tmp_skin); - font_manager = new FontManager(); - font_manager->loadFonts(); - delete tmp_skin; - GUIEngine::setSkin(NULL); + font_manager = new FontManager(); // Fonts are loaded in GUIEngine::init input_manager = new InputManager(); #ifdef __SWITCH__ diff --git a/src/states_screens/options/options_screen_ui.cpp b/src/states_screens/options/options_screen_ui.cpp index ba2082612..54f606407 100644 --- a/src/states_screens/options/options_screen_ui.cpp +++ b/src/states_screens/options/options_screen_ui.cpp @@ -583,8 +583,7 @@ void OptionsScreenUI::reloadGUIEngine() if (reload_font) { delete font_manager; - font_manager = new FontManager(); - font_manager->loadFonts(); + font_manager = new FontManager(); // Fonts are loaded in GUIEngine::init GUIEngine::init(irr_driver->getDevice(), irr_driver->getVideoDriver(), StateManager::get(), false/*loading*/); }