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.
This commit is contained in:
QwertyChouskie 2021-10-28 21:24:25 -07:00 committed by Benau
parent 1470eb3939
commit 9ca2c2eddc
5 changed files with 14 additions and 25 deletions

View File

@ -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);

View File

@ -1137,6 +1137,8 @@ namespace GUIEngine
}
}
font_manager->loadFonts();
RegularFace* regular = font_manager->getFont<RegularFace>();
BoldFace* bold = font_manager->getFont<BoldFace>();
DigitFace* digit = font_manager->getFont<DigitFace>();

View File

@ -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)
{
assert(fallback_skin != NULL);
m_fallback_skin = fallback_skin;
m_fallback_skin->grab();
assert(fallback_skin != NULL);
}
m_dialog = false;
m_dialog_size = 0.0f;

View File

@ -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__

View File

@ -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*/);
}