- automated the SmallFont selection based on a filter string in the language table.

This commit is contained in:
Christoph Oelckers 2019-04-21 12:38:43 +02:00
parent 13841655aa
commit 5b6bae409e
3 changed files with 591 additions and 535 deletions

View file

@ -38,6 +38,8 @@
#include "g_game.h" #include "g_game.h"
#include "gstrings.h" #include "gstrings.h"
#include "i_system.h" #include "i_system.h"
#include "v_font.h"
#include "utf8.h"
CVAR (Bool, cl_spreaddecals, true, CVAR_ARCHIVE) CVAR (Bool, cl_spreaddecals, true, CVAR_ARCHIVE)
CVAR(Bool, var_pushers, true, CVAR_SERVERINFO); CVAR(Bool, var_pushers, true, CVAR_SERVERINFO);
@ -134,13 +136,54 @@ CUSTOM_CVAR(Float, teamdamage, 0.f, CVAR_SERVERINFO | CVAR_NOINITCALL)
bool generic_ui; bool generic_ui;
bool CheckFontComplete(FFont *font)
{
// Also check if the SmallFont contains all characters this language needs.
// If not, switch back to the original one.
const uint8_t* checkstr = (const uint8_t*)GStrings["REQUIRED_CHARACTERS"];
bool incomplete = false;
if (!checkstr) return true;
while (int c = GetCharFromString(checkstr))
{
bool redirected;
int cc = font->GetCharCode(c, true);
if (c != cc && (c != 0x1e9e || cc != 0xdf))
{
return false;
}
}
return true;
}
void UpdateGenericUI(bool cvar) void UpdateGenericUI(bool cvar)
{ {
auto switchstr = GStrings["USE_GENERIC_FONT"]; auto switchstr = GStrings["USE_GENERIC_FONT"];
generic_ui = (cvar || (switchstr && strtoll(switchstr, nullptr, 0))); generic_ui = (cvar || (switchstr && strtoll(switchstr, nullptr, 0)));
if (!generic_ui)
{
// Use the mod's SmallFont if it is complete.
// Otherwise use the stock Smallfont if it is complete.
// If none is complete, fall back to the VGA font.
// The font being set here will be used in 3 places: Notifications, centered messages and menu confirmations.
if (CheckFontComplete(SmallFont))
{
AlternativeSmallFont = SmallFont;
}
else if (OriginalSmallFont && CheckFontComplete(OriginalSmallFont))
{
AlternativeSmallFont = OriginalSmallFont;
}
else
{
AlternativeSmallFont = NewSmallFont;
} }
CUSTOM_CVAR(Bool, ui_generic, false, 0) // This is for allowing to test the generic font system with all languages // Todo: Do the same for the BigFont
}
}
CUSTOM_CVAR(Bool, ui_generic, false, CVAR_NOINITCALL) // This is for allowing to test the generic font system with all languages
{ {
UpdateGenericUI(self); UpdateGenericUI(self);
} }

View file

@ -71,6 +71,7 @@
// PRIVATE FUNCTION PROTOTYPES --------------------------------------------- // PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
static int TranslationMapCompare (const void *a, const void *b); static int TranslationMapCompare (const void *a, const void *b);
void UpdateGenericUI(bool cvar);
// EXTERNAL DATA DECLARATIONS ---------------------------------------------- // EXTERNAL DATA DECLARATIONS ----------------------------------------------
@ -1601,6 +1602,7 @@ void V_InitFonts()
BigFont = NewSmallFont; BigFont = NewSmallFont;
} }
AlternativeSmallFont = OriginalSmallFont; AlternativeSmallFont = OriginalSmallFont;
UpdateGenericUI(false);
} }
void V_ClearFonts() void V_ClearFonts()

File diff suppressed because it is too large Load diff