From 5cb0e750936f09513b98a8b0fd57746ca18dc8bc Mon Sep 17 00:00:00 2001 From: flow Date: Sat, 2 Apr 2022 19:21:02 -0300 Subject: [PATCH] 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(-) 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()