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);
|
||||
|
||||
// --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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
@ -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<std::tuple<const char *, const char *, const State *>> reset_options = {
|
||||
{"Revert", "Last Saved", &original_state},
|
||||
{"Reset", "Default", &default_state}
|
||||
};
|
||||
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
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user