diff --git a/desktop_version/src/CustomLevels.cpp b/desktop_version/src/CustomLevels.cpp index 6157f6f2..2e956254 100644 --- a/desktop_version/src/CustomLevels.cpp +++ b/desktop_version/src/CustomLevels.cpp @@ -231,6 +231,7 @@ TAG_FINDER(find_desc1, "Desc1") TAG_FINDER(find_desc2, "Desc2") TAG_FINDER(find_desc3, "Desc3") TAG_FINDER(find_website, "website") +TAG_FINDER(find_font, "font") /* For CliPlaytestArgs */ TAG_FINDER(find_playtest, "Playtest") @@ -312,6 +313,10 @@ bool customlevelclass::getLevelMetaDataAndPlaytestArgs(const std::string& _path, _data.Desc2 = find_desc2(buf); _data.Desc3 = find_desc3(buf); _data.website = find_website(buf); + if (!font::find_main_font_by_name(find_font(buf).c_str(), &_data.level_main_font_idx)) + { + _data.level_main_font_idx = font::get_font_idx_8x8(); + } if (pt_args != NULL) @@ -1026,6 +1031,7 @@ bool customlevelclass::load(std::string& _path) #endif version = 0; + level_font_name = "font"; for (pElem = hDoc .FirstChildElement() @@ -1088,6 +1094,11 @@ bool customlevelclass::load(std::string& _path) { onewaycol_override = help.Int(pText_); } + + if(SDL_strcmp(pKey_, "font") == 0) + { + level_font_name = pText_; + } } } @@ -1320,7 +1331,7 @@ next: #endif loc::loadtext_custom(_path.c_str()); - font::load_custom(); + font::load_custom(level_font_name.c_str()); version=2; @@ -1395,6 +1406,20 @@ bool customlevelclass::save(const std::string& _path) } } + if (level_font_name != "" && level_font_name != "font") + { + xml::update_tag(msg, "font", level_font_name.c_str()); + } + else + { + // Get rid of it completely, same as + tinyxml2::XMLElement* element; + while ((element = msg->FirstChildElement("font")) != NULL) + { + doc.DeleteNode(element); + } + } + xml::update_tag(data, "mapwidth", mapwidth); xml::update_tag(data, "mapheight", mapheight); diff --git a/desktop_version/src/CustomLevels.h b/desktop_version/src/CustomLevels.h index da553b78..0000a705 100644 --- a/desktop_version/src/CustomLevels.h +++ b/desktop_version/src/CustomLevels.h @@ -63,6 +63,10 @@ struct LevelMetaData * was stored in this struct (for the levels list) */ bool title_is_gettext; bool creator_is_gettext; + + /* This is for the metadata in the levels list, + * so it will only be a main font (no custom ones). */ + uint8_t level_main_font_idx; }; struct CliPlaytestArgs @@ -158,6 +162,8 @@ public: int levmusic; int mapwidth, mapheight; //Actual width and height of stage + std::string level_font_name; + int version; SDL_Color getonewaycol(int rx, int ry); diff --git a/desktop_version/src/Font.cpp b/desktop_version/src/Font.cpp index 5a5bc534..8a7ad421 100644 --- a/desktop_version/src/Font.cpp +++ b/desktop_version/src/Font.cpp @@ -417,7 +417,14 @@ static void set_custom_font(const char* name) font_idx_custom_is_custom = false; if (!find_font_by_name(&fonts_main, name, &font_idx_custom)) { - font_idx_custom = font_idx_8x8; + if (SDL_strcmp(name, "font") != 0) + { + set_custom_font("font"); + } + else + { + font_idx_custom = font_idx_8x8; + } } } } @@ -462,7 +469,7 @@ void load_main(void) FILESYSTEM_freeEnumerate(&handle); } -void load_custom(void) +void load_custom(const char* name) { // Load all custom (level-specific assets) fonts unload_custom(); @@ -474,8 +481,7 @@ void load_custom(void) } FILESYSTEM_freeEnumerate(&handle); - // TODO: here instead of "font", fill in the font chosen by the level - set_custom_font("font"); + set_custom_font(name); } void unload_font(Font* f) diff --git a/desktop_version/src/Font.h b/desktop_version/src/Font.h index fb506388..66ecafc1 100644 --- a/desktop_version/src/Font.h +++ b/desktop_version/src/Font.h @@ -65,7 +65,7 @@ const char* get_main_font_name(uint8_t idx); uint8_t get_font_idx_8x8(void); void load_main(void); -void load_custom(void); +void load_custom(const char* name); void unload_custom(void); void destroy(void); diff --git a/desktop_version/src/Game.cpp b/desktop_version/src/Game.cpp index 3f958b16..4df093b3 100644 --- a/desktop_version/src/Game.cpp +++ b/desktop_version/src/Game.cpp @@ -6266,7 +6266,13 @@ void Game::createmenu( enum Menu::MenuName t, bool samemenu/*= false*/ ) { text[ii] = SDL_tolower(text[ii]); } - option(text, true, cl.ListOfMetaData[i].title_is_gettext ? PR_FONT_INTERFACE : PR_FONT_8X8); // TODO level font + option( + text, + true, + cl.ListOfMetaData[i].title_is_gettext ? PR_FONT_INTERFACE : PR_FONT_IDX( + cl.ListOfMetaData[i].level_main_font_idx + ) + ); } } if (cl.ListOfMetaData.size() > 8) diff --git a/desktop_version/src/Render.cpp b/desktop_version/src/Render.cpp index 08df1645..a1bc0f4d 100644 --- a/desktop_version/src/Render.cpp +++ b/desktop_version/src/Render.cpp @@ -197,8 +197,7 @@ static void menurender(void) if(nextlastoptions && game.menuoptions.size() - game.currentmenuoption<=3){ }else{ - // TODO: Use level-specific font (via PR_FONT_IDX?) - uint32_t level_flags = PR_FONT_8X8; // TEMP + uint32_t level_flags = PR_FONT_IDX(cl.ListOfMetaData[tmp].level_main_font_idx); uint32_t title_flags = cl.ListOfMetaData[tmp].title_is_gettext ? PR_FONT_INTERFACE : level_flags; uint32_t creator_flags = cl.ListOfMetaData[tmp].creator_is_gettext ? PR_FONT_INTERFACE : level_flags;