2023-01-23 19:33:55 +05:30
|
|
|
// SPDX-FileCopyrightText: 2023 flowln <flowlnlnln@gmail.com>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
|
2022-03-03 05:47:10 +05:30
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QWidget>
|
|
|
|
|
|
|
|
#include "modplatform/ModIndex.h"
|
2022-11-25 17:53:46 +05:30
|
|
|
|
2022-12-19 00:11:46 +05:30
|
|
|
#include "ui/pages/modplatform/ModModel.h"
|
2023-06-03 02:34:06 +05:30
|
|
|
#include "ui/pages/modplatform/ResourcePage.h"
|
2022-04-14 18:57:03 +05:30
|
|
|
#include "ui/widgets/ModFilterWidget.h"
|
2022-03-03 05:47:10 +05:30
|
|
|
|
|
|
|
namespace Ui {
|
2022-11-25 17:53:46 +05:30
|
|
|
class ResourcePage;
|
2022-03-03 05:47:10 +05:30
|
|
|
}
|
|
|
|
|
2022-12-17 03:33:52 +05:30
|
|
|
namespace ResourceDownload {
|
|
|
|
|
|
|
|
class ModDownloadDialog;
|
|
|
|
|
2022-03-08 19:42:35 +05:30
|
|
|
/* This page handles most logic related to browsing and selecting mods to download. */
|
2022-11-25 17:53:46 +05:30
|
|
|
class ModPage : public ResourcePage {
|
2022-03-03 05:47:10 +05:30
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2023-06-03 02:34:06 +05:30
|
|
|
template <typename T>
|
2022-11-25 17:53:46 +05:30
|
|
|
static T* create(ModDownloadDialog* dialog, BaseInstance& instance)
|
2022-08-21 19:20:10 +05:30
|
|
|
{
|
|
|
|
auto page = new T(dialog, instance);
|
2022-12-19 00:11:46 +05:30
|
|
|
auto model = static_cast<ModModel*>(page->getModel());
|
2022-08-21 19:20:10 +05:30
|
|
|
|
2023-06-03 02:34:06 +05:30
|
|
|
auto filter_widget =
|
|
|
|
ModFilterWidget::create(static_cast<MinecraftInstance&>(instance).getPackProfile()->getComponentVersion("net.minecraft"), page);
|
2022-08-21 19:20:10 +05:30
|
|
|
page->setFilterWidget(filter_widget);
|
2022-12-19 00:11:46 +05:30
|
|
|
model->setFilter(page->getFilter());
|
|
|
|
|
|
|
|
connect(model, &ResourceModel::versionListUpdated, page, &ResourcePage::updateVersionList);
|
|
|
|
connect(model, &ResourceModel::projectInfoUpdated, page, &ResourcePage::updateUi);
|
2022-08-21 19:20:10 +05:30
|
|
|
|
|
|
|
return page;
|
|
|
|
}
|
|
|
|
|
2022-12-31 01:29:35 +05:30
|
|
|
//: The plural version of 'mod'
|
|
|
|
[[nodiscard]] inline QString resourcesString() const override { return tr("mods"); }
|
|
|
|
//: The singular version of 'mods'
|
2022-11-25 17:53:46 +05:30
|
|
|
[[nodiscard]] inline QString resourceString() const override { return tr("mod"); }
|
2022-03-03 05:47:10 +05:30
|
|
|
|
2022-11-25 17:53:46 +05:30
|
|
|
[[nodiscard]] QMap<QString, QString> urlHandlers() const override;
|
2022-03-07 00:34:24 +05:30
|
|
|
|
2023-06-03 02:34:06 +05:30
|
|
|
void addResourceToPage(ModPlatform::IndexedPack::Ptr,
|
|
|
|
ModPlatform::IndexedVersion&,
|
|
|
|
const std::shared_ptr<ResourceFolderModel>) override;
|
2022-03-25 02:54:51 +05:30
|
|
|
|
2023-06-03 02:34:06 +05:30
|
|
|
virtual auto validateVersion(ModPlatform::IndexedVersion& ver,
|
|
|
|
QString mineVer,
|
|
|
|
std::optional<ResourceAPI::ModLoaderTypes> loaders = {}) const -> bool = 0;
|
2022-05-24 18:08:48 +05:30
|
|
|
|
2022-11-25 17:53:46 +05:30
|
|
|
[[nodiscard]] bool supportsFiltering() const override { return true; };
|
2022-04-14 18:57:03 +05:30
|
|
|
auto getFilter() const -> const std::shared_ptr<ModFilterWidget::Filter> { return m_filter; }
|
2022-08-21 19:20:10 +05:30
|
|
|
void setFilterWidget(unique_qobject_ptr<ModFilterWidget>&);
|
|
|
|
|
2022-11-25 17:53:46 +05:30
|
|
|
public slots:
|
|
|
|
void updateVersionList() override;
|
2022-03-03 05:47:10 +05:30
|
|
|
|
|
|
|
protected:
|
2022-11-25 17:53:46 +05:30
|
|
|
ModPage(ModDownloadDialog* dialog, BaseInstance& instance);
|
2022-03-03 05:47:10 +05:30
|
|
|
|
|
|
|
protected slots:
|
2022-04-03 04:38:37 +05:30
|
|
|
virtual void filterMods();
|
2022-11-25 17:53:46 +05:30
|
|
|
void triggerSearch() override;
|
2022-03-03 05:47:10 +05:30
|
|
|
|
|
|
|
protected:
|
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-03-03 05:47:10 +05:30
|
|
|
};
|
2022-12-17 03:33:52 +05:30
|
|
|
|
|
|
|
} // namespace ResourceDownload
|