From fd84922a9203bf5be26a32a95bd377efdfa64a20 Mon Sep 17 00:00:00 2001 From: Dav999 Date: Wed, 30 Aug 2023 16:45:04 +0200 Subject: [PATCH] Add warning messages for missing fonts/lang folders If someone makes a build of the game without copying the correct folders, their version will have no translations, and display some text wrong (like credits or button glyphs, or any custom levels that rely on characters in the fonts being there). So I added a message in the bottom left corner of the title screen to warn for that. --- desktop_version/src/FileSystemUtils.cpp | 29 ++++++++++++++++++------- desktop_version/src/FileSystemUtils.h | 2 ++ desktop_version/src/Render.cpp | 27 +++++++++++++++++++++-- 3 files changed, 48 insertions(+), 10 deletions(-) diff --git a/desktop_version/src/FileSystemUtils.cpp b/desktop_version/src/FileSystemUtils.cpp index 54e0bb4a..a4607a47 100644 --- a/desktop_version/src/FileSystemUtils.cpp +++ b/desktop_version/src/FileSystemUtils.cpp @@ -50,6 +50,8 @@ static char saveDir[MAX_PATH] = {'\0'}; static char levelDir[MAX_PATH] = {'\0'}; static char mainLangDir[MAX_PATH] = {'\0'}; static bool isMainLangDirFromRepo = false; +static bool doesLangDirExist = false; +static bool doesFontsDirExist = false; static char assetDir[MAX_PATH] = {'\0'}; static char virtualMountPath[MAX_PATH] = {'\0'}; @@ -74,7 +76,7 @@ static const PHYSFS_Allocator allocator = { SDL_free }; -static void mount_pre_datazip( +static bool mount_pre_datazip( char* out_path, const char* real_dirname, const char* mount_point, @@ -95,12 +97,11 @@ static void mount_pre_datazip( { SDL_strlcpy(out_path, user_path, MAX_PATH); } + return true; } - else - { - vlog_warn("User-supplied %s directory is invalid!", real_dirname); - } - return; + + vlog_warn("User-supplied %s directory is invalid!", real_dirname); + return false; } /* Try to detect the directory, it's next to data.zip in distributed builds */ @@ -170,6 +171,8 @@ static void mount_pre_datazip( { vlog_warn("Cannot find the %s directory anywhere!", real_dirname); } + + return dir_found; } int FILESYSTEM_init(char *argvZero, char* baseDir, char *assetsPath, char* langDir, char* fontsDir) @@ -255,10 +258,10 @@ int FILESYSTEM_init(char *argvZero, char* baseDir, char *assetsPath, char* langD basePath = SDL_strdup("./"); } - mount_pre_datazip(mainLangDir, "lang", "lang/", langDir); + doesLangDirExist = mount_pre_datazip(mainLangDir, "lang", "lang/", langDir); vlog_info("Languages directory: %s", mainLangDir); - mount_pre_datazip(NULL, "fonts", "graphics/", fontsDir); + doesFontsDirExist = mount_pre_datazip(NULL, "fonts", "graphics/", fontsDir); /* Mount the stock content last */ if (assetsPath) @@ -339,6 +342,16 @@ bool FILESYSTEM_isMainLangDirFromRepo(void) return isMainLangDirFromRepo; } +bool FILESYSTEM_doesLangDirExist(void) +{ + return doesLangDirExist; +} + +bool FILESYSTEM_doesFontsDirExist(void) +{ + return doesFontsDirExist; +} + bool FILESYSTEM_restoreWriteDir(void) { return PHYSFS_setWriteDir(writeDir); diff --git a/desktop_version/src/FileSystemUtils.h b/desktop_version/src/FileSystemUtils.h index e4d8160b..667f180c 100644 --- a/desktop_version/src/FileSystemUtils.h +++ b/desktop_version/src/FileSystemUtils.h @@ -17,6 +17,8 @@ char *FILESYSTEM_getUserSaveDirectory(void); char *FILESYSTEM_getUserLevelDirectory(void); char *FILESYSTEM_getUserMainLangDirectory(void); bool FILESYSTEM_isMainLangDirFromRepo(void); +bool FILESYSTEM_doesLangDirExist(void); +bool FILESYSTEM_doesFontsDirExist(void); bool FILESYSTEM_setLangWriteDir(void); bool FILESYSTEM_restoreWriteDir(void); diff --git a/desktop_version/src/Render.cpp b/desktop_version/src/Render.cpp index 507362c1..d305884c 100644 --- a/desktop_version/src/Render.cpp +++ b/desktop_version/src/Render.cpp @@ -220,8 +220,31 @@ static void menurender(void) #endif font::print(PR_RIGHT, 310, 230, RELEASE_VERSION, tr/2, tg/2, tb/2); - if(music.mmmmmm){ - font::print(0, 10, 230, loc::gettext("[MMMMMM Mod Installed]"), tr/2, tg/2, tb/2); + const char* left_msg = NULL; + + const bool fonts_error = !FILESYSTEM_doesFontsDirExist(); + const bool lang_error = !FILESYSTEM_doesLangDirExist(); + + if (fonts_error && lang_error) + { + left_msg = "[No fonts&lang folders]"; + } + else if (fonts_error) + { + left_msg = "[No fonts folder]"; + } + else if (lang_error) + { + left_msg = "[No lang folder]"; + } + else if (music.mmmmmm) + { + left_msg = loc::gettext("[MMMMMM Mod Installed]"); + } + + if (left_msg != NULL) + { + font::print(0, 10, 230, left_msg, tr/2, tg/2, tb/2); } break; }