From 0313fedf1068d982285572f1bad2bd9bb5efbd15 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Tue, 28 Dec 2021 17:56:43 -0800 Subject: [PATCH] Qt: Save positions of multiplayer windows (closes #2128) --- CHANGES | 1 + src/platform/qt/GBAApp.cpp | 2 +- src/platform/qt/Window.cpp | 19 +++++++++++++++---- src/platform/qt/Window.h | 3 ++- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/CHANGES b/CHANGES index 62f6daa64..6caf301f1 100644 --- a/CHANGES +++ b/CHANGES @@ -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: diff --git a/src/platform/qt/GBAApp.cpp b/src/platform/qt/GBAApp.cpp index 7d4252841..466cefa9f 100644 --- a/src/platform/qt/GBAApp.cpp +++ b/src/platform/qt/GBAApp.cpp @@ -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) { diff --git a/src/platform/qt/Window.cpp b/src/platform/qt/Window.cpp index a57106152..ef47b4945 100644 --- a/src/platform/qt/Window.cpp +++ b/src/platform/qt/Window.cpp @@ -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; } diff --git a/src/platform/qt/Window.h b/src/platform/qt/Window.h index 6d93948a1..a99a882b5 100644 --- a/src/platform/qt/Window.h +++ b/src/platform/qt/Window.h @@ -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 m_overrideView; std::unique_ptr m_sensorView;