Undo last save

This commit is contained in:
iota97 2021-08-07 13:28:43 +02:00
parent af3ad2ca03
commit b643d60f72
6 changed files with 37 additions and 1 deletions

View File

@ -533,6 +533,8 @@ static ConfigSetting generalSettings[] = {
ConfigSetting("StateSlot", &g_Config.iCurrentStateSlot, 0, true, true),
ConfigSetting("EnableStateUndo", &g_Config.bEnableStateUndo, &DefaultEnableStateUndo, true, true),
ConfigSetting("StateLoadUndoGame", &g_Config.sStateLoadUndoGame, "NA", true, false),
ConfigSetting("StateUndoLastSaveGame", &g_Config.sStateUndoLastSaveGame, "NA", true, false),
ConfigSetting("StateUndoLastSaveSlot", &g_Config.iStateUndoLastSaveSlot, -5, true, false), // Start with an "invalid" value
ConfigSetting("RewindFlipFrequency", &g_Config.iRewindFlipFrequency, 0, true, true),
ConfigSetting("ShowOnScreenMessage", &g_Config.bShowOnScreenMessages, true, true, false),

View File

@ -210,6 +210,8 @@ public:
bool bUISound;
bool bEnableStateUndo;
std::string sStateLoadUndoGame;
std::string sStateUndoLastSaveGame;
int iStateUndoLastSaveSlot;
int iAutoLoadSaveState; // 0 = off, 1 = oldest, 2 = newest, >2 = slot number + 3
bool bEnableCheats;
bool bReloadCheats;

View File

@ -531,6 +531,8 @@ namespace SaveState
if (g_Config.bEnableStateUndo) {
DeleteIfExists(fnUndo);
RenameIfExists(fn, fnUndo);
g_Config.sStateUndoLastSaveGame = GenerateFullDiscId(gameFilename);
g_Config.iStateUndoLastSaveSlot = slot;
} else {
DeleteIfExists(fn);
}
@ -571,6 +573,14 @@ namespace SaveState
return false;
}
bool UndoLastSave(const Path &gameFilename) {
if (g_Config.sStateUndoLastSaveGame != GenerateFullDiscId(gameFilename))
return false;
return UndoSaveSlot(gameFilename, g_Config.iStateUndoLastSaveSlot);
}
bool HasSaveInSlot(const Path &gameFilename, int slot)
{
Path fn = GenerateSaveSlotFilename(gameFilename, slot, STATE_EXTENSION);
@ -583,6 +593,14 @@ namespace SaveState
return File::Exists(fn);
}
bool HasUndoLastSave(const Path &gameFilename)
{
if (g_Config.sStateUndoLastSaveGame != GenerateFullDiscId(gameFilename))
return false;
return HasUndoSaveInSlot(gameFilename, g_Config.iStateUndoLastSaveSlot);
}
bool HasScreenshotInSlot(const Path &gameFilename, int slot)
{
Path fn = GenerateSaveSlotFilename(gameFilename, slot, SCREENSHOT_EXTENSION);

View File

@ -47,10 +47,12 @@ namespace SaveState
void SaveSlot(const Path &gameFilename, int slot, Callback callback, void *cbUserData = 0);
void LoadSlot(const Path &gameFilename, int slot, Callback callback, void *cbUserData = 0);
bool UndoSaveSlot(const Path &gameFilename, int slot);
bool UndoLastSave(const Path &gameFilename);
bool UndoLoad(const Path &gameFilename, Callback callback, void *cbUserData = 0);
// Checks whether there's an existing save in the specified slot.
bool HasSaveInSlot(const Path &gameFilename, int slot);
bool HasUndoSaveInSlot(const Path &gameFilename, int slot);
bool HasUndoLastSave(const Path &gameFilename);
bool HasUndoLoad(const Path &gameFilename);
bool HasScreenshotInSlot(const Path &gameFilename, int slot);

View File

@ -392,9 +392,13 @@ void GamePauseScreen::CreateViews() {
LinearLayout *buttonRow = leftColumnItems->Add(new LinearLayout(ORIENT_HORIZONTAL));
if (g_Config.bEnableStateUndo) {
UI::Choice *loadUndoButton = buttonRow->Add(new Choice(pa->T("Undo last state load")));
UI::Choice *loadUndoButton = buttonRow->Add(new Choice(pa->T("Undo last load")));
loadUndoButton->SetEnabled(SaveState::HasUndoLoad(gamePath_));
loadUndoButton->OnClick.Handle(this, &GamePauseScreen::OnLoadUndo);
UI::Choice *saveUndoButton = buttonRow->Add(new Choice(pa->T("Undo last save")));
saveUndoButton->SetEnabled(SaveState::HasUndoLastSave(gamePath_));
saveUndoButton->OnClick.Handle(this, &GamePauseScreen::OnLastSaveUndo);
}
if (g_Config.iRewindFlipFrequency > 0) {
@ -506,6 +510,13 @@ UI::EventReturn GamePauseScreen::OnLoadUndo(UI::EventParams &e) {
return UI::EVENT_DONE;
}
UI::EventReturn GamePauseScreen::OnLastSaveUndo(UI::EventParams &e) {
SaveState::UndoLastSave(gamePath_);
RecreateViews();
return UI::EVENT_DONE;
}
UI::EventReturn GamePauseScreen::OnCwCheat(UI::EventParams &e) {
screenManager()->push(new CwCheatScreen(gamePath_));
return UI::EVENT_DONE;

View File

@ -45,6 +45,7 @@ private:
UI::EventReturn OnRewind(UI::EventParams &e);
UI::EventReturn OnLoadUndo(UI::EventParams &e);
UI::EventReturn OnLastSaveUndo(UI::EventParams &e);
UI::EventReturn OnScreenshotClicked(UI::EventParams &e);
UI::EventReturn OnCwCheat(UI::EventParams &e);