From a8dfe98b1a0a887175579e2a57dd8a00837de9fa Mon Sep 17 00:00:00 2001 From: Gingeh <39150378+Gingeh@users.noreply.github.com> Date: Mon, 1 Aug 2022 20:18:48 +1000 Subject: [PATCH 1/5] Disable "Check for Updates" if all mods are removed Signed-off-by: Gingeh <39150378+Gingeh@users.noreply.github.com> --- launcher/ui/pages/instance/ModFolderPage.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/launcher/ui/pages/instance/ModFolderPage.cpp b/launcher/ui/pages/instance/ModFolderPage.cpp index 14e1f1e5..ae96ec2f 100644 --- a/launcher/ui/pages/instance/ModFolderPage.cpp +++ b/launcher/ui/pages/instance/ModFolderPage.cpp @@ -89,6 +89,9 @@ ModFolderPage::ModFolderPage(BaseInstance* inst, std::shared_ptr connect(mods.get(), &ModFolderModel::rowsInserted, this, [this] { ui->actionUpdateItem->setEnabled(ui->treeView->selectionModel()->hasSelection() || !m_model->empty()); }); + + connect(mods.get(), &ModFolderModel::rowsRemoved, this, + [this] { ui->actionUpdateItem->setEnabled(ui->treeView->selectionModel()->hasSelection() || !m_model->empty()); }); connect(mods.get(), &ModFolderModel::updateFinished, this, [this, mods] { ui->actionUpdateItem->setEnabled(ui->treeView->selectionModel()->hasSelection() || !m_model->empty()); From 77b640b76b5ca4948763e3c260ac1c832c72b0f2 Mon Sep 17 00:00:00 2001 From: Gingeh <39150378+Gingeh@users.noreply.github.com> Date: Mon, 1 Aug 2022 20:19:20 +1000 Subject: [PATCH 2/5] Disable "Check for Updates" and "Download Mods" while the game is running Signed-off-by: Gingeh <39150378+Gingeh@users.noreply.github.com> --- launcher/ui/pages/instance/ExternalResourcesPage.h | 2 +- launcher/ui/pages/instance/ModFolderPage.cpp | 7 +++++++ launcher/ui/pages/instance/ModFolderPage.h | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/launcher/ui/pages/instance/ExternalResourcesPage.h b/launcher/ui/pages/instance/ExternalResourcesPage.h index 41237139..ff294678 100644 --- a/launcher/ui/pages/instance/ExternalResourcesPage.h +++ b/launcher/ui/pages/instance/ExternalResourcesPage.h @@ -46,7 +46,7 @@ class ExternalResourcesPage : public QMainWindow, public BasePage { protected slots: void itemActivated(const QModelIndex& index); void filterTextChanged(const QString& newContents); - void runningStateChanged(bool running); + virtual void runningStateChanged(bool running); virtual void addItem(); virtual void removeItem(); diff --git a/launcher/ui/pages/instance/ModFolderPage.cpp b/launcher/ui/pages/instance/ModFolderPage.cpp index ae96ec2f..0db6a0ca 100644 --- a/launcher/ui/pages/instance/ModFolderPage.cpp +++ b/launcher/ui/pages/instance/ModFolderPage.cpp @@ -106,6 +106,13 @@ CoreModFolderPage::CoreModFolderPage(BaseInstance* inst, std::shared_ptractionDownloadItem->setEnabled(!running); + ui->actionUpdateItem->setEnabled(!running); +} + bool ModFolderPage::shouldDisplay() const { return true; diff --git a/launcher/ui/pages/instance/ModFolderPage.h b/launcher/ui/pages/instance/ModFolderPage.h index 0a7fc9fa..522d2a60 100644 --- a/launcher/ui/pages/instance/ModFolderPage.h +++ b/launcher/ui/pages/instance/ModFolderPage.h @@ -53,6 +53,7 @@ class ModFolderPage : public ExternalResourcesPage { virtual QString helpPage() const override { return "Loader-mods"; } virtual bool shouldDisplay() const override; + virtual void runningStateChanged(bool running); private slots: void installMods(); From 0d10ebb7caf7bb8292198af1933120c2c6e02cb8 Mon Sep 17 00:00:00 2001 From: Gingeh <39150378+Gingeh@users.noreply.github.com> Date: Tue, 2 Aug 2022 12:48:32 +1000 Subject: [PATCH 3/5] Update launcher/ui/pages/instance/ModFolderPage.h Co-authored-by: flow Signed-off-by: Gingeh <39150378+Gingeh@users.noreply.github.com> --- launcher/ui/pages/instance/ModFolderPage.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/ui/pages/instance/ModFolderPage.h b/launcher/ui/pages/instance/ModFolderPage.h index 522d2a60..93889707 100644 --- a/launcher/ui/pages/instance/ModFolderPage.h +++ b/launcher/ui/pages/instance/ModFolderPage.h @@ -53,7 +53,7 @@ class ModFolderPage : public ExternalResourcesPage { virtual QString helpPage() const override { return "Loader-mods"; } virtual bool shouldDisplay() const override; - virtual void runningStateChanged(bool running); + void runningStateChanged(bool running) override; private slots: void installMods(); From f33b31e048affecf76083fbc56d02e883d0fffad Mon Sep 17 00:00:00 2001 From: Gingeh <39150378+Gingeh@users.noreply.github.com> Date: Tue, 2 Aug 2022 14:14:45 +1000 Subject: [PATCH 4/5] Check for running instance when re-opening the mod folder page and when selecting mods Signed-off-by: Gingeh <39150378+Gingeh@users.noreply.github.com> --- .../pages/instance/ExternalResourcesPage.cpp | 2 +- launcher/ui/pages/instance/ModFolderPage.cpp | 25 +++++++++++++------ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/launcher/ui/pages/instance/ExternalResourcesPage.cpp b/launcher/ui/pages/instance/ExternalResourcesPage.cpp index 69c20309..39fbe3e2 100644 --- a/launcher/ui/pages/instance/ExternalResourcesPage.cpp +++ b/launcher/ui/pages/instance/ExternalResourcesPage.cpp @@ -101,7 +101,7 @@ ExternalResourcesPage::ExternalResourcesPage(BaseInstance* instance, std::shared { ui->setupUi(this); - runningStateChanged(m_instance && m_instance->isRunning()); + ExternalResourcesPage::runningStateChanged(m_instance && m_instance->isRunning()); ui->actionsToolbar->insertSpacer(ui->actionViewConfigs); diff --git a/launcher/ui/pages/instance/ModFolderPage.cpp b/launcher/ui/pages/instance/ModFolderPage.cpp index 0db6a0ca..b3f4759f 100644 --- a/launcher/ui/pages/instance/ModFolderPage.cpp +++ b/launcher/ui/pages/instance/ModFolderPage.cpp @@ -84,21 +84,30 @@ ModFolderPage::ModFolderPage(BaseInstance* inst, std::shared_ptr ui->actionsToolbar->insertActionAfter(ui->actionAddItem, ui->actionUpdateItem); connect(ui->actionUpdateItem, &QAction::triggered, this, &ModFolderPage::updateMods); - connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, - [this] { ui->actionUpdateItem->setEnabled(ui->treeView->selectionModel()->hasSelection() || !m_model->empty()); }); + connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, [this] { + ui->actionUpdateItem->setEnabled(!(m_instance && m_instance->isRunning()) && + (ui->treeView->selectionModel()->hasSelection() || !m_model->empty())); + }); - connect(mods.get(), &ModFolderModel::rowsInserted, this, - [this] { ui->actionUpdateItem->setEnabled(ui->treeView->selectionModel()->hasSelection() || !m_model->empty()); }); + connect(mods.get(), &ModFolderModel::rowsInserted, this, [this] { + ui->actionUpdateItem->setEnabled(!(m_instance && m_instance->isRunning()) && + (ui->treeView->selectionModel()->hasSelection() || !m_model->empty())); + }); + + connect(mods.get(), &ModFolderModel::rowsRemoved, this, [this] { + ui->actionUpdateItem->setEnabled(!(m_instance && m_instance->isRunning()) && + (ui->treeView->selectionModel()->hasSelection() || !m_model->empty())); + }); - connect(mods.get(), &ModFolderModel::rowsRemoved, this, - [this] { ui->actionUpdateItem->setEnabled(ui->treeView->selectionModel()->hasSelection() || !m_model->empty()); }); - connect(mods.get(), &ModFolderModel::updateFinished, this, [this, mods] { - ui->actionUpdateItem->setEnabled(ui->treeView->selectionModel()->hasSelection() || !m_model->empty()); + ui->actionUpdateItem->setEnabled(!(m_instance && m_instance->isRunning()) && + (ui->treeView->selectionModel()->hasSelection() || !m_model->empty())); // Prevent a weird crash when trying to open the mods page twice in a session o.O disconnect(mods.get(), &ModFolderModel::updateFinished, this, 0); }); + + ModFolderPage::runningStateChanged(m_instance && m_instance->isRunning()); } } From a8aa86291965ddd3cdfa2bb5f5fc7a34170559ed Mon Sep 17 00:00:00 2001 From: Gingeh <39150378+Gingeh@users.noreply.github.com> Date: Wed, 3 Aug 2022 16:39:30 +1000 Subject: [PATCH 5/5] Move large condition into a new lambda Signed-off-by: Gingeh <39150378+Gingeh@users.noreply.github.com> --- launcher/ui/pages/instance/ModFolderPage.cpp | 25 ++++++++++---------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/launcher/ui/pages/instance/ModFolderPage.cpp b/launcher/ui/pages/instance/ModFolderPage.cpp index b3f4759f..1b2cde0c 100644 --- a/launcher/ui/pages/instance/ModFolderPage.cpp +++ b/launcher/ui/pages/instance/ModFolderPage.cpp @@ -84,24 +84,25 @@ ModFolderPage::ModFolderPage(BaseInstance* inst, std::shared_ptr ui->actionsToolbar->insertActionAfter(ui->actionAddItem, ui->actionUpdateItem); connect(ui->actionUpdateItem, &QAction::triggered, this, &ModFolderPage::updateMods); - connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, [this] { - ui->actionUpdateItem->setEnabled(!(m_instance && m_instance->isRunning()) && - (ui->treeView->selectionModel()->hasSelection() || !m_model->empty())); + auto check_allow_update = [this] { + return (!m_instance || !m_instance->isRunning()) && + (ui->treeView->selectionModel()->hasSelection() || !m_model->empty()); + }; + + connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, [this, check_allow_update] { + ui->actionUpdateItem->setEnabled(check_allow_update()); }); - connect(mods.get(), &ModFolderModel::rowsInserted, this, [this] { - ui->actionUpdateItem->setEnabled(!(m_instance && m_instance->isRunning()) && - (ui->treeView->selectionModel()->hasSelection() || !m_model->empty())); + connect(mods.get(), &ModFolderModel::rowsInserted, this, [this, check_allow_update] { + ui->actionUpdateItem->setEnabled(check_allow_update()); }); - connect(mods.get(), &ModFolderModel::rowsRemoved, this, [this] { - ui->actionUpdateItem->setEnabled(!(m_instance && m_instance->isRunning()) && - (ui->treeView->selectionModel()->hasSelection() || !m_model->empty())); + connect(mods.get(), &ModFolderModel::rowsRemoved, this, [this, check_allow_update] { + ui->actionUpdateItem->setEnabled(check_allow_update()); }); - connect(mods.get(), &ModFolderModel::updateFinished, this, [this, mods] { - ui->actionUpdateItem->setEnabled(!(m_instance && m_instance->isRunning()) && - (ui->treeView->selectionModel()->hasSelection() || !m_model->empty())); + connect(mods.get(), &ModFolderModel::updateFinished, this, [this, check_allow_update, mods] { + ui->actionUpdateItem->setEnabled(check_allow_update()); // Prevent a weird crash when trying to open the mods page twice in a session o.O disconnect(mods.get(), &ModFolderModel::updateFinished, this, 0);