Qt: Save positions of multiplayer windows (closes #2128)

This commit is contained in:
Vicki Pfau 2021-12-28 17:56:43 -08:00
parent ee610db141
commit 0313fedf10
4 changed files with 19 additions and 6 deletions

View File

@ -28,6 +28,7 @@ Misc:
- Qt: Clean up cheats dialog
- Qt: Only set default controller bindings if loading fails (fixes mgba.io/i/799)
- Qt: Save converter now supports importing GameShark Advance saves
- Qt: Save positions of multiplayer windows (closes mgba.io/i/2128)
0.9.3: (2021-12-17)
Emulation fixes:

View File

@ -120,7 +120,7 @@ Window* GBAApp::newWindow() {
if (m_windows.count() >= MAX_GBAS) {
return nullptr;
}
Window* w = new Window(&m_manager, m_configController, m_multiplayer.attached());
Window* w = new Window(&m_manager, m_configController, m_windows.count());
connect(w, &Window::destroyed, [this, w]() {
m_windows.removeAll(w);
for (Window* w : m_windows) {

View File

@ -88,6 +88,7 @@ Window::Window(CoreManager* manager, ConfigController* config, int playerId, QWi
, m_config(config)
, m_inputController(playerId, this)
, m_shortcutController(new ShortcutController(this))
, m_playerId(playerId)
{
setFocusPolicy(Qt::StrongFocus);
setAcceptDrops(true);
@ -217,6 +218,16 @@ void Window::resizeFrame(const QSize& size) {
}
}
void Window::updateMultiplayerStatus(bool canOpenAnother) {
m_multiWindow->setEnabled(canOpenAnother);
if (m_controller) {
MultiplayerController* multiplayer = m_controller->multiplayerController();
if (multiplayer) {
m_playerId = multiplayer->playerId(m_controller.get());
}
}
}
void Window::updateMultiplayerActive(bool active) {
m_multiActive = active;
updateMute();
@ -678,7 +689,7 @@ void Window::showEvent(QShowEvent* event) {
}
m_wasOpened = true;
resizeFrame(m_screenWidget->sizeHint());
QVariant windowPos = m_config->getQtOption("windowPos");
QVariant windowPos = m_config->getQtOption("windowPos", m_playerId > 0 ? QString("player%0").arg(m_playerId) : QString());
bool maximized = m_config->getQtOption("maximized").toBool();
QRect geom = windowHandle()->screen()->availableGeometry();
if (!windowPos.isNull() && geom.contains(windowPos.toPoint())) {
@ -719,7 +730,7 @@ void Window::hideEvent(QHideEvent* event) {
void Window::closeEvent(QCloseEvent* event) {
emit shutdown();
m_config->setQtOption("windowPos", pos());
m_config->setQtOption("windowPos", pos(), m_playerId > 0 ? QString("player%0").arg(m_playerId) : QString());
m_config->setQtOption("maximized", isMaximized());
if (m_savedScale > 0) {
@ -1098,7 +1109,7 @@ void Window::updateTitle(float fps) {
MultiplayerController* multiplayer = m_controller->multiplayerController();
if (multiplayer && multiplayer->attached() > 1) {
title += tr(" - Player %1 of %2").arg(multiplayer->playerId(m_controller.get()) + 1).arg(multiplayer->attached());
title += tr(" - Player %1 of %2").arg(m_playerId + 1).arg(multiplayer->attached());
for (Action* action : m_nonMpActions) {
action->setEnabled(false);
}
@ -2023,7 +2034,7 @@ void Window::updateMute() {
QString multiplayerAudio = m_config->getQtOption("multiplayerAudio").toString();
if (multiplayerAudio == QLatin1String("p1")) {
MultiplayerController* multiplayer = m_controller->multiplayerController();
mute = multiplayer && multiplayer->attached() > 1 && multiplayer->playerId(m_controller.get());
mute = multiplayer && multiplayer->attached() > 1 && m_playerId;
} else if (multiplayerAudio == QLatin1String("active")) {
mute = !m_multiActive;
}

View File

@ -63,7 +63,7 @@ public:
void resizeFrame(const QSize& size);
void updateMultiplayerStatus(bool canOpenAnother) { m_multiWindow->setEnabled(canOpenAnother); }
void updateMultiplayerStatus(bool canOpenAnother);
void updateMultiplayerActive(bool active);
signals:
@ -230,6 +230,7 @@ private:
bool m_inactiveMute = false;
bool m_multiActive = true;
int m_playerId;
std::unique_ptr<OverrideView> m_overrideView;
std::unique_ptr<SensorView> m_sensorView;