From c2b97c3e3f5ecb5a995b342c4e0afec6a1a3b2f6 Mon Sep 17 00:00:00 2001 From: flow Date: Sat, 2 Apr 2022 18:33:50 -0300 Subject: feat: Integrate newly created filter dialog in ModPage --- launcher/ui/pages/modplatform/ModPage.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'launcher/ui/pages/modplatform/ModPage.h') diff --git a/launcher/ui/pages/modplatform/ModPage.h b/launcher/ui/pages/modplatform/ModPage.h index 0cd13f37..3c71e6fe 100644 --- a/launcher/ui/pages/modplatform/ModPage.h +++ b/launcher/ui/pages/modplatform/ModPage.h @@ -5,6 +5,7 @@ #include "Application.h" #include "modplatform/ModAPI.h" #include "modplatform/ModIndex.h" +#include "ui/dialogs/FilterModsDialog.h" #include "ui/pages/BasePage.h" #include "ui/pages/modplatform/ModModel.h" @@ -39,6 +40,7 @@ class ModPage : public QWidget, public BasePage { virtual auto validateVersion(ModPlatform::IndexedVersion& ver, QString mineVer, QString loaderVer = "") const -> bool = 0; auto apiProvider() const -> const ModAPI* { return api.get(); }; + auto getFilter() const -> const std::shared_ptr { return m_filter; } auto getCurrent() -> ModPlatform::IndexedPack& { return current; } void updateModVersions(); @@ -52,6 +54,7 @@ class ModPage : public QWidget, public BasePage { void updateSelectionButton(); protected slots: + void filterMods(); void triggerSearch(); void onSelectionChanged(QModelIndex first, QModelIndex second); void onVersionSelectionChanged(QString data); @@ -60,6 +63,10 @@ class ModPage : public QWidget, public BasePage { protected: Ui::ModPage* ui = nullptr; ModDownloadDialog* dialog = nullptr; + + FilterModsDialog filter_dialog; + std::shared_ptr m_filter; + ModPlatform::ListModel* listModel = nullptr; ModPlatform::IndexedPack current; -- 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/ui/pages/modplatform/ModPage.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 From 63bce0464895236a043aa8a98e2905ab1bf34cc1 Mon Sep 17 00:00:00 2001 From: flow Date: Sun, 3 Apr 2022 10:21:48 -0300 Subject: fix: Polish usage in some cases Also fiz some typos --- launcher/ui/dialogs/FilterModsDialog.cpp | 42 +++++++++++++++++----- launcher/ui/dialogs/FilterModsDialog.h | 8 +++++ launcher/ui/pages/modplatform/ModPage.cpp | 19 +++++----- launcher/ui/pages/modplatform/ModPage.h | 2 +- .../ui/pages/modplatform/flame/FlameModPage.cpp | 20 +++++------ 5 files changed, 64 insertions(+), 27 deletions(-) (limited to 'launcher/ui/pages/modplatform/ModPage.h') diff --git a/launcher/ui/dialogs/FilterModsDialog.cpp b/launcher/ui/dialogs/FilterModsDialog.cpp index bf4999e0..9440d897 100644 --- a/launcher/ui/dialogs/FilterModsDialog.cpp +++ b/launcher/ui/dialogs/FilterModsDialog.cpp @@ -2,7 +2,7 @@ #include "ui_FilterModsDialog.h" FilterModsDialog::FilterModsDialog(Version def, QWidget* parent) - : QDialog(parent), m_filter(new Filter()), ui(new Ui::FilterModsDialog) + : QDialog(parent), m_filter(new Filter()), m_internal_filter(new Filter()), ui(new Ui::FilterModsDialog) { ui->setupUi(this); @@ -13,28 +13,44 @@ FilterModsDialog::FilterModsDialog(Version def, QWidget* parent) connect(&m_mcVersion_buttons, SIGNAL(idClicked(int)), this, SLOT(onVersionFilterChanged(int))); - m_filter->versions.push_front(def); + m_internal_filter->versions.push_front(def); + commitChanges(); } int FilterModsDialog::execWithInstance(MinecraftInstance* instance) { m_instance = instance; + auto* pressed_button = m_mcVersion_buttons.checkedButton(); + // Fix first openening behaviour - onVersionFilterChanged(0); + onVersionFilterChanged(m_previous_mcVersion_id); auto mcVersionSplit = mcVersionStr().split("."); ui->strictVersionButton->setText( tr("Strict match (= %1)").arg(mcVersionStr())); ui->majorVersionButton->setText( - tr("Major varsion match (= %1.%2.x)").arg(mcVersionSplit[0], mcVersionSplit[1])); + tr("Major version match (= %1.%2.x)").arg(mcVersionSplit[0], mcVersionSplit[1])); ui->allVersionsButton->setText( - tr("Any version match")); + tr("Any version")); //ui->betweenVersionsButton->setText( // tr("Between two versions")); int ret = QDialog::exec(); + + if(ret == QDialog::DialogCode::Accepted){ + // If there's no change, let's sey it's a cancel to the caller + if(*m_internal_filter.get() == *m_filter.get()) + return QDialog::DialogCode::Rejected; + + m_previous_mcVersion_id = (VersionButtonID) m_mcVersion_buttons.checkedId(); + commitChanges(); + } else { + pressed_button->click(); + revertChanges(); + } + m_instance = nullptr; return ret; } @@ -59,6 +75,16 @@ void FilterModsDialog::disableVersionButton(VersionButtonID id) } } +// Do deep copy +void FilterModsDialog::commitChanges() +{ + m_filter->versions = m_internal_filter->versions; +} +void FilterModsDialog::revertChanges() +{ + m_internal_filter->versions = m_filter->versions; +} + void FilterModsDialog::onVersionFilterChanged(int id) { //ui->lowerVersionComboBox->setEnabled(id == VersionButtonID::Between); @@ -67,15 +93,15 @@ void FilterModsDialog::onVersionFilterChanged(int id) auto versionSplit = mcVersionStr().split("."); int index = 0; - m_filter->versions.clear(); + m_internal_filter->versions.clear(); switch(id){ case(VersionButtonID::Strict): - m_filter->versions.push_front(mcVersion()); + m_internal_filter->versions.push_front(mcVersion()); break; case(VersionButtonID::Major): for(auto i = Version(QString("%1.%2").arg(versionSplit[0], versionSplit[1])); i <= mcVersion(); index++){ - m_filter->versions.push_front(i); + m_internal_filter->versions.push_front(i); i = Version(QString("%1.%2.%3").arg(versionSplit[0], versionSplit[1], QString("%1").arg(index))); } break; diff --git a/launcher/ui/dialogs/FilterModsDialog.h b/launcher/ui/dialogs/FilterModsDialog.h index 3684b03c..fac28ca4 100644 --- a/launcher/ui/dialogs/FilterModsDialog.h +++ b/launcher/ui/dialogs/FilterModsDialog.h @@ -26,9 +26,13 @@ public: struct Filter { std::list versions; + + bool operator==(const Filter& other) const { return versions == other.versions; } + bool operator!=(const Filter& other) const { return !(*this == other); } }; std::shared_ptr m_filter; + std::shared_ptr m_internal_filter; public: explicit FilterModsDialog(Version def, QWidget* parent = nullptr); @@ -45,6 +49,9 @@ private: inline auto mcVersionStr() const -> QString { return m_instance ? m_instance->getPackProfile()->getComponentVersion("net.minecraft") : ""; } inline auto mcVersion() const -> Version { return { mcVersionStr() }; } + void commitChanges(); + void revertChanges(); + private slots: void onVersionFilterChanged(int id); @@ -54,4 +61,5 @@ private: MinecraftInstance* m_instance = nullptr; QButtonGroup m_mcVersion_buttons; + VersionButtonID m_previous_mcVersion_id = VersionButtonID::Strict; }; diff --git a/launcher/ui/pages/modplatform/ModPage.cpp b/launcher/ui/pages/modplatform/ModPage.cpp index ba56c3b8..37f68291 100644 --- a/launcher/ui/pages/modplatform/ModPage.cpp +++ b/launcher/ui/pages/modplatform/ModPage.cpp @@ -59,14 +59,15 @@ auto ModPage::eventFilter(QObject* watched, QEvent* event) -> bool void ModPage::filterMods() { - filter_dialog.execWithInstance(static_cast(m_instance)); - + auto ret = filter_dialog.execWithInstance(static_cast(m_instance)); m_filter = filter_dialog.getFilter(); - listModel->refresh(); - if(ui->versionSelectionBox->count() > 0){ + if(ret == QDialog::DialogCode::Accepted){ + listModel->refresh(); + + int prev_count = ui->versionSelectionBox->count(); ui->versionSelectionBox->clear(); - updateModVersions(); + updateModVersions(prev_count); } } @@ -152,7 +153,7 @@ void ModPage::retranslate() ui->retranslateUi(this); } -void ModPage::updateModVersions() +void ModPage::updateModVersions(int prev_count) { auto packProfile = (dynamic_cast(m_instance))->getPackProfile(); @@ -173,9 +174,11 @@ void ModPage::updateModVersions() 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)); } + if (ui->versionSelectionBox->count() == 0 && prev_count != 0) { + ui->versionSelectionBox->addItem(tr("No valid version found!"), QVariant(-1)); + ui->modSelectionButton->setText(tr("Cannot select invalid version :(")); + } - ui->modSelectionButton->setText(tr("Cannot select invalid version :(")); updateSelectionButton(); } diff --git a/launcher/ui/pages/modplatform/ModPage.h b/launcher/ui/pages/modplatform/ModPage.h index 0befc7c3..06581ab2 100644 --- a/launcher/ui/pages/modplatform/ModPage.h +++ b/launcher/ui/pages/modplatform/ModPage.h @@ -43,7 +43,7 @@ class ModPage : public QWidget, public BasePage { auto getFilter() const -> const std::shared_ptr { return m_filter; } auto getCurrent() -> ModPlatform::IndexedPack& { return current; } - void updateModVersions(); + void updateModVersions(int prev_count = -1); void openedImpl() override; auto eventFilter(QObject* watched, QEvent* event) -> bool override; diff --git a/launcher/ui/pages/modplatform/flame/FlameModPage.cpp b/launcher/ui/pages/modplatform/flame/FlameModPage.cpp index 5398bda3..6e666c4c 100644 --- a/launcher/ui/pages/modplatform/flame/FlameModPage.cpp +++ b/launcher/ui/pages/modplatform/flame/FlameModPage.cpp @@ -67,22 +67,22 @@ 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 :( +// We override this so that it refreshes correctly, otherwise it would show +// invalid mods on the mod list, because the API would return mods for the +// wrong mod loader :( void FlameModPage::filterMods() { - filter_dialog.execWithInstance(static_cast(m_instance)); - - int prev_size = m_filter->versions.size(); + auto ret = filter_dialog.execWithInstance(static_cast(m_instance)); m_filter = filter_dialog.getFilter(); - int new_size = m_filter->versions.size(); - if(new_size <= 1 && new_size != prev_size) - listModel->refresh(); + if(ret == QDialog::DialogCode::Accepted){ + // CF API can't handle well this + if(!m_filter->versions.empty()) + listModel->refresh(); - if(ui->versionSelectionBox->count() > 0){ + int prev_count = ui->versionSelectionBox->count(); ui->versionSelectionBox->clear(); - updateModVersions(); + updateModVersions(prev_count); } } -- cgit From 277de4120052b2630850a18969a56ee92e8c2c63 Mon Sep 17 00:00:00 2001 From: flow Date: Thu, 14 Apr 2022 10:27:03 -0300 Subject: rework: make the filter as a tabbed widget in the dialog itself Still needs a clear indication that the filter only applies after you click the search button... --- launcher/ui/dialogs/FilterModsDialog.cpp | 122 ------------------- launcher/ui/dialogs/FilterModsDialog.h | 65 ---------- launcher/ui/dialogs/FilterModsDialog.ui | 135 --------------------- launcher/ui/pages/modplatform/ModModel.cpp | 9 +- launcher/ui/pages/modplatform/ModModel.h | 2 +- launcher/ui/pages/modplatform/ModPage.cpp | 30 +++-- launcher/ui/pages/modplatform/ModPage.h | 8 +- launcher/ui/pages/modplatform/ModPage.ui | 27 +++-- .../ui/pages/modplatform/flame/FlameModPage.cpp | 19 --- launcher/ui/pages/modplatform/flame/FlameModPage.h | 2 - launcher/ui/widgets/ModFilterWidget.cpp | 99 +++++++++++++++ launcher/ui/widgets/ModFilterWidget.h | 65 ++++++++++ launcher/ui/widgets/ModFilterWidget.ui | 54 +++++++++ 13 files changed, 264 insertions(+), 373 deletions(-) delete mode 100644 launcher/ui/dialogs/FilterModsDialog.cpp delete mode 100644 launcher/ui/dialogs/FilterModsDialog.h delete mode 100644 launcher/ui/dialogs/FilterModsDialog.ui create mode 100644 launcher/ui/widgets/ModFilterWidget.cpp create mode 100644 launcher/ui/widgets/ModFilterWidget.h create mode 100644 launcher/ui/widgets/ModFilterWidget.ui (limited to 'launcher/ui/pages/modplatform/ModPage.h') diff --git a/launcher/ui/dialogs/FilterModsDialog.cpp b/launcher/ui/dialogs/FilterModsDialog.cpp deleted file mode 100644 index 9440d897..00000000 --- a/launcher/ui/dialogs/FilterModsDialog.cpp +++ /dev/null @@ -1,122 +0,0 @@ -#include "FilterModsDialog.h" -#include "ui_FilterModsDialog.h" - -FilterModsDialog::FilterModsDialog(Version def, QWidget* parent) - : QDialog(parent), m_filter(new Filter()), m_internal_filter(new Filter()), ui(new Ui::FilterModsDialog) -{ - ui->setupUi(this); - - 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); - - connect(&m_mcVersion_buttons, SIGNAL(idClicked(int)), this, SLOT(onVersionFilterChanged(int))); - - m_internal_filter->versions.push_front(def); - commitChanges(); -} - -int FilterModsDialog::execWithInstance(MinecraftInstance* instance) -{ - m_instance = instance; - - auto* pressed_button = m_mcVersion_buttons.checkedButton(); - - // Fix first openening behaviour - onVersionFilterChanged(m_previous_mcVersion_id); - - auto mcVersionSplit = mcVersionStr().split("."); - - ui->strictVersionButton->setText( - tr("Strict match (= %1)").arg(mcVersionStr())); - ui->majorVersionButton->setText( - tr("Major version match (= %1.%2.x)").arg(mcVersionSplit[0], mcVersionSplit[1])); - ui->allVersionsButton->setText( - tr("Any version")); - //ui->betweenVersionsButton->setText( - // tr("Between two versions")); - - int ret = QDialog::exec(); - - if(ret == QDialog::DialogCode::Accepted){ - // If there's no change, let's sey it's a cancel to the caller - if(*m_internal_filter.get() == *m_filter.get()) - return QDialog::DialogCode::Rejected; - - m_previous_mcVersion_id = (VersionButtonID) m_mcVersion_buttons.checkedId(); - commitChanges(); - } else { - pressed_button->click(); - revertChanges(); - } - - 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; - } -} - -// Do deep copy -void FilterModsDialog::commitChanges() -{ - m_filter->versions = m_internal_filter->versions; -} -void FilterModsDialog::revertChanges() -{ - m_internal_filter->versions = m_filter->versions; -} - -void FilterModsDialog::onVersionFilterChanged(int id) -{ - //ui->lowerVersionComboBox->setEnabled(id == VersionButtonID::Between); - //ui->upperVersionComboBox->setEnabled(id == VersionButtonID::Between); - - auto versionSplit = mcVersionStr().split("."); - int index = 0; - - m_internal_filter->versions.clear(); - - switch(id){ - case(VersionButtonID::Strict): - m_internal_filter->versions.push_front(mcVersion()); - break; - case(VersionButtonID::Major): - for(auto i = Version(QString("%1.%2").arg(versionSplit[0], versionSplit[1])); i <= mcVersion(); index++){ - m_internal_filter->versions.push_front(i); - i = Version(QString("%1.%2.%3").arg(versionSplit[0], versionSplit[1], QString("%1").arg(index))); - } - break; - case(VersionButtonID::All): - // Empty list to avoid enumerating all versions :P - break; - case(VersionButtonID::Between): - // TODO - break; - default: - break; - } -} - -FilterModsDialog::~FilterModsDialog() -{ - delete ui; -} diff --git a/launcher/ui/dialogs/FilterModsDialog.h b/launcher/ui/dialogs/FilterModsDialog.h deleted file mode 100644 index fac28ca4..00000000 --- a/launcher/ui/dialogs/FilterModsDialog.h +++ /dev/null @@ -1,65 +0,0 @@ -#pragma once - -#include -#include - -#include "Version.h" -#include "minecraft/MinecraftInstance.h" -#include "minecraft/PackProfile.h" - -class MinecraftInstance; - -namespace Ui { -class FilterModsDialog; -} - -class FilterModsDialog : public QDialog -{ - Q_OBJECT -public: - enum VersionButtonID { - Strict = 0, - Major = 1, - All = 2, - Between = 3 - }; - - struct Filter { - std::list versions; - - bool operator==(const Filter& other) const { return versions == other.versions; } - bool operator!=(const Filter& other) const { return !(*this == other); } - }; - - std::shared_ptr m_filter; - std::shared_ptr m_internal_filter; - -public: - explicit FilterModsDialog(Version def, QWidget* parent = nullptr); - ~FilterModsDialog(); - - int execWithInstance(MinecraftInstance* instance); - - /// By default all buttons are enabled - void disableVersionButton(VersionButtonID); - - auto getFilter() -> std::shared_ptr { return m_filter; } - -private: - inline auto mcVersionStr() const -> QString { return m_instance ? m_instance->getPackProfile()->getComponentVersion("net.minecraft") : ""; } - inline auto mcVersion() const -> Version { return { mcVersionStr() }; } - - void commitChanges(); - void revertChanges(); - -private slots: - void onVersionFilterChanged(int id); - -private: - Ui::FilterModsDialog* ui; - - MinecraftInstance* m_instance = nullptr; - - QButtonGroup m_mcVersion_buttons; - VersionButtonID m_previous_mcVersion_id = VersionButtonID::Strict; -}; diff --git a/launcher/ui/dialogs/FilterModsDialog.ui b/launcher/ui/dialogs/FilterModsDialog.ui deleted file mode 100644 index 67a63bfd..00000000 --- a/launcher/ui/dialogs/FilterModsDialog.ui +++ /dev/null @@ -1,135 +0,0 @@ - - - FilterModsDialog - - - Qt::ApplicationModal - - - - 0 - 0 - 345 - 169 - - - - - 0 - 0 - - - - Filter options - - - true - - - true - - - - - - - 0 - 0 - - - - Minecraft versions - - - false - - - false - - - - - - QLayout::SetDefaultConstraint - - - - - - - StrictVersion - - - true - - - - - - - MajorVersion - - - - - - - AllVersions - - - - - - - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - - buttonBox - accepted() - FilterModsDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - FilterModsDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - - diff --git a/launcher/ui/pages/modplatform/ModModel.cpp b/launcher/ui/pages/modplatform/ModModel.cpp index 0ff784db..da0331b5 100644 --- a/launcher/ui/pages/modplatform/ModModel.cpp +++ b/launcher/ui/pages/modplatform/ModModel.cpp @@ -91,9 +91,14 @@ void ListModel::refresh() performPaginatedSearch(); } -void ListModel::searchWithTerm(const QString& term, const int sort) +void ListModel::searchWithTerm(const QString& term, const int sort, const bool filter_changed) { - if (currentSearchTerm == term && currentSearchTerm.isNull() == term.isNull() && currentSort == sort) { return; } + if (currentSearchTerm == term + && currentSearchTerm.isNull() == term.isNull() + && currentSort == sort + && !filter_changed) + { return; } + currentSearchTerm = term; currentSort = sort; diff --git a/launcher/ui/pages/modplatform/ModModel.h b/launcher/ui/pages/modplatform/ModModel.h index d4dc872d..d460cff2 100644 --- a/launcher/ui/pages/modplatform/ModModel.h +++ b/launcher/ui/pages/modplatform/ModModel.h @@ -35,7 +35,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 searchWithTerm(const QString& term, const int sort, const bool filter_changed); void requestModVersions(const ModPlatform::IndexedPack& current); virtual void loadIndexedPack(ModPlatform::IndexedPack& m, QJsonObject& obj) = 0; diff --git a/launcher/ui/pages/modplatform/ModPage.cpp b/launcher/ui/pages/modplatform/ModPage.cpp index 37f68291..57c2e45d 100644 --- a/launcher/ui/pages/modplatform/ModPage.cpp +++ b/launcher/ui/pages/modplatform/ModPage.cpp @@ -13,7 +13,7 @@ ModPage::ModPage(ModDownloadDialog* dialog, BaseInstance* instance, ModAPI* api) , m_instance(instance) , ui(new Ui::ModPage) , dialog(dialog) - , filter_dialog(static_cast(instance)->getPackProfile()->getComponentVersion("net.minecraft"), this) + , filter_widget(static_cast(instance)->getPackProfile()->getComponentVersion("net.minecraft"), this) , api(api) { ui->setupUi(this); @@ -24,7 +24,10 @@ ModPage::ModPage(ModDownloadDialog* dialog, BaseInstance* instance, ModAPI* api) ui->versionSelectionBox->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); ui->versionSelectionBox->view()->parentWidget()->setMaximumHeight(300); - m_filter = filter_dialog.getFilter(); + ui->gridLayout_3->addWidget(&filter_widget, 0, 0, 1, ui->gridLayout_3->columnCount()); + + filter_widget.setInstance(static_cast(m_instance)); + m_filter = filter_widget.getFilter(); } ModPage::~ModPage() @@ -59,21 +62,22 @@ auto ModPage::eventFilter(QObject* watched, QEvent* event) -> bool void ModPage::filterMods() { - auto ret = filter_dialog.execWithInstance(static_cast(m_instance)); - m_filter = filter_dialog.getFilter(); - - if(ret == QDialog::DialogCode::Accepted){ - listModel->refresh(); - - int prev_count = ui->versionSelectionBox->count(); - ui->versionSelectionBox->clear(); - updateModVersions(prev_count); - } + filter_widget.setHidden(!filter_widget.isHidden()); } void ModPage::triggerSearch() { - listModel->searchWithTerm(ui->searchEdit->text(), ui->sortByBox->currentIndex()); + auto changed = filter_widget.changed(); + m_filter = filter_widget.getFilter(); + + if(changed){ + ui->packView->clearSelection(); + ui->packDescription->clear(); + ui->versionSelectionBox->clear(); + updateSelectionButton(); + } + + listModel->searchWithTerm(ui->searchEdit->text(), ui->sortByBox->currentIndex(), changed); } void ModPage::onSelectionChanged(QModelIndex first, QModelIndex second) diff --git a/launcher/ui/pages/modplatform/ModPage.h b/launcher/ui/pages/modplatform/ModPage.h index 06581ab2..85aaede9 100644 --- a/launcher/ui/pages/modplatform/ModPage.h +++ b/launcher/ui/pages/modplatform/ModPage.h @@ -5,9 +5,9 @@ #include "Application.h" #include "modplatform/ModAPI.h" #include "modplatform/ModIndex.h" -#include "ui/dialogs/FilterModsDialog.h" #include "ui/pages/BasePage.h" #include "ui/pages/modplatform/ModModel.h" +#include "ui/widgets/ModFilterWidget.h" class ModDownloadDialog; @@ -40,7 +40,7 @@ class ModPage : public QWidget, public BasePage { virtual auto validateVersion(ModPlatform::IndexedVersion& ver, QString mineVer, QString loaderVer = "") const -> bool = 0; auto apiProvider() const -> const ModAPI* { return api.get(); }; - auto getFilter() const -> const std::shared_ptr { return m_filter; } + auto getFilter() const -> const std::shared_ptr { return m_filter; } auto getCurrent() -> ModPlatform::IndexedPack& { return current; } void updateModVersions(int prev_count = -1); @@ -64,8 +64,8 @@ class ModPage : public QWidget, public BasePage { Ui::ModPage* ui = nullptr; ModDownloadDialog* dialog = nullptr; - FilterModsDialog filter_dialog; - std::shared_ptr m_filter; + ModFilterWidget filter_widget; + std::shared_ptr m_filter; ModPlatform::ListModel* listModel = nullptr; ModPlatform::IndexedPack current; diff --git a/launcher/ui/pages/modplatform/ModPage.ui b/launcher/ui/pages/modplatform/ModPage.ui index 4444583e..afcd9bb7 100644 --- a/launcher/ui/pages/modplatform/ModPage.ui +++ b/launcher/ui/pages/modplatform/ModPage.ui @@ -11,7 +11,7 @@ - + @@ -41,7 +41,7 @@ - + Search @@ -55,7 +55,7 @@ - + @@ -80,15 +80,22 @@ - - - - Filter options - - - + + + + Filter options + + + + + + + Qt::Vertical + + + diff --git a/launcher/ui/pages/modplatform/flame/FlameModPage.cpp b/launcher/ui/pages/modplatform/flame/FlameModPage.cpp index 6e666c4c..864ae8e6 100644 --- a/launcher/ui/pages/modplatform/flame/FlameModPage.cpp +++ b/launcher/ui/pages/modplatform/flame/FlameModPage.cpp @@ -67,25 +67,6 @@ auto FlameModPage::validateVersion(ModPlatform::IndexedVersion& ver, QString min return ver.mcVersion.contains(mineVer); } -// We override this so that it refreshes correctly, otherwise it would show -// invalid mods on the mod list, because the API would return mods for the -// wrong mod loader :( -void FlameModPage::filterMods() -{ - auto ret = filter_dialog.execWithInstance(static_cast(m_instance)); - m_filter = filter_dialog.getFilter(); - - if(ret == QDialog::DialogCode::Accepted){ - // CF API can't handle well this - if(!m_filter->versions.empty()) - listModel->refresh(); - - int prev_count = ui->versionSelectionBox->count(); - ui->versionSelectionBox->clear(); - updateModVersions(prev_count); - } -} - // 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 7078e889..dc58fd7f 100644 --- a/launcher/ui/pages/modplatform/flame/FlameModPage.h +++ b/launcher/ui/pages/modplatform/flame/FlameModPage.h @@ -56,7 +56,5 @@ class FlameModPage : public ModPage { auto validateVersion(ModPlatform::IndexedVersion& ver, QString mineVer, QString loaderVer = "") const -> bool override; - void filterMods() override; - auto shouldDisplay() const -> bool override; }; diff --git a/launcher/ui/widgets/ModFilterWidget.cpp b/launcher/ui/widgets/ModFilterWidget.cpp new file mode 100644 index 00000000..339ecb4b --- /dev/null +++ b/launcher/ui/widgets/ModFilterWidget.cpp @@ -0,0 +1,99 @@ +#include "ModFilterWidget.h" +#include "ui_ModFilterWidget.h" + +ModFilterWidget::ModFilterWidget(Version def, QWidget* parent) + : QTabWidget(parent), m_filter(new Filter()), ui(new Ui::ModFilterWidget) +{ + ui->setupUi(this); + + m_mcVersion_buttons.addButton(ui->strictVersionButton, VersionButtonID::Strict); + ui->strictVersionButton->click(); + m_mcVersion_buttons.addButton(ui->majorVersionButton, VersionButtonID::Major); + m_mcVersion_buttons.addButton(ui->allVersionsButton, VersionButtonID::All); + //m_mcVersion_buttons.addButton(ui->betweenVersionsButton, VersionButtonID::Between); + + connect(&m_mcVersion_buttons, SIGNAL(idClicked(int)), this, SLOT(onVersionFilterChanged(int))); + + m_filter->versions.push_front(def); + + setHidden(true); +} + +void ModFilterWidget::setInstance(MinecraftInstance* instance) +{ + m_instance = instance; + + auto mcVersionSplit = mcVersionStr().split("."); + + ui->strictVersionButton->setText( + tr("Strict match (= %1)").arg(mcVersionStr())); + ui->majorVersionButton->setText( + tr("Major version match (= %1.%2.x)").arg(mcVersionSplit[0], mcVersionSplit[1])); + ui->allVersionsButton->setText( + tr("Any version")); + //ui->betweenVersionsButton->setText( + // tr("Between two versions")); +} + +auto ModFilterWidget::getFilter() -> std::shared_ptr +{ + m_last_version_id = m_version_id; + return m_filter; +} + +void ModFilterWidget::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 ModFilterWidget::onVersionFilterChanged(int id) +{ + //ui->lowerVersionComboBox->setEnabled(id == VersionButtonID::Between); + //ui->upperVersionComboBox->setEnabled(id == VersionButtonID::Between); + + auto versionSplit = mcVersionStr().split("."); + int index = 0; + + auto cast_id = (VersionButtonID) id; + m_version_id = cast_id; + + m_filter->versions.clear(); + + switch(cast_id){ + case(VersionButtonID::Strict): + m_filter->versions.push_front(mcVersion()); + break; + case(VersionButtonID::Major): + for(auto i = Version(QString("%1.%2").arg(versionSplit[0], versionSplit[1])); i <= mcVersion(); index++){ + m_filter->versions.push_front(i); + i = Version(QString("%1.%2.%3").arg(versionSplit[0], versionSplit[1], QString("%1").arg(index))); + } + break; + case(VersionButtonID::All): + // Empty list to avoid enumerating all versions :P + break; + case(VersionButtonID::Between): + // TODO + break; + } +} + +ModFilterWidget::~ModFilterWidget() +{ + delete ui; +} diff --git a/launcher/ui/widgets/ModFilterWidget.h b/launcher/ui/widgets/ModFilterWidget.h new file mode 100644 index 00000000..5348882f --- /dev/null +++ b/launcher/ui/widgets/ModFilterWidget.h @@ -0,0 +1,65 @@ +#pragma once + +#include +#include + +#include "Version.h" +#include "minecraft/MinecraftInstance.h" +#include "minecraft/PackProfile.h" + +class MinecraftInstance; + +namespace Ui { +class ModFilterWidget; +} + +class ModFilterWidget : public QTabWidget +{ + Q_OBJECT +public: + enum VersionButtonID { + Strict = 0, + Major = 1, + All = 2, + Between = 3 + }; + + struct Filter { + std::list versions; + + bool operator==(const Filter& other) const { return versions == other.versions; } + bool operator!=(const Filter& other) const { return !(*this == other); } + }; + + std::shared_ptr m_filter; + +public: + explicit ModFilterWidget(Version def, QWidget* parent = nullptr); + ~ModFilterWidget(); + + void setInstance(MinecraftInstance* instance); + + /// By default all buttons are enabled + void disableVersionButton(VersionButtonID); + + auto getFilter() -> std::shared_ptr; + auto changed() const -> bool { return m_last_version_id != m_version_id; } + +private: + inline auto mcVersionStr() const -> QString { return m_instance ? m_instance->getPackProfile()->getComponentVersion("net.minecraft") : ""; } + inline auto mcVersion() const -> Version { return { mcVersionStr() }; } + +private slots: + void onVersionFilterChanged(int id); + +private: + Ui::ModFilterWidget* ui; + + MinecraftInstance* m_instance = nullptr; + + QButtonGroup m_mcVersion_buttons; + + /* Used to tell if the filter was changed since the last getFilter() call */ + VersionButtonID m_last_version_id = VersionButtonID::Strict; + VersionButtonID m_version_id = VersionButtonID::Strict; +}; diff --git a/launcher/ui/widgets/ModFilterWidget.ui b/launcher/ui/widgets/ModFilterWidget.ui new file mode 100644 index 00000000..ad1090e2 --- /dev/null +++ b/launcher/ui/widgets/ModFilterWidget.ui @@ -0,0 +1,54 @@ + + + ModFilterWidget + + + + 0 + 0 + 400 + 300 + + + + + 0 + 0 + + + + + Minecraft versions + + + + + + + + allVersions + + + + + + + strictVersion + + + + + + + majorVersion + + + + + + + + + + + -- cgit