1
0
mirror of synced 2025-01-30 03:27:25 +01:00

sys: Fixed settings not initializing correctly

This commit is contained in:
WerWolv 2021-09-12 13:59:23 +02:00
parent 86096708da
commit 987840e480
4 changed files with 17 additions and 7 deletions

View File

@ -15,7 +15,7 @@ namespace hex::plugin::builtin {
/* General */ /* General */
ContentRegistry::Settings::add("hex.builtin.setting.general", "hex.builtin.setting.general.show_tips", 1, [](auto name, nlohmann::json &setting) { ContentRegistry::Settings::add("hex.builtin.setting.general", "hex.builtin.setting.general.show_tips", 1, [](auto name, nlohmann::json &setting) {
static bool enabled = setting.is_number() ? static_cast<int>(setting) : 1; static bool enabled = static_cast<int>(setting);
if (ImGui::Checkbox(name.data(), &enabled)) { if (ImGui::Checkbox(name.data(), &enabled)) {
setting = static_cast<int>(enabled); setting = static_cast<int>(enabled);
@ -28,7 +28,7 @@ namespace hex::plugin::builtin {
/* Interface */ /* Interface */
ContentRegistry::Settings::add("hex.builtin.setting.interface", "hex.builtin.setting.interface.color", 0, [](auto name, nlohmann::json &setting) { ContentRegistry::Settings::add("hex.builtin.setting.interface", "hex.builtin.setting.interface.color", 0, [](auto name, nlohmann::json &setting) {
static int selection = setting.is_number() ? static_cast<int>(setting) : 0; static int selection = static_cast<int>(setting);
const char* themes[] = { const char* themes[] = {
"hex.builtin.setting.interface.color.dark"_lang, "hex.builtin.setting.interface.color.dark"_lang,
@ -45,7 +45,7 @@ namespace hex::plugin::builtin {
}); });
ContentRegistry::Settings::add("hex.builtin.setting.interface", "hex.builtin.setting.interface.scaling", 0, [](auto name, nlohmann::json &setting) { ContentRegistry::Settings::add("hex.builtin.setting.interface", "hex.builtin.setting.interface.scaling", 0, [](auto name, nlohmann::json &setting) {
static int selection = setting.is_number() ? static_cast<int>(setting) : 0; static int selection = static_cast<int>(setting);
const char* scaling[] = { const char* scaling[] = {
"hex.builtin.setting.interface.scaling.native"_lang, "hex.builtin.setting.interface.scaling.native"_lang,
@ -81,7 +81,7 @@ namespace hex::plugin::builtin {
}(); }();
static auto languageNames = [&]() { static auto languageNames = [&]() {
std::vector<const char*> result; std::vector<const char*> result(languages.size());
for (auto &[languageCode, languageName] : languages) for (auto &[languageCode, languageName] : languages)
result.push_back(languageName.c_str()); result.push_back(languageName.c_str());
@ -107,7 +107,7 @@ namespace hex::plugin::builtin {
}); });
ContentRegistry::Settings::add("hex.builtin.setting.interface", "hex.builtin.setting.interface.fps", 60, [](auto name, nlohmann::json &setting) { ContentRegistry::Settings::add("hex.builtin.setting.interface", "hex.builtin.setting.interface.fps", 60, [](auto name, nlohmann::json &setting) {
static int fps = setting.is_number() ? static_cast<int>(setting) : 60; static int fps = static_cast<int>(setting);
if (ImGui::SliderInt(name.data(), &fps, 15, 60)) { if (ImGui::SliderInt(name.data(), &fps, 15, 60)) {
setting = fps; setting = fps;
@ -118,7 +118,7 @@ namespace hex::plugin::builtin {
}); });
ContentRegistry::Settings::add("hex.builtin.setting.interface", "hex.builtin.setting.interface.highlight_alpha", 0x80, [](auto name, nlohmann::json &setting) { ContentRegistry::Settings::add("hex.builtin.setting.interface", "hex.builtin.setting.interface.highlight_alpha", 0x80, [](auto name, nlohmann::json &setting) {
static int alpha = setting.is_number() ? static_cast<int>(setting) : 0x80; static int alpha = static_cast<int>(setting);
if (ImGui::SliderInt(name.data(), &alpha, 0x00, 0xFF)) { if (ImGui::SliderInt(name.data(), &alpha, 0x00, 0xFF)) {
setting = alpha; setting = alpha;

View File

@ -97,6 +97,9 @@ namespace hex {
if (!json[unlocalizedCategory].contains(unlocalizedName)) if (!json[unlocalizedCategory].contains(unlocalizedName))
return defaultValue; return defaultValue;
if (!json[unlocalizedCategory][unlocalizedName].is_number())
json[unlocalizedCategory][unlocalizedName] = defaultValue;
return json[unlocalizedCategory][unlocalizedName].get<s64>(); return json[unlocalizedCategory][unlocalizedName].get<s64>();
} }
@ -108,6 +111,9 @@ namespace hex {
if (!json[unlocalizedCategory].contains(unlocalizedName)) if (!json[unlocalizedCategory].contains(unlocalizedName))
return defaultValue; return defaultValue;
if (!json[unlocalizedCategory][unlocalizedName].is_string())
json[unlocalizedCategory][unlocalizedName] = defaultValue;
return json[unlocalizedCategory][unlocalizedName].get<std::string>(); return json[unlocalizedCategory][unlocalizedName].get<std::string>();
} }
@ -119,6 +125,9 @@ namespace hex {
if (!json[unlocalizedCategory].contains(unlocalizedName)) if (!json[unlocalizedCategory].contains(unlocalizedName))
return defaultValue; return defaultValue;
if (!json[unlocalizedCategory][unlocalizedName].is_number())
json[unlocalizedCategory][unlocalizedName] = defaultValue;
return json[unlocalizedCategory][unlocalizedName].get<std::vector<std::string>>(); return json[unlocalizedCategory][unlocalizedName].get<std::vector<std::string>>();
} }

View File

@ -304,8 +304,8 @@ namespace hex::init {
{ "Downloading information...", downloadInformation }, { "Downloading information...", downloadInformation },
{ "Creating directories...", createDirectories }, { "Creating directories...", createDirectories },
{ "Loading default views...", loadDefaultViews }, { "Loading default views...", loadDefaultViews },
{ "Loading plugins...", loadPlugins },
{ "Loading settings...", loadSettings }, { "Loading settings...", loadSettings },
{ "Loading plugins...", loadPlugins },
{ "Loading fonts...", loadFonts }, { "Loading fonts...", loadFonts },
}; };
} }

View File

@ -248,6 +248,7 @@ namespace hex {
this->m_logoTexture = ImGui::LoadImageFromMemory(imhex_logo, imhex_logo_size); this->m_logoTexture = ImGui::LoadImageFromMemory(imhex_logo, imhex_logo_size);
ContentRegistry::Settings::store();
EventManager::post<EventSettingsChanged>(); EventManager::post<EventSettingsChanged>();
} }