1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2025-01-09 10:29:45 +01:00

Allow levels to select a font via XML, show correct font in levels list

There still needs to be a menu for selecting a font, but it can now be
loaded and saved correctly in the XML!
This commit is contained in:
Dav999-v 2023-01-20 03:56:17 +01:00 committed by Misa Elizabeth Kai
parent 8d5e3b1a8a
commit 7db0e73109
6 changed files with 51 additions and 9 deletions

View file

@ -231,6 +231,7 @@ TAG_FINDER(find_desc1, "Desc1")
TAG_FINDER(find_desc2, "Desc2") TAG_FINDER(find_desc2, "Desc2")
TAG_FINDER(find_desc3, "Desc3") TAG_FINDER(find_desc3, "Desc3")
TAG_FINDER(find_website, "website") TAG_FINDER(find_website, "website")
TAG_FINDER(find_font, "font")
/* For CliPlaytestArgs */ /* For CliPlaytestArgs */
TAG_FINDER(find_playtest, "Playtest") TAG_FINDER(find_playtest, "Playtest")
@ -312,6 +313,10 @@ bool customlevelclass::getLevelMetaDataAndPlaytestArgs(const std::string& _path,
_data.Desc2 = find_desc2(buf); _data.Desc2 = find_desc2(buf);
_data.Desc3 = find_desc3(buf); _data.Desc3 = find_desc3(buf);
_data.website = find_website(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) if (pt_args != NULL)
@ -1026,6 +1031,7 @@ bool customlevelclass::load(std::string& _path)
#endif #endif
version = 0; version = 0;
level_font_name = "font";
for (pElem = hDoc for (pElem = hDoc
.FirstChildElement() .FirstChildElement()
@ -1088,6 +1094,11 @@ bool customlevelclass::load(std::string& _path)
{ {
onewaycol_override = help.Int(pText_); onewaycol_override = help.Int(pText_);
} }
if(SDL_strcmp(pKey_, "font") == 0)
{
level_font_name = pText_;
}
} }
} }
@ -1320,7 +1331,7 @@ next:
#endif #endif
loc::loadtext_custom(_path.c_str()); loc::loadtext_custom(_path.c_str());
font::load_custom(); font::load_custom(level_font_name.c_str());
version=2; 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 <onewaycol_override>
tinyxml2::XMLElement* element;
while ((element = msg->FirstChildElement("font")) != NULL)
{
doc.DeleteNode(element);
}
}
xml::update_tag(data, "mapwidth", mapwidth); xml::update_tag(data, "mapwidth", mapwidth);
xml::update_tag(data, "mapheight", mapheight); xml::update_tag(data, "mapheight", mapheight);

View file

@ -63,6 +63,10 @@ struct LevelMetaData
* was stored in this struct (for the levels list) */ * was stored in this struct (for the levels list) */
bool title_is_gettext; bool title_is_gettext;
bool creator_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 struct CliPlaytestArgs
@ -158,6 +162,8 @@ public:
int levmusic; int levmusic;
int mapwidth, mapheight; //Actual width and height of stage int mapwidth, mapheight; //Actual width and height of stage
std::string level_font_name;
int version; int version;
SDL_Color getonewaycol(int rx, int ry); SDL_Color getonewaycol(int rx, int ry);

View file

@ -417,7 +417,14 @@ static void set_custom_font(const char* name)
font_idx_custom_is_custom = false; font_idx_custom_is_custom = false;
if (!find_font_by_name(&fonts_main, name, &font_idx_custom)) 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); FILESYSTEM_freeEnumerate(&handle);
} }
void load_custom(void) void load_custom(const char* name)
{ {
// Load all custom (level-specific assets) fonts // Load all custom (level-specific assets) fonts
unload_custom(); unload_custom();
@ -474,8 +481,7 @@ void load_custom(void)
} }
FILESYSTEM_freeEnumerate(&handle); FILESYSTEM_freeEnumerate(&handle);
// TODO: here instead of "font", fill in the font chosen by the level set_custom_font(name);
set_custom_font("font");
} }
void unload_font(Font* f) void unload_font(Font* f)

View file

@ -65,7 +65,7 @@ const char* get_main_font_name(uint8_t idx);
uint8_t get_font_idx_8x8(void); uint8_t get_font_idx_8x8(void);
void load_main(void); void load_main(void);
void load_custom(void); void load_custom(const char* name);
void unload_custom(void); void unload_custom(void);
void destroy(void); void destroy(void);

View file

@ -6266,7 +6266,13 @@ void Game::createmenu( enum Menu::MenuName t, bool samemenu/*= false*/ )
{ {
text[ii] = SDL_tolower(text[ii]); 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) if (cl.ListOfMetaData.size() > 8)

View file

@ -197,8 +197,7 @@ static void menurender(void)
if(nextlastoptions && game.menuoptions.size() - game.currentmenuoption<=3){ if(nextlastoptions && game.menuoptions.size() - game.currentmenuoption<=3){
}else{ }else{
// TODO: Use level-specific font (via PR_FONT_IDX?) uint32_t level_flags = PR_FONT_IDX(cl.ListOfMetaData[tmp].level_main_font_idx);
uint32_t level_flags = PR_FONT_8X8; // TEMP
uint32_t title_flags = cl.ListOfMetaData[tmp].title_is_gettext ? PR_FONT_INTERFACE : level_flags; 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; uint32_t creator_flags = cl.ListOfMetaData[tmp].creator_is_gettext ? PR_FONT_INTERFACE : level_flags;