Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add undo last save as well #14697

Merged
merged 1 commit into from
Aug 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions Core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ struct Config {
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;
Expand Down
18 changes: 18 additions & 0 deletions Core/SaveState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions Core/SaveState.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
13 changes: 12 additions & 1 deletion UI/PauseScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions UI/PauseScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class GamePauseScreen : public UIDialogScreenWithGameBackground {

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);
Expand Down