From 1a8c972aefae75ee91295ea5a926cca71d95140a Mon Sep 17 00:00:00 2001 From: timoreo Date: Fri, 14 Jan 2022 20:22:15 +0100 Subject: [PATCH] Fixed icons Also having a mod loader is now enforced --- launcher/ModDownloadTask.h | 2 +- .../modrinth/ModrinthPackIndex.cpp | 2 +- launcher/ui/dialogs/ModDownloadDialog.cpp | 7 +-- launcher/ui/dialogs/ModDownloadDialog.h | 3 +- launcher/ui/pages/instance/ModFolderPage.cpp | 47 +++++++++++-------- .../modplatform/modrinth/ModrinthModel.cpp | 3 +- .../modplatform/modrinth/ModrinthPage.cpp | 6 ++- .../pages/modplatform/modrinth/ModrinthPage.h | 3 +- 8 files changed, 43 insertions(+), 30 deletions(-) diff --git a/launcher/ModDownloadTask.h b/launcher/ModDownloadTask.h index 8b39917c7..950a4048b 100644 --- a/launcher/ModDownloadTask.h +++ b/launcher/ModDownloadTask.h @@ -34,7 +34,7 @@ protected: private: QUrl m_sourceUrl; - std::shared_ptr m_filesNetJob; + NetJob::Ptr m_filesNetJob; const std::shared_ptr mods; const QString filename; diff --git a/launcher/modplatform/modrinth/ModrinthPackIndex.cpp b/launcher/modplatform/modrinth/ModrinthPackIndex.cpp index fbfaeac87..89e827b45 100644 --- a/launcher/modplatform/modrinth/ModrinthPackIndex.cpp +++ b/launcher/modplatform/modrinth/ModrinthPackIndex.cpp @@ -12,7 +12,7 @@ void Modrinth::loadIndexedPack(Modrinth::IndexedPack & pack, QJsonObject & obj) pack.description = Json::ensureString(obj, "description", ""); pack.logoUrl = Json::requireString(obj, "icon_url"); - pack.logoName = "logoName"; + pack.logoName = pack.addonId; Modrinth::ModpackAuthor packAuthor; packAuthor.name = Json::requireString(obj, "author"); diff --git a/launcher/ui/dialogs/ModDownloadDialog.cpp b/launcher/ui/dialogs/ModDownloadDialog.cpp index 3b4e11e52..ac5639e05 100644 --- a/launcher/ui/dialogs/ModDownloadDialog.cpp +++ b/launcher/ui/dialogs/ModDownloadDialog.cpp @@ -31,8 +31,9 @@ #include "ModDownloadTask.h" -ModDownloadDialog::ModDownloadDialog(const std::shared_ptr& mods, QWidget *parent) - : QDialog(parent), mods(mods) +ModDownloadDialog::ModDownloadDialog(const std::shared_ptr &mods, QWidget *parent, + BaseInstance *instance) + : QDialog(parent), mods(mods), m_instance(instance) { setObjectName(QStringLiteral("ModDownloadDialog")); resize(400, 347); @@ -88,7 +89,7 @@ void ModDownloadDialog::accept() QList ModDownloadDialog::getPages() { - modrinthPage = new ModrinthPage(this); + modrinthPage = new ModrinthPage(this, m_instance); return { modrinthPage diff --git a/launcher/ui/dialogs/ModDownloadDialog.h b/launcher/ui/dialogs/ModDownloadDialog.h index ac40257d3..7b2d18a08 100644 --- a/launcher/ui/dialogs/ModDownloadDialog.h +++ b/launcher/ui/dialogs/ModDownloadDialog.h @@ -37,7 +37,7 @@ class ModDownloadDialog : public QDialog, public BasePageProvider Q_OBJECT public: - explicit ModDownloadDialog(const std::shared_ptr& mods, QWidget *parent = nullptr); + explicit ModDownloadDialog(const std::shared_ptr &mods, QWidget *parent, BaseInstance *instance); ~ModDownloadDialog(); QString dialogTitle() override; @@ -63,4 +63,5 @@ private: ModrinthPage *modrinthPage = nullptr; std::unique_ptr modTask; + BaseInstance *m_instance; }; diff --git a/launcher/ui/pages/instance/ModFolderPage.cpp b/launcher/ui/pages/instance/ModFolderPage.cpp index d2f5deadc..7ebf66f61 100644 --- a/launcher/ui/pages/instance/ModFolderPage.cpp +++ b/launcher/ui/pages/instance/ModFolderPage.cpp @@ -349,25 +349,34 @@ void ModFolderPage::on_actionInstall_mods_triggered() if(!m_controlsEnabled) { return; } - ModDownloadDialog mdownload(m_mods, this); - mdownload.exec(); - ModDownloadTask * task = mdownload.getTask(); - if(task){ - connect(task, &Task::failed, [this](QString reason) - { - CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show(); - }); - connect(task, &Task::succeeded, [this, task]() - { - QStringList warnings = task->warnings(); - if(warnings.count()) - { - CustomMessageBox::selectable(this, tr("Warnings"), warnings.join('\n'), QMessageBox::Warning)->show(); - } - }); - ProgressDialog loadDialog(this); - loadDialog.setSkipButton(true, tr("Abort")); - loadDialog.execWithTask(task); + if(m_inst->typeName() != "Minecraft"){ + return; //this is a null instance or a legacy instance + } + bool hasFabric = !((MinecraftInstance *)m_inst)->getPackProfile()->getComponentVersion("net.fabricmc.fabric-loader").isEmpty(); + bool hasForge = !((MinecraftInstance *)m_inst)->getPackProfile()->getComponentVersion("net.minecraftforge").isEmpty(); + if (!hasFabric && !hasForge) { + QMessageBox::critical(this,tr("Error"),tr("Please install a mod loader first !")); + return; + } + ModDownloadDialog mdownload(m_mods, this, m_inst); + if(mdownload.exec()) { + ModDownloadTask *task = mdownload.getTask(); + if (task) { + connect(task, &Task::failed, [this](QString reason) { + CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show(); + }); + connect(task, &Task::succeeded, [this, task]() { + QStringList warnings = task->warnings(); + if (warnings.count()) { + CustomMessageBox::selectable(this, tr("Warnings"), warnings.join('\n'), + QMessageBox::Warning)->show(); + } + }); + ProgressDialog loadDialog(this); + loadDialog.setSkipButton(true, tr("Abort")); + loadDialog.execWithTask(task); + m_mods->update(); + } } } diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp index 3bc70e34b..0242465b9 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp @@ -100,7 +100,7 @@ void ListModel::requestLogo(QString logo, QString url) } MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry("ModrinthPacks", QString("logos/%1").arg(logo.section(".", 0, 0))); - NetJob *job = new NetJob(QString("Modrinth Icon Download %1").arg(logo), APPLICATION->network()); + auto job = new NetJob(QString("Modrinth Icon Download %1").arg(logo), APPLICATION->network()); job->addNetAction(Net::Download::makeCached(QUrl(url), entry)); auto fullPath = entry->getFullPath(); @@ -119,7 +119,6 @@ void ListModel::requestLogo(QString logo, QString url) }); job->start(); - m_loadingLogos.append(logo); } diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp index b68597acd..e72a57f65 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp @@ -9,9 +9,11 @@ #include "InstanceImportTask.h" #include "ModrinthModel.h" #include "ModDownloadTask.h" +#include "ui/pages/instance/ModFolderPage.h" +#include "minecraft/PackProfile.h" -ModrinthPage::ModrinthPage(ModDownloadDialog* dialog, QWidget *parent) - : QWidget(parent), ui(new Ui::ModrinthPage), dialog(dialog) +ModrinthPage::ModrinthPage(ModDownloadDialog *dialog, BaseInstance *instance) + : QWidget(dialog), ui(new Ui::ModrinthPage), dialog(dialog), m_instance(instance) { ui->setupUi(this); connect(ui->searchButton, &QPushButton::clicked, this, &ModrinthPage::triggerSearch); diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h index 1f7b12aff..59671d0e2 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h @@ -38,7 +38,7 @@ class ModrinthPage : public QWidget, public BasePage Q_OBJECT public: - explicit ModrinthPage(ModDownloadDialog* dialog, QWidget *parent = 0); + explicit ModrinthPage(ModDownloadDialog *dialog, BaseInstance *instance); virtual ~ModrinthPage(); virtual QString displayName() const override { @@ -77,4 +77,5 @@ private: Modrinth::IndexedPack current; QString selectedVersion; + BaseInstance *m_instance; };