From c730fd6e5f125cde324d110282ed33ea4b9df136 Mon Sep 17 00:00:00 2001 From: flow Date: Sat, 2 Apr 2022 18:34:26 -0300 Subject: feat: Use version filter when searching mods --- launcher/modplatform/modrinth/ModrinthAPI.h | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'launcher/modplatform/modrinth/ModrinthAPI.h') diff --git a/launcher/modplatform/modrinth/ModrinthAPI.h b/launcher/modplatform/modrinth/ModrinthAPI.h index eefa4a85..0d652568 100644 --- a/launcher/modplatform/modrinth/ModrinthAPI.h +++ b/launcher/modplatform/modrinth/ModrinthAPI.h @@ -27,7 +27,7 @@ class ModrinthAPI : public NetworkModAPI { .arg(args.search) .arg(args.sorting) .arg(getModLoaderString(args.mod_loader)) - .arg(args.version); + .arg(getGameVersionsString(args.versions)); }; inline auto getVersionsURL(VersionSearchArgs& args) const -> QString override @@ -40,17 +40,6 @@ class ModrinthAPI : public NetworkModAPI { .arg(getModLoaderString(args.loader)); }; - inline auto getGameVersionsString(QList mcVersions) const -> QString - { - QString s; - for(int i = 0; i < mcVersions.count(); i++){ - s += mcVersions.at(i); - if(i < mcVersions.count() - 1) - s += ","; - } - return s; - } - static auto getModLoaderString(ModLoaderType type) -> const QString { if (type == Unspecified) -- cgit From 5cb0e750936f09513b98a8b0fd57746ca18dc8bc Mon Sep 17 00:00:00 2001 From: flow Date: Sat, 2 Apr 2022 19:21:02 -0300 Subject: fix(ui): Refresh mod list when changing filtering options --- launcher/modplatform/ModAPI.h | 5 ++--- launcher/modplatform/modrinth/ModrinthAPI.h | 14 ++++++++++++-- launcher/ui/pages/modplatform/ModModel.cpp | 14 ++++++++++---- launcher/ui/pages/modplatform/ModModel.h | 1 + launcher/ui/pages/modplatform/ModPage.cpp | 7 +++++++ 5 files changed, 32 insertions(+), 9 deletions(-) (limited to 'launcher/modplatform/modrinth/ModrinthAPI.h') diff --git a/launcher/modplatform/ModAPI.h b/launcher/modplatform/ModAPI.h index 6a906aa4..8e6cd45c 100644 --- a/launcher/modplatform/ModAPI.h +++ b/launcher/modplatform/ModAPI.h @@ -61,10 +61,9 @@ class ModAPI { { QString s; for(auto& ver : mcVersions){ - s += ver.toString(); - if(ver != mcVersions.back()) - s += ","; + s += QString("%1,").arg(ver.toString()); } + s.remove(s.length() - 1, 1); //remove last comma return s; } }; diff --git a/launcher/modplatform/modrinth/ModrinthAPI.h b/launcher/modplatform/modrinth/ModrinthAPI.h index 0d652568..87534ee9 100644 --- a/launcher/modplatform/modrinth/ModrinthAPI.h +++ b/launcher/modplatform/modrinth/ModrinthAPI.h @@ -22,12 +22,12 @@ class ModrinthAPI : public NetworkModAPI { "limit=25&" "query=%2&" "index=%3&" - "facets=[[\"categories:%4\"],[\"versions:%5\"],[\"project_type:mod\"]]") + "facets=[[\"categories:%4\"],[%5],[\"project_type:mod\"]]") .arg(args.offset) .arg(args.search) .arg(args.sorting) .arg(getModLoaderString(args.mod_loader)) - .arg(getGameVersionsString(args.versions)); + .arg(getGameVersionsArray(args.versions)); }; inline auto getVersionsURL(VersionSearchArgs& args) const -> QString override @@ -40,6 +40,16 @@ class ModrinthAPI : public NetworkModAPI { .arg(getModLoaderString(args.loader)); }; + auto getGameVersionsArray(std::list mcVersions) const -> QString + { + QString s; + for(auto& ver : mcVersions){ + s += QString("\"versions:%1\",").arg(ver.toString()); + } + s.remove(s.length() - 1, 1); //remove last comma + return s; + } + static auto getModLoaderString(ModLoaderType type) -> const QString { if (type == Unspecified) diff --git a/launcher/ui/pages/modplatform/ModModel.cpp b/launcher/ui/pages/modplatform/ModModel.cpp index 1998fe99..0ff784db 100644 --- a/launcher/ui/pages/modplatform/ModModel.cpp +++ b/launcher/ui/pages/modplatform/ModModel.cpp @@ -75,11 +75,8 @@ void ListModel::performPaginatedSearch() { nextSearchOffset, currentSearchTerm, getSorts()[currentSort], profile->getModLoader(), getMineVersions() }); } -void ListModel::searchWithTerm(const QString& term, const int sort) +void ListModel::refresh() { - if (currentSearchTerm == term && currentSearchTerm.isNull() == term.isNull() && currentSort == sort) { return; } - currentSearchTerm = term; - currentSort = sort; if (jobPtr) { jobPtr->abort(); searchState = ResetRequested; @@ -94,6 +91,15 @@ void ListModel::searchWithTerm(const QString& term, const int sort) performPaginatedSearch(); } +void ListModel::searchWithTerm(const QString& term, const int sort) +{ + if (currentSearchTerm == term && currentSearchTerm.isNull() == term.isNull() && currentSort == sort) { return; } + currentSearchTerm = term; + currentSort = sort; + + refresh(); +} + void ListModel::getLogo(const QString& logo, const QString& logoUrl, LogoCallback callback) { if (m_logoMap.contains(logo)) { diff --git a/launcher/ui/pages/modplatform/ModModel.h b/launcher/ui/pages/modplatform/ModModel.h index 1b7601c2..d4dc872d 100644 --- a/launcher/ui/pages/modplatform/ModModel.h +++ b/launcher/ui/pages/modplatform/ModModel.h @@ -34,6 +34,7 @@ class ListModel : public QAbstractListModel { /* Ask the API for more information */ void fetchMore(const QModelIndex& parent) override; + void refresh(); void searchWithTerm(const QString& term, const int sort); void requestModVersions(const ModPlatform::IndexedPack& current); diff --git a/launcher/ui/pages/modplatform/ModPage.cpp b/launcher/ui/pages/modplatform/ModPage.cpp index 16e44c0d..ece97ef2 100644 --- a/launcher/ui/pages/modplatform/ModPage.cpp +++ b/launcher/ui/pages/modplatform/ModPage.cpp @@ -62,6 +62,13 @@ void ModPage::filterMods() filter_dialog.execWithInstance(static_cast(m_instance)); m_filter = filter_dialog.getFilter(); + + listModel->refresh(); + + if(ui->versionSelectionBox->count() > 0){ + ui->versionSelectionBox->clear(); + updateModVersions(); + } } void ModPage::triggerSearch() -- cgit From 76dfb7825ade6554095ac3a09b3accdbd4db5138 Mon Sep 17 00:00:00 2001 From: flow Date: Sat, 2 Apr 2022 20:08:37 -0300 Subject: fix: 'All' filter working and get around CF API capabilities --- launcher/modplatform/flame/FlameAPI.h | 6 ++- launcher/modplatform/modrinth/ModrinthAPI.h | 4 +- launcher/ui/dialogs/FilterModsDialog.cpp | 31 +++++++++-- launcher/ui/dialogs/FilterModsDialog.h | 17 +++--- launcher/ui/dialogs/FilterModsDialog.ui | 62 +++------------------- launcher/ui/pages/modplatform/ModPage.cpp | 5 +- launcher/ui/pages/modplatform/ModPage.h | 2 +- .../ui/pages/modplatform/flame/FlameModPage.cpp | 19 +++++++ launcher/ui/pages/modplatform/flame/FlameModPage.h | 2 + 9 files changed, 74 insertions(+), 74 deletions(-) (limited to 'launcher/modplatform/modrinth/ModrinthAPI.h') diff --git a/launcher/modplatform/flame/FlameAPI.h b/launcher/modplatform/flame/FlameAPI.h index 690ee15c..9bcc357e 100644 --- a/launcher/modplatform/flame/FlameAPI.h +++ b/launcher/modplatform/flame/FlameAPI.h @@ -6,6 +6,8 @@ class FlameAPI : public NetworkModAPI { private: inline auto getModSearchURL(SearchArgs& args) const -> QString override { + auto gameVersionStr = args.versions.size() != 0 ? QString("gameVersion=%1").arg(args.versions.front().toString()) : QString(); + return QString( "https://addons-ecs.forgesvc.net/api/v2/addon/search?" "gameId=432&" @@ -17,12 +19,12 @@ class FlameAPI : public NetworkModAPI { "searchFilter=%2&" "sort=%3&" "modLoaderType=%4&" - "gameVersion=%5") + "%5") .arg(args.offset) .arg(args.search) .arg(args.sorting) .arg(args.mod_loader) - .arg(getGameVersionsString(args.versions)); + .arg(gameVersionStr); }; inline auto getVersionsURL(VersionSearchArgs& args) const -> QString override diff --git a/launcher/modplatform/modrinth/ModrinthAPI.h b/launcher/modplatform/modrinth/ModrinthAPI.h index 87534ee9..6604d772 100644 --- a/launcher/modplatform/modrinth/ModrinthAPI.h +++ b/launcher/modplatform/modrinth/ModrinthAPI.h @@ -22,7 +22,7 @@ class ModrinthAPI : public NetworkModAPI { "limit=25&" "query=%2&" "index=%3&" - "facets=[[\"categories:%4\"],[%5],[\"project_type:mod\"]]") + "facets=[[\"categories:%4\"],%5[\"project_type:mod\"]]") .arg(args.offset) .arg(args.search) .arg(args.sorting) @@ -47,7 +47,7 @@ class ModrinthAPI : public NetworkModAPI { s += QString("\"versions:%1\",").arg(ver.toString()); } s.remove(s.length() - 1, 1); //remove last comma - return s; + return s.isEmpty() ? QString() : QString("[%1],").arg(s); } static auto getModLoaderString(ModLoaderType type) -> const QString diff --git a/launcher/ui/dialogs/FilterModsDialog.cpp b/launcher/ui/dialogs/FilterModsDialog.cpp index a36f4ba4..bf4999e0 100644 --- a/launcher/ui/dialogs/FilterModsDialog.cpp +++ b/launcher/ui/dialogs/FilterModsDialog.cpp @@ -9,7 +9,7 @@ FilterModsDialog::FilterModsDialog(Version def, QWidget* parent) m_mcVersion_buttons.addButton(ui->strictVersionButton, VersionButtonID::Strict); m_mcVersion_buttons.addButton(ui->majorVersionButton, VersionButtonID::Major); m_mcVersion_buttons.addButton(ui->allVersionsButton, VersionButtonID::All); - m_mcVersion_buttons.addButton(ui->betweenVersionsButton, VersionButtonID::Between); + //m_mcVersion_buttons.addButton(ui->betweenVersionsButton, VersionButtonID::Between); connect(&m_mcVersion_buttons, SIGNAL(idClicked(int)), this, SLOT(onVersionFilterChanged(int))); @@ -31,18 +31,38 @@ int FilterModsDialog::execWithInstance(MinecraftInstance* instance) tr("Major varsion match (= %1.%2.x)").arg(mcVersionSplit[0], mcVersionSplit[1])); ui->allVersionsButton->setText( tr("Any version match")); - ui->betweenVersionsButton->setText( - tr("Between two versions")); + //ui->betweenVersionsButton->setText( + // tr("Between two versions")); int ret = QDialog::exec(); m_instance = nullptr; return ret; } +void FilterModsDialog::disableVersionButton(VersionButtonID id) +{ + switch(id){ + case(VersionButtonID::Strict): + ui->strictVersionButton->setEnabled(false); + break; + case(VersionButtonID::Major): + ui->majorVersionButton->setEnabled(false); + break; + case(VersionButtonID::All): + ui->allVersionsButton->setEnabled(false); + break; + case(VersionButtonID::Between): + // ui->betweenVersionsButton->setEnabled(false); + break; + default: + break; + } +} + void FilterModsDialog::onVersionFilterChanged(int id) { - ui->lowerVersionComboBox->setEnabled(id == VersionButtonID::Between); - ui->upperVersionComboBox->setEnabled(id == VersionButtonID::Between); + //ui->lowerVersionComboBox->setEnabled(id == VersionButtonID::Between); + //ui->upperVersionComboBox->setEnabled(id == VersionButtonID::Between); auto versionSplit = mcVersionStr().split("."); int index = 0; @@ -60,6 +80,7 @@ void FilterModsDialog::onVersionFilterChanged(int id) } break; case(VersionButtonID::All): + // Empty list to avoid enumerating all versions :P break; case(VersionButtonID::Between): // TODO diff --git a/launcher/ui/dialogs/FilterModsDialog.h b/launcher/ui/dialogs/FilterModsDialog.h index b119e8e5..3684b03c 100644 --- a/launcher/ui/dialogs/FilterModsDialog.h +++ b/launcher/ui/dialogs/FilterModsDialog.h @@ -17,6 +17,13 @@ class FilterModsDialog : public QDialog { Q_OBJECT public: + enum VersionButtonID { + Strict = 0, + Major = 1, + All = 2, + Between = 3 + }; + struct Filter { std::list versions; }; @@ -29,16 +36,12 @@ public: int execWithInstance(MinecraftInstance* instance); + /// By default all buttons are enabled + void disableVersionButton(VersionButtonID); + auto getFilter() -> std::shared_ptr { return m_filter; } private: - enum VersionButtonID { - Strict = 0, - Major = 1, - All = 2, - Between = 3 - }; - inline auto mcVersionStr() const -> QString { return m_instance ? m_instance->getPackProfile()->getComponentVersion("net.minecraft") : ""; } inline auto mcVersion() const -> Version { return { mcVersionStr() }; } diff --git a/launcher/ui/dialogs/FilterModsDialog.ui b/launcher/ui/dialogs/FilterModsDialog.ui index da368aac..67a63bfd 100644 --- a/launcher/ui/dialogs/FilterModsDialog.ui +++ b/launcher/ui/dialogs/FilterModsDialog.ui @@ -10,15 +10,17 @@ 0 0 345 - 323 + 169 - - Copy Instance + + + 0 + 0 + - - - :/icons/toolbar/copy:/icons/toolbar/copy + + Filter options true @@ -78,59 +80,11 @@ - - - - - - - - BetweenVersions - - - - - - - From - - - - - - - - - - To - - - - - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - diff --git a/launcher/ui/pages/modplatform/ModPage.cpp b/launcher/ui/pages/modplatform/ModPage.cpp index ece97ef2..ba56c3b8 100644 --- a/launcher/ui/pages/modplatform/ModPage.cpp +++ b/launcher/ui/pages/modplatform/ModPage.cpp @@ -64,7 +64,6 @@ void ModPage::filterMods() m_filter = filter_dialog.getFilter(); listModel->refresh(); - if(ui->versionSelectionBox->count() > 0){ ui->versionSelectionBox->clear(); updateModVersions(); @@ -164,14 +163,14 @@ void ModPage::updateModVersions() for (int i = 0; i < current.versions.size(); i++) { auto version = current.versions[i]; bool valid = false; - //NOTE: Flame doesn't care about loaderString, so passing it changes nothing. for(auto& mcVer : m_filter->versions){ + //NOTE: Flame doesn't care about loaderString, so passing it changes nothing. if (validateVersion(version, mcVer.toString(), loaderString)) { valid = true; break; } } - if(valid) + if(valid || m_filter->versions.size() == 0) ui->versionSelectionBox->addItem(version.version, QVariant(i)); } if (ui->versionSelectionBox->count() == 0) { ui->versionSelectionBox->addItem(tr("No valid version found!"), QVariant(-1)); } diff --git a/launcher/ui/pages/modplatform/ModPage.h b/launcher/ui/pages/modplatform/ModPage.h index 3c71e6fe..0befc7c3 100644 --- a/launcher/ui/pages/modplatform/ModPage.h +++ b/launcher/ui/pages/modplatform/ModPage.h @@ -54,7 +54,7 @@ class ModPage : public QWidget, public BasePage { void updateSelectionButton(); protected slots: - void filterMods(); + virtual void filterMods(); void triggerSearch(); void onSelectionChanged(QModelIndex first, QModelIndex second); void onVersionSelectionChanged(QString data); diff --git a/launcher/ui/pages/modplatform/flame/FlameModPage.cpp b/launcher/ui/pages/modplatform/flame/FlameModPage.cpp index 864ae8e6..5398bda3 100644 --- a/launcher/ui/pages/modplatform/flame/FlameModPage.cpp +++ b/launcher/ui/pages/modplatform/flame/FlameModPage.cpp @@ -67,6 +67,25 @@ auto FlameModPage::validateVersion(ModPlatform::IndexedVersion& ver, QString min return ver.mcVersion.contains(mineVer); } +// We override this so that it refreshes correctly, otherwise it wouldn't show +// any mod on the mod list, because the CF API does not support it :( +void FlameModPage::filterMods() +{ + filter_dialog.execWithInstance(static_cast(m_instance)); + + int prev_size = m_filter->versions.size(); + m_filter = filter_dialog.getFilter(); + int new_size = m_filter->versions.size(); + + if(new_size <= 1 && new_size != prev_size) + listModel->refresh(); + + if(ui->versionSelectionBox->count() > 0){ + ui->versionSelectionBox->clear(); + updateModVersions(); + } +} + // I don't know why, but doing this on the parent class makes it so that // other mod providers start loading before being selected, at least with // my Qt, so we need to implement this in every derived class... diff --git a/launcher/ui/pages/modplatform/flame/FlameModPage.h b/launcher/ui/pages/modplatform/flame/FlameModPage.h index dc58fd7f..7078e889 100644 --- a/launcher/ui/pages/modplatform/flame/FlameModPage.h +++ b/launcher/ui/pages/modplatform/flame/FlameModPage.h @@ -56,5 +56,7 @@ class FlameModPage : public ModPage { auto validateVersion(ModPlatform::IndexedVersion& ver, QString mineVer, QString loaderVer = "") const -> bool override; + void filterMods() override; + auto shouldDisplay() const -> bool override; }; -- cgit