From 9c6727e27f55dd888c8cfc5147fdf0f6f8378f46 Mon Sep 17 00:00:00 2001 From: flow Date: Mon, 21 Feb 2022 21:34:06 -0300 Subject: feat: change task container in ModDownloadDialog to a QHash Previously, we used a unique_ptr to a ModDownloadTask to keep track of the selected mod to download when we accepted the dialog. In order to allow multiple mods to be selected at once for download, this has been changed to a QHash where the key is the mods name (since it doesn't seem right to allow for multiple versions of the same mod to be downloaded at once), and the value is a pointer to the corresponding ModDownloadTask. --- launcher/ui/dialogs/ModDownloadDialog.cpp | 33 ++++++++++++++++++++++++++----- launcher/ui/dialogs/ModDownloadDialog.h | 8 +++++--- 2 files changed, 33 insertions(+), 8 deletions(-) (limited to 'launcher/ui/dialogs') diff --git a/launcher/ui/dialogs/ModDownloadDialog.cpp b/launcher/ui/dialogs/ModDownloadDialog.cpp index 6b807b8c..c2bf2d6f 100644 --- a/launcher/ui/dialogs/ModDownloadDialog.cpp +++ b/launcher/ui/dialogs/ModDownloadDialog.cpp @@ -52,6 +52,7 @@ ModDownloadDialog::ModDownloadDialog(const std::shared_ptr &mods HelpButton->setDefault(false); HelpButton->setAutoDefault(false); connect(HelpButton, &QPushButton::clicked, m_container, &PageContainer::help); + QMetaObject::connectSlotsByName(this); setWindowModality(Qt::WindowModal); setWindowTitle("Download mods"); @@ -83,16 +84,38 @@ QList ModDownloadDialog::getPages() }; } -void ModDownloadDialog::setSuggestedMod(const QString& name, ModDownloadTask* task) +void ModDownloadDialog::addSelectedMod(const QString& name, ModDownloadTask* task) +{ + if(modTask.contains(name)) + delete modTask.find(name).value(); + + if(task) + modTask.insert(name, task); + else + modTask.remove(name); + + m_buttons->button(QDialogButtonBox::Ok)->setEnabled(!modTask.isEmpty()); +} + +void ModDownloadDialog::removeSelectedMod(const QString &name) +{ + if(modTask.contains(name)) + delete modTask.find(name).value(); + modTask.remove(name); +} + +bool ModDownloadDialog::isModSelected(const QString &name, const QString& filename) const { - modTask.reset(task); - m_buttons->button(QDialogButtonBox::Ok)->setEnabled(task); + // FIXME: Is there a way to check for versions without checking the filename + // as a heuristic, other than adding such info to ModDownloadTask itself? + auto iter = modTask.find(name); + return iter != modTask.end() && (iter.value()->getFilename() == filename); } ModDownloadDialog::~ModDownloadDialog() { } -ModDownloadTask *ModDownloadDialog::getTask() { - return modTask.release(); +const QList ModDownloadDialog::getTasks() { + return modTask.values(); } diff --git a/launcher/ui/dialogs/ModDownloadDialog.h b/launcher/ui/dialogs/ModDownloadDialog.h index ece8e328..02870c6c 100644 --- a/launcher/ui/dialogs/ModDownloadDialog.h +++ b/launcher/ui/dialogs/ModDownloadDialog.h @@ -29,9 +29,11 @@ public: QString dialogTitle() override; QList getPages() override; - void setSuggestedMod(const QString & name = QString(), ModDownloadTask * task = nullptr); + void addSelectedMod(const QString & name = QString(), ModDownloadTask * task = nullptr); + void removeSelectedMod(const QString & name = QString()); + bool isModSelected(const QString & name, const QString & filename) const; - ModDownloadTask * getTask(); + const QList getTasks(); const std::shared_ptr &mods; public slots: @@ -49,6 +51,6 @@ private: ModrinthPage *modrinthPage = nullptr; FlameModPage *flameModPage = nullptr; - std::unique_ptr modTask; + QHash modTask; BaseInstance *m_instance; }; -- cgit From 0102e9194075a53c2816966afb9d12b84ed4c276 Mon Sep 17 00:00:00 2001 From: flow Date: Mon, 21 Feb 2022 23:00:50 -0300 Subject: feat: add confirm dialog for installing mods When selecting multiple mods at once, it can become hard to keep track of which ones you selected. To address this, a dialog is now displayed when you finish selecting the mods to download, showing you which ones you selected and their filenames. From there, you can either accept it and download the mods, or you can cancel it and go back to the mod selection dialog. --- launcher/ui/dialogs/ModDownloadDialog.cpp | 28 +++++++++++++++++++++++++++- launcher/ui/dialogs/ModDownloadDialog.h | 1 + 2 files changed, 28 insertions(+), 1 deletion(-) (limited to 'launcher/ui/dialogs') diff --git a/launcher/ui/dialogs/ModDownloadDialog.cpp b/launcher/ui/dialogs/ModDownloadDialog.cpp index c2bf2d6f..6240ecdc 100644 --- a/launcher/ui/dialogs/ModDownloadDialog.cpp +++ b/launcher/ui/dialogs/ModDownloadDialog.cpp @@ -5,6 +5,7 @@ #include #include "ProgressDialog.h" +#include "CustomMessageBox.h" #include #include @@ -41,7 +42,7 @@ ModDownloadDialog::ModDownloadDialog(const std::shared_ptr &mods auto OkButton = m_buttons->button(QDialogButtonBox::Ok); OkButton->setDefault(true); OkButton->setAutoDefault(true); - connect(OkButton, &QPushButton::clicked, this, &ModDownloadDialog::accept); + connect(OkButton, &QPushButton::clicked, this, &ModDownloadDialog::confirm); auto CancelButton = m_buttons->button(QDialogButtonBox::Cancel); CancelButton->setDefault(false); @@ -68,6 +69,31 @@ void ModDownloadDialog::reject() QDialog::reject(); } +void ModDownloadDialog::confirm() +{ + auto info = QString("You're about to download the following mods:\n\n"); + for(auto task : modTask.keys()){ + info.append(task); + info.append("\n --> File name: "); + info.append(modTask.find(task).value()->getFilename()); + info.append('\n'); + } + + auto confirm_dialog = CustomMessageBox::selectable( + this, + tr("Confirm mods to download"), + info, + QMessageBox::NoIcon, + {QMessageBox::Cancel, QMessageBox::Ok}, + QMessageBox::Ok + ); + + auto AcceptButton = confirm_dialog->button(QMessageBox::Ok); + connect(AcceptButton, &QPushButton::clicked, this, &ModDownloadDialog::accept); + + confirm_dialog->open(); +} + void ModDownloadDialog::accept() { QDialog::accept(); diff --git a/launcher/ui/dialogs/ModDownloadDialog.h b/launcher/ui/dialogs/ModDownloadDialog.h index 02870c6c..309d89d0 100644 --- a/launcher/ui/dialogs/ModDownloadDialog.h +++ b/launcher/ui/dialogs/ModDownloadDialog.h @@ -37,6 +37,7 @@ public: const std::shared_ptr &mods; public slots: + void confirm(); void accept() override; void reject() override; -- cgit From f8b0d6453ae81488ddfd4c83b329e2c88787c49e Mon Sep 17 00:00:00 2001 From: flow Date: Mon, 21 Feb 2022 23:25:33 -0300 Subject: fix: sort mod list in confirmation dialog --- launcher/ui/dialogs/ModDownloadDialog.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'launcher/ui/dialogs') diff --git a/launcher/ui/dialogs/ModDownloadDialog.cpp b/launcher/ui/dialogs/ModDownloadDialog.cpp index 6240ecdc..439f22c4 100644 --- a/launcher/ui/dialogs/ModDownloadDialog.cpp +++ b/launcher/ui/dialogs/ModDownloadDialog.cpp @@ -71,8 +71,11 @@ void ModDownloadDialog::reject() void ModDownloadDialog::confirm() { + auto keys = modTask.keys(); + keys.sort(Qt::CaseInsensitive); + auto info = QString("You're about to download the following mods:\n\n"); - for(auto task : modTask.keys()){ + for(auto task : keys){ info.append(task); info.append("\n --> File name: "); info.append(modTask.find(task).value()->getFilename()); -- cgit From 04840d0638f933416a0d14b2ef822c6f8da5e373 Mon Sep 17 00:00:00 2001 From: flow Date: Wed, 23 Feb 2022 14:44:55 -0300 Subject: fix(ui): add translation func to text in the confirm dialog --- launcher/ui/dialogs/ModDownloadDialog.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'launcher/ui/dialogs') diff --git a/launcher/ui/dialogs/ModDownloadDialog.cpp b/launcher/ui/dialogs/ModDownloadDialog.cpp index 439f22c4..a56c2e64 100644 --- a/launcher/ui/dialogs/ModDownloadDialog.cpp +++ b/launcher/ui/dialogs/ModDownloadDialog.cpp @@ -74,10 +74,12 @@ void ModDownloadDialog::confirm() auto keys = modTask.keys(); keys.sort(Qt::CaseInsensitive); - auto info = QString("You're about to download the following mods:\n\n"); + auto info = QString(tr("You're about to download the following mods:")); + info.append("\n\n"); for(auto task : keys){ info.append(task); - info.append("\n --> File name: "); + info.append("\n --> "); + info.append(tr("File name: ")); info.append(modTask.find(task).value()->getFilename()); info.append('\n'); } -- cgit From 40a9828fbab0e9a8b7f070714bdd87d3f279e18c Mon Sep 17 00:00:00 2001 From: flow Date: Wed, 23 Feb 2022 19:17:33 -0300 Subject: fix: improve readability and set ok button as disabled by default --- launcher/ui/dialogs/ModDownloadDialog.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'launcher/ui/dialogs') diff --git a/launcher/ui/dialogs/ModDownloadDialog.cpp b/launcher/ui/dialogs/ModDownloadDialog.cpp index a56c2e64..23ca8731 100644 --- a/launcher/ui/dialogs/ModDownloadDialog.cpp +++ b/launcher/ui/dialogs/ModDownloadDialog.cpp @@ -40,6 +40,7 @@ ModDownloadDialog::ModDownloadDialog(const std::shared_ptr &mods // Bonk Qt over its stupid head and make sure it understands which button is the default one... // See: https://stackoverflow.com/questions/24556831/qbuttonbox-set-default-button auto OkButton = m_buttons->button(QDialogButtonBox::Ok); + OkButton->setEnabled(false); OkButton->setDefault(true); OkButton->setAutoDefault(true); connect(OkButton, &QPushButton::clicked, this, &ModDownloadDialog::confirm); @@ -89,7 +90,7 @@ void ModDownloadDialog::confirm() tr("Confirm mods to download"), info, QMessageBox::NoIcon, - {QMessageBox::Cancel, QMessageBox::Ok}, + QMessageBox::Cancel | QMessageBox::Ok, QMessageBox::Ok ); @@ -117,13 +118,8 @@ QList ModDownloadDialog::getPages() void ModDownloadDialog::addSelectedMod(const QString& name, ModDownloadTask* task) { - if(modTask.contains(name)) - delete modTask.find(name).value(); - - if(task) - modTask.insert(name, task); - else - modTask.remove(name); + removeSelectedMod(name); + modTask.insert(name, task); m_buttons->button(QDialogButtonBox::Ok)->setEnabled(!modTask.isEmpty()); } @@ -133,6 +129,8 @@ void ModDownloadDialog::removeSelectedMod(const QString &name) if(modTask.contains(name)) delete modTask.find(name).value(); modTask.remove(name); + + m_buttons->button(QDialogButtonBox::Ok)->setEnabled(!modTask.isEmpty()); } bool ModDownloadDialog::isModSelected(const QString &name, const QString& filename) const -- cgit