From 64b44efbf15168b03ee5f02ca03f55f519e4824f Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Tue, 2 Oct 2018 09:39:27 -0700 Subject: [PATCH] Qt: State file load/save menu options --- CHANGES | 1 + src/platform/qt/Window.cpp | 28 ++++++++++++++++++++++++++++ src/platform/qt/Window.h | 1 + 3 files changed, 30 insertions(+) diff --git a/CHANGES b/CHANGES index 63ba1d53e..af13230da 100644 --- a/CHANGES +++ b/CHANGES @@ -104,6 +104,7 @@ Features: - Qt: Separate fast forward volume control (fixes mgba.io/i/846, mgba.io/i/1143) - Switch: Rumble support - Switch: Rotation support + - Qt: State file load/save menu options Bugfixes: - PSP2: Fix audio crackling after fast forward - PSP2: Fix audio crackling when buffer is full diff --git a/src/platform/qt/Window.cpp b/src/platform/qt/Window.cpp index 10254984f..b9dba9374 100644 --- a/src/platform/qt/Window.cpp +++ b/src/platform/qt/Window.cpp @@ -362,6 +362,22 @@ void Window::selectSave(bool temporary) { } } +void Window::selectState(bool load) { + QStringList formats{"*.ss0", "*.ss1", "*.ss2", "*.ss3", "*.ss4", "*.ss5", "*.ss6", "*.ss7", "*.ss8", "*.ss9"}; + QString filter = tr("mGBA savestate files (%1)").arg(formats.join(QChar(' '))); + if (load) { + QString filename = GBAApp::app()->getOpenFileName(this, tr("Select savestate"), filter); + if (!filename.isEmpty()) { + m_controller->loadState(filename); + } + } else { + QString filename = GBAApp::app()->getSaveFileName(this, tr("Select savestate"), filter); + if (!filename.isEmpty()) { + m_controller->saveState(filename); + } + } +} + void Window::multiplayerChanged() { if (!m_controller) { return; @@ -1046,6 +1062,12 @@ void Window::setupMenu(QMenuBar* menubar) { m_nonMpActions.append(loadState); addControlledAction(fileMenu, loadState, "loadState"); + QAction* loadStateFile = new QAction(tr("Load state file..."), fileMenu); + connect(loadStateFile, &QAction::triggered, [this]() { this->selectState(true); }); + m_gameActions.append(loadStateFile); + m_nonMpActions.append(loadStateFile); + addControlledAction(fileMenu, loadStateFile, "loadStateFile"); + QAction* saveState = new QAction(tr("&Save state"), fileMenu); saveState->setShortcut(tr("Shift+F10")); connect(saveState, &QAction::triggered, [this]() { this->openStateWindow(LoadSave::SAVE); }); @@ -1053,6 +1075,12 @@ void Window::setupMenu(QMenuBar* menubar) { m_nonMpActions.append(saveState); addControlledAction(fileMenu, saveState, "saveState"); + QAction* saveStateFile = new QAction(tr("Save state file..."), fileMenu); + connect(saveStateFile, &QAction::triggered, [this]() { this->selectState(false); }); + m_gameActions.append(saveStateFile); + m_nonMpActions.append(saveStateFile); + addControlledAction(fileMenu, saveStateFile, "saveStateFile"); + QMenu* quickLoadMenu = fileMenu->addMenu(tr("Quick load")); QMenu* quickSaveMenu = fileMenu->addMenu(tr("Quick save")); m_shortcutController->addMenu(quickLoadMenu); diff --git a/src/platform/qt/Window.h b/src/platform/qt/Window.h index 44b8e812a..f30e524af 100644 --- a/src/platform/qt/Window.h +++ b/src/platform/qt/Window.h @@ -70,6 +70,7 @@ public slots: void addDirToLibrary(); #endif void selectSave(bool temporary); + void selectState(bool load); void selectPatch(); void enterFullScreen(); void exitFullScreen();