diff --git a/CHANGES b/CHANGES index fe93e9f5f..6152465a1 100644 --- a/CHANGES +++ b/CHANGES @@ -24,6 +24,7 @@ Misc: - Libretro: Use anonymous memory mappers for large blocks of memory - Qt: Add 'Apply' button to settings window - Qt: Prevent savestate window from opening while in multiplayer + - Qt: Disable menu items in multiplayer that don't make sense to have enabled 0.3.0: (2015-08-16) Features: diff --git a/src/platform/qt/GBAApp.cpp b/src/platform/qt/GBAApp.cpp index 72c72cda8..24f59af4a 100644 --- a/src/platform/qt/GBAApp.cpp +++ b/src/platform/qt/GBAApp.cpp @@ -86,6 +86,7 @@ GBAApp::GBAApp(int& argc, char* argv[]) w->show(); w->controller()->setMultiplayerController(&m_multiplayer); + w->multiplayerChanged(); } bool GBAApp::event(QEvent* event) { @@ -110,6 +111,7 @@ Window* GBAApp::newWindow() { w->loadConfig(); w->show(); w->controller()->setMultiplayerController(&m_multiplayer); + w->multiplayerChanged(); return w; } diff --git a/src/platform/qt/MultiplayerController.cpp b/src/platform/qt/MultiplayerController.cpp index 827900c70..20da04e2e 100644 --- a/src/platform/qt/MultiplayerController.cpp +++ b/src/platform/qt/MultiplayerController.cpp @@ -35,6 +35,7 @@ bool MultiplayerController::attachGame(GameController* controller) { } thread->sioDrivers.multiplayer = &node->d; controller->threadContinue(); + emit gameAttached(); return true; } @@ -60,6 +61,7 @@ void MultiplayerController::detachGame(GameController* controller) { } MutexUnlock(&m_lockstep.mutex); controller->threadContinue(); + emit gameDetached(); } int MultiplayerController::attached() { diff --git a/src/platform/qt/MultiplayerController.h b/src/platform/qt/MultiplayerController.h index ac3514c1b..f849d8ad1 100644 --- a/src/platform/qt/MultiplayerController.h +++ b/src/platform/qt/MultiplayerController.h @@ -6,6 +6,8 @@ #ifndef QGBA_MULTIPLAYER_CONTROLLER #define QGBA_MULTIPLAYER_CONTROLLER +#include + extern "C" { #include "gba/sio/lockstep.h" } @@ -14,7 +16,9 @@ namespace QGBA { class GameController; -class MultiplayerController { +class MultiplayerController : public QObject { +Q_OBJECT + public: MultiplayerController(); ~MultiplayerController(); @@ -24,6 +28,10 @@ public: int attached(); +signals: + void gameAttached(); + void gameDetached(); + private: GBASIOLockstep m_lockstep; }; diff --git a/src/platform/qt/Window.cpp b/src/platform/qt/Window.cpp index 882ed87e3..3cdf65f44 100644 --- a/src/platform/qt/Window.cpp +++ b/src/platform/qt/Window.cpp @@ -271,6 +271,22 @@ void Window::replaceROM() { } } +void Window::multiplayerChanged() { + disconnect(nullptr, this, SLOT(multiplayerChanged())); + int attached = 1; + MultiplayerController* multiplayer = m_controller->multiplayerController(); + if (multiplayer) { + attached = multiplayer->attached(); + connect(multiplayer, SIGNAL(gameAttached()), this, SLOT(multiplayerChanged())); + connect(multiplayer, SIGNAL(gameDetached()), this, SLOT(multiplayerChanged())); + } + if (m_controller->isLoaded()) { + for (QAction* action : m_nonMpActions) { + action->setDisabled(attached > 1); + } + } +} + void Window::selectBIOS() { QString filename = GBAApp::app()->getOpenFileName(this, tr("Select BIOS")); if (!filename.isEmpty()) { @@ -569,6 +585,7 @@ void Window::gameStarted(GBAThread* context) { foreach (QAction* action, m_gameActions) { action->setDisabled(false); } + multiplayerChanged(); if (context->fname) { setWindowFilePath(context->fname); appendMRU(context->fname); @@ -740,12 +757,14 @@ void Window::setupMenu(QMenuBar* menubar) { loadState->setShortcut(tr("F10")); connect(loadState, &QAction::triggered, [this]() { this->openStateWindow(LoadSave::LOAD); }); m_gameActions.append(loadState); + m_nonMpActions.append(loadState); addControlledAction(fileMenu, loadState, "loadState"); QAction* saveState = new QAction(tr("&Save state"), fileMenu); saveState->setShortcut(tr("Shift+F10")); connect(saveState, &QAction::triggered, [this]() { this->openStateWindow(LoadSave::SAVE); }); m_gameActions.append(saveState); + m_nonMpActions.append(saveState); addControlledAction(fileMenu, saveState, "saveState"); QMenu* quickLoadMenu = fileMenu->addMenu(tr("Quick load")); @@ -756,11 +775,13 @@ void Window::setupMenu(QMenuBar* menubar) { QAction* quickLoad = new QAction(tr("Load recent"), quickLoadMenu); connect(quickLoad, SIGNAL(triggered()), m_controller, SLOT(loadState())); m_gameActions.append(quickLoad); + m_nonMpActions.append(quickLoad); addControlledAction(quickLoadMenu, quickLoad, "quickLoad"); QAction* quickSave = new QAction(tr("Save recent"), quickSaveMenu); connect(quickSave, SIGNAL(triggered()), m_controller, SLOT(saveState())); m_gameActions.append(quickSave); + m_nonMpActions.append(quickSave); addControlledAction(quickSaveMenu, quickSave, "quickSave"); quickLoadMenu->addSeparator(); @@ -770,12 +791,14 @@ void Window::setupMenu(QMenuBar* menubar) { undoLoadState->setShortcut(tr("F11")); connect(undoLoadState, SIGNAL(triggered()), m_controller, SLOT(loadBackupState())); m_gameActions.append(undoLoadState); + m_nonMpActions.append(undoLoadState); addControlledAction(quickLoadMenu, undoLoadState, "undoLoadState"); QAction* undoSaveState = new QAction(tr("Undo save state"), quickSaveMenu); undoSaveState->setShortcut(tr("Shift+F11")); connect(undoSaveState, SIGNAL(triggered()), m_controller, SLOT(saveBackupState())); m_gameActions.append(undoSaveState); + m_nonMpActions.append(undoSaveState); addControlledAction(quickSaveMenu, undoSaveState, "undoSaveState"); quickLoadMenu->addSeparator(); @@ -787,12 +810,14 @@ void Window::setupMenu(QMenuBar* menubar) { quickLoad->setShortcut(tr("F%1").arg(i)); connect(quickLoad, &QAction::triggered, [this, i]() { m_controller->loadState(i); }); m_gameActions.append(quickLoad); + m_nonMpActions.append(quickLoad); addControlledAction(quickLoadMenu, quickLoad, QString("quickLoad.%1").arg(i)); quickSave = new QAction(tr("State &%1").arg(i), quickSaveMenu); quickSave->setShortcut(tr("Shift+F%1").arg(i)); connect(quickSave, &QAction::triggered, [this, i]() { m_controller->saveState(i); }); m_gameActions.append(quickSave); + m_nonMpActions.append(quickSave); addControlledAction(quickSaveMenu, quickSave, QString("quickSave.%1").arg(i)); } @@ -861,6 +886,7 @@ void Window::setupMenu(QMenuBar* menubar) { frameAdvance->setShortcut(tr("Ctrl+N")); connect(frameAdvance, SIGNAL(triggered()), m_controller, SLOT(frameAdvance())); m_gameActions.append(frameAdvance); + m_nonMpActions.append(frameAdvance); addControlledAction(emulationMenu, frameAdvance, "frameAdvance"); emulationMenu->addSeparator(); @@ -901,6 +927,7 @@ void Window::setupMenu(QMenuBar* menubar) { rewind->setShortcut(tr("`")); connect(rewind, SIGNAL(triggered()), m_controller, SLOT(rewind())); m_gameActions.append(rewind); + m_nonMpActions.append(rewind); addControlledAction(emulationMenu, rewind, "rewind"); QAction* frameRewind = new QAction(tr("Step backwards"), emulationMenu); @@ -909,6 +936,7 @@ void Window::setupMenu(QMenuBar* menubar) { m_controller->rewind(1); }); m_gameActions.append(frameRewind); + m_nonMpActions.append(frameRewind); addControlledAction(emulationMenu, frameRewind, "frameRewind"); ConfigOption* videoSync = m_config->addOption("videoSync"); diff --git a/src/platform/qt/Window.h b/src/platform/qt/Window.h index eeff65df6..1a9ef24f0 100644 --- a/src/platform/qt/Window.h +++ b/src/platform/qt/Window.h @@ -69,6 +69,8 @@ public slots: void replaceROM(); + void multiplayerChanged(); + void importSharkport(); void exportSharkport(); @@ -149,6 +151,7 @@ private: GameController* m_controller; Display* m_display; QList m_gameActions; + QList m_nonMpActions; QMap m_frameSizes; LogController m_log; LogView* m_logView;