aboutsummaryrefslogtreecommitdiff
path: root/launcher/ui/pages/modplatform
diff options
context:
space:
mode:
Diffstat (limited to 'launcher/ui/pages/modplatform')
-rw-r--r--launcher/ui/pages/modplatform/ShaderPackModel.cpp42
-rw-r--r--launcher/ui/pages/modplatform/ShaderPackModel.h39
-rw-r--r--launcher/ui/pages/modplatform/ShaderPackPage.cpp50
-rw-r--r--launcher/ui/pages/modplatform/ShaderPackPage.h50
-rw-r--r--launcher/ui/pages/modplatform/flame/FlameResourcePages.h1
-rw-r--r--launcher/ui/pages/modplatform/modrinth/ModrinthResourceModels.cpp22
-rw-r--r--launcher/ui/pages/modplatform/modrinth/ModrinthResourceModels.h18
-rw-r--r--launcher/ui/pages/modplatform/modrinth/ModrinthResourcePages.cpp19
-rw-r--r--launcher/ui/pages/modplatform/modrinth/ModrinthResourcePages.h24
9 files changed, 265 insertions, 0 deletions
diff --git a/launcher/ui/pages/modplatform/ShaderPackModel.cpp b/launcher/ui/pages/modplatform/ShaderPackModel.cpp
new file mode 100644
index 00000000..36993288
--- /dev/null
+++ b/launcher/ui/pages/modplatform/ShaderPackModel.cpp
@@ -0,0 +1,42 @@
+#include "ShaderPackModel.h"
+
+#include <QMessageBox>
+
+namespace ResourceDownload {
+
+ShaderPackResourceModel::ShaderPackResourceModel(BaseInstance const& base_inst, ResourceAPI* api)
+ : ResourceModel(api), m_base_instance(base_inst){};
+
+/******** Make data requests ********/
+
+ResourceAPI::SearchArgs ShaderPackResourceModel::createSearchArguments()
+{
+ auto sort = getCurrentSortingMethodByIndex();
+ return { ModPlatform::ResourceType::SHADER_PACK, m_next_search_offset, m_search_term, sort };
+}
+
+ResourceAPI::VersionSearchArgs ShaderPackResourceModel::createVersionsArguments(QModelIndex& entry)
+{
+ auto& pack = m_packs[entry.row()];
+ return { pack };
+}
+
+ResourceAPI::ProjectInfoArgs ShaderPackResourceModel::createInfoArguments(QModelIndex& entry)
+{
+ auto& pack = m_packs[entry.row()];
+ return { pack };
+}
+
+void ShaderPackResourceModel::searchWithTerm(const QString& term, unsigned int sort)
+{
+ if (m_search_term == term && m_search_term.isNull() == term.isNull() && m_current_sort_index == sort) {
+ return;
+ }
+
+ setSearchTerm(term);
+ m_current_sort_index = sort;
+
+ refresh();
+}
+
+} // namespace ResourceDownload
diff --git a/launcher/ui/pages/modplatform/ShaderPackModel.h b/launcher/ui/pages/modplatform/ShaderPackModel.h
new file mode 100644
index 00000000..c84df15a
--- /dev/null
+++ b/launcher/ui/pages/modplatform/ShaderPackModel.h
@@ -0,0 +1,39 @@
+#pragma once
+
+#include <QAbstractListModel>
+
+#include "BaseInstance.h"
+
+#include "modplatform/ModIndex.h"
+
+#include "ui/pages/modplatform/ResourceModel.h"
+
+class Version;
+
+namespace ResourceDownload {
+
+class ShaderPackResourceModel : public ResourceModel {
+ Q_OBJECT
+
+ public:
+ ShaderPackResourceModel(BaseInstance const&, ResourceAPI*);
+
+ /* Ask the API for more information */
+ void searchWithTerm(const QString& term, unsigned int sort);
+
+ void loadIndexedPack(ModPlatform::IndexedPack&, QJsonObject&) override = 0;
+ void loadExtraPackInfo(ModPlatform::IndexedPack&, QJsonObject&) override = 0;
+ void loadIndexedPackVersions(ModPlatform::IndexedPack&, QJsonArray&) override = 0;
+
+ public slots:
+ ResourceAPI::SearchArgs createSearchArguments() override;
+ ResourceAPI::VersionSearchArgs createVersionsArguments(QModelIndex&) override;
+ ResourceAPI::ProjectInfoArgs createInfoArguments(QModelIndex&) override;
+
+ protected:
+ const BaseInstance& m_base_instance;
+
+ auto documentToArray(QJsonDocument& obj) const -> QJsonArray override = 0;
+};
+
+} // namespace ResourceDownload
diff --git a/launcher/ui/pages/modplatform/ShaderPackPage.cpp b/launcher/ui/pages/modplatform/ShaderPackPage.cpp
new file mode 100644
index 00000000..364d0a54
--- /dev/null
+++ b/launcher/ui/pages/modplatform/ShaderPackPage.cpp
@@ -0,0 +1,50 @@
+#include "ShaderPackPage.h"
+#include "ui_ResourcePage.h"
+
+#include "ShaderPackModel.h"
+
+#include "ui/dialogs/ResourceDownloadDialog.h"
+
+#include <QRegularExpression>
+
+namespace ResourceDownload {
+
+ShaderPackResourcePage::ShaderPackResourcePage(ShaderPackDownloadDialog* dialog, BaseInstance& instance)
+ : ResourcePage(dialog, instance)
+{
+ connect(m_ui->searchButton, &QPushButton::clicked, this, &ShaderPackResourcePage::triggerSearch);
+ connect(m_ui->packView, &QListView::doubleClicked, this, &ShaderPackResourcePage::onResourceSelected);
+}
+
+/******** Callbacks to events in the UI (set up in the derived classes) ********/
+
+void ShaderPackResourcePage::triggerSearch()
+{
+ m_ui->packView->clearSelection();
+ m_ui->packDescription->clear();
+ m_ui->versionSelectionBox->clear();
+
+ updateSelectionButton();
+
+ static_cast<ShaderPackResourceModel*>(m_model)->searchWithTerm(getSearchTerm(), m_ui->sortByBox->currentData().toUInt());
+ m_fetch_progress.watch(m_model->activeSearchJob().get());
+}
+
+QMap<QString, QString> ShaderPackResourcePage::urlHandlers() const
+{
+ QMap<QString, QString> map;
+ map.insert(QRegularExpression::anchoredPattern("(?:www\\.)?modrinth\\.com\\/shaders\\/([^\\/]+)\\/?"), "modrinth");
+ map.insert(QRegularExpression::anchoredPattern("(?:www\\.)?curseforge\\.com\\/minecraft\\/customization\\/([^\\/]+)\\/?"), "curseforge");
+ map.insert(QRegularExpression::anchoredPattern("minecraft\\.curseforge\\.com\\/projects\\/([^\\/]+)\\/?"), "curseforge");
+ return map;
+}
+
+void ShaderPackResourcePage::addResourceToDialog(ModPlatform::IndexedPack& pack, ModPlatform::IndexedVersion& version)
+{
+ if (version.loaders.contains(QStringLiteral("canvas")))
+ version.custom_target_folder = QStringLiteral("resourcepacks");
+
+ m_parent_dialog->addResource(pack, version);
+}
+
+} // namespace ResourceDownload
diff --git a/launcher/ui/pages/modplatform/ShaderPackPage.h b/launcher/ui/pages/modplatform/ShaderPackPage.h
new file mode 100644
index 00000000..92a9c3ee
--- /dev/null
+++ b/launcher/ui/pages/modplatform/ShaderPackPage.h
@@ -0,0 +1,50 @@
+#pragma once
+
+#include "ui/pages/modplatform/ResourcePage.h"
+#include "ui/pages/modplatform/ShaderPackModel.h"
+
+namespace Ui {
+class ResourcePage;
+}
+
+namespace ResourceDownload {
+
+class ShaderPackDownloadDialog;
+
+class ShaderPackResourcePage : public ResourcePage {
+ Q_OBJECT
+
+ public:
+ template <typename T>
+ static T* create(ShaderPackDownloadDialog* dialog, BaseInstance& instance)
+ {
+ auto page = new T(dialog, instance);
+ auto model = static_cast<ShaderPackResourceModel*>(page->getModel());
+
+ connect(model, &ResourceModel::versionListUpdated, page, &ResourcePage::updateVersionList);
+ connect(model, &ResourceModel::projectInfoUpdated, page, &ResourcePage::updateUi);
+
+ return page;
+ }
+
+ ~ShaderPackResourcePage() override = default;
+
+ //: The plural version of 'shader pack'
+ [[nodiscard]] inline QString resourcesString() const override { return tr("shader packs"); }
+ //: The singular version of 'shader packs'
+ [[nodiscard]] inline QString resourceString() const override { return tr("shader pack"); }
+
+ [[nodiscard]] bool supportsFiltering() const override { return false; };
+
+ void addResourceToDialog(ModPlatform::IndexedPack&, ModPlatform::IndexedVersion&) override;
+
+ [[nodiscard]] QMap<QString, QString> urlHandlers() const override;
+
+ protected:
+ ShaderPackResourcePage(ShaderPackDownloadDialog* dialog, BaseInstance& instance);
+
+ protected slots:
+ void triggerSearch() override;
+};
+
+} // namespace ResourceDownload
diff --git a/launcher/ui/pages/modplatform/flame/FlameResourcePages.h b/launcher/ui/pages/modplatform/flame/FlameResourcePages.h
index 03cf7795..4507a32a 100644
--- a/launcher/ui/pages/modplatform/flame/FlameResourcePages.h
+++ b/launcher/ui/pages/modplatform/flame/FlameResourcePages.h
@@ -44,6 +44,7 @@
#include "ui/pages/modplatform/ModPage.h"
#include "ui/pages/modplatform/ResourcePackPage.h"
+#include "ui/pages/modplatform/ShaderPackPage.h"
namespace ResourceDownload {
diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthResourceModels.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthResourceModels.cpp
index b36339d7..bd433121 100644
--- a/launcher/ui/pages/modplatform/modrinth/ModrinthResourceModels.cpp
+++ b/launcher/ui/pages/modplatform/modrinth/ModrinthResourceModels.cpp
@@ -69,4 +69,26 @@ auto ModrinthResourcePackModel::documentToArray(QJsonDocument& obj) const -> QJs
return obj.object().value("hits").toArray();
}
+ModrinthShaderPackModel::ModrinthShaderPackModel(const BaseInstance& base) : ShaderPackResourceModel(base, new ModrinthAPI){}
+
+void ModrinthShaderPackModel::loadIndexedPack(ModPlatform::IndexedPack& m, QJsonObject& obj)
+{
+ ::Modrinth::loadIndexedPack(m, obj);
+}
+
+void ModrinthShaderPackModel::loadExtraPackInfo(ModPlatform::IndexedPack& m, QJsonObject& obj)
+{
+ ::Modrinth::loadExtraPackData(m, obj);
+}
+
+void ModrinthShaderPackModel::loadIndexedPackVersions(ModPlatform::IndexedPack& m, QJsonArray& arr)
+{
+ ::Modrinth::loadIndexedPackVersions(m, arr, APPLICATION->network(), &m_base_instance);
+}
+
+auto ModrinthShaderPackModel::documentToArray(QJsonDocument& obj) const -> QJsonArray
+{
+ return obj.object().value("hits").toArray();
+}
+
} // namespace ResourceDownload
diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthResourceModels.h b/launcher/ui/pages/modplatform/modrinth/ModrinthResourceModels.h
index 0a91ef23..80a48089 100644
--- a/launcher/ui/pages/modplatform/modrinth/ModrinthResourceModels.h
+++ b/launcher/ui/pages/modplatform/modrinth/ModrinthResourceModels.h
@@ -62,4 +62,22 @@ class ModrinthResourcePackModel : public ResourcePackResourceModel {
auto documentToArray(QJsonDocument& obj) const -> QJsonArray override;
};
+class ModrinthShaderPackModel : public ShaderPackResourceModel {
+ Q_OBJECT
+
+ public:
+ ModrinthShaderPackModel(const BaseInstance&);
+ ~ModrinthShaderPackModel() override = default;
+
+ private:
+ [[nodiscard]] QString debugName() const override { return Modrinth::debugName() + " (Model)"; }
+ [[nodiscard]] QString metaEntryBase() const override { return Modrinth::metaEntryBase(); }
+
+ void loadIndexedPack(ModPlatform::IndexedPack& m, QJsonObject& obj) override;
+ void loadExtraPackInfo(ModPlatform::IndexedPack& m, QJsonObject& obj) override;
+ void loadIndexedPackVersions(ModPlatform::IndexedPack& m, QJsonArray& arr) override;
+
+ auto documentToArray(QJsonDocument& obj) const -> QJsonArray override;
+};
+
} // namespace ResourceDownload
diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthResourcePages.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthResourcePages.cpp
index d32b9091..2826b5d3 100644
--- a/launcher/ui/pages/modplatform/modrinth/ModrinthResourcePages.cpp
+++ b/launcher/ui/pages/modplatform/modrinth/ModrinthResourcePages.cpp
@@ -100,10 +100,29 @@ ModrinthResourcePackPage::ModrinthResourcePackPage(ResourcePackDownloadDialog* d
m_ui->packDescription->setMetaEntry(metaEntryBase());
}
+ModrinthShaderPackPage::ModrinthShaderPackPage(ShaderPackDownloadDialog* dialog, BaseInstance& instance)
+ : ShaderPackResourcePage(dialog, instance)
+{
+ m_model = new ModrinthShaderPackModel(instance);
+ m_ui->packView->setModel(m_model);
+
+ addSortings();
+
+ // sometimes Qt just ignores virtual slots and doesn't work as intended it seems,
+ // so it's best not to connect them in the parent's constructor...
+ connect(m_ui->sortByBox, SIGNAL(currentIndexChanged(int)), this, SLOT(triggerSearch()));
+ connect(m_ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &ModrinthShaderPackPage::onSelectionChanged);
+ connect(m_ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &ModrinthShaderPackPage::onVersionSelectionChanged);
+ connect(m_ui->resourceSelectionButton, &QPushButton::clicked, this, &ModrinthShaderPackPage::onResourceSelected);
+
+ m_ui->packDescription->setMetaEntry(metaEntryBase());
+}
+
// 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...
auto ModrinthModPage::shouldDisplay() const -> bool { return true; }
auto ModrinthResourcePackPage::shouldDisplay() const -> bool { return true; }
+auto ModrinthShaderPackPage::shouldDisplay() const -> bool { return true; }
} // namespace ResourceDownload
diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthResourcePages.h b/launcher/ui/pages/modplatform/modrinth/ModrinthResourcePages.h
index be3740a1..8733a1b2 100644
--- a/launcher/ui/pages/modplatform/modrinth/ModrinthResourcePages.h
+++ b/launcher/ui/pages/modplatform/modrinth/ModrinthResourcePages.h
@@ -43,6 +43,7 @@
#include "ui/pages/modplatform/ModPage.h"
#include "ui/pages/modplatform/ResourcePackPage.h"
+#include "ui/pages/modplatform/ShaderPackPage.h"
namespace ResourceDownload {
@@ -102,4 +103,27 @@ class ModrinthResourcePackPage : public ResourcePackResourcePage {
[[nodiscard]] inline auto helpPage() const -> QString override { return ""; }
};
+class ModrinthShaderPackPage : public ShaderPackResourcePage {
+ Q_OBJECT
+
+ public:
+ static ModrinthShaderPackPage* create(ShaderPackDownloadDialog* dialog, BaseInstance& instance)
+ {
+ return ShaderPackResourcePage::create<ModrinthShaderPackPage>(dialog, instance);
+ }
+
+ ModrinthShaderPackPage(ShaderPackDownloadDialog* dialog, BaseInstance& instance);
+ ~ModrinthShaderPackPage() override = default;
+
+ [[nodiscard]] bool shouldDisplay() const override;
+
+ [[nodiscard]] inline auto displayName() const -> QString override { return Modrinth::displayName(); }
+ [[nodiscard]] inline auto icon() const -> QIcon override { return Modrinth::icon(); }
+ [[nodiscard]] inline auto id() const -> QString override { return Modrinth::id(); }
+ [[nodiscard]] inline auto debugName() const -> QString override { return Modrinth::debugName(); }
+ [[nodiscard]] inline auto metaEntryBase() const -> QString override { return Modrinth::metaEntryBase(); }
+
+ [[nodiscard]] inline auto helpPage() const -> QString override { return ""; }
+};
+
} // namespace ResourceDownload