diff options
author | timoreo <timo.oreo34@gmail.com> | 2022-01-15 08:51:47 +0100 |
---|---|---|
committer | timoreo <timo.oreo34@gmail.com> | 2022-01-15 08:51:47 +0100 |
commit | 4b37c46889cb8973d8eb8c22f0c45fe36fdb81cf (patch) | |
tree | 070b7bad81ec464eeb60de1ce4105636e245777e /launcher/ui/pages/modplatform/modrinth | |
parent | 2896f70cd83761a1248d55b28e2b5cc2cf465049 (diff) | |
download | PrismLauncher-4b37c46889cb8973d8eb8c22f0c45fe36fdb81cf.tar.gz PrismLauncher-4b37c46889cb8973d8eb8c22f0c45fe36fdb81cf.tar.bz2 PrismLauncher-4b37c46889cb8973d8eb8c22f0c45fe36fdb81cf.zip |
Filtering per mod loader & mc version
Diffstat (limited to 'launcher/ui/pages/modplatform/modrinth')
4 files changed, 27 insertions, 14 deletions
diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp index 0242465b..e7f66768 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp @@ -1,18 +1,19 @@ #include "ModrinthModel.h" #include "Application.h" +#include "minecraft/MinecraftInstance.h" +#include "minecraft/PackProfile.h" +#include "ModrinthPage.h" #include <Json.h> #include <MMCStrings.h> #include <Version.h> #include <QtMath> -#include <QLabel> -#include <RWStorage.h> namespace Modrinth { -ListModel::ListModel(QObject *parent) : QAbstractListModel(parent) +ListModel::ListModel(ModrinthPage *parent) : QAbstractListModel(parent) { } @@ -158,14 +159,18 @@ const char* sorts[4]{"relevance","downloads","updated","newest"}; void ListModel::performPaginatedSearch() { - NetJob *netJob = new NetJob("Modrinth::Search", APPLICATION->network()); + + QString mcVersion = ((MinecraftInstance *)((ModrinthPage *)parent())->m_instance)->getPackProfile()->getComponentVersion("net.minecraft"); + bool hasFabric = !((MinecraftInstance *)((ModrinthPage *)parent())->m_instance)->getPackProfile()->getComponentVersion("net.fabricmc.fabric-loader").isEmpty(); + auto netJob = new NetJob("Modrinth::Search", APPLICATION->network()); auto searchUrl = QString( "https://api.modrinth.com/api/v1/mod?" "offset=%1&" "limit=25&" "query=%2&" - "index=%3" - ).arg(nextSearchOffset).arg(currentSearchTerm).arg(sorts[currentSort]); + "index=%3&" + "filters=categories=\"%4\" AND versions=\"%5\"" + ).arg(nextSearchOffset).arg(currentSearchTerm).arg(sorts[currentSort]).arg(hasFabric ? "fabric" : "forge").arg(mcVersion); netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), &response)); jobPtr = netJob; jobPtr->start(); @@ -173,7 +178,7 @@ void ListModel::performPaginatedSearch() QObject::connect(netJob, &NetJob::failed, this, &ListModel::searchRequestFailed); } -void ListModel::searchWithTerm(const QString& term, int sort) +void ListModel::searchWithTerm(const QString &term, const int sort) { if(currentSearchTerm == term && currentSearchTerm.isNull() == term.isNull() && currentSort == sort) { return; diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.h b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.h index 7bd06f6a..53f1f134 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.h +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.h @@ -17,6 +17,8 @@ #include <modplatform/flame/FlamePackIndex.h> #include "modplatform/modrinth/ModrinthPackIndex.h" +#include "BaseInstance.h" +#include "ModrinthPage.h" namespace Modrinth { @@ -29,7 +31,7 @@ class ListModel : public QAbstractListModel Q_OBJECT public: - ListModel(QObject *parent); + ListModel(ModrinthPage *parent); virtual ~ListModel(); int rowCount(const QModelIndex &parent) const override; @@ -40,7 +42,7 @@ public: void fetchMore(const QModelIndex & parent) override; void getLogo(const QString &logo, const QString &logoUrl, LogoCallback callback); - void searchWithTerm(const QString & term, const int sort); + void searchWithTerm(const QString &term, const int sort); private slots: void performPaginatedSearch(); diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp index e72a57f6..96797062 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp @@ -9,11 +9,11 @@ #include "InstanceImportTask.h" #include "ModrinthModel.h" #include "ModDownloadTask.h" -#include "ui/pages/instance/ModFolderPage.h" +#include "minecraft/MinecraftInstance.h" #include "minecraft/PackProfile.h" ModrinthPage::ModrinthPage(ModDownloadDialog *dialog, BaseInstance *instance) - : QWidget(dialog), ui(new Ui::ModrinthPage), dialog(dialog), m_instance(instance) + : QWidget(dialog), m_instance(instance), ui(new Ui::ModrinthPage), dialog(dialog) { ui->setupUi(this); connect(ui->searchButton, &QPushButton::clicked, this, &ModrinthPage::triggerSearch); @@ -135,8 +135,13 @@ void ModrinthPage::onSelectionChanged(QModelIndex first, QModelIndex second) qDebug() << *response; qWarning() << "Error while reading Modrinth mod version: " << e.cause(); } - - for(auto version : current.versions) { + auto packProfile = ((MinecraftInstance *)m_instance)->getPackProfile(); + QString mcVersion = packProfile->getComponentVersion("net.minecraft"); + QString loaderString = (packProfile->getComponentVersion("net.minecraftforge").isEmpty()) ? "fabric" : "forge"; + for(const auto& version : current.versions) { + if(!version.mcVersion.contains(mcVersion) || !version.loaders.contains(loaderString)){ + continue; + } ui->versionSelectionBox->addItem(version.version, QVariant(version.downloadUrl)); } diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h index 8ff5cbe4..3748d836 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h @@ -47,6 +47,8 @@ public: bool eventFilter(QObject * watched, QEvent * event) override; + BaseInstance *m_instance; + private: void suggestCurrent(); @@ -62,5 +64,4 @@ private: Modrinth::IndexedPack current; QString selectedVersion; - BaseInstance *m_instance; }; |