diff --git a/default.cfg b/default.cfg new file mode 100644 index 0000000..808c7b4 Binary files /dev/null and b/default.cfg differ 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