Qt: Migrate multiplayer window handling into GBAApp

This commit is contained in:
Jeffrey Pfau 2015-05-29 22:57:30 -07:00
parent 03543eeab4
commit 27b4f35139
7 changed files with 56 additions and 31 deletions

View File

@ -45,6 +45,7 @@ Misc:
- GBA: GBARewind now returns how many states it has rewound
- All: Enable static linking for Windows
- All: Enable static linking for OS X
- Qt: Migrate multiplayer window handling into GBAApp
0.2.1: (2015-05-13)
Bugfixes:

View File

@ -7,6 +7,7 @@
#include "AudioProcessor.h"
#include "GameController.h"
#include "Window.h"
#include <QFileOpenEvent>
@ -17,10 +18,13 @@ extern "C" {
using namespace QGBA;
GBAApp* g_app = nullptr;
GBAApp::GBAApp(int& argc, char* argv[])
: QApplication(argc, argv)
, m_window(&m_configController)
{
g_app = this;
#ifdef BUILD_SDL
SDL_Init(SDL_INIT_NOPARACHUTE);
#endif
@ -31,30 +35,53 @@ GBAApp::GBAApp(int& argc, char* argv[])
QApplication::setApplicationName(projectName);
QApplication::setApplicationVersion(projectVersion);
Window* w = new Window(&m_configController);
m_windows[0] = w;
#ifndef Q_OS_MAC
m_window.show();
w->show();
#endif
GBAArguments args;
if (m_configController.parseArguments(&args, argc, argv)) {
m_window.argumentsPassed(&args);
w->argumentsPassed(&args);
} else {
m_window.loadConfig();
w->loadConfig();
}
freeArguments(&args);
AudioProcessor::setDriver(static_cast<AudioProcessor::Driver>(m_configController.getQtOption("audioDriver").toInt()));
m_window.controller()->reloadAudioDriver();
w->controller()->reloadAudioDriver();
w->controller()->setMultiplayerController(&m_multiplayer);
#ifdef Q_OS_MAC
m_window.show();
w->show();
#endif
}
bool GBAApp::event(QEvent* event) {
if (event->type() == QEvent::FileOpen) {
m_window.controller()->loadGame(static_cast<QFileOpenEvent*>(event)->file());
m_windows[0]->controller()->loadGame(static_cast<QFileOpenEvent*>(event)->file());
return true;
}
return QApplication::event(event);
}
Window* GBAApp::newWindowInternal() {
Window* w = new Window(&m_configController, m_multiplayer.attached());
m_windows[m_multiplayer.attached()] = w;
w->setAttribute(Qt::WA_DeleteOnClose);
#ifndef Q_OS_MAC
w->show();
#endif
w->loadConfig();
w->controller()->setMultiplayerController(&m_multiplayer);
#ifdef Q_OS_MAC
w->show();
#endif
return w;
}
Window* GBAApp::newWindow() {
return g_app->newWindowInternal();
}

View File

@ -9,11 +9,16 @@
#include <QApplication>
#include "ConfigController.h"
#include "Window.h"
#include "MultiplayerController.h"
extern "C" {
#include "gba/sio.h"
}
namespace QGBA {
class GameController;
class Window;
class GBAApp : public QApplication {
Q_OBJECT
@ -21,12 +26,17 @@ Q_OBJECT
public:
GBAApp(int& argc, char* argv[]);
static Window* newWindow();
protected:
bool event(QEvent*);
private:
Window* newWindowInternal();
ConfigController m_configController;
Window m_window;
Window* m_windows[MAX_GBAS];
MultiplayerController m_multiplayer;
};
}

View File

@ -178,7 +178,7 @@ GameController::~GameController() {
delete[] m_drawContext;
}
void GameController::setMultiplayerController(std::shared_ptr<MultiplayerController> controller) {
void GameController::setMultiplayerController(MultiplayerController* controller) {
if (controller == m_multiplayer) {
return;
}
@ -192,7 +192,7 @@ void GameController::clearMultiplayerController() {
return;
}
m_multiplayer->detachGame(this);
m_multiplayer.reset();
m_multiplayer = nullptr;
}
void GameController::setOverride(const GBACartridgeOverride& override) {

View File

@ -63,8 +63,8 @@ public:
void setInputController(InputController* controller) { m_inputController = controller; }
void setOverrides(Configuration* overrides) { m_threadContext.overrides = overrides; }
void setMultiplayerController(std::shared_ptr<MultiplayerController> controller);
std::shared_ptr<MultiplayerController> multiplayerController() { return m_multiplayer; }
void setMultiplayerController(MultiplayerController* controller);
MultiplayerController* multiplayerController() { return m_multiplayer; }
void clearMultiplayerController();
void setOverride(const GBACartridgeOverride& override);
@ -191,7 +191,7 @@ private:
int m_stateSlot;
InputController* m_inputController;
std::shared_ptr<MultiplayerController> m_multiplayer;
MultiplayerController* m_multiplayer;
struct GameControllerLux : GBALuminanceSource {
GameController* p;

View File

@ -83,7 +83,7 @@ void PaletteView::exportPalette(int start, int length) {
length = 512 - start;
}
m_controller->threadInterrupt();
QString filename = QFileDialog::getSaveFileName(this, tr("Export palette"), QString(), tr("Windows PAL (*.pal)"));
QString filename = QFileDialog::getSaveFileName(this, tr("Export palette"), QString(), tr("Windows PAL (*.pal);;Adobe Color Table (*.act)"));
if (filename.isNull()) {
m_controller->threadContinue();
return;

View File

@ -19,6 +19,7 @@
#include "ConfigController.h"
#include "DisplayGL.h"
#include "GameController.h"
#include "GBAApp.h"
#include "GBAKeyEditor.h"
#include "GDBController.h"
#include "GDBWindow.h"
@ -604,7 +605,7 @@ void Window::updateTitle(float fps) {
title = (gameTitle);
}
std::shared_ptr<MultiplayerController> multiplayer = m_controller->multiplayerController();
MultiplayerController* multiplayer = m_controller->multiplayerController();
if (multiplayer && multiplayer->attached() > 1) {
title += tr(" - Player %1 of %2").arg(m_playerId + 1).arg(multiplayer->attached());
}
@ -712,21 +713,7 @@ void Window::setupMenu(QMenuBar* menubar) {
fileMenu->addSeparator();
QAction* multiWindow = new QAction(tr("New multiplayer window"), fileMenu);
connect(multiWindow, &QAction::triggered, [this]() {
std::shared_ptr<MultiplayerController> multiplayer = m_controller->multiplayerController();
if (!multiplayer) {
multiplayer = std::make_shared<MultiplayerController>();
m_controller->setMultiplayerController(multiplayer);
}
Window* w2 = new Window(m_config, multiplayer->attached());
w2->setAttribute(Qt::WA_DeleteOnClose);
#ifndef Q_OS_MAC
w2->show();
#endif
w2->loadConfig();
w2->controller()->setMultiplayerController(multiplayer);
#ifdef Q_OS_MAC
w2->show();
#endif
GBAApp::newWindow();
});
addControlledAction(fileMenu, multiWindow, "multiWindow");