Add autodowloading chinese font when needed

This commit is contained in:
Grinch_ 2022-08-02 02:10:43 +06:00
parent 42c6156ce5
commit 1f48e7f723
5 changed files with 40 additions and 6 deletions

View File

@ -112,6 +112,19 @@ void D3dHook::ProcessFrame(void* ptr)
{ {
ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData()); ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
} }
if (FontMgr::IsFontReloadRequired())
{
FontMgr::ReloadAll();
if (gRenderer == Render_DirectX9)
{
ImGui_ImplDX9_InvalidateDeviceObjects();
}
else
{
ImGui_ImplDX11_InvalidateDeviceObjects();
}
}
} }
else else
{ {

View File

@ -87,7 +87,8 @@ void MenuThread(void* param)
bool modloader = GetModuleHandle("modloader.asi"); bool modloader = GetModuleHandle("modloader.asi");
const char *path = PLUGIN_PATH((char*)""); const char *path = PLUGIN_PATH((char*)"");
Log::Print<eLogLevel::None>("Install location: {}", modloader && strstr(path, "modloader") ? "Modloader" : "Game directory"); Log::Print<eLogLevel::None>("Install location: {}", modloader && strstr(path, "modloader") ? "Modloader" : "Game directory");
Log::Print<eLogLevel::None>("CLEO installed: {}", GetModuleHandle("cleo.asi") || GetModuleHandle("cleo_redux.asi") ? "True" : "False"); Log::Print<eLogLevel::None>("Font support package: {}", FontMgr::IsSupportPackageInstalled() ? "True" : "False");
Log::Print<eLogLevel::None>("\nCLEO installed: {}", GetModuleHandle("cleo.asi") || GetModuleHandle("cleo_redux.asi") ? "True" : "False");
Log::Print<eLogLevel::None>("FLA installed: {}", GetModuleHandle("$fastman92limitAdjuster.asi") ? "True" : "False"); Log::Print<eLogLevel::None>("FLA installed: {}", GetModuleHandle("$fastman92limitAdjuster.asi") ? "True" : "False");
Log::Print<eLogLevel::None>("Mixsets installed: {}", GetModuleHandle("MixSets.asi") ? "True" : "False"); Log::Print<eLogLevel::None>("Mixsets installed: {}", GetModuleHandle("MixSets.asi") ? "True" : "False");
Log::Print<eLogLevel::None>("Modloader installed: {}", modloader ? "True" : "False"); Log::Print<eLogLevel::None>("Modloader installed: {}", modloader ? "True" : "False");

View File

@ -51,7 +51,9 @@ ImFont* FontMgr::Load(const char* fontID, const char* path, float fontMul)
void FontMgr::UnloadAll() void FontMgr::UnloadAll()
{ {
ImGui::GetIO().Fonts->Clear(); ImGuiIO& io = ImGui::GetIO();
io.Fonts->Clear();
io.Fonts->ClearFonts();
} }
void FontMgr::ReloadAll() void FontMgr::ReloadAll()
@ -66,11 +68,12 @@ void FontMgr::ReloadAll()
} }
io.FontDefault = Get("text"); io.FontDefault = Get("text");
io.Fonts->Build(); io.Fonts->Build();
m_bFontReloadRequired = false;
} }
void FontMgr::Process() void FontMgr::Process()
{ {
if (curState != eStates::Idle) if (curState == eStates::Idle)
{ {
return; return;
} }
@ -83,10 +86,21 @@ void FontMgr::Process()
Util::SetMessage(TEXT("Updater.Failed")); Util::SetMessage(TEXT("Updater.Failed"));
return; return;
} }
m_bFontReloadRequired = true;
curState = eStates::Idle; curState = eStates::Idle;
} }
bool FontMgr::IsSupportPackageInstalled()
{
return std::filesystem::file_size(MENU_DATA_PATH("fonts/text.ttf")) > 1000000; // 1 MB
}
bool FontMgr::IsFontReloadRequired()
{
return m_bFontReloadRequired;
}
void FontMgr::StartOptionalFontDownload() void FontMgr::StartOptionalFontDownload()
{ {
if (curState == eStates::Idle) if (curState == eStates::Idle)

View File

@ -23,6 +23,7 @@ private:
}; };
static inline std::vector<FontInfo> m_vecFonts; static inline std::vector<FontInfo> m_vecFonts;
static inline eStates curState = eStates::Idle; static inline eStates curState = eStates::Idle;
static inline bool m_bFontReloadRequired = false;
public: public:
FontMgr() = delete; FontMgr() = delete;
@ -49,6 +50,12 @@ public:
// Downloads optional font package // Downloads optional font package
static void StartOptionalFontDownload(); static void StartOptionalFontDownload();
// Returns true if font support package is already installed
static bool IsSupportPackageInstalled();
// Returns true if font needs to be reloaded
static bool IsFontReloadRequired();
}; };

View File

@ -27,10 +27,9 @@ void Menu::ShowPage()
{ {
static int selected = Locale::GetCurrentLocaleIndex(); static int selected = Locale::GetCurrentLocaleIndex();
static std::vector<std::string>& vec = Locale::GetLocaleList(); static std::vector<std::string>& vec = Locale::GetLocaleList();
static size_t fontSz = std::filesystem::file_size(MENU_DATA_PATH("fonts/text.ttf"));
if (Locale::GetLocaleList()[Locale::GetCurrentLocaleIndex()] == "Chinese" if (Locale::GetLocaleList()[Locale::GetCurrentLocaleIndex()] == "Chinese"
&& fontSz < 1000000) // Normal font size is < 1 MB && !FontMgr::IsSupportPackageInstalled())
{ {
ImGui::Spacing(); ImGui::Spacing();
ImGui::TextWrapped("Font support package is required to display this language! This may take a while depending on your connection."); ImGui::TextWrapped("Font support package is required to display this language! This may take a while depending on your connection.");