diff options
author | flow <thiagodonato300@gmail.com> | 2022-02-21 21:34:53 -0300 |
---|---|---|
committer | flow <thiagodonato300@gmail.com> | 2022-02-21 21:34:53 -0300 |
commit | 512395e3f1ada7e16fa547f7fbe050e20a6d3209 (patch) | |
tree | 6cd42c8dc55560f446b7d0f74bb6e723f813055f /launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp | |
parent | 9c6727e27f55dd888c8cfc5147fdf0f6f8378f46 (diff) | |
download | PrismLauncher-512395e3f1ada7e16fa547f7fbe050e20a6d3209.tar.gz PrismLauncher-512395e3f1ada7e16fa547f7fbe050e20a6d3209.tar.bz2 PrismLauncher-512395e3f1ada7e16fa547f7fbe050e20a6d3209.zip |
feat(ui): allow downloading multiple mods in Modrinth at once
Diffstat (limited to 'launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp')
-rw-r--r-- | launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp | 54 |
1 files changed, 35 insertions, 19 deletions
diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp index c5a54c29..5b209fa3 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp @@ -34,6 +34,7 @@ ModrinthPage::ModrinthPage(ModDownloadDialog *dialog, BaseInstance *instance) connect(ui->sortByBox, SIGNAL(currentIndexChanged(int)), this, SLOT(triggerSearch())); connect(ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &ModrinthPage::onSelectionChanged); connect(ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &ModrinthPage::onVersionSelectionChanged); + connect(ui->modSelectionButton, &QPushButton::clicked, this, &ModrinthPage::onModSelected); } ModrinthPage::~ModrinthPage() @@ -61,7 +62,7 @@ bool ModrinthPage::shouldDisplay() const void ModrinthPage::openedImpl() { - suggestCurrent(); + updateSelectionButton(); triggerSearch(); } @@ -76,10 +77,6 @@ void ModrinthPage::onSelectionChanged(QModelIndex first, QModelIndex second) if(!first.isValid()) { - if(isOpened) - { - dialog->setSuggestedMod(); - } return; } @@ -97,6 +94,10 @@ void ModrinthPage::onSelectionChanged(QModelIndex first, QModelIndex second) if (!current.versionsLoaded) { qDebug() << "Loading Modrinth mod versions"; + + ui->modSelectionButton->setText(tr("Loading versions...")); + ui->modSelectionButton->setEnabled(false); + auto netJob = new NetJob(QString("Modrinth::ModVersions(%1)").arg(current.name), APPLICATION->network()); std::shared_ptr<QByteArray> response = std::make_shared<QByteArray>(); QString addonId = current.addonId; @@ -136,8 +137,9 @@ void ModrinthPage::onSelectionChanged(QModelIndex first, QModelIndex second) ui->versionSelectionBox->addItem(tr("No Valid Version found !"), QVariant(-1)); } - suggestCurrent(); + updateSelectionButton(); }); + netJob->start(); } else @@ -148,33 +150,47 @@ void ModrinthPage::onSelectionChanged(QModelIndex first, QModelIndex second) if(ui->versionSelectionBox->count() == 0){ ui->versionSelectionBox->addItem(tr("No Valid Version found !"), QVariant(-1)); } - suggestCurrent(); + + updateSelectionButton(); } } -void ModrinthPage::suggestCurrent() +void ModrinthPage::updateSelectionButton() { - if(!isOpened) - { + if(!isOpened || selectedVersion < 0){ + ui->modSelectionButton->setEnabled(false); return; } - if (selectedVersion == -1) - { - dialog->setSuggestedMod(); - return; + ui->modSelectionButton->setEnabled(true); + auto& version = current.versions[selectedVersion]; + if(!dialog->isModSelected(current.name, version.fileName)){ + ui->modSelectionButton->setText(tr("Select mod for download")); + } + else{ + ui->modSelectionButton->setText(tr("Deselect mod for download")); } - auto version = current.versions[selectedVersion]; - dialog->setSuggestedMod(current.name, new ModDownloadTask(version.downloadUrl, version.fileName , dialog->mods)); } void ModrinthPage::onVersionSelectionChanged(QString data) { - if(data.isNull() || data.isEmpty()) - { + if (data.isNull() || data.isEmpty()){ selectedVersion = -1; return; } selectedVersion = ui->versionSelectionBox->currentData().toInt(); - suggestCurrent(); + updateSelectionButton(); +} + +void ModrinthPage::onModSelected() +{ + auto& version = current.versions[selectedVersion]; + if (dialog->isModSelected(current.name, version.fileName)){ + dialog->removeSelectedMod(current.name); + } + else{ + dialog->addSelectedMod(current.name, new ModDownloadTask(version.downloadUrl, version.fileName , dialog->mods)); + } + + updateSelectionButton(); } |