Fixed icons

Also having a mod loader is now enforced
This commit is contained in:
timoreo 2022-01-14 20:22:15 +01:00
parent 9e6fa8f29a
commit 1a8c972aef
No known key found for this signature in database
GPG Key ID: 121A72C3512BA288
8 changed files with 43 additions and 30 deletions

View File

@ -34,7 +34,7 @@ protected:
private:
QUrl m_sourceUrl;
std::shared_ptr<NetJob> m_filesNetJob;
NetJob::Ptr m_filesNetJob;
const std::shared_ptr<ModFolderModel> mods;
const QString filename;

View File

@ -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");

View File

@ -31,8 +31,9 @@
#include "ModDownloadTask.h"
ModDownloadDialog::ModDownloadDialog(const std::shared_ptr<ModFolderModel>& mods, QWidget *parent)
: QDialog(parent), mods(mods)
ModDownloadDialog::ModDownloadDialog(const std::shared_ptr<ModFolderModel> &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<BasePage *> ModDownloadDialog::getPages()
{
modrinthPage = new ModrinthPage(this);
modrinthPage = new ModrinthPage(this, m_instance);
return
{
modrinthPage

View File

@ -37,7 +37,7 @@ class ModDownloadDialog : public QDialog, public BasePageProvider
Q_OBJECT
public:
explicit ModDownloadDialog(const std::shared_ptr<ModFolderModel>& mods, QWidget *parent = nullptr);
explicit ModDownloadDialog(const std::shared_ptr<ModFolderModel> &mods, QWidget *parent, BaseInstance *instance);
~ModDownloadDialog();
QString dialogTitle() override;
@ -63,4 +63,5 @@ private:
ModrinthPage *modrinthPage = nullptr;
std::unique_ptr<ModDownloadTask> modTask;
BaseInstance *m_instance;
};

View File

@ -349,25 +349,34 @@ void ModFolderPage::on_actionInstall_mods_triggered()
if(!m_controlsEnabled) {
return;
}
ModDownloadDialog mdownload(m_mods, this);
mdownload.exec();
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)
{
connect(task, &Task::failed, [this](QString reason) {
CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show();
});
connect(task, &Task::succeeded, [this, task]()
{
connect(task, &Task::succeeded, [this, task]() {
QStringList warnings = task->warnings();
if(warnings.count())
{
CustomMessageBox::selectable(this, tr("Warnings"), warnings.join('\n'), QMessageBox::Warning)->show();
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();
}
}
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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;
};