1
0
mirror of synced 2024-11-24 15:50:16 +01:00

fix: Language setting not defaulting to English anymore

This commit is contained in:
WerWolv 2023-10-22 17:31:53 +02:00
parent beca8033cf
commit c51db87c34
3 changed files with 14 additions and 4 deletions

View File

@ -190,7 +190,7 @@ namespace hex {
}; };
class DropDown : public Widget { class DropDown : public Widget {
public: public:
explicit DropDown(const std::vector<std::string> &items, const std::vector<nlohmann::json> &settingsValues) : m_items(items), m_settingsValues(settingsValues) { } explicit DropDown(const std::vector<std::string> &items, const std::vector<nlohmann::json> &settingsValues, const nlohmann::json &defaultItem) : m_items(items), m_settingsValues(settingsValues), m_defaultItem(defaultItem) { }
bool draw(const std::string &name) override; bool draw(const std::string &name) override;
@ -203,6 +203,8 @@ namespace hex {
private: private:
std::vector<std::string> m_items; std::vector<std::string> m_items;
std::vector<nlohmann::json> m_settingsValues; std::vector<nlohmann::json> m_settingsValues;
nlohmann::json m_defaultItem;
int m_value = 0; int m_value = 0;
}; };
class TextBox : public Widget { class TextBox : public Widget {

View File

@ -289,15 +289,22 @@ namespace hex {
void DropDown::load(const nlohmann::json &data) { void DropDown::load(const nlohmann::json &data) {
this->m_value = 0; this->m_value = 0;
int defaultItemIndex = 0;
int index = 0; int index = 0;
for (const auto &item : this->m_settingsValues) { for (const auto &item : this->m_settingsValues) {
if (item == this->m_defaultItem)
defaultItemIndex = index;
if (item == data) { if (item == data) {
this->m_value = index; this->m_value = index;
break; return;
} }
index += 1; index += 1;
} }
this->m_value = defaultItemIndex;
} }
nlohmann::json DropDown::store() { nlohmann::json DropDown::store() {

View File

@ -215,7 +215,8 @@ namespace hex::plugin::builtin {
ContentRegistry::Settings::add<Widgets::DropDown>("hex.builtin.setting.interface", "", "hex.builtin.setting.interface.color", ContentRegistry::Settings::add<Widgets::DropDown>("hex.builtin.setting.interface", "", "hex.builtin.setting.interface.color",
themeNames, themeNames,
themeJsons).setChangedCallback([](auto &widget) { themeJsons,
"Dark").setChangedCallback([](auto &widget) {
auto dropDown = static_cast<Widgets::DropDown *>(&widget); auto dropDown = static_cast<Widgets::DropDown *>(&widget);
if (dropDown->getValue() == ThemeManager::NativeTheme) if (dropDown->getValue() == ThemeManager::NativeTheme)
@ -236,7 +237,7 @@ namespace hex::plugin::builtin {
languageCodes.emplace_back(languageCode); languageCodes.emplace_back(languageCode);
} }
ContentRegistry::Settings::add<Widgets::DropDown>("hex.builtin.setting.interface", "", "hex.builtin.setting.interface.language", languageNames, languageCodes); ContentRegistry::Settings::add<Widgets::DropDown>("hex.builtin.setting.interface", "", "hex.builtin.setting.interface.language", languageNames, languageCodes, LangEntry::getFallbackLanguage());
ContentRegistry::Settings::add<Widgets::TextBox>("hex.builtin.setting.interface", "", "hex.builtin.setting.interface.wiki_explain_language", "en"); ContentRegistry::Settings::add<Widgets::TextBox>("hex.builtin.setting.interface", "", "hex.builtin.setting.interface.wiki_explain_language", "en");
ContentRegistry::Settings::add<FPSWidget>("hex.builtin.setting.interface", "", "hex.builtin.setting.interface.fps"); ContentRegistry::Settings::add<FPSWidget>("hex.builtin.setting.interface", "", "hex.builtin.setting.interface.fps");