From 633b165af0092436aa68e71dbaedaf1e322be0d0 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Thu, 21 Nov 2024 14:47:48 -0500 Subject: [PATCH] Tweak UI --- launcher/src/client/configuration.cpp | 7 ++++-- launcher/src/client/configuration.h | 4 ++++ launcher/src/client/flags/flags.cpp | 10 ++++++++ launcher/src/client/ui.cpp | 34 +++++++++++++++++++-------- 4 files changed, 43 insertions(+), 12 deletions(-) diff --git a/launcher/src/client/configuration.cpp b/launcher/src/client/configuration.cpp index c94bd8bfee..ad197da74f 100644 --- a/launcher/src/client/configuration.cpp +++ b/launcher/src/client/configuration.cpp @@ -33,8 +33,11 @@ void State::update(const bool save) { update_from_env(MCPI_USERNAME_ENV, username, save); update_from_env(MCPI_RENDER_DISTANCE_ENV, render_distance, save); } - -#define DIALOG_TITLE "Launcher" +bool State::operator==(const State &other) const { +#define test(x) static_cast(x) == static_cast(other.x) + return test(username) && test(render_distance) && test(flags); +#undef test +} // Handle Non-Launch Commands void handle_non_launch_client_only_commands(const options_t &options) { diff --git a/launcher/src/client/configuration.h b/launcher/src/client/configuration.h index d856813218..6c697d58b9 100644 --- a/launcher/src/client/configuration.h +++ b/launcher/src/client/configuration.h @@ -16,6 +16,7 @@ struct State { explicit State(const launcher_cache &cache); // Methods void update(bool save); + bool operator==(const State &other) const; // Properties std::string username; std::string render_distance; @@ -27,9 +28,12 @@ struct ConfigurationUI final : Frame { explicit ConfigurationUI(State &state_); int render() override; private: + void update_render_distance(); + int draw_bottom(); void draw_main(); void draw_advanced() const; static void draw_category(FlagNode &category); + const State empty_state; State &state; int render_distance_index; }; diff --git a/launcher/src/client/flags/flags.cpp b/launcher/src/client/flags/flags.cpp index e471471559..fd7b7de860 100644 --- a/launcher/src/client/flags/flags.cpp +++ b/launcher/src/client/flags/flags.cpp @@ -51,6 +51,16 @@ Flags::Flags(const std::string &data) { } // Sort root.sort(); + // Check For Duplicates + std::unordered_set seen; + root.for_each_const([&seen](const FlagNode &node) { + const std::string &name = node.name; + if (seen.contains(name)) { + ERR("Duplicate Feature Flag: %s", name.c_str()); + } else { + seen.insert(name); + } + }); } Flags::operator std::string() const { std::string out; diff --git a/launcher/src/client/ui.cpp b/launcher/src/client/ui.cpp index 7cc6e42527..382e95d168 100644 --- a/launcher/src/client/ui.cpp +++ b/launcher/src/client/ui.cpp @@ -17,7 +17,11 @@ static std::vector render_distances = { static constexpr int size = 400; ConfigurationUI::ConfigurationUI(State &state_): Frame("Launcher", size, size), + empty_state(empty_cache), state(state_) { + update_render_distance(); +} +void ConfigurationUI::update_render_distance() { render_distance_index = 0; for (std::vector::size_type i = 0; i < render_distances.size(); i++) { if (std::string(render_distances[i]) == state.render_distance) { @@ -29,17 +33,16 @@ ConfigurationUI::ConfigurationUI(State &state_): // Render int ConfigurationUI::render() { - const ImGuiStyle &style = ImGui::GetStyle(); - if (ImGui::BeginChild("General", ImVec2(0, -ImGui::GetFrameHeightWithSpacing() /* Leave Room For One Line */), ImGuiChildFlags_None, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) { + if (ImGui::BeginChild("Main", ImVec2(0, -ImGui::GetFrameHeightWithSpacing() /* Leave Room For Bottom Row */), ImGuiChildFlags_None, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) { // Tabs - if (ImGui::BeginTabBar("tab_bar", ImGuiTabBarFlags_None)) { - if (ImGui::BeginTabItem("General", nullptr, ImGuiTabItemFlags_None)) { - // Main Tab + if (ImGui::BeginTabBar("TabBar")) { + // Main Tab + if (ImGui::BeginTabItem("General")) { draw_main(); ImGui::EndTabItem(); } - if (ImGui::BeginTabItem("Advanced", nullptr, ImGuiTabItemFlags_None)) { - // Advanced Tab + // Advanced Tab + if (ImGui::BeginTabItem("Advanced")) { draw_advanced(); ImGui::EndTabItem(); } @@ -48,11 +51,21 @@ int ConfigurationUI::render() { } ImGui::EndChild(); // Bottom Row + return draw_bottom(); +} + +// Bottom Row +int ConfigurationUI::draw_bottom() { + // Reset All Settings + ImGui::BeginDisabled(state == empty_state); if (ImGui::Button("Reset To Defaults")) { - state = State(empty_cache); + state = empty_state; + update_render_distance(); } + ImGui::EndDisabled(); ImGui::SameLine(); // Right-Align Buttons + const ImGuiStyle &style = ImGui::GetStyle(); const char *bottom_row_text[] = {"Quit", "Launch"}; float width_needed = 0; for (const char *text : bottom_row_text) { @@ -62,13 +75,14 @@ int ConfigurationUI::render() { width_needed += ImGui::CalcTextSize(text).x + style.FramePadding.x * 2.f; } ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - width_needed); + // Quit if (ImGui::Button(bottom_row_text[0])) { - // Quit return -1; } + ImGui::SetItemTooltip("Changes Will Not Be Saved!"); ImGui::SameLine(); + // Launch if (ImGui::Button(bottom_row_text[1])) { - // Launch return 1; } // Return