mirror of https://github.com/mgba-emu/mgba.git
Qt: Migrate multiplayer window handling into GBAApp
This commit is contained in:
parent
03543eeab4
commit
27b4f35139
1
CHANGES
1
CHANGES
|
@ -45,6 +45,7 @@ Misc:
|
||||||
- GBA: GBARewind now returns how many states it has rewound
|
- GBA: GBARewind now returns how many states it has rewound
|
||||||
- All: Enable static linking for Windows
|
- All: Enable static linking for Windows
|
||||||
- All: Enable static linking for OS X
|
- All: Enable static linking for OS X
|
||||||
|
- Qt: Migrate multiplayer window handling into GBAApp
|
||||||
|
|
||||||
0.2.1: (2015-05-13)
|
0.2.1: (2015-05-13)
|
||||||
Bugfixes:
|
Bugfixes:
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include "AudioProcessor.h"
|
#include "AudioProcessor.h"
|
||||||
#include "GameController.h"
|
#include "GameController.h"
|
||||||
|
#include "Window.h"
|
||||||
|
|
||||||
#include <QFileOpenEvent>
|
#include <QFileOpenEvent>
|
||||||
|
|
||||||
|
@ -17,10 +18,13 @@ extern "C" {
|
||||||
|
|
||||||
using namespace QGBA;
|
using namespace QGBA;
|
||||||
|
|
||||||
|
GBAApp* g_app = nullptr;
|
||||||
|
|
||||||
GBAApp::GBAApp(int& argc, char* argv[])
|
GBAApp::GBAApp(int& argc, char* argv[])
|
||||||
: QApplication(argc, argv)
|
: QApplication(argc, argv)
|
||||||
, m_window(&m_configController)
|
|
||||||
{
|
{
|
||||||
|
g_app = this;
|
||||||
|
|
||||||
#ifdef BUILD_SDL
|
#ifdef BUILD_SDL
|
||||||
SDL_Init(SDL_INIT_NOPARACHUTE);
|
SDL_Init(SDL_INIT_NOPARACHUTE);
|
||||||
#endif
|
#endif
|
||||||
|
@ -31,30 +35,53 @@ GBAApp::GBAApp(int& argc, char* argv[])
|
||||||
QApplication::setApplicationName(projectName);
|
QApplication::setApplicationName(projectName);
|
||||||
QApplication::setApplicationVersion(projectVersion);
|
QApplication::setApplicationVersion(projectVersion);
|
||||||
|
|
||||||
|
Window* w = new Window(&m_configController);
|
||||||
|
m_windows[0] = w;
|
||||||
|
|
||||||
#ifndef Q_OS_MAC
|
#ifndef Q_OS_MAC
|
||||||
m_window.show();
|
w->show();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
GBAArguments args;
|
GBAArguments args;
|
||||||
if (m_configController.parseArguments(&args, argc, argv)) {
|
if (m_configController.parseArguments(&args, argc, argv)) {
|
||||||
m_window.argumentsPassed(&args);
|
w->argumentsPassed(&args);
|
||||||
} else {
|
} else {
|
||||||
m_window.loadConfig();
|
w->loadConfig();
|
||||||
}
|
}
|
||||||
freeArguments(&args);
|
freeArguments(&args);
|
||||||
|
|
||||||
AudioProcessor::setDriver(static_cast<AudioProcessor::Driver>(m_configController.getQtOption("audioDriver").toInt()));
|
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
|
#ifdef Q_OS_MAC
|
||||||
m_window.show();
|
w->show();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GBAApp::event(QEvent* event) {
|
bool GBAApp::event(QEvent* event) {
|
||||||
if (event->type() == QEvent::FileOpen) {
|
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 true;
|
||||||
}
|
}
|
||||||
return QApplication::event(event);
|
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();
|
||||||
|
}
|
||||||
|
|
|
@ -9,11 +9,16 @@
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
|
||||||
#include "ConfigController.h"
|
#include "ConfigController.h"
|
||||||
#include "Window.h"
|
#include "MultiplayerController.h"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include "gba/sio.h"
|
||||||
|
}
|
||||||
|
|
||||||
namespace QGBA {
|
namespace QGBA {
|
||||||
|
|
||||||
class GameController;
|
class GameController;
|
||||||
|
class Window;
|
||||||
|
|
||||||
class GBAApp : public QApplication {
|
class GBAApp : public QApplication {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -21,12 +26,17 @@ Q_OBJECT
|
||||||
public:
|
public:
|
||||||
GBAApp(int& argc, char* argv[]);
|
GBAApp(int& argc, char* argv[]);
|
||||||
|
|
||||||
|
static Window* newWindow();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool event(QEvent*);
|
bool event(QEvent*);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Window* newWindowInternal();
|
||||||
|
|
||||||
ConfigController m_configController;
|
ConfigController m_configController;
|
||||||
Window m_window;
|
Window* m_windows[MAX_GBAS];
|
||||||
|
MultiplayerController m_multiplayer;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -178,7 +178,7 @@ GameController::~GameController() {
|
||||||
delete[] m_drawContext;
|
delete[] m_drawContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameController::setMultiplayerController(std::shared_ptr<MultiplayerController> controller) {
|
void GameController::setMultiplayerController(MultiplayerController* controller) {
|
||||||
if (controller == m_multiplayer) {
|
if (controller == m_multiplayer) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -192,7 +192,7 @@ void GameController::clearMultiplayerController() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_multiplayer->detachGame(this);
|
m_multiplayer->detachGame(this);
|
||||||
m_multiplayer.reset();
|
m_multiplayer = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameController::setOverride(const GBACartridgeOverride& override) {
|
void GameController::setOverride(const GBACartridgeOverride& override) {
|
||||||
|
|
|
@ -63,8 +63,8 @@ public:
|
||||||
void setInputController(InputController* controller) { m_inputController = controller; }
|
void setInputController(InputController* controller) { m_inputController = controller; }
|
||||||
void setOverrides(Configuration* overrides) { m_threadContext.overrides = overrides; }
|
void setOverrides(Configuration* overrides) { m_threadContext.overrides = overrides; }
|
||||||
|
|
||||||
void setMultiplayerController(std::shared_ptr<MultiplayerController> controller);
|
void setMultiplayerController(MultiplayerController* controller);
|
||||||
std::shared_ptr<MultiplayerController> multiplayerController() { return m_multiplayer; }
|
MultiplayerController* multiplayerController() { return m_multiplayer; }
|
||||||
void clearMultiplayerController();
|
void clearMultiplayerController();
|
||||||
|
|
||||||
void setOverride(const GBACartridgeOverride& override);
|
void setOverride(const GBACartridgeOverride& override);
|
||||||
|
@ -191,7 +191,7 @@ private:
|
||||||
int m_stateSlot;
|
int m_stateSlot;
|
||||||
|
|
||||||
InputController* m_inputController;
|
InputController* m_inputController;
|
||||||
std::shared_ptr<MultiplayerController> m_multiplayer;
|
MultiplayerController* m_multiplayer;
|
||||||
|
|
||||||
struct GameControllerLux : GBALuminanceSource {
|
struct GameControllerLux : GBALuminanceSource {
|
||||||
GameController* p;
|
GameController* p;
|
||||||
|
|
|
@ -83,7 +83,7 @@ void PaletteView::exportPalette(int start, int length) {
|
||||||
length = 512 - start;
|
length = 512 - start;
|
||||||
}
|
}
|
||||||
m_controller->threadInterrupt();
|
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()) {
|
if (filename.isNull()) {
|
||||||
m_controller->threadContinue();
|
m_controller->threadContinue();
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "ConfigController.h"
|
#include "ConfigController.h"
|
||||||
#include "DisplayGL.h"
|
#include "DisplayGL.h"
|
||||||
#include "GameController.h"
|
#include "GameController.h"
|
||||||
|
#include "GBAApp.h"
|
||||||
#include "GBAKeyEditor.h"
|
#include "GBAKeyEditor.h"
|
||||||
#include "GDBController.h"
|
#include "GDBController.h"
|
||||||
#include "GDBWindow.h"
|
#include "GDBWindow.h"
|
||||||
|
@ -604,7 +605,7 @@ void Window::updateTitle(float fps) {
|
||||||
|
|
||||||
title = (gameTitle);
|
title = (gameTitle);
|
||||||
}
|
}
|
||||||
std::shared_ptr<MultiplayerController> multiplayer = m_controller->multiplayerController();
|
MultiplayerController* multiplayer = m_controller->multiplayerController();
|
||||||
if (multiplayer && multiplayer->attached() > 1) {
|
if (multiplayer && multiplayer->attached() > 1) {
|
||||||
title += tr(" - Player %1 of %2").arg(m_playerId + 1).arg(multiplayer->attached());
|
title += tr(" - Player %1 of %2").arg(m_playerId + 1).arg(multiplayer->attached());
|
||||||
}
|
}
|
||||||
|
@ -712,21 +713,7 @@ void Window::setupMenu(QMenuBar* menubar) {
|
||||||
fileMenu->addSeparator();
|
fileMenu->addSeparator();
|
||||||
QAction* multiWindow = new QAction(tr("New multiplayer window"), fileMenu);
|
QAction* multiWindow = new QAction(tr("New multiplayer window"), fileMenu);
|
||||||
connect(multiWindow, &QAction::triggered, [this]() {
|
connect(multiWindow, &QAction::triggered, [this]() {
|
||||||
std::shared_ptr<MultiplayerController> multiplayer = m_controller->multiplayerController();
|
GBAApp::newWindow();
|
||||||
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
|
|
||||||
});
|
});
|
||||||
addControlledAction(fileMenu, multiWindow, "multiWindow");
|
addControlledAction(fileMenu, multiWindow, "multiWindow");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue