UI: Added "load last session" menu option + shortcut

This commit is contained in:
Sour 2022-02-04 22:36:40 -05:00
parent 3c3264ace8
commit 322795d2f9
9 changed files with 28 additions and 7 deletions

View file

@ -275,7 +275,7 @@ void Emulator::RunSingleFrame()
_controlManager->UpdateControlDevices();*/
}
void Emulator::Stop(bool sendNotification)
void Emulator::Stop(bool sendNotification, bool preventRecentGameSave)
{
BlockDebuggerRequests();
@ -290,7 +290,7 @@ void Emulator::Stop(bool sendNotification)
_emuThread.release();
}
if(_console && !_settings->GetPreferences().DisableGameSelectionScreen && !_audioPlayerHud) {
if(!preventRecentGameSave && _console && !_settings->GetPreferences().DisableGameSelectionScreen && !_audioPlayerHud) {
RomInfo romInfo = GetRomInfo();
_saveStateManager->SaveRecentGame(romInfo.RomFile.GetFileName(), romInfo.RomFile, romInfo.PatchFile);
}
@ -425,7 +425,9 @@ bool Emulator::LoadRom(VirtualFile romFile, VirtualFile patchFile, bool stopRom,
}
if(stopRom) {
Stop(false);
//Only update the recent game entry if the game that was loaded is a different game
bool gameChanged = (string)_rom.RomFile != (string)romFile || (string)_rom.PatchFile != (string)patchFile;
Stop(false, !gameChanged);
//TODO PERF
//KeyManager::UpdateDevices();
}
@ -435,9 +437,7 @@ bool Emulator::LoadRom(VirtualFile romFile, VirtualFile patchFile, bool stopRom,
//Cast VirtualFiles to string to ensure the original file data isn't kept in memory
_rom.RomFile = (string)romFile;
if(patchFile.IsValid()) {
_rom.PatchFile = (string)patchFile;
}
_rom.PatchFile = (string)patchFile;
_rom.Format = console->GetRomFormat();
if(_rom.Format == RomFormat::Spc || _rom.Format == RomFormat::Nsf || _rom.Format == RomFormat::Gbs) {

View file

@ -155,7 +155,7 @@ public:
void Run();
void RunSingleFrame();
void Stop(bool sendNotification);
void Stop(bool sendNotification, bool preventRecentGameSave = false);
void OnBeforeSendFrame();
void ProcessEndOfFrame();

View file

@ -639,6 +639,7 @@ enum class EmulatorShortcut
LoadStateSlotAuto,
LoadStateFromFile,
LoadStateDialog,
LoadLastSession,
OpenFile,
LoadRandomGame,

View file

@ -159,6 +159,7 @@ bool ShortcutKeyHandler::IsShortcutAllowed(EmulatorShortcut shortcut, uint32_t s
case EmulatorShortcut::LoadStateDialog:
case EmulatorShortcut::LoadStateFromFile:
case EmulatorShortcut::LoadState:
case EmulatorShortcut::LoadLastSession:
return isRunning && !isNetplayClient && !isMovieActive;
}

View file

@ -103,6 +103,7 @@ namespace Mesen.Config.Shortcuts
LoadStateSlotAuto,
LoadStateFromFile,
LoadStateDialog,
LoadLastSession,
OpenFile,
LoadRandomGame,

View file

@ -548,5 +548,6 @@ namespace Mesen.Debugger.Utilities
LoadStateFromFile,
RecentFiles,
LoadLastSession,
}
}

View file

@ -82,6 +82,16 @@ namespace Mesen.Utilities
case EmulatorShortcut.LoadStateFromFile: LoadStateFromFile(); break;
case EmulatorShortcut.SaveStateToFile: SaveStateToFile(); break;
case EmulatorShortcut.LoadLastSession:
string filename = Path.Combine(ConfigManager.RecentGamesFolder, MainWindowModel.RomInfo.GetRomName() + ".rgd");
Task.Run(() => {
//Run in another thread to prevent deadlocks etc. when emulator notifications are processed UI-side
if(File.Exists(filename)) {
EmuApi.LoadRecentGame(filename, false);
}
});
break;
case EmulatorShortcut.LoadStateDialog:
//TODO
/*if(_displayManager.ExclusiveFullscreen) {

View file

@ -143,6 +143,12 @@ namespace Mesen.ViewModels
new MainMenuAction(EmulatorShortcut.LoadStateFromFile) { ActionType = ActionType.LoadStateFromFile },
}
},
new MainMenuAction(EmulatorShortcut.LoadLastSession) {
ActionType = ActionType.LoadLastSession,
IsEnabled = () => File.Exists(Path.Combine(ConfigManager.RecentGamesFolder, MainWindow.RomInfo.GetRomName() + ".rgd"))
},
new ContextMenuSeparator(),
new MainMenuAction() {
ActionType = ActionType.RecentFiles,

View file

@ -104,6 +104,7 @@ namespace Mesen.ViewModels
EmulatorShortcut.LoadStateSlotAuto,
EmulatorShortcut.LoadStateFromFile,
EmulatorShortcut.LoadStateDialog,
EmulatorShortcut.LoadLastSession,
EmulatorShortcut.SelectSaveSlot1,
EmulatorShortcut.SelectSaveSlot2,