From c51db87c3427a63bfbbd98a323a43d52fcaf2fbd Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sun, 22 Oct 2023 17:31:53 +0200 Subject: [PATCH] fix: Language setting not defaulting to English anymore --- lib/libimhex/include/hex/api/content_registry.hpp | 4 +++- lib/libimhex/source/api/content_registry.cpp | 9 ++++++++- plugins/builtin/source/content/settings_entries.cpp | 5 +++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/libimhex/include/hex/api/content_registry.hpp b/lib/libimhex/include/hex/api/content_registry.hpp index e7530f799..aa5e771ac 100644 --- a/lib/libimhex/include/hex/api/content_registry.hpp +++ b/lib/libimhex/include/hex/api/content_registry.hpp @@ -190,7 +190,7 @@ namespace hex { }; class DropDown : public Widget { public: - explicit DropDown(const std::vector &items, const std::vector &settingsValues) : m_items(items), m_settingsValues(settingsValues) { } + explicit DropDown(const std::vector &items, const std::vector &settingsValues, const nlohmann::json &defaultItem) : m_items(items), m_settingsValues(settingsValues), m_defaultItem(defaultItem) { } bool draw(const std::string &name) override; @@ -203,6 +203,8 @@ namespace hex { private: std::vector m_items; std::vector m_settingsValues; + nlohmann::json m_defaultItem; + int m_value = 0; }; class TextBox : public Widget { diff --git a/lib/libimhex/source/api/content_registry.cpp b/lib/libimhex/source/api/content_registry.cpp index 4982b4d76..1662797b0 100644 --- a/lib/libimhex/source/api/content_registry.cpp +++ b/lib/libimhex/source/api/content_registry.cpp @@ -289,15 +289,22 @@ namespace hex { void DropDown::load(const nlohmann::json &data) { this->m_value = 0; + int defaultItemIndex = 0; + int index = 0; for (const auto &item : this->m_settingsValues) { + if (item == this->m_defaultItem) + defaultItemIndex = index; + if (item == data) { this->m_value = index; - break; + return; } index += 1; } + + this->m_value = defaultItemIndex; } nlohmann::json DropDown::store() { diff --git a/plugins/builtin/source/content/settings_entries.cpp b/plugins/builtin/source/content/settings_entries.cpp index d41781d55..55bca9da1 100644 --- a/plugins/builtin/source/content/settings_entries.cpp +++ b/plugins/builtin/source/content/settings_entries.cpp @@ -215,7 +215,8 @@ namespace hex::plugin::builtin { ContentRegistry::Settings::add("hex.builtin.setting.interface", "", "hex.builtin.setting.interface.color", themeNames, - themeJsons).setChangedCallback([](auto &widget) { + themeJsons, + "Dark").setChangedCallback([](auto &widget) { auto dropDown = static_cast(&widget); if (dropDown->getValue() == ThemeManager::NativeTheme) @@ -236,7 +237,7 @@ namespace hex::plugin::builtin { languageCodes.emplace_back(languageCode); } - ContentRegistry::Settings::add("hex.builtin.setting.interface", "", "hex.builtin.setting.interface.language", languageNames, languageCodes); + ContentRegistry::Settings::add("hex.builtin.setting.interface", "", "hex.builtin.setting.interface.language", languageNames, languageCodes, LangEntry::getFallbackLanguage()); ContentRegistry::Settings::add("hex.builtin.setting.interface", "", "hex.builtin.setting.interface.wiki_explain_language", "en"); ContentRegistry::Settings::add("hex.builtin.setting.interface", "", "hex.builtin.setting.interface.fps");