From 445d7323b35a05ddcf1b45e65c584ce2f9a028ae Mon Sep 17 00:00:00 2001 From: William JCM Date: Fri, 23 Jul 2021 14:17:42 +0200 Subject: [PATCH] SaveTool: add configuration system. --- src/SaveTool/SaveTool.cpp | 24 ++++++++++++++++++ src/SaveTool/SaveTool.h | 4 +++ src/SaveTool/SaveTool_MainManager.cpp | 34 ++++++++------------------ src/SaveTool/SaveTool_drawMainMenu.cpp | 13 ++++++++-- 4 files changed, 49 insertions(+), 26 deletions(-) diff --git a/src/SaveTool/SaveTool.cpp b/src/SaveTool/SaveTool.cpp index eaf9b1a..d4e2ec9 100644 --- a/src/SaveTool/SaveTool.cpp +++ b/src/SaveTool/SaveTool.cpp @@ -131,10 +131,16 @@ SaveTool::SaveTool(const Arguments& arguments): exit(EXIT_FAILURE); return; } + + initialiseConfiguration(); } SaveTool::~SaveTool() { SDL_RemoveTimer(_gameCheckTimerId); + + _conf.setValue("unsafe_mode", _unsafeMode); + _conf.setValue("startup_update_check", _checkUpdatesOnStartup); + _conf.save(); } void SaveTool::handleFileAction(efsw::WatchID watch_id, @@ -283,6 +289,24 @@ void SaveTool::updateCheckEvent(SDL_Event& event) { // TODO: implement } +void SaveTool::initialiseConfiguration() { + if(_conf.hasValue("unsafe_mode")) { + _unsafeMode = _conf.value("unsafe_mode"); + } + else { + _conf.setValue("unsafe_mode", _unsafeMode); + } + + if(_conf.hasValue("startup_update_check")) { + _checkUpdatesOnStartup = _conf.value("startup_update_check"); + } + else { + _conf.setValue("startup_update_check", _checkUpdatesOnStartup); + } + + _conf.save(); +} + void SaveTool::initialiseGui() { ImGui::CreateContext(); diff --git a/src/SaveTool/SaveTool.h b/src/SaveTool/SaveTool.h index e786b0b..24a63c2 100644 --- a/src/SaveTool/SaveTool.h +++ b/src/SaveTool/SaveTool.h @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -73,6 +74,7 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener void updateCheckEvent(SDL_Event& event); // Initialisation methods + void initialiseConfiguration(); void initialiseGui(); void initialiseManager(); auto findGameDataDirectory() -> bool; @@ -139,6 +141,7 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener void checkForUpdates(); + Utility::Configuration _conf{"MassBuilderSaveTool.ini"}; Utility::Resource _rs{"assets"}; // GUI-related members @@ -191,5 +194,6 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener }; Containers::StaticArray<2, efsw::WatchID> _watchIDs; + bool _checkUpdatesOnStartup{true}; bool _unsafeMode{false}; }; diff --git a/src/SaveTool/SaveTool_MainManager.cpp b/src/SaveTool/SaveTool_MainManager.cpp index 2c44f93..36a19f9 100644 --- a/src/SaveTool/SaveTool_MainManager.cpp +++ b/src/SaveTool/SaveTool_MainManager.cpp @@ -42,30 +42,16 @@ void SaveTool::drawManager() { return; } - if(ImGui::BeginTable("##TopRow", 2)) { - ImGui::TableSetupColumn("##ProfileInfo", ImGuiTableColumnFlags_WidthStretch); - ImGui::TableSetupColumn("##Unsafe", ImGuiTableColumnFlags_WidthFixed); - - ImGui::TableNextRow(); - ImGui::TableSetColumnIndex(0); - ImGui::AlignTextToFramePadding(); - ImGui::Text("Current profile: %s (%s)", - _currentProfile->companyName().c_str(), - _currentProfile->type() == ProfileType::Demo ? "demo" : "full game"); - ImGui::SameLine(); - if(ImGui::Button("Close")) { - _currentProfile = nullptr; - _massManager.reset(); - _fileWatcher.reset(); - _uiState = UiState::ProfileManager; - } - - ImGui::TableSetColumnIndex(1); - ImGui::Checkbox("Unsafe mode", &_unsafeMode); - drawTooltip("Enabling this allows interactions deemed to be unsafe to do while the game is running.", - Float(windowSize().x()) * 0.35f); - - ImGui::EndTable(); + ImGui::AlignTextToFramePadding(); + ImGui::Text("Current profile: %s (%s)", + _currentProfile->companyName().c_str(), + _currentProfile->type() == ProfileType::Demo ? "demo" : "full game"); + ImGui::SameLine(); + if(ImGui::Button("Close")) { + _currentProfile = nullptr; + _massManager.reset(); + _fileWatcher.reset(); + _uiState = UiState::ProfileManager; } if(ImGui::BeginChild("##ProfileInfo", diff --git a/src/SaveTool/SaveTool_drawMainMenu.cpp b/src/SaveTool/SaveTool_drawMainMenu.cpp index 87b3d25..f86fde9 100644 --- a/src/SaveTool/SaveTool_drawMainMenu.cpp +++ b/src/SaveTool/SaveTool_drawMainMenu.cpp @@ -54,8 +54,17 @@ void SaveTool::drawMainMenu() { ImGui::Separator(); - if(ImGui::MenuItem(ICON_FA_SYNC_ALT " Check for updates", nullptr, false, false)) { - // TODO: implement + if(ImGui::BeginMenu(ICON_FA_COG " Settings")) { + ImGui::Checkbox("Unsafe mode", &_unsafeMode); + ImGui::SameLine(); + drawHelpMarker("This allows changing the state of save files in the game's save folder even when the game is running.", + Float(windowSize().x()) * 0.4f); + + ImGui::Checkbox("Check for updates on startup", &_checkUpdatesOnStartup); + ImGui::SameLine(); + ImGui::Button(ICON_FA_SYNC_ALT " Check now"); + + ImGui::EndMenu(); } ImGui::Separator();