2022-03-03 05:47:10 +05:30
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QWidget>
|
|
|
|
|
2022-03-06 23:53:00 +05:30
|
|
|
#include "Application.h"
|
2022-03-03 07:31:23 +05:30
|
|
|
#include "modplatform/ModAPI.h"
|
2022-03-03 05:47:10 +05:30
|
|
|
#include "modplatform/ModIndex.h"
|
|
|
|
#include "ui/pages/BasePage.h"
|
|
|
|
#include "ui/pages/modplatform/ModModel.h"
|
2022-04-14 18:57:03 +05:30
|
|
|
#include "ui/widgets/ModFilterWidget.h"
|
2022-07-15 21:48:12 +05:30
|
|
|
#include "ui/widgets/ProgressWidget.h"
|
2022-03-03 05:47:10 +05:30
|
|
|
|
|
|
|
class ModDownloadDialog;
|
|
|
|
|
|
|
|
namespace Ui {
|
|
|
|
class ModPage;
|
|
|
|
}
|
|
|
|
|
2022-03-08 19:42:35 +05:30
|
|
|
/* This page handles most logic related to browsing and selecting mods to download. */
|
2022-03-03 05:47:10 +05:30
|
|
|
class ModPage : public QWidget, public BasePage {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2022-08-21 19:20:10 +05:30
|
|
|
template<typename T>
|
|
|
|
static T* create(ModDownloadDialog* dialog, BaseInstance* instance)
|
|
|
|
{
|
|
|
|
auto page = new T(dialog, instance);
|
|
|
|
|
|
|
|
auto filter_widget = ModFilterWidget::create(static_cast<MinecraftInstance*>(instance)->getPackProfile()->getComponentVersion("net.minecraft"), page);
|
|
|
|
page->setFilterWidget(filter_widget);
|
|
|
|
|
|
|
|
return page;
|
|
|
|
}
|
|
|
|
|
2022-03-08 19:42:35 +05:30
|
|
|
~ModPage() override;
|
2022-03-03 05:47:10 +05:30
|
|
|
|
2022-03-07 00:34:24 +05:30
|
|
|
/* Affects what the user sees */
|
2022-03-08 19:42:35 +05:30
|
|
|
auto displayName() const -> QString override = 0;
|
|
|
|
auto icon() const -> QIcon override = 0;
|
|
|
|
auto id() const -> QString override = 0;
|
|
|
|
auto helpPage() const -> QString override = 0;
|
2022-03-03 05:47:10 +05:30
|
|
|
|
2022-03-07 00:34:24 +05:30
|
|
|
/* Used internally */
|
2022-03-08 19:42:35 +05:30
|
|
|
virtual auto metaEntryBase() const -> QString = 0;
|
|
|
|
virtual auto debugName() const -> QString = 0;
|
2022-03-03 05:47:10 +05:30
|
|
|
|
2022-03-07 00:34:24 +05:30
|
|
|
|
2022-03-25 02:54:51 +05:30
|
|
|
void retranslate() override;
|
|
|
|
|
2022-05-24 18:08:48 +05:30
|
|
|
void updateUi();
|
|
|
|
|
2022-03-08 19:42:35 +05:30
|
|
|
auto shouldDisplay() const -> bool override = 0;
|
2022-05-19 12:10:28 +05:30
|
|
|
virtual auto validateVersion(ModPlatform::IndexedVersion& ver, QString mineVer, ModAPI::ModLoaderTypes loaders = ModAPI::Unspecified) const -> bool = 0;
|
2022-10-12 18:56:14 +05:30
|
|
|
virtual bool optedOut(ModPlatform::IndexedVersion& ver) const { return false; };
|
2022-03-08 03:59:59 +05:30
|
|
|
|
2022-05-24 18:08:48 +05:30
|
|
|
auto apiProvider() -> ModAPI* { return api.get(); };
|
2022-04-14 18:57:03 +05:30
|
|
|
auto getFilter() const -> const std::shared_ptr<ModFilterWidget::Filter> { return m_filter; }
|
2022-04-29 04:44:03 +05:30
|
|
|
auto getDialog() const -> const ModDownloadDialog* { return dialog; }
|
2022-03-03 05:47:10 +05:30
|
|
|
|
2022-07-15 19:50:08 +05:30
|
|
|
/** Get the current term in the search bar. */
|
|
|
|
auto getSearchTerm() const -> QString;
|
|
|
|
/** Programatically set the term in the search bar. */
|
|
|
|
void setSearchTerm(QString);
|
|
|
|
|
2022-08-21 19:20:10 +05:30
|
|
|
void setFilterWidget(unique_qobject_ptr<ModFilterWidget>&);
|
|
|
|
|
2022-03-08 19:42:35 +05:30
|
|
|
auto getCurrent() -> ModPlatform::IndexedPack& { return current; }
|
2022-04-03 18:51:48 +05:30
|
|
|
void updateModVersions(int prev_count = -1);
|
2022-03-06 23:53:00 +05:30
|
|
|
|
2022-03-03 05:47:10 +05:30
|
|
|
void openedImpl() override;
|
2022-03-08 19:42:35 +05:30
|
|
|
auto eventFilter(QObject* watched, QEvent* event) -> bool override;
|
2022-03-03 05:47:10 +05:30
|
|
|
|
|
|
|
BaseInstance* m_instance;
|
|
|
|
|
|
|
|
protected:
|
2022-08-21 19:20:10 +05:30
|
|
|
ModPage(ModDownloadDialog* dialog, BaseInstance* instance, ModAPI* api);
|
2022-03-03 05:47:10 +05:30
|
|
|
void updateSelectionButton();
|
|
|
|
|
|
|
|
protected slots:
|
2022-04-03 04:38:37 +05:30
|
|
|
virtual void filterMods();
|
2022-03-03 05:47:10 +05:30
|
|
|
void triggerSearch();
|
|
|
|
void onSelectionChanged(QModelIndex first, QModelIndex second);
|
|
|
|
void onVersionSelectionChanged(QString data);
|
|
|
|
void onModSelected();
|
2022-11-01 22:28:22 +05:30
|
|
|
virtual void openUrl(const QUrl& url);
|
2022-03-03 05:47:10 +05:30
|
|
|
|
|
|
|
protected:
|
|
|
|
Ui::ModPage* ui = nullptr;
|
|
|
|
ModDownloadDialog* dialog = nullptr;
|
2022-04-03 03:03:50 +05:30
|
|
|
|
2022-08-21 19:20:10 +05:30
|
|
|
unique_qobject_ptr<ModFilterWidget> m_filter_widget;
|
2022-04-14 18:57:03 +05:30
|
|
|
std::shared_ptr<ModFilterWidget::Filter> m_filter;
|
2022-04-03 03:03:50 +05:30
|
|
|
|
2022-07-15 21:48:12 +05:30
|
|
|
ProgressWidget m_fetch_progress;
|
|
|
|
|
2022-03-03 05:47:10 +05:30
|
|
|
ModPlatform::ListModel* listModel = nullptr;
|
|
|
|
ModPlatform::IndexedPack current;
|
|
|
|
|
2022-03-06 22:24:05 +05:30
|
|
|
std::unique_ptr<ModAPI> api;
|
|
|
|
|
2022-03-03 05:47:10 +05:30
|
|
|
int selectedVersion = -1;
|
2022-07-15 20:27:27 +05:30
|
|
|
|
|
|
|
// Used to do instant searching with a delay to cache quick changes
|
|
|
|
QTimer m_search_timer;
|
2022-03-03 05:47:10 +05:30
|
|
|
};
|