all repos — mgba @ 11d9b492cdd71ec0b01bd0f5be505628d2c9ffc9

mGBA Game Boy Advance Emulator

Qt: Disable menu items in multiplayer that don't make sense to have enabled
Jeffrey Pfau jeffrey@endrift.com
Mon, 14 Sep 2015 20:21:16 -0700
commit

11d9b492cdd71ec0b01bd0f5be505628d2c9ffc9

parent

5b7e39e45f03f0d30857d91158a293ff742506e6

M CHANGESCHANGES

@@ -24,6 +24,7 @@ - ARM7: Force disable LTO on two files to work around a GCC bug

- 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:
M src/platform/qt/GBAApp.cppsrc/platform/qt/GBAApp.cpp

@@ -86,6 +86,7 @@

w->show(); w->controller()->setMultiplayerController(&m_multiplayer); + w->multiplayerChanged(); } bool GBAApp::event(QEvent* event) {

@@ -110,6 +111,7 @@ w->setAttribute(Qt::WA_DeleteOnClose);

w->loadConfig(); w->show(); w->controller()->setMultiplayerController(&m_multiplayer); + w->multiplayerChanged(); return w; }
M src/platform/qt/MultiplayerController.cppsrc/platform/qt/MultiplayerController.cpp

@@ -35,6 +35,7 @@ GBASIOSetDriver(&thread->gba->sio, &node->d, SIO_MULTI);

} thread->sioDrivers.multiplayer = &node->d; controller->threadContinue(); + emit gameAttached(); return true; }

@@ -60,6 +61,7 @@ delete node;

} MutexUnlock(&m_lockstep.mutex); controller->threadContinue(); + emit gameDetached(); } int MultiplayerController::attached() {
M src/platform/qt/MultiplayerController.hsrc/platform/qt/MultiplayerController.h

@@ -6,6 +6,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef QGBA_MULTIPLAYER_CONTROLLER #define QGBA_MULTIPLAYER_CONTROLLER +#include <QObject> + 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();

@@ -23,6 +27,10 @@ bool attachGame(GameController*);

void detachGame(GameController*); int attached(); + +signals: + void gameAttached(); + void gameDetached(); private: GBASIOLockstep m_lockstep;
M src/platform/qt/Window.cppsrc/platform/qt/Window.cpp

@@ -271,6 +271,22 @@ m_controller->replaceGame(filename);

} } +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 @@ MutexUnlock(&context->stateMutex);

foreach (QAction* action, m_gameActions) { action->setDisabled(false); } + multiplayerChanged(); if (context->fname) { setWindowFilePath(context->fname); appendMRU(context->fname);

@@ -740,12 +757,14 @@ QAction* loadState = new QAction(tr("&Load state"), fileMenu);

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 @@

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 @@ QAction* undoLoadState = new QAction(tr("Undo load state"), quickLoadMenu);

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 @@ quickLoad = new QAction(tr("State &%1").arg(i), quickLoadMenu);

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 @@ QAction* frameAdvance = new QAction(tr("&Next frame"), emulationMenu);

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 @@ QAction* rewind = new QAction(tr("Re&wind"), emulationMenu);

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 @@ connect(frameRewind, &QAction::triggered, [this] () {

m_controller->rewind(1); }); m_gameActions.append(frameRewind); + m_nonMpActions.append(frameRewind); addControlledAction(emulationMenu, frameRewind, "frameRewind"); ConfigOption* videoSync = m_config->addOption("videoSync");
M src/platform/qt/Window.hsrc/platform/qt/Window.h

@@ -69,6 +69,8 @@ void saveConfig();

void replaceROM(); + void multiplayerChanged(); + void importSharkport(); void exportSharkport();

@@ -149,6 +151,7 @@

GameController* m_controller; Display* m_display; QList<QAction*> m_gameActions; + QList<QAction*> m_nonMpActions; QMap<int, QAction*> m_frameSizes; LogController m_log; LogView* m_logView;