Add "Revert" Button
This commit is contained in:
parent
633b165af0
commit
900169a728
@ -64,9 +64,10 @@ void configure_client(const options_t &options) {
|
|||||||
state.update(false);
|
state.update(false);
|
||||||
|
|
||||||
// --default
|
// --default
|
||||||
|
bool save_settings = !options.no_cache;
|
||||||
if (!options.use_default) {
|
if (!options.use_default) {
|
||||||
// Show UI
|
// Show UI
|
||||||
ConfigurationUI *ui = new ConfigurationUI(state);
|
ConfigurationUI *ui = new ConfigurationUI(state, save_settings);
|
||||||
const int ret = ui->run();
|
const int ret = ui->run();
|
||||||
delete ui;
|
delete ui;
|
||||||
if (ret <= 0) {
|
if (ret <= 0) {
|
||||||
@ -75,7 +76,7 @@ void configure_client(const options_t &options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Save Cache
|
// Save Cache
|
||||||
if (!options.no_cache) {
|
if (save_settings) {
|
||||||
save_cache(state);
|
save_cache(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ struct State {
|
|||||||
|
|
||||||
// UI
|
// UI
|
||||||
struct ConfigurationUI final : Frame {
|
struct ConfigurationUI final : Frame {
|
||||||
explicit ConfigurationUI(State &state_);
|
explicit ConfigurationUI(State &state_, bool &save_settings_);
|
||||||
int render() override;
|
int render() override;
|
||||||
private:
|
private:
|
||||||
void update_render_distance();
|
void update_render_distance();
|
||||||
@ -33,8 +33,10 @@ private:
|
|||||||
void draw_main();
|
void draw_main();
|
||||||
void draw_advanced() const;
|
void draw_advanced() const;
|
||||||
static void draw_category(FlagNode &category);
|
static void draw_category(FlagNode &category);
|
||||||
const State empty_state;
|
const State default_state;
|
||||||
|
const State original_state;
|
||||||
State &state;
|
State &state;
|
||||||
|
bool &save_settings;
|
||||||
int render_distance_index;
|
int render_distance_index;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -15,10 +15,12 @@ static std::vector render_distances = {
|
|||||||
|
|
||||||
// Construct
|
// Construct
|
||||||
static constexpr int size = 400;
|
static constexpr int size = 400;
|
||||||
ConfigurationUI::ConfigurationUI(State &state_):
|
ConfigurationUI::ConfigurationUI(State &state_, bool &save_settings_):
|
||||||
Frame("Launcher", size, size),
|
Frame("Launcher", size, size),
|
||||||
empty_state(empty_cache),
|
default_state(empty_cache),
|
||||||
state(state_) {
|
original_state(state_),
|
||||||
|
state(state_),
|
||||||
|
save_settings(save_settings_) {
|
||||||
update_render_distance();
|
update_render_distance();
|
||||||
}
|
}
|
||||||
void ConfigurationUI::update_render_distance() {
|
void ConfigurationUI::update_render_distance() {
|
||||||
@ -57,13 +59,21 @@ int ConfigurationUI::render() {
|
|||||||
// Bottom Row
|
// Bottom Row
|
||||||
int ConfigurationUI::draw_bottom() {
|
int ConfigurationUI::draw_bottom() {
|
||||||
// Reset All Settings
|
// Reset All Settings
|
||||||
ImGui::BeginDisabled(state == empty_state);
|
std::vector<std::tuple<const char *, const char *, const State *>> reset_options = {
|
||||||
if (ImGui::Button("Reset To Defaults")) {
|
{"Revert", "Last Saved", &original_state},
|
||||||
state = empty_state;
|
{"Reset", "Default", &default_state}
|
||||||
update_render_distance();
|
};
|
||||||
|
for (const std::tuple<const char *, const char *, const State *> &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
|
// Right-Align Buttons
|
||||||
const ImGuiStyle &style = ImGui::GetStyle();
|
const ImGuiStyle &style = ImGui::GetStyle();
|
||||||
const char *bottom_row_text[] = {"Quit", "Launch"};
|
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()));
|
ImGui::Combo(labels[1], &render_distance_index, render_distances.data(), int(render_distances.size()));
|
||||||
state.render_distance = render_distances[render_distance_index];
|
state.render_distance = render_distances[render_distance_index];
|
||||||
ImGui::PopItemWidth();
|
ImGui::PopItemWidth();
|
||||||
|
ImGui::Checkbox("Save Settings On Launch", &save_settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Advanced Tab
|
// Advanced Tab
|
||||||
|
Loading…
Reference in New Issue
Block a user