From e99ff14749bfc1d3ea7a472b87845e29e7814c24 Mon Sep 17 00:00:00 2001 From: William JCM Date: Wed, 28 Jul 2021 15:00:15 +0200 Subject: [PATCH] SaveTool: add a "cheat mode" toggle. --- src/SaveTool/SaveTool.cpp | 8 ++++ src/SaveTool/SaveTool.h | 2 + src/SaveTool/SaveTool_MainManager.cpp | 54 ++++++++++++++------------ src/SaveTool/SaveTool_drawMainMenu.cpp | 7 ++++ 4 files changed, 47 insertions(+), 24 deletions(-) diff --git a/src/SaveTool/SaveTool.cpp b/src/SaveTool/SaveTool.cpp index 96899eb..e95aff6 100644 --- a/src/SaveTool/SaveTool.cpp +++ b/src/SaveTool/SaveTool.cpp @@ -145,6 +145,7 @@ SaveTool::SaveTool(const Arguments& arguments): SaveTool::~SaveTool() { SDL_RemoveTimer(_gameCheckTimerId); + _conf.setValue("cheat_mode", _cheatMode); _conf.setValue("unsafe_mode", _unsafeMode); _conf.setValue("startup_update_check", _checkUpdatesOnStartup); _conf.save(); @@ -357,6 +358,13 @@ void SaveTool::updateCheckEvent(SDL_Event& event) { } void SaveTool::initialiseConfiguration() { + if(_conf.hasValue("cheat_mode")) { + _cheatMode = _conf.value("cheat_mode"); + } + else { + _conf.setValue("cheat_mode", _cheatMode); + } + if(_conf.hasValue("unsafe_mode")) { _unsafeMode = _conf.value("unsafe_mode"); } diff --git a/src/SaveTool/SaveTool.h b/src/SaveTool/SaveTool.h index da0266a..7577848 100644 --- a/src/SaveTool/SaveTool.h +++ b/src/SaveTool/SaveTool.h @@ -204,4 +204,6 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener std::string _latestVersion; std::string _releaseLink; std::string _downloadLink; + + bool _cheatMode{false}; }; diff --git a/src/SaveTool/SaveTool_MainManager.cpp b/src/SaveTool/SaveTool_MainManager.cpp index 36a19f9..0e5ee5b 100644 --- a/src/SaveTool/SaveTool_MainManager.cpp +++ b/src/SaveTool/SaveTool_MainManager.cpp @@ -231,6 +231,10 @@ void SaveTool::drawGeneralInfo() { } } + if(!_cheatMode) { + return; + } + ImGui::SameLine(); static Int credits; @@ -295,30 +299,32 @@ void SaveTool::drawResearchInventory() { ImGui::TableSetColumnIndex(1); \ ImGui::TextDisabled("Unavailable as of M.A.S.S. Builder version " SUPPORTED_GAME_VERSION); - #define matRow(name, var, getter, setter) \ - ImGui::TableNextRow(); \ - ImGui::TableSetColumnIndex(0); \ - ImGui::TextUnformatted((name)); \ - ImGui::TableSetColumnIndex(1); \ - if(_currentProfile->getter() != -1) { \ - drawUnsafeText("%i", _currentProfile->getter()); \ - ImGui::TableSetColumnIndex(2); \ - ImGui::PushID(#setter); \ - static Int var = _currentProfile->getter(); \ - if(drawUnsafeWidget([]{ return ImGui::SmallButton(ICON_FA_EDIT); })) { \ - (var) = _currentProfile->getter(); \ - ImGui::OpenPopup("int_edit"); \ - } \ - if(drawIntEditPopup(&(var), 9999)) { \ - if(!_currentProfile->set##setter((var))) { \ - SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", \ - _currentProfile->lastError().c_str(), window()); \ - } \ - } \ - ImGui::PopID(); \ - } \ - else { \ - ImGui::TextDisabled("Not found in the save file"); \ + #define matRow(name, var, getter, setter) \ + ImGui::TableNextRow(); \ + ImGui::TableSetColumnIndex(0); \ + ImGui::TextUnformatted((name)); \ + ImGui::TableSetColumnIndex(1); \ + if(_currentProfile->getter() != -1) { \ + ImGui::Text("%i", _currentProfile->getter()); \ + if(_cheatMode) { \ + ImGui::TableSetColumnIndex(2); \ + ImGui::PushID(#setter); \ + static Int var = _currentProfile->getter(); \ + if(drawUnsafeWidget([]{ return ImGui::SmallButton(ICON_FA_EDIT); })) { \ + (var) = _currentProfile->getter(); \ + ImGui::OpenPopup("int_edit"); \ + } \ + if(drawIntEditPopup(&(var), 9999)) { \ + if(!_currentProfile->set##setter((var))) { \ + SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", \ + _currentProfile->lastError().c_str(), window()); \ + } \ + } \ + ImGui::PopID(); \ + } \ + } \ + else { \ + ImGui::TextDisabled("Not found in the save file"); \ } if(ImGui::BeginTable("##ResearchInventoryTable", 3, diff --git a/src/SaveTool/SaveTool_drawMainMenu.cpp b/src/SaveTool/SaveTool_drawMainMenu.cpp index 3094079..40513d9 100644 --- a/src/SaveTool/SaveTool_drawMainMenu.cpp +++ b/src/SaveTool/SaveTool_drawMainMenu.cpp @@ -55,8 +55,15 @@ void SaveTool::drawMainMenu() { ImGui::Separator(); if(ImGui::BeginMenu(ICON_FA_COG " Settings")) { + ImGui::Checkbox("Cheat mode", &_cheatMode); + ImGui::SameLine(); + ImGui::AlignTextToFramePadding(); + drawHelpMarker("This gives access to save edition features that can be considered cheats.", + Float(windowSize().x()) * 0.4f); + ImGui::Checkbox("Unsafe mode", &_unsafeMode); ImGui::SameLine(); + ImGui::AlignTextToFramePadding(); 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);