1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-22 09:39:43 +01:00

Translate level title and creator on-the-fly

These weren't getting updated when cycling language with CTRL+F8. This
is because they would be already baked. Luckily, at least the bool
keeping track of whether or not to translate them in the first place
already exists, so we can just rely on that.
This commit is contained in:
Misa 2024-02-02 15:58:46 -08:00 committed by Misa Elizabeth Kai
parent 0aea27f237
commit 53ed33039f
5 changed files with 52 additions and 31 deletions

View file

@ -87,26 +87,14 @@ static bool compare_nocase (std::string first, std::string second)
* as being translated, while they're actually stored in English in the level file.
* This way we translate "Untitled Level" and "Unknown" without
* spreading around translations in level files posted online! */
std::string translate_title(const std::string& title, bool* is_gettext)
bool translate_title(const std::string& title)
{
if (title == "Untitled Level")
{
*is_gettext = true;
return loc::gettext("Untitled Level");
}
*is_gettext = false;
return title;
return title == "Untitled Level";
}
std::string translate_creator(const std::string& creator, bool* is_gettext)
bool translate_creator(const std::string& creator)
{
if (creator == "Unknown")
{
*is_gettext = true;
return loc::gettext("Unknown");
}
*is_gettext = false;
return creator;
return creator == "Unknown";
}
static void levelZipCallback(const char* filename)
@ -306,8 +294,10 @@ bool customlevelclass::getLevelMetaDataAndPlaytestArgs(const std::string& _path,
return false;
}
_data.creator = translate_creator(find_creator(buf), &_data.creator_is_gettext);
_data.title = translate_title(find_title(buf), &_data.title_is_gettext);
_data.creator = find_creator(buf);
_data.creator_is_gettext = translate_creator(_data.creator);
_data.title = find_title(buf);
_data.title_is_gettext = translate_title(_data.title);
_data.Desc1 = find_desc1(buf);
_data.Desc2 = find_desc2(buf);
_data.Desc3 = find_desc3(buf);

View file

@ -171,9 +171,9 @@ public:
bool onewaycol_override;
};
std::string translate_title(const std::string& title, bool* is_gettext);
bool translate_title(const std::string& title);
std::string translate_creator(const std::string& creator, bool* is_gettext);
bool translate_creator(const std::string& creator);
#ifndef CL_DEFINITION
extern customlevelclass cl;

View file

@ -544,13 +544,31 @@ static void editormenurender(int tr, int tg, int tb)
}
else
{
bool title_is_gettext;
std::string title = translate_title(cl.title, &title_is_gettext);
const char* title = cl.title.c_str();
const bool title_is_gettext = translate_title(cl.title);
if (title_is_gettext)
{
title = loc::gettext(title);
}
font::print(PR_2X | PR_CEN | (title_is_gettext ? PR_FONT_INTERFACE : PR_FONT_LEVEL), -1, 35, title, tr, tg, tb);
}
bool creator_is_gettext = false;
std::string creator = (ed.current_text_mode == TEXT_CREATOR) ? input_text : translate_creator(cl.creator, &creator_is_gettext);
bool creator_is_gettext;
const char* creator;
if (ed.current_text_mode == TEXT_CREATOR)
{
creator_is_gettext = false;
creator = input_text.c_str();
}
else
{
creator_is_gettext = translate_creator(cl.creator);
creator = cl.creator.c_str();
}
if (creator_is_gettext)
{
creator = loc::gettext(creator);
}
int sp = SDL_max(10, font::height(PR_FONT_LEVEL));
graphics.print_level_creator((creator_is_gettext ? PR_FONT_INTERFACE : PR_FONT_LEVEL), 60, creator, tr, tg, tb);
@ -2653,8 +2671,7 @@ static void editormenuactionpress(void)
{
case 0:
{
bool title_is_gettext;
translate_title(cl.title, &title_is_gettext);
const bool title_is_gettext = translate_title(cl.title);
ed.current_text_mode = TEXT_TITLE;
ed.substate = EditorSubState_MENU_INPUT;
@ -2673,8 +2690,7 @@ static void editormenuactionpress(void)
}
case 1:
{
bool creator_is_gettext;
translate_creator(cl.creator, &creator_is_gettext);
const bool creator_is_gettext = translate_creator(cl.creator);
ed.current_text_mode = TEXT_CREATOR;
ed.substate = EditorSubState_MENU_INPUT;

View file

@ -6638,6 +6638,11 @@ void Game::createmenu( enum Menu::MenuName t, bool samemenu/*= false*/ )
prefix = "";
break;
}
const char* title = cl.ListOfMetaData[i].title.c_str();
if (cl.ListOfMetaData[i].title_is_gettext)
{
title = loc::gettext(title);
}
/* We have to make sure the stars and spaces are consistently on the
* correct side of the title, no matter what bidi characters are in there.
* So just always let the bidi engine handle it, with a few control chars. */
@ -6650,7 +6655,7 @@ void Game::createmenu( enum Menu::MenuName t, bool samemenu/*= false*/ )
prefix,
// FIRST STRONG ISOLATE, to start an isolated block oriented however bidi sees fit
UTF8_encode(0x2068).bytes,
cl.ListOfMetaData[i].title.c_str(),
title,
// POP DIRECTIONAL ISOLATE, exit isolated level title
UTF8_encode(0x2069).bytes
);

View file

@ -272,10 +272,20 @@ static void menurender(void)
);
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;
const char* title = cl.ListOfMetaData[tmp].title.c_str();
if (cl.ListOfMetaData[tmp].title_is_gettext)
{
title = loc::gettext(title);
}
const char* creator = cl.ListOfMetaData[tmp].creator.c_str();
if (cl.ListOfMetaData[tmp].creator_is_gettext)
{
creator = loc::gettext(creator);
}
font::print(title_flags | PR_2X | PR_CEN, -1, 15, cl.ListOfMetaData[tmp].title, tr, tg, tb);
font::print(title_flags | PR_2X | PR_CEN, -1, 15, title, tr, tg, tb);
int sp = SDL_max(10, font::height(level_flags));
graphics.print_level_creator(creator_flags, 40, cl.ListOfMetaData[tmp].creator, tr, tg, tb);
graphics.print_level_creator(creator_flags, 40, creator, tr, tg, tb);
font::print(level_flags | PR_CEN, -1, 40+sp, cl.ListOfMetaData[tmp].website, tr, tg, tb);
font::print(level_flags | PR_CEN, -1, 40+sp*3, cl.ListOfMetaData[tmp].Desc1, tr, tg, tb);
font::print(level_flags | PR_CEN, -1, 40+sp*4, cl.ListOfMetaData[tmp].Desc2, tr, tg, tb);