1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-22 17:49:43 +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_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 <onewaycol_override>
tinyxml2::XMLElement* element;
while ((element = msg->FirstChildElement("font")) != NULL)
{
doc.DeleteNode(element);
}
}
xml::update_tag(data, "mapwidth", mapwidth);
xml::update_tag(data, "mapheight", mapheight);

View file

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

View file

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

View file

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

View file

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

View file

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