From 7dc0e2b859a2aa652ff2500489f508909295cccc Mon Sep 17 00:00:00 2001 From: Grinch_ Date: Fri, 4 Mar 2022 02:55:19 +0600 Subject: [PATCH] Add fallback to English.json --- src/cheatmenu.cpp | 2 +- src/locale.cpp | 19 ++++++++++++++++--- src/locale.h | 12 ++++++++++-- src/version.h | 2 +- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/cheatmenu.cpp b/src/cheatmenu.cpp index ee4c0c9..e5af9eb 100644 --- a/src/cheatmenu.cpp +++ b/src/cheatmenu.cpp @@ -208,7 +208,7 @@ void CheatMenu::Init() m_fMenuSize.y = gConfig.GetValue("window.sizeY", screen::GetScreenHeight() / 1.2f); srand(CTimer::m_snTimeInMilliseconds); - Locale::Init("CheatMenu/locale/"); + Locale::Init("CheatMenu/locale/", "English", "English"); CheatMenu::GenHeaderList(); diff --git a/src/locale.cpp b/src/locale.cpp index 04d7d32..2351e78 100644 --- a/src/locale.cpp +++ b/src/locale.cpp @@ -2,7 +2,7 @@ #include "locale.h" #include -Locale::eReturnCodes Locale::Init(const char* path, const char* def) +Locale::eReturnCodes Locale::Init(const char* path, const char* def, const char* callback) { std::string localePath = path; if (localePath.back() != '/') @@ -36,10 +36,23 @@ Locale::eReturnCodes Locale::Init(const char* path, const char* def) { if (entry.path().extension() == ".json") { + std::string fileName = entry.path().stem().string(); #ifdef _GTA_ - gLog << "Found locale: " << entry.path().stem().string() << std::endl; + gLog << "Found locale: " << fileName << std::endl; #endif - m_locales.push_back(entry.path().stem().string()); + m_locales.push_back(fileName); + + if (!strcmp(callback, fileName.c_str())) + { + std::string localePath = m_path + fileName + ".json"; + + if(m_pCallbackJson) + { + delete m_pCallbackJson; + m_pCallbackJson = nullptr; + } + m_pCallbackJson = new CJson(localePath.c_str(), true); + } } } diff --git a/src/locale.h b/src/locale.h index 64b7e87..38454b7 100644 --- a/src/locale.h +++ b/src/locale.h @@ -14,6 +14,7 @@ private: static inline std::vector m_locales; static inline std::string m_path; static inline CJson *m_pJson = nullptr; + static inline CJson *m_pCallbackJson = nullptr; static inline size_t localeIndex; public: @@ -35,7 +36,7 @@ public: Loads json files from the locale directory Calling it multiple times will unload previous data */ - static eReturnCodes Init(const char* path, const char* def = "English"); + static eReturnCodes Init(const char* path, const char* def = "English", const char* callback = ""); // Returns a vector of available languages static std::vector& GetLocaleList(); @@ -60,7 +61,14 @@ public: // But VS Code complains about it so.. defaultValue += "##" + key; #endif - return m_pJson->GetValueStr(key, defaultValue); + std::string rtn = m_pJson->GetValueStr(key, defaultValue); + + if (rtn == defaultValue) + { + return m_pCallbackJson->GetValueStr(key, defaultValue); + } + + return rtn; } /* diff --git a/src/version.h b/src/version.h index 5fa8921..77e77b1 100644 --- a/src/version.h +++ b/src/version.h @@ -2,5 +2,5 @@ #define MENU_NAME "Cheat Menu" #define MENU_VERSION_NUMBER "3.2" #define MENU_VERSION MENU_VERSION_NUMBER"-beta" -#define BUILD_NUMBER "20220226" +#define BUILD_NUMBER "20220304" #define MENU_TITLE MENU_NAME " v" MENU_VERSION