This commit is contained in:
TheBrokenRail 2024-11-21 14:47:48 -05:00
parent 86e8c0dd67
commit 633b165af0
4 changed files with 43 additions and 12 deletions

View File

@ -33,8 +33,11 @@ void State::update(const bool save) {
update_from_env(MCPI_USERNAME_ENV, username, save); update_from_env(MCPI_USERNAME_ENV, username, save);
update_from_env(MCPI_RENDER_DISTANCE_ENV, render_distance, save); update_from_env(MCPI_RENDER_DISTANCE_ENV, render_distance, save);
} }
bool State::operator==(const State &other) const {
#define DIALOG_TITLE "Launcher" #define test(x) static_cast<std::string>(x) == static_cast<std::string>(other.x)
return test(username) && test(render_distance) && test(flags);
#undef test
}
// Handle Non-Launch Commands // Handle Non-Launch Commands
void handle_non_launch_client_only_commands(const options_t &options) { void handle_non_launch_client_only_commands(const options_t &options) {

View File

@ -16,6 +16,7 @@ struct State {
explicit State(const launcher_cache &cache); explicit State(const launcher_cache &cache);
// Methods // Methods
void update(bool save); void update(bool save);
bool operator==(const State &other) const;
// Properties // Properties
std::string username; std::string username;
std::string render_distance; std::string render_distance;
@ -27,9 +28,12 @@ struct ConfigurationUI final : Frame {
explicit ConfigurationUI(State &state_); explicit ConfigurationUI(State &state_);
int render() override; int render() override;
private: private:
void update_render_distance();
int draw_bottom();
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;
State &state; State &state;
int render_distance_index; int render_distance_index;
}; };

View File

@ -51,6 +51,16 @@ Flags::Flags(const std::string &data) {
} }
// Sort // Sort
root.sort(); root.sort();
// Check For Duplicates
std::unordered_set<std::string> 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 { Flags::operator std::string() const {
std::string out; std::string out;

View File

@ -17,7 +17,11 @@ static std::vector render_distances = {
static constexpr int size = 400; static constexpr int size = 400;
ConfigurationUI::ConfigurationUI(State &state_): ConfigurationUI::ConfigurationUI(State &state_):
Frame("Launcher", size, size), Frame("Launcher", size, size),
empty_state(empty_cache),
state(state_) { state(state_) {
update_render_distance();
}
void ConfigurationUI::update_render_distance() {
render_distance_index = 0; render_distance_index = 0;
for (std::vector<std::string>::size_type i = 0; i < render_distances.size(); i++) { for (std::vector<std::string>::size_type i = 0; i < render_distances.size(); i++) {
if (std::string(render_distances[i]) == state.render_distance) { if (std::string(render_distances[i]) == state.render_distance) {
@ -29,17 +33,16 @@ ConfigurationUI::ConfigurationUI(State &state_):
// Render // Render
int ConfigurationUI::render() { int ConfigurationUI::render() {
const ImGuiStyle &style = ImGui::GetStyle(); if (ImGui::BeginChild("Main", ImVec2(0, -ImGui::GetFrameHeightWithSpacing() /* Leave Room For Bottom Row */), ImGuiChildFlags_None, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) {
if (ImGui::BeginChild("General", ImVec2(0, -ImGui::GetFrameHeightWithSpacing() /* Leave Room For One Line */), ImGuiChildFlags_None, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) {
// Tabs // Tabs
if (ImGui::BeginTabBar("tab_bar", ImGuiTabBarFlags_None)) { if (ImGui::BeginTabBar("TabBar")) {
if (ImGui::BeginTabItem("General", nullptr, ImGuiTabItemFlags_None)) {
// Main Tab // Main Tab
if (ImGui::BeginTabItem("General")) {
draw_main(); draw_main();
ImGui::EndTabItem(); ImGui::EndTabItem();
} }
if (ImGui::BeginTabItem("Advanced", nullptr, ImGuiTabItemFlags_None)) {
// Advanced Tab // Advanced Tab
if (ImGui::BeginTabItem("Advanced")) {
draw_advanced(); draw_advanced();
ImGui::EndTabItem(); ImGui::EndTabItem();
} }
@ -48,11 +51,21 @@ int ConfigurationUI::render() {
} }
ImGui::EndChild(); ImGui::EndChild();
// Bottom Row // Bottom Row
if (ImGui::Button("Reset To Defaults")) { return draw_bottom();
state = State(empty_cache);
} }
// 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();
}
ImGui::EndDisabled();
ImGui::SameLine(); ImGui::SameLine();
// Right-Align Buttons // Right-Align Buttons
const ImGuiStyle &style = ImGui::GetStyle();
const char *bottom_row_text[] = {"Quit", "Launch"}; const char *bottom_row_text[] = {"Quit", "Launch"};
float width_needed = 0; float width_needed = 0;
for (const char *text : bottom_row_text) { 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; width_needed += ImGui::CalcTextSize(text).x + style.FramePadding.x * 2.f;
} }
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - width_needed); ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - width_needed);
if (ImGui::Button(bottom_row_text[0])) {
// Quit // Quit
if (ImGui::Button(bottom_row_text[0])) {
return -1; return -1;
} }
ImGui::SetItemTooltip("Changes Will Not Be Saved!");
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button(bottom_row_text[1])) {
// Launch // Launch
if (ImGui::Button(bottom_row_text[1])) {
return 1; return 1;
} }
// Return // Return