From d4bcd7062985cdc4fe6af2f176b20420135922f9 Mon Sep 17 00:00:00 2001 From: Andreas Maerten <24669514+Yimura@users.noreply.github.com> Date: Tue, 27 Jun 2023 20:24:08 +0200 Subject: [PATCH] Fix settings::write_default_config & added reset all settings button (#1547) * fix(settings): correctly write default settings * feat(Settings): Added button to reset all settings * fix(Settings): Use SeparatorText for subtitle --- src/core/globals.cpp | 19 +++++++++---------- src/core/globals.hpp | 2 +- src/views/settings/view_settings.cpp | 8 +++++++- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/core/globals.cpp b/src/core/globals.cpp index aadbeace..c03130af 100644 --- a/src/core/globals.cpp +++ b/src/core/globals.cpp @@ -83,6 +83,15 @@ namespace big return true; } + bool menu_settings::write_default_config() + { + std::ofstream file(m_save_file->get_path(), std::ios::out | std::ios::trunc); + file << m_default_options.dump(4); + file.close(); + + return true; + } + bool menu_settings::deep_compare(nlohmann::json& current_settings, const nlohmann::json& default_settings, bool compare_value) { bool should_save = false; @@ -122,14 +131,4 @@ namespace big return true; } - - bool menu_settings::write_default_config() - { - std::ofstream file(m_save_file->get_path(), std::ios::out | std::ios::trunc); - nlohmann::json j = *this; - file << j.dump(4); - file.close(); - - return true; - } } \ No newline at end of file diff --git a/src/core/globals.hpp b/src/core/globals.hpp index 5f3f1b72..3cc21732 100644 --- a/src/core/globals.hpp +++ b/src/core/globals.hpp @@ -49,11 +49,11 @@ namespace big void attempt_save(); bool load(); + bool write_default_config(); private: bool deep_compare(nlohmann::json& current_settings, const nlohmann::json& default_settings, bool compare_value = false); bool save(); - bool write_default_config(); private: bool m_running; diff --git a/src/views/settings/view_settings.cpp b/src/views/settings/view_settings.cpp index e7a3026a..eb3ba3f4 100644 --- a/src/views/settings/view_settings.cpp +++ b/src/views/settings/view_settings.cpp @@ -4,7 +4,13 @@ namespace big { void view::settings() { - components::sub_title("SETTINGS_MISC"_T); + ImGui::SeparatorText("SETTINGS_MISC"_T.data()); ImGui::Checkbox("SETTINGS_MISC_DEV_DLC"_T.data(), &g.settings.dev_dlc); + + if (ImGui::Button("Reset Settings")) + { + g.write_default_config(); + g.load(); + } } } \ No newline at end of file