diff --git a/soh/soh/Enhancements/game-interactor/GameInteractor_HookTable.h b/soh/soh/Enhancements/game-interactor/GameInteractor_HookTable.h index edbdf1500..c8a85aae4 100644 --- a/soh/soh/Enhancements/game-interactor/GameInteractor_HookTable.h +++ b/soh/soh/Enhancements/game-interactor/GameInteractor_HookTable.h @@ -47,6 +47,7 @@ DEFINE_HOOK(OnVanillaBehavior, (GIVanillaBehavior flag, bool* result, va_list or DEFINE_HOOK(OnSaveFile, (int32_t fileNum)); DEFINE_HOOK(OnLoadFile, (int32_t fileNum)); DEFINE_HOOK(OnDeleteFile, (int32_t fileNum)); +DEFINE_HOOK(OnDeleteSelectedFile, ()); DEFINE_HOOK(OnDeleteAllFiles, ()); DEFINE_HOOK(OnDialogMessage, ()); diff --git a/soh/soh/SaveManager.cpp b/soh/soh/SaveManager.cpp index ae8db834d..ef5d1aa25 100644 --- a/soh/soh/SaveManager.cpp +++ b/soh/soh/SaveManager.cpp @@ -127,6 +127,11 @@ SaveManager::SaveManager() { GameInteractor::Instance->RegisterGameHook( [this]() { this->DeleteAllZeldaFiles(); }); + GameInteractor::Instance->RegisterGameHook([this]() { + int selectedFileNum = CVarGetInteger(CVAR_SETTING("DeleteSelectedSaveFileNum"), 0); + this->DeleteZeldaFile(selectedFileNum - 1 ); + }); + GameInteractor::Instance->RegisterGameHook( [this](uint32_t fileNum) { ThreadPoolWait(); }); diff --git a/soh/soh/SohGui/SohMenuSettings.cpp b/soh/soh/SohGui/SohMenuSettings.cpp index e2bff6154..b507eb1ee 100644 --- a/soh/soh/SohGui/SohMenuSettings.cpp +++ b/soh/soh/SohGui/SohMenuSettings.cpp @@ -187,28 +187,51 @@ void SohMenu::AddMenuSettings() { SDL_OpenURL(std::string("file:///" + std::filesystem::absolute(filesPath).string()).c_str()); }) .Options(ButtonOptions().Tooltip("Opens the folder that contains the save and mods folders, etc.")); - AddWidget(path, "Enable Delete All Saves", WIDGET_CVAR_CHECKBOX) - .CVar(CVAR_SETTING("EnableDeleteAllSaveFilesButton")) + + AddWidget(path, "Saves", WIDGET_SEPARATOR_TEXT); + auto deleteSaveFilesDisabledFunc = [](WidgetInfo& info) { + info.options->disabled = !CVarGetInteger(CVAR_SETTING("EnableDeleteAllSelectedSaveFiles"), 0); + info.options->disabledTooltip = + "This button is disabled because \"Enable Delete All/Selected Saves\" is turned off."; + }; + AddWidget(path, "Enable Delete All/Selected Saves", WIDGET_CVAR_CHECKBOX) + .CVar(CVAR_SETTING("EnableDeleteAllSelectedSaveFiles")) .RaceDisable(false) .Options(CheckboxOptions() - .Tooltip("Turn on to enable the \"Delete All Saves\" button.Turns off automatically " - "when \"Delete All Saves\" is pressed") + .Tooltip("Turn on to enable the Save deletion options below.Turns off automatically " + "when \"Delete All/Selected Saves\" button is pressed") .DefaultValue(false)); AddWidget(path, "Delete All Saves", WIDGET_BUTTON) .RaceDisable(false) - .PreFunc([](WidgetInfo& info) { - info.options->disabled = !CVarGetInteger(CVAR_SETTING("EnableDeleteAllSaveFilesButton"), 0); - info.options->disabledTooltip = - "This button is disabled because \"Enable Delete All Saves\" is turned off."; - }) + .PreFunc(deleteSaveFilesDisabledFunc) .Callback([](WidgetInfo& info) { GameInteractor::Instance->ExecuteHooks(); - CVarSetInteger(CVAR_SETTING("EnableDeleteAllSaveFilesButton"), 0); + CVarSetInteger(CVAR_SETTING("EnableDeleteAllSelectedSaveFiles"), 0); std::reinterpret_pointer_cast( Ship::Context::GetInstance()->GetWindow()->GetGui()->GetGuiWindow("Console")) ->Dispatch("reset"); }) - .Options(ButtonOptions().Tooltip("Warning deletes all save files")); + .Options(ButtonOptions().Tooltip("Warning deletes all save files")); + AddWidget(path, "Select Save File To Delete: ", WIDGET_CVAR_SLIDER_INT) + .CVar(CVAR_SETTING("DeleteSelectedSaveFileNum")) + .PreFunc(deleteSaveFilesDisabledFunc) + .Options(IntSliderOptions() + .Min(1) + .Max(3) + .DefaultValue(1) + .Format("File %d ") + .Tooltip("Select which save file to delete.Then press \"Delete Selected Save File\" to delete.")); + AddWidget(path, "Delete Selected Save File", WIDGET_BUTTON) + .RaceDisable(false) + .PreFunc(deleteSaveFilesDisabledFunc) + .Callback([](WidgetInfo& info) { + GameInteractor::Instance->ExecuteHooks(); + CVarSetInteger(CVAR_SETTING("EnableDeleteAllSelectedSaveFiles"), 0); + std::reinterpret_pointer_cast( + Ship::Context::GetInstance()->GetWindow()->GetGui()->GetGuiWindow("Console")) + ->Dispatch("reset"); + }) + .Options(ButtonOptions().Tooltip("Warning deletes selected save file")); AddWidget(path, "Boot", WIDGET_SEPARATOR_TEXT); AddWidget(path, "Boot Sequence", WIDGET_CVAR_COMBOBOX)