Skip to content

Commit

Permalink
Merge pull request #1605 from TheKodeToad/flame-shaders
Browse files Browse the repository at this point in the history
  • Loading branch information
Scrumplex committed Sep 16, 2023
2 parents 4cb4244 + 94c1cd6 commit bf6dc10
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 0 deletions.
2 changes: 2 additions & 0 deletions launcher/modplatform/flame/FlameAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class FlameAPI : public NetworkResourceAPI {
return 6;
case ModPlatform::ResourceType::RESOURCE_PACK:
return 12;
case ModPlatform::ResourceType::SHADER_PACK:
return 6552;
}
}

Expand Down
2 changes: 2 additions & 0 deletions launcher/ui/dialogs/ResourceDownloadDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,8 @@ QList<BasePage*> ShaderPackDownloadDialog::getPages()
{
QList<BasePage*> pages;
pages.append(ModrinthShaderPackPage::create(this, *m_instance));
if (APPLICATION->capabilities() & Application::SupportsFlame)
pages.append(FlameShaderPackPage::create(this, *m_instance));
return pages;
}

Expand Down
23 changes: 23 additions & 0 deletions launcher/ui/pages/modplatform/flame/FlameResourceModels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,27 @@ auto FlameTexturePackModel::documentToArray(QJsonDocument& obj) const -> QJsonAr
return Json::ensureArray(obj.object(), "data");
}

FlameShaderPackModel::FlameShaderPackModel(const BaseInstance& base) : ShaderPackResourceModel(base, new FlameAPI) {}

void FlameShaderPackModel::loadIndexedPack(ModPlatform::IndexedPack& m, QJsonObject& obj)
{
FlameMod::loadIndexedPack(m, obj);
}

// We already deal with the URLs when initializing the pack, due to the API response's structure
void FlameShaderPackModel::loadExtraPackInfo(ModPlatform::IndexedPack& m, QJsonObject& obj)
{
FlameMod::loadBody(m, obj);
}

void FlameShaderPackModel::loadIndexedPackVersions(ModPlatform::IndexedPack& m, QJsonArray& arr)
{
FlameMod::loadIndexedPackVersions(m, arr, APPLICATION->network(), &m_base_instance);
}

auto FlameShaderPackModel::documentToArray(QJsonDocument& obj) const -> QJsonArray
{
return Json::ensureArray(obj.object(), "data");
}

} // namespace ResourceDownload
17 changes: 17 additions & 0 deletions launcher/ui/pages/modplatform/flame/FlameResourceModels.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,21 @@ class FlameTexturePackModel : public TexturePackResourceModel {
auto documentToArray(QJsonDocument& obj) const -> QJsonArray override;
};

class FlameShaderPackModel : public ShaderPackResourceModel {
Q_OBJECT

public:
FlameShaderPackModel(const BaseInstance&);
~FlameShaderPackModel() override = default;

private:
[[nodiscard]] QString debugName() const override { return Flame::debugName() + " (Model)"; }
[[nodiscard]] QString metaEntryBase() const override { return Flame::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
43 changes: 43 additions & 0 deletions launcher/ui/pages/modplatform/flame/FlameResourcePages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,45 @@ void FlameTexturePackPage::openUrl(const QUrl& url)
TexturePackResourcePage::openUrl(url);
}

FlameShaderPackPage::FlameShaderPackPage(ShaderPackDownloadDialog* dialog, BaseInstance& instance)
: ShaderPackResourcePage(dialog, instance)
{
m_model = new FlameShaderPackModel(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, &FlameShaderPackPage::onSelectionChanged);
connect(m_ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &FlameShaderPackPage::onVersionSelectionChanged);
connect(m_ui->resourceSelectionButton, &QPushButton::clicked, this, &FlameShaderPackPage::onResourceSelected);

m_ui->packDescription->setMetaEntry(metaEntryBase());
}

bool FlameShaderPackPage::optedOut(ModPlatform::IndexedVersion& ver) const
{
return isOptedOut(ver);
}

void FlameShaderPackPage::openUrl(const QUrl& url)
{
if (url.scheme().isEmpty()) {
QString query = url.query(QUrl::FullyDecoded);

if (query.startsWith("remoteUrl=")) {
// attempt to resolve url from warning page
query.remove(0, 10);
ShaderPackResourcePage::openUrl({ QUrl::fromPercentEncoding(query.toUtf8()) }); // double decoding is necessary
return;
}
}

ShaderPackResourcePage::openUrl(url);
}

// 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...
Expand All @@ -188,5 +227,9 @@ auto FlameTexturePackPage::shouldDisplay() const -> bool
{
return true;
}
auto FlameShaderPackPage::shouldDisplay() const -> bool
{
return true;
}

} // namespace ResourceDownload
28 changes: 28 additions & 0 deletions launcher/ui/pages/modplatform/flame/FlameResourcePages.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

#include "ui/pages/modplatform/ModPage.h"
#include "ui/pages/modplatform/ResourcePackPage.h"
#include "ui/pages/modplatform/ShaderPackPage.h"
#include "ui/pages/modplatform/TexturePackPage.h"

namespace ResourceDownload {
Expand Down Expand Up @@ -155,4 +156,31 @@ class FlameTexturePackPage : public TexturePackResourcePage {
void openUrl(const QUrl& url) override;
};

class FlameShaderPackPage : public ShaderPackResourcePage {
Q_OBJECT

public:
static FlameShaderPackPage* create(ShaderPackDownloadDialog* dialog, BaseInstance& instance)
{
return ShaderPackResourcePage::create<FlameShaderPackPage>(dialog, instance);
}

FlameShaderPackPage(ShaderPackDownloadDialog* dialog, BaseInstance& instance);
~FlameShaderPackPage() override = default;

[[nodiscard]] bool shouldDisplay() const override;

[[nodiscard]] inline auto displayName() const -> QString override { return Flame::displayName(); }
[[nodiscard]] inline auto icon() const -> QIcon override { return Flame::icon(); }
[[nodiscard]] inline auto id() const -> QString override { return Flame::id(); }
[[nodiscard]] inline auto debugName() const -> QString override { return Flame::debugName(); }
[[nodiscard]] inline auto metaEntryBase() const -> QString override { return Flame::metaEntryBase(); }

[[nodiscard]] inline auto helpPage() const -> QString override { return ""; }

bool optedOut(ModPlatform::IndexedVersion& ver) const override;

void openUrl(const QUrl& url) override;
};

} // namespace ResourceDownload

0 comments on commit bf6dc10

Please sign in to comment.