feat: Integrate newly created filter dialog in ModPage

This commit is contained in:
flow 2022-04-02 18:33:50 -03:00
parent e0ab8207ed
commit c2b97c3e3f
4 changed files with 41 additions and 7 deletions

View File

@ -80,7 +80,7 @@ void ModDownloadDialog::confirm()
tr("Confirm mods to download") tr("Confirm mods to download")
); );
for(auto task : keys){ for(auto& task : keys){
confirm_dialog->appendMod(task, modTask.find(task).value()->getFilename()); confirm_dialog->appendMod(task, modTask.find(task).value()->getFilename());
} }

View File

@ -2,21 +2,29 @@
#include "ui_ModPage.h" #include "ui_ModPage.h"
#include <QKeyEvent> #include <QKeyEvent>
#include <memory>
#include "minecraft/MinecraftInstance.h" #include "minecraft/MinecraftInstance.h"
#include "minecraft/PackProfile.h" #include "minecraft/PackProfile.h"
#include "ui/dialogs/ModDownloadDialog.h" #include "ui/dialogs/ModDownloadDialog.h"
ModPage::ModPage(ModDownloadDialog* dialog, BaseInstance* instance, ModAPI* api) ModPage::ModPage(ModDownloadDialog* dialog, BaseInstance* instance, ModAPI* api)
: QWidget(dialog), m_instance(instance), ui(new Ui::ModPage), dialog(dialog), api(api) : QWidget(dialog)
, m_instance(instance)
, ui(new Ui::ModPage)
, dialog(dialog)
, filter_dialog(static_cast<MinecraftInstance*>(instance)->getPackProfile()->getComponentVersion("net.minecraft"), this)
, api(api)
{ {
ui->setupUi(this); ui->setupUi(this);
connect(ui->searchButton, &QPushButton::clicked, this, &ModPage::triggerSearch); connect(ui->searchButton, &QPushButton::clicked, this, &ModPage::triggerSearch);
connect(ui->modFilterButton, &QPushButton::clicked, this, &ModPage::filterMods);
ui->searchEdit->installEventFilter(this); ui->searchEdit->installEventFilter(this);
ui->versionSelectionBox->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); ui->versionSelectionBox->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
ui->versionSelectionBox->view()->parentWidget()->setMaximumHeight(300); ui->versionSelectionBox->view()->parentWidget()->setMaximumHeight(300);
m_filter = filter_dialog.getFilter();
} }
ModPage::~ModPage() ModPage::~ModPage()
@ -49,6 +57,13 @@ auto ModPage::eventFilter(QObject* watched, QEvent* event) -> bool
/******** Callbacks to events in the UI (set up in the derived classes) ********/ /******** Callbacks to events in the UI (set up in the derived classes) ********/
void ModPage::filterMods()
{
filter_dialog.execWithInstance(static_cast<MinecraftInstance*>(m_instance));
m_filter = filter_dialog.getFilter();
}
void ModPage::triggerSearch() void ModPage::triggerSearch()
{ {
listModel->searchWithTerm(ui->searchEdit->text(), ui->sortByBox->currentIndex()); listModel->searchWithTerm(ui->searchEdit->text(), ui->sortByBox->currentIndex());
@ -141,10 +156,15 @@ void ModPage::updateModVersions()
for (int i = 0; i < current.versions.size(); i++) { for (int i = 0; i < current.versions.size(); i++) {
auto version = current.versions[i]; auto version = current.versions[i];
bool valid = false;
//NOTE: Flame doesn't care about loaderString, so passing it changes nothing. //NOTE: Flame doesn't care about loaderString, so passing it changes nothing.
if (!validateVersion(version, mcVersion, loaderString)) { for(auto& mcVer : m_filter->versions){
continue; if (validateVersion(version, mcVer.toString(), loaderString)) {
valid = true;
break;
} }
}
if(valid)
ui->versionSelectionBox->addItem(version.version, QVariant(i)); 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) { ui->versionSelectionBox->addItem(tr("No valid version found!"), QVariant(-1)); }

View File

@ -5,6 +5,7 @@
#include "Application.h" #include "Application.h"
#include "modplatform/ModAPI.h" #include "modplatform/ModAPI.h"
#include "modplatform/ModIndex.h" #include "modplatform/ModIndex.h"
#include "ui/dialogs/FilterModsDialog.h"
#include "ui/pages/BasePage.h" #include "ui/pages/BasePage.h"
#include "ui/pages/modplatform/ModModel.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; virtual auto validateVersion(ModPlatform::IndexedVersion& ver, QString mineVer, QString loaderVer = "") const -> bool = 0;
auto apiProvider() const -> const ModAPI* { return api.get(); }; auto apiProvider() const -> const ModAPI* { return api.get(); };
auto getFilter() const -> const std::shared_ptr<FilterModsDialog::Filter> { return m_filter; }
auto getCurrent() -> ModPlatform::IndexedPack& { return current; } auto getCurrent() -> ModPlatform::IndexedPack& { return current; }
void updateModVersions(); void updateModVersions();
@ -52,6 +54,7 @@ class ModPage : public QWidget, public BasePage {
void updateSelectionButton(); void updateSelectionButton();
protected slots: protected slots:
void filterMods();
void triggerSearch(); void triggerSearch();
void onSelectionChanged(QModelIndex first, QModelIndex second); void onSelectionChanged(QModelIndex first, QModelIndex second);
void onVersionSelectionChanged(QString data); void onVersionSelectionChanged(QString data);
@ -60,6 +63,10 @@ class ModPage : public QWidget, public BasePage {
protected: protected:
Ui::ModPage* ui = nullptr; Ui::ModPage* ui = nullptr;
ModDownloadDialog* dialog = nullptr; ModDownloadDialog* dialog = nullptr;
FilterModsDialog filter_dialog;
std::shared_ptr<FilterModsDialog::Filter> m_filter;
ModPlatform::ListModel* listModel = nullptr; ModPlatform::ListModel* listModel = nullptr;
ModPlatform::IndexedPack current; ModPlatform::IndexedPack current;

View File

@ -51,12 +51,12 @@
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLineEdit" name="searchEdit"> <widget class="QLineEdit" name="searchEdit">
<property name="placeholderText"> <property name="placeholderText">
<string>Search and filter...</string> <string>Search for mods...</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="0" colspan="2"> <item row="2" column="0" colspan="2">
<layout class="QGridLayout" name="gridLayout_4" columnstretch="0,0,0,0"> <layout class="QGridLayout" name="gridLayout_4" columnstretch="0,0,0">
<item row="0" column="2"> <item row="0" column="2">
<widget class="QComboBox" name="versionSelectionBox"/> <widget class="QComboBox" name="versionSelectionBox"/>
</item> </item>
@ -80,6 +80,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0">
<widget class="QPushButton" name="modFilterButton">
<property name="text">
<string>Filter options</string>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>