From 1ccab9d5180a1b21d134ab6eb1ddf51c395f557b Mon Sep 17 00:00:00 2001 From: Wizzard <rich@bandaholics.cash> Date: Fri, 4 Apr 2025 17:27:31 -0400 Subject: [PATCH] Default config --- default.cfg | Bin 0 -> 64 bytes src/include/settings.h | 1 + src/menu.c | 19 +++++++++++++++++++ src/settings.c | 16 ++++++++++++++++ 4 files changed, 36 insertions(+) create mode 100644 default.cfg diff --git a/default.cfg b/default.cfg new file mode 100644 index 0000000000000000000000000000000000000000..808c7b4e2ee18feb32de223313ab00fb1f6e3847 GIT binary patch literal 64 vcmZQ(U|?Vb;#o7dIWd9(ki)RRfq_B65yXN4Mvx*fSl|F+Cj;5W#@S8)y@CbN literal 0 HcmV?d00001 diff --git a/src/include/settings.h b/src/include/settings.h index 4dab14d..7edc536 100644 --- a/src/include/settings.h +++ b/src/include/settings.h @@ -58,6 +58,7 @@ void settings_init(void); void settings_reset(void); bool settings_save_to_file(const char* filename); bool settings_load_from_file(const char* filename); +bool settings_set_as_default(void); const char* get_config_dir(void); inline void init_default_settings(void) { diff --git a/src/menu.c b/src/menu.c index 022f7b4..14b4a84 100644 --- a/src/menu.c +++ b/src/menu.c @@ -400,6 +400,16 @@ extern "C" void menu_render(void) { ImGui::Separator(); + if (ImGui::Button("Set as Default", ImVec2(120, 30))) { + if (settings_set_as_default()) { + ImGui::OpenPopup("DefaultSaved"); + } else { + ImGui::OpenPopup("ConfigError"); + } + } + + ImGui::SameLine(); + if (ImGui::Button("Delete Config", ImVec2(120, 30))) { ImGui::OpenPopup("ConfirmDelete"); } @@ -470,6 +480,15 @@ extern "C" void menu_render(void) { ImGui::EndPopup(); } + if (ImGui::BeginPopupModal("DefaultSaved", NULL, ImGuiWindowFlags_AlwaysAutoResize)) { + ImGui::Text("Current settings saved as default configuration!"); + ImGui::Text("These settings will load automatically on startup."); + if (ImGui::Button("OK", ImVec2(120, 0))) { + ImGui::CloseCurrentPopup(); + } + ImGui::EndPopup(); + } + if (ImGui::BeginPopupModal("ConfigError", NULL, ImGuiWindowFlags_AlwaysAutoResize)) { ImGui::Text("Error with configuration operation!"); ImGui::Text("Check console for details."); diff --git a/src/settings.c b/src/settings.c index 87b05dd..fc50d89 100644 --- a/src/settings.c +++ b/src/settings.c @@ -19,9 +19,21 @@ void settings_init(void) { char filepath[1024]; snprintf(filepath, sizeof(filepath), "%s/default.cfg", config_dir); + if (access(filepath, F_OK) != 0) { + char cmd[2048]; + snprintf(cmd, sizeof(cmd), "cp -f default.cfg %s/ 2>/dev/null", config_dir); + if (system(cmd) == 0) { + i_engine->Con_Printf("Copied default config from project root to %s\n", config_dir); + } else { + i_engine->Con_Printf("No default config found in project root or couldn't copy\n"); + } + } + if (access(filepath, F_OK) == 0) { i_engine->Con_Printf("Loading default configuration...\n"); settings_load_from_file("default"); + } else { + i_engine->Con_Printf("No default config found, using built-in defaults\n"); } } @@ -148,4 +160,8 @@ bool settings_load_from_file(const char* filename) { i_engine->Con_Printf("Settings loaded from %s\n", filepath); return true; +} + +bool settings_set_as_default(void) { + return settings_save_to_file("default"); } \ No newline at end of file