From 900169a728b20deb37227ef0230041fa5056c53a Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Thu, 21 Nov 2024 16:16:53 -0500 Subject: [PATCH] Add "Revert" Button --- launcher/src/client/configuration.cpp | 5 +++-- launcher/src/client/configuration.h | 6 ++++-- launcher/src/client/ui.cpp | 29 ++++++++++++++++++--------- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/launcher/src/client/configuration.cpp b/launcher/src/client/configuration.cpp index ad197da74f..1cb254fa1d 100644 --- a/launcher/src/client/configuration.cpp +++ b/launcher/src/client/configuration.cpp @@ -64,9 +64,10 @@ void configure_client(const options_t &options) { state.update(false); // --default + bool save_settings = !options.no_cache; if (!options.use_default) { // Show UI - ConfigurationUI *ui = new ConfigurationUI(state); + ConfigurationUI *ui = new ConfigurationUI(state, save_settings); const int ret = ui->run(); delete ui; if (ret <= 0) { @@ -75,7 +76,7 @@ void configure_client(const options_t &options) { } // Save Cache - if (!options.no_cache) { + if (save_settings) { save_cache(state); } diff --git a/launcher/src/client/configuration.h b/launcher/src/client/configuration.h index 6c697d58b9..0eff011b6a 100644 --- a/launcher/src/client/configuration.h +++ b/launcher/src/client/configuration.h @@ -25,7 +25,7 @@ struct State { // UI struct ConfigurationUI final : Frame { - explicit ConfigurationUI(State &state_); + explicit ConfigurationUI(State &state_, bool &save_settings_); int render() override; private: void update_render_distance(); @@ -33,8 +33,10 @@ private: void draw_main(); void draw_advanced() const; static void draw_category(FlagNode &category); - const State empty_state; + const State default_state; + const State original_state; State &state; + bool &save_settings; int render_distance_index; }; diff --git a/launcher/src/client/ui.cpp b/launcher/src/client/ui.cpp index 382e95d168..83cff49720 100644 --- a/launcher/src/client/ui.cpp +++ b/launcher/src/client/ui.cpp @@ -15,10 +15,12 @@ static std::vector render_distances = { // Construct static constexpr int size = 400; -ConfigurationUI::ConfigurationUI(State &state_): +ConfigurationUI::ConfigurationUI(State &state_, bool &save_settings_): Frame("Launcher", size, size), - empty_state(empty_cache), - state(state_) { + default_state(empty_cache), + original_state(state_), + state(state_), + save_settings(save_settings_) { update_render_distance(); } void ConfigurationUI::update_render_distance() { @@ -57,13 +59,21 @@ int ConfigurationUI::render() { // Bottom Row int ConfigurationUI::draw_bottom() { // Reset All Settings - ImGui::BeginDisabled(state == empty_state); - if (ImGui::Button("Reset To Defaults")) { - state = empty_state; - update_render_distance(); + std::vector> reset_options = { + {"Revert", "Last Saved", &original_state}, + {"Reset", "Default", &default_state} + }; + for (const std::tuple &option : reset_options) { + const State &new_state = *std::get<2>(option); + ImGui::BeginDisabled(state == new_state); + if (ImGui::Button(std::get<0>(option))) { + state = new_state; + update_render_distance(); + } + ImGui::SetItemTooltip("Use %s Settings", std::get<1>(option)); + ImGui::EndDisabled(); + ImGui::SameLine(); } - ImGui::EndDisabled(); - ImGui::SameLine(); // Right-Align Buttons const ImGuiStyle &style = ImGui::GetStyle(); const char *bottom_row_text[] = {"Quit", "Launch"}; @@ -104,6 +114,7 @@ void ConfigurationUI::draw_main() { ImGui::Combo(labels[1], &render_distance_index, render_distances.data(), int(render_distances.size())); state.render_distance = render_distances[render_distance_index]; ImGui::PopItemWidth(); + ImGui::Checkbox("Save Settings On Launch", &save_settings); } // Advanced Tab