From 3a81c07ecf8a93c77f2ed65b1c5d2a232c06a5ef Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 5 Oct 2020 00:41:26 +0200 Subject: [PATCH] - moved language switching code to 'common'. --- src/common/engine/i_interface.h | 3 ++ src/common/engine/stringtable.cpp | 2 + src/common/fonts/v_text.cpp | 44 ++++++++++++++++++++ src/common/scripting/interface/vmnatives.cpp | 2 + src/g_cvars.cpp | 44 +------------------- src/scripting/vmthunks.cpp | 1 - 6 files changed, 53 insertions(+), 43 deletions(-) diff --git a/src/common/engine/i_interface.h b/src/common/engine/i_interface.h index 7bcdab763..e482d282d 100644 --- a/src/common/engine/i_interface.h +++ b/src/common/engine/i_interface.h @@ -38,3 +38,6 @@ struct WadStuff extern FString endoomName; extern bool batchrun; extern float menuBlurAmount; +extern bool generic_ui; + +void UpdateGenericUI(bool cvar); diff --git a/src/common/engine/stringtable.cpp b/src/common/engine/stringtable.cpp index 56b5b6390..eea149ef0 100644 --- a/src/common/engine/stringtable.cpp +++ b/src/common/engine/stringtable.cpp @@ -666,3 +666,5 @@ const char *StringMap::MatchString (const char *string) const } FStringTable GStrings; + + diff --git a/src/common/fonts/v_text.cpp b/src/common/fonts/v_text.cpp index 375e2d67b..742a99e6f 100644 --- a/src/common/fonts/v_text.cpp +++ b/src/common/fonts/v_text.cpp @@ -46,6 +46,7 @@ #include "gstrings.h" #include "vm.h" #include "serializer.h" +#include "c_cvars.h" //========================================================================== // @@ -240,3 +241,46 @@ DEFINE_ACTION_FUNCTION(FFont, BreakLines) auto broken = V_BreakLines(self, maxwidth, text, true); ACTION_RETURN_OBJECT(Create(broken)); } + + +bool generic_ui; +EXTERN_CVAR(String, language) + +bool CheckFontComplete(FFont* font) +{ + // Also check if the SmallFont contains all characters this language needs. + // If not, switch back to the original one. + return font->CanPrint(GStrings["REQUIRED_CHARACTERS"]); +} + +void UpdateGenericUI(bool cvar) +{ + auto switchstr = GStrings["USE_GENERIC_FONT"]; + 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; + } + + // 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); +} diff --git a/src/common/scripting/interface/vmnatives.cpp b/src/common/scripting/interface/vmnatives.cpp index 04a28d4df..ed0308e63 100644 --- a/src/common/scripting/interface/vmnatives.cpp +++ b/src/common/scripting/interface/vmnatives.cpp @@ -47,6 +47,7 @@ #include "gstrings.h" #include "printf.h" #include "s_music.h" +#include "i_interface.h" //========================================================================== @@ -660,3 +661,4 @@ DEFINE_FIELD_X(MusPlayingInfo, MusPlayingInfo, loop); DEFINE_GLOBAL_NAMED(PClass::AllClasses, AllClasses) DEFINE_GLOBAL(Bindings) DEFINE_GLOBAL(AutomapBindings) +DEFINE_GLOBAL(generic_ui) diff --git a/src/g_cvars.cpp b/src/g_cvars.cpp index 7c5e6a0e5..30733dd3b 100644 --- a/src/g_cvars.cpp +++ b/src/g_cvars.cpp @@ -41,6 +41,7 @@ #include "v_font.h" #include "utf8.h" #include "gi.h" +#include "i_interface.h" void I_UpdateWindowTitle(); @@ -156,48 +157,7 @@ CUSTOM_CVAR(Float, teamdamage, 0.f, CVAR_SERVERINFO | CVAR_NOINITCALL) } } -bool generic_ui; -EXTERN_CVAR(String, language) - -bool CheckFontComplete(FFont *font) -{ - // Also check if the SmallFont contains all characters this language needs. - // If not, switch back to the original one. - return font->CanPrint(GStrings["REQUIRED_CHARACTERS"]); -} - -void UpdateGenericUI(bool cvar) -{ - auto switchstr = GStrings["USE_GENERIC_FONT"]; - generic_ui = (cvar || (switchstr && strtoll(switchstr, nullptr, 0)) || ((gameinfo.gametype & GAME_Raven) && !strnicmp(language, "el", 2))); - 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; - } - - // 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); -} - +EXTERN_CVAR(Bool, ui_generic) CUSTOM_CVAR(String, language, "auto", CVAR_ARCHIVE | CVAR_NOINITCALL | CVAR_GLOBALCONFIG) { diff --git a/src/scripting/vmthunks.cpp b/src/scripting/vmthunks.cpp index c7cdbda60..d9698d24a 100644 --- a/src/scripting/vmthunks.cpp +++ b/src/scripting/vmthunks.cpp @@ -2967,4 +2967,3 @@ DEFINE_FIELD(DBaseStatusBar, itemflashFade); DEFINE_FIELD(DHUDFont, mFont); DEFINE_GLOBAL(StatusBar); -DEFINE_GLOBAL(generic_ui)