Merge pull request #392 from flowln/mod_filter
This commit is contained in:
@ -72,14 +72,11 @@ void ListModel::performPaginatedSearch()
|
||||
auto profile = (dynamic_cast<MinecraftInstance*>((dynamic_cast<ModPage*>(parent()))->m_instance))->getPackProfile();
|
||||
|
||||
m_parent->apiProvider()->searchMods(this,
|
||||
{ nextSearchOffset, currentSearchTerm, getSorts()[currentSort], profile->getModLoader(), getMineVersions().at(0) });
|
||||
{ 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,20 @@ void ListModel::searchWithTerm(const QString& term, const int sort)
|
||||
performPaginatedSearch();
|
||||
}
|
||||
|
||||
void ListModel::searchWithTerm(const QString& term, const int sort, const bool filter_changed)
|
||||
{
|
||||
if (currentSearchTerm == term
|
||||
&& currentSearchTerm.isNull() == term.isNull()
|
||||
&& currentSort == sort
|
||||
&& !filter_changed)
|
||||
{ return; }
|
||||
|
||||
currentSearchTerm = term;
|
||||
currentSort = sort;
|
||||
|
||||
refresh();
|
||||
}
|
||||
|
||||
void ListModel::getLogo(const QString& logo, const QString& logoUrl, LogoCallback callback)
|
||||
{
|
||||
if (m_logoMap.contains(logo)) {
|
||||
@ -223,9 +234,7 @@ void ListModel::versionRequestSucceeded(QJsonDocument doc, QString addonId)
|
||||
|
||||
/******** Helpers ********/
|
||||
|
||||
auto ModPlatform::ListModel::getMineVersions() const -> QList<QString>
|
||||
auto ModPlatform::ListModel::getMineVersions() const -> std::list<Version>
|
||||
{
|
||||
return { (dynamic_cast<MinecraftInstance*>((dynamic_cast<ModPage*>(parent()))->m_instance))
|
||||
->getPackProfile()
|
||||
->getComponentVersion("net.minecraft") };
|
||||
return m_parent->getFilter()->versions;
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "net/NetJob.h"
|
||||
|
||||
class ModPage;
|
||||
class Version;
|
||||
|
||||
namespace ModPlatform {
|
||||
|
||||
@ -33,7 +34,8 @@ class ListModel : public QAbstractListModel {
|
||||
|
||||
/* Ask the API for more information */
|
||||
void fetchMore(const QModelIndex& parent) override;
|
||||
void searchWithTerm(const QString& term, const int sort);
|
||||
void refresh();
|
||||
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;
|
||||
@ -62,7 +64,7 @@ class ListModel : public QAbstractListModel {
|
||||
|
||||
void requestLogo(QString file, QString url);
|
||||
|
||||
inline auto getMineVersions() const -> QList<QString>;
|
||||
inline auto getMineVersions() const -> std::list<Version>;
|
||||
|
||||
protected:
|
||||
ModPage* m_parent;
|
||||
|
@ -2,21 +2,39 @@
|
||||
#include "ui_ModPage.h"
|
||||
|
||||
#include <QKeyEvent>
|
||||
#include <memory>
|
||||
|
||||
#include "minecraft/MinecraftInstance.h"
|
||||
#include "minecraft/PackProfile.h"
|
||||
#include "ui/dialogs/ModDownloadDialog.h"
|
||||
|
||||
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_widget(static_cast<MinecraftInstance*>(instance)->getPackProfile()->getComponentVersion("net.minecraft"), this)
|
||||
, api(api)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
connect(ui->searchButton, &QPushButton::clicked, this, &ModPage::triggerSearch);
|
||||
connect(ui->modFilterButton, &QPushButton::clicked, this, &ModPage::filterMods);
|
||||
ui->searchEdit->installEventFilter(this);
|
||||
|
||||
ui->versionSelectionBox->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
ui->versionSelectionBox->view()->parentWidget()->setMaximumHeight(300);
|
||||
|
||||
ui->gridLayout_3->addWidget(&filter_widget, 0, 0, 1, ui->gridLayout_3->columnCount());
|
||||
|
||||
filter_widget.setInstance(static_cast<MinecraftInstance*>(m_instance));
|
||||
m_filter = filter_widget.getFilter();
|
||||
|
||||
connect(&filter_widget, &ModFilterWidget::filterChanged, this, [&]{
|
||||
ui->searchButton->setStyleSheet("text-decoration: underline");
|
||||
});
|
||||
connect(&filter_widget, &ModFilterWidget::filterUnchanged, this, [&]{
|
||||
ui->searchButton->setStyleSheet("text-decoration: none");
|
||||
});
|
||||
}
|
||||
|
||||
ModPage::~ModPage()
|
||||
@ -49,9 +67,24 @@ auto ModPage::eventFilter(QObject* watched, QEvent* event) -> bool
|
||||
|
||||
/******** Callbacks to events in the UI (set up in the derived classes) ********/
|
||||
|
||||
void ModPage::filterMods()
|
||||
{
|
||||
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)
|
||||
@ -131,7 +164,7 @@ void ModPage::retranslate()
|
||||
ui->retranslateUi(this);
|
||||
}
|
||||
|
||||
void ModPage::updateModVersions()
|
||||
void ModPage::updateModVersions(int prev_count)
|
||||
{
|
||||
auto packProfile = (dynamic_cast<MinecraftInstance*>(m_instance))->getPackProfile();
|
||||
|
||||
@ -141,15 +174,22 @@ void ModPage::updateModVersions()
|
||||
|
||||
for (int i = 0; i < current.versions.size(); i++) {
|
||||
auto version = current.versions[i];
|
||||
//NOTE: Flame doesn't care about loaderString, so passing it changes nothing.
|
||||
if (!validateVersion(version, mcVersion, loaderString)) {
|
||||
continue;
|
||||
bool valid = false;
|
||||
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;
|
||||
}
|
||||
}
|
||||
ui->versionSelectionBox->addItem(version.version, QVariant(i));
|
||||
if(valid || m_filter->versions.size() == 0)
|
||||
ui->versionSelectionBox->addItem(version.version, QVariant(i));
|
||||
}
|
||||
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 :("));
|
||||
}
|
||||
if (ui->versionSelectionBox->count() == 0) { ui->versionSelectionBox->addItem(tr("No valid version found!"), QVariant(-1)); }
|
||||
|
||||
ui->modSelectionButton->setText(tr("Cannot select invalid version :("));
|
||||
updateSelectionButton();
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "modplatform/ModIndex.h"
|
||||
#include "ui/pages/BasePage.h"
|
||||
#include "ui/pages/modplatform/ModModel.h"
|
||||
#include "ui/widgets/ModFilterWidget.h"
|
||||
|
||||
class ModDownloadDialog;
|
||||
|
||||
@ -39,9 +40,10 @@ 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<ModFilterWidget::Filter> { 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;
|
||||
@ -52,6 +54,7 @@ class ModPage : public QWidget, public BasePage {
|
||||
void updateSelectionButton();
|
||||
|
||||
protected slots:
|
||||
virtual 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;
|
||||
|
||||
ModFilterWidget filter_widget;
|
||||
std::shared_ptr<ModFilterWidget::Filter> m_filter;
|
||||
|
||||
ModPlatform::ListModel* listModel = nullptr;
|
||||
ModPlatform::IndexedPack current;
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0" colspan="2">
|
||||
<item row="1" column="0" colspan="4">
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="1" column="2">
|
||||
<widget class="QTextBrowser" name="packDescription">
|
||||
@ -41,7 +41,7 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<item row="0" column="3">
|
||||
<widget class="QPushButton" name="searchButton">
|
||||
<property name="text">
|
||||
<string>Search</string>
|
||||
@ -51,12 +51,12 @@
|
||||
<item row="0" column="0">
|
||||
<widget class="QLineEdit" name="searchEdit">
|
||||
<property name="placeholderText">
|
||||
<string>Search and filter...</string>
|
||||
<string>Search for mods...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<layout class="QGridLayout" name="gridLayout_4" columnstretch="0,0,0,0">
|
||||
<item row="2" column="0" colspan="4">
|
||||
<layout class="QGridLayout" name="gridLayout_4" columnstretch="0,0,0">
|
||||
<item row="0" column="2">
|
||||
<widget class="QComboBox" name="versionSelectionBox"/>
|
||||
</item>
|
||||
@ -82,6 +82,20 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QPushButton" name="modFilterButton">
|
||||
<property name="text">
|
||||
<string>Filter options</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
|
Reference in New Issue
Block a user