diff --git a/source/common/engine/i_interface.h b/source/common/engine/i_interface.h index 131e0cce2..d734dbee9 100644 --- a/source/common/engine/i_interface.h +++ b/source/common/engine/i_interface.h @@ -31,6 +31,7 @@ struct SystemCallbacks bool (*CheckMenudefOption)(const char* opt); void (*ConsoleToggled)(int state); bool (*PreBindTexture)(FRenderState* state, FGameTexture*& tex, EUpscaleFlags& flags, int& scaleflags, int& clampmode, int& translation, int& overrideshader); + void (*FontCharCreated)(FGameTexture* base, FGameTexture* untranslated, FGameTexture* translated); }; extern SystemCallbacks sysCallbacks; diff --git a/source/common/fonts/font.cpp b/source/common/fonts/font.cpp index 2a67aab37..755ef1129 100644 --- a/source/common/fonts/font.cpp +++ b/source/common/fonts/font.cpp @@ -55,6 +55,7 @@ #include "fontchars.h" #include "multipatchtexture.h" #include "texturemanager.h" +#include "i_interface.h" #include "fontinternals.h" @@ -342,6 +343,7 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla { Chars[i].TranslatedPic = tex; } + if (sysCallbacks.FontCharCreated) sysCallbacks.FontCharCreated(pic, Chars[i].OriginalPic, Chars[i].TranslatedPic); Chars[i].XMove = (int)Chars[i].TranslatedPic->GetDisplayWidth(); } diff --git a/source/common/fonts/specialfont.cpp b/source/common/fonts/specialfont.cpp index 7e9c0778d..637cbf866 100644 --- a/source/common/fonts/specialfont.cpp +++ b/source/common/fonts/specialfont.cpp @@ -38,6 +38,7 @@ #include "image.h" #include "fontchars.h" #include "texturemanager.h" +#include "i_interface.h" #include "fontinternals.h" @@ -116,6 +117,7 @@ FSpecialFont::FSpecialFont (const char *name, int first, int count, FGameTexture } else Chars[i].TranslatedPic = Chars[i].OriginalPic; Chars[i].XMove = (int)Chars[i].TranslatedPic->GetDisplayWidth(); + if (sysCallbacks.FontCharCreated) sysCallbacks.FontCharCreated(pic, Chars[i].OriginalPic, Chars[i].TranslatedPic); } else { diff --git a/source/core/gamecontrol.cpp b/source/core/gamecontrol.cpp index 0d76bb3f5..15d8bdcb4 100644 --- a/source/core/gamecontrol.cpp +++ b/source/core/gamecontrol.cpp @@ -133,6 +133,7 @@ void MainLoop(); void SetConsoleNotifyBuffer(); bool PreBindTexture(FRenderState* state, FGameTexture*& tex, EUpscaleFlags& flags, int& scaleflags, int& clampmode, int& translation, int& overrideshader); void PostLoadSetup(); +void FontCharCreated(FGameTexture* base, FGameTexture* untranslated, FGameTexture* translated); DBaseStatusBar* StatusBar; @@ -525,7 +526,8 @@ int GameMain() System_MenuClosed, nullptr, nullptr, - PreBindTexture + PreBindTexture, + FontCharCreated }; try diff --git a/source/core/textures/hightile.cpp b/source/core/textures/hightile.cpp index 701a11aa0..eb0d2080d 100644 --- a/source/core/textures/hightile.cpp +++ b/source/core/textures/hightile.cpp @@ -62,6 +62,24 @@ struct HightileReplacement static TMap> tileReplacements; static TMap> textureReplacements; +struct FontCharInf +{ + FGameTexture* base; + FGameTexture* untranslated; + FGameTexture* translated; +}; + +static TArray deferredChars; + +void FontCharCreated(FGameTexture* base, FGameTexture* untranslated, FGameTexture* translated) +{ + // Store these in a list for now - they can only be processed in the finalization step. + if (translated == untranslated) translated = nullptr; + FontCharInf fci = { base, untranslated, translated }; + deferredChars.Push(fci); +} + + //=========================================================================== // // Replacement textures @@ -185,6 +203,32 @@ void PostLoadSetup() textureReplacements.Insert(tex->GetID().GetIndex(), std::move(*Hightile)); } tileReplacements.Clear(); + + int i = 0; + for (auto& ci : deferredChars) + { + i++; + auto rep = textureReplacements.CheckKey(ci.base->GetID().GetIndex()); + if (rep) + { + if (ci.untranslated) + { + auto rrep = *rep; + textureReplacements.Insert(ci.untranslated->GetID().GetIndex(), std::move(rrep)); + } + + if (ci.translated) + { + //auto reptex = FindReplacement(ci.base->GetID(), 0, false); + //if (reptex) + { + // Todo: apply the translation. + //auto rrep = *rep; + //textureReplacements.Insert(ci.translated->GetID().GetIndex(), std::move(rrep)); + } + } + } + } } //========================================================================== diff --git a/source/exhumed/src/exhumed.cpp b/source/exhumed/src/exhumed.cpp index 83f721232..6be7e5c77 100644 --- a/source/exhumed/src/exhumed.cpp +++ b/source/exhumed/src/exhumed.cpp @@ -82,7 +82,6 @@ void InstallEngine() } uploadCinemaPalettes(); LoadPaletteLookups(); - InitFonts(); } void RemoveEngine() @@ -527,6 +526,7 @@ void GameInterface::app_init() // temp - moving InstallEngine(); before FadeOut as we use nextpage() in FadeOut InstallEngine(); LoadDefinitions(); + InitFonts(); SetTileNames(); TileFiles.SetBackup(); diff --git a/source/games/duke/src/game.cpp b/source/games/duke/src/game.cpp index efbd1425c..fd103596d 100644 --- a/source/games/duke/src/game.cpp +++ b/source/games/duke/src/game.cpp @@ -317,7 +317,6 @@ void GameInterface::app_init() //Net_SendClientInfo(); initTiles(); - fi.InitFonts(); genspriteremaps(); SetupGameButtons(); InitCheats(); @@ -333,6 +332,7 @@ void GameInterface::app_init() } LoadDefinitions(); + fi.InitFonts(); SetTileNames(); TileFiles.SetBackup(); C_InitConback(TexMan.CheckForTexture("MENUSCREEN", ETextureType::Any), false, 0.75); diff --git a/source/sw/src/game.cpp b/source/sw/src/game.cpp index 2f6a57fd2..ccaf42fba 100644 --- a/source/sw/src/game.cpp +++ b/source/sw/src/game.cpp @@ -221,7 +221,6 @@ void GameInterface::app_init() } TileFiles.LoadArtSet("tiles%03d.art"); - InitFonts(); //Connect(); SortBreakInfo(); @@ -240,6 +239,7 @@ void GameInterface::app_init() LoadCustomInfoFromScript("swcustom.txt"); // Load user customisation information LoadDefinitions(); + InitFonts(); SetTileNames(); TileFiles.SetBackup(); userConfig.AddDefs.reset();