diff --git a/launcher/ui/pages/modplatform/DataPackModel.cpp b/launcher/ui/pages/modplatform/DataPackModel.cpp index 10dd82952..d0efbd45f 100644 --- a/launcher/ui/pages/modplatform/DataPackModel.cpp +++ b/launcher/ui/pages/modplatform/DataPackModel.cpp @@ -9,11 +9,11 @@ namespace ResourceDownload { -DataPackResourceModel::DataPackResourceModel(const BaseInstance& base_inst, +DataPackResourceModel::DataPackResourceModel(ResourceFolderModel* resourceList, const ResourceAPI* api, QString debugName, QString metaEntryBase) - : ResourceModel(api), m_base_instance(base_inst), m_debugName(debugName + " (Model)"), m_metaEntryBase(metaEntryBase) + : ResourceModel(resourceList, api), m_debugName(debugName + " (Model)"), m_metaEntryBase(metaEntryBase) {} /******** Make data requests ********/ @@ -21,13 +21,17 @@ DataPackResourceModel::DataPackResourceModel(const BaseInstance& base_inst, ResourceAPI::SearchArgs DataPackResourceModel::createSearchArguments() { auto sort = getCurrentSortingMethodByIndex(); - return { ModPlatform::ResourceType::DataPack, m_nextSearchOffset, m_searchTerm, sort, ModPlatform::ModLoaderType::DataPack }; + return { .type = ModPlatform::ResourceType::DataPack, + .offset = m_nextSearchOffset, + .search = m_searchTerm, + .sorting = sort, + .loaders = ModPlatform::ModLoaderType::DataPack }; } ResourceAPI::VersionSearchArgs DataPackResourceModel::createVersionsArguments(const QModelIndex& entry) { auto pack = m_packs[entry.row()]; - return { pack, {}, ModPlatform::ModLoaderType::DataPack }; + return { .pack = pack, .mcVersions = {}, .loaders = ModPlatform::ModLoaderType::DataPack }; } ResourceAPI::ProjectInfoArgs DataPackResourceModel::createInfoArguments(const QModelIndex& entry) diff --git a/launcher/ui/pages/modplatform/DataPackModel.h b/launcher/ui/pages/modplatform/DataPackModel.h index e5ed5129e..6a23d4989 100644 --- a/launcher/ui/pages/modplatform/DataPackModel.h +++ b/launcher/ui/pages/modplatform/DataPackModel.h @@ -21,7 +21,7 @@ class DataPackResourceModel : public ResourceModel { Q_OBJECT public: - DataPackResourceModel(BaseInstance const&, const ResourceAPI*, QString, QString); + DataPackResourceModel(ResourceFolderModel*, const ResourceAPI*, QString, QString); /* Ask the API for more information */ void searchWithTerm(const QString& term, unsigned int sort); @@ -34,9 +34,6 @@ class DataPackResourceModel : public ResourceModel { ResourceAPI::VersionSearchArgs createVersionsArguments(const QModelIndex&) override; ResourceAPI::ProjectInfoArgs createInfoArguments(const QModelIndex&) override; - protected: - const BaseInstance& m_base_instance; - private: QString m_debugName; QString m_metaEntryBase; diff --git a/launcher/ui/pages/modplatform/DataPackPage.cpp b/launcher/ui/pages/modplatform/DataPackPage.cpp index c5aecafdc..160b5f211 100644 --- a/launcher/ui/pages/modplatform/DataPackPage.cpp +++ b/launcher/ui/pages/modplatform/DataPackPage.cpp @@ -43,7 +43,7 @@ DataPackResourcePage::DataPackResourcePage(ResourceDownloadDialog* dialog, const ResourceAPI* api) : ResourcePage(dialog, instance, prepareDataPackDescriptor(), std::move(provider)) { - m_model = new DataPackResourceModel(instance, api, debugName(), metaEntryBase()); + m_model = new DataPackResourceModel(getDialog()->getBaseModel(), api, debugName(), metaEntryBase()); m_ui->packView->setModel(m_model); addSortings(); diff --git a/launcher/ui/pages/modplatform/ModModel.cpp b/launcher/ui/pages/modplatform/ModModel.cpp index b447fd824..8993bc321 100644 --- a/launcher/ui/pages/modplatform/ModModel.cpp +++ b/launcher/ui/pages/modplatform/ModModel.cpp @@ -21,8 +21,15 @@ namespace ResourceDownload { -ModModel::ModModel(BaseInstance& baseInst, const ResourceAPI* api, const QString& debugName, QString metaEntryBase) - : ResourceModel(api), m_baseInstance(baseInst), m_debugName(debugName + " (Model)"), m_metaEntryBase(std::move(metaEntryBase)) +ModModel::ModModel(BaseInstance& baseInst, + ResourceFolderModel* resourceList, + const ResourceAPI* api, + const QString& debugName, + QString metaEntryBase) + : ResourceModel(resourceList, api) + , m_baseInstance(baseInst) + , m_debugName(debugName + " (Model)") + , m_metaEntryBase(std::move(metaEntryBase)) {} /******** Make data requests ********/ @@ -104,28 +111,6 @@ void ModModel::searchWithTerm(const QString& term, unsigned int sort, bool filte refresh(); } -bool ModModel::isPackInstalled(ModPlatform::IndexedPack::Ptr pack) const -{ - auto allMods = static_cast(m_baseInstance).loaderModList()->allMods(); - return std::ranges::any_of(allMods, [pack](Mod* mod) { - if (auto meta = mod->metadata(); meta) { - return meta->provider == pack->provider && meta->project_id == pack->addonId; - } - return false; - }); -} - -QVariant ModModel::getInstalledPackVersion(ModPlatform::IndexedPack::Ptr pack) const -{ - auto allMods = static_cast(m_baseInstance).loaderModList()->allMods(); - for (auto* mod : allMods) { - if (auto meta = mod->metadata(); meta && meta->provider == pack->provider && meta->project_id == pack->addonId) { - return meta->version(); - } - } - return {}; -} - namespace { bool checkSide(ModPlatform::SideType filter, ModPlatform::SideType value) diff --git a/launcher/ui/pages/modplatform/ModModel.h b/launcher/ui/pages/modplatform/ModModel.h index 0e314279d..ca5a6d808 100644 --- a/launcher/ui/pages/modplatform/ModModel.h +++ b/launcher/ui/pages/modplatform/ModModel.h @@ -28,14 +28,12 @@ class ModModel : public ResourceModel { Q_OBJECT public: - ModModel(BaseInstance&, const ResourceAPI* api, const QString& debugName, QString metaEntryBase); + ModModel(BaseInstance&, ResourceFolderModel*, const ResourceAPI* api, const QString& debugName, QString metaEntryBase); /* Ask the API for more information */ void searchWithTerm(const QString& term, unsigned int sort, bool filterChanged); void setFilter(std::shared_ptr filter) { m_filter = std::move(filter); } - QVariant getInstalledPackVersion(ModPlatform::IndexedPack::Ptr pack) const override; - [[nodiscard]] QString debugName() const override { return m_debugName; } [[nodiscard]] QString metaEntryBase() const override { return m_metaEntryBase; } @@ -45,8 +43,6 @@ class ModModel : public ResourceModel { ResourceAPI::ProjectInfoArgs createInfoArguments(const QModelIndex& index) override; protected: - bool isPackInstalled(ModPlatform::IndexedPack::Ptr pack) const override; - bool checkFilters(ModPlatform::IndexedPack::Ptr pack) override; bool checkVersionFilters(const ModPlatform::IndexedVersion& version) override; diff --git a/launcher/ui/pages/modplatform/ModPage.cpp b/launcher/ui/pages/modplatform/ModPage.cpp index bd935077c..0e138c36f 100644 --- a/launcher/ui/pages/modplatform/ModPage.cpp +++ b/launcher/ui/pages/modplatform/ModPage.cpp @@ -76,7 +76,7 @@ ModPage::ModPage(ResourceDownloadDialog* dialog, ModFilterWidget* filterWidget) : ResourcePage(dialog, instance, prepareModDescriptor(), std::move(p)), m_api(api) { - auto* model = new ModModel(instance, api, debugName(), metaEntryBase()); + auto* model = new ModModel(instance, getDialog()->getBaseModel(), api, debugName(), metaEntryBase()); m_model = model; m_ui->packView->setModel(m_model); diff --git a/launcher/ui/pages/modplatform/ResourceModel.cpp b/launcher/ui/pages/modplatform/ResourceModel.cpp index d09054317..21d486ee4 100644 --- a/launcher/ui/pages/modplatform/ResourceModel.cpp +++ b/launcher/ui/pages/modplatform/ResourceModel.cpp @@ -18,19 +18,19 @@ #include "BuildConfig.h" #include "settings/SettingsObject.h" +#include "minecraft/mod/ResourceFolderModel.h" +#include "modplatform/ModIndex.h" #include "modplatform/ResourceAPI.h" #include "net/ApiRequest.h" #include "net/NetJob.h" -#include "modplatform/ModIndex.h" - #include "ui/widgets/ProjectItem.h" namespace ResourceDownload { QHash ResourceModel::s_runningModels; -ResourceModel::ResourceModel(const ResourceAPI* api) : m_api(api) +ResourceModel::ResourceModel(ResourceFolderModel* resourceList, const ResourceAPI* api) : m_resourceList(resourceList), m_api(api) { s_runningModels.insert(this, true); if (APPLICATION_DYN) { @@ -43,6 +43,38 @@ ResourceModel::~ResourceModel() s_runningModels.find(this).value() = false; } +bool ResourceModel::isPackInstalled(ModPlatform::IndexedPack::Ptr pack) const +{ + if (!m_resourceList) { + return false; + } + + for (qsizetype i = 0; i < m_resourceList->size(); ++i) { + auto& resource = m_resourceList->at(i); + if (auto meta = resource.metadata(); meta && meta->provider == pack->provider && meta->project_id == pack->addonId) { + return true; + } + } + return false; +} + +QVariant ResourceModel::getInstalledPackVersion(ModPlatform::IndexedPack::Ptr pack) const +{ + if (!m_resourceList) { + return {}; + } + + for (qsizetype i = 0; i < m_resourceList->size(); ++i) { + auto& resource = m_resourceList->at(i); + if (auto meta = resource.metadata(); meta) { + if (meta->provider == pack->provider && meta->project_id == pack->addonId) { + return meta->version(); + } + } + } + return {}; +} + auto ResourceModel::data(const QModelIndex& index, int role) const -> QVariant { int pos = index.row(); diff --git a/launcher/ui/pages/modplatform/ResourceModel.h b/launcher/ui/pages/modplatform/ResourceModel.h index 43dd586e2..b5f713a15 100644 --- a/launcher/ui/pages/modplatform/ResourceModel.h +++ b/launcher/ui/pages/modplatform/ResourceModel.h @@ -19,6 +19,7 @@ class NetJob; class ResourceAPI; +class ResourceFolderModel; namespace ModPlatform { struct IndexedPack; @@ -34,7 +35,7 @@ class ResourceModel : public QAbstractListModel { public: using DownloadTaskPtr = shared_qobject_ptr; - explicit ResourceModel(const ResourceAPI* api); + ResourceModel(ResourceFolderModel*, const ResourceAPI* api); ~ResourceModel() override; auto data(const QModelIndex& /*index*/, int role) const -> QVariant override; @@ -54,7 +55,7 @@ class ResourceModel : public QAbstractListModel { auto getSortingMethods() const { return m_api->getSortingMethods(); } - virtual QVariant getInstalledPackVersion(ModPlatform::IndexedPack::Ptr /*unused*/) const { return {}; } + virtual QVariant getInstalledPackVersion(ModPlatform::IndexedPack::Ptr /*unused*/) const; /** Whether the version is opted out or not. Currently only makes sense in CF. */ virtual bool optedOut(const ModPlatform::IndexedVersion& ver) const { @@ -110,7 +111,7 @@ class ResourceModel : public QAbstractListModel { auto getCurrentSortingMethodByIndex() const -> std::optional; - virtual bool isPackInstalled(ModPlatform::IndexedPack::Ptr /*unused*/) const { return false; } + virtual bool isPackInstalled(ModPlatform::IndexedPack::Ptr /*unused*/) const; protected: /* Basic search parameters */ @@ -119,6 +120,8 @@ class ResourceModel : public QAbstractListModel { QString m_searchTerm; unsigned int m_currentSortIndex = 0; + ResourceFolderModel* m_resourceList = nullptr; + const ResourceAPI* m_api; // Job for searching for new entries diff --git a/launcher/ui/pages/modplatform/ResourcePackModel.cpp b/launcher/ui/pages/modplatform/ResourcePackModel.cpp index 2ba844f92..c076260fb 100644 --- a/launcher/ui/pages/modplatform/ResourcePackModel.cpp +++ b/launcher/ui/pages/modplatform/ResourcePackModel.cpp @@ -9,11 +9,11 @@ namespace ResourceDownload { -ResourcePackResourceModel::ResourcePackResourceModel(const BaseInstance& base_inst, +ResourcePackResourceModel::ResourcePackResourceModel(ResourceFolderModel* resourceList, const ResourceAPI* api, const QString& debugName, QString metaEntryBase) - : ResourceModel(api), m_base_instance(base_inst), m_debugName(debugName + " (Model)"), m_metaEntryBase(std::move(metaEntryBase)) + : ResourceModel(resourceList, api), m_debugName(debugName + " (Model)"), m_metaEntryBase(std::move(metaEntryBase)) {} /******** Make data requests ********/ diff --git a/launcher/ui/pages/modplatform/ResourcePackModel.h b/launcher/ui/pages/modplatform/ResourcePackModel.h index 6958276fa..3a2c15dcf 100644 --- a/launcher/ui/pages/modplatform/ResourcePackModel.h +++ b/launcher/ui/pages/modplatform/ResourcePackModel.h @@ -18,7 +18,7 @@ class ResourcePackResourceModel : public ResourceModel { Q_OBJECT public: - ResourcePackResourceModel(const BaseInstance&, const ResourceAPI*, const QString& debugName, QString metaEntryBase); + ResourcePackResourceModel(ResourceFolderModel*, const ResourceAPI*, const QString& debugName, QString metaEntryBase); /* Ask the API for more information */ void searchWithTerm(const QString& term, unsigned int sort); @@ -31,9 +31,6 @@ class ResourcePackResourceModel : public ResourceModel { ResourceAPI::VersionSearchArgs createVersionsArguments(const QModelIndex&) override; ResourceAPI::ProjectInfoArgs createInfoArguments(const QModelIndex&) override; - protected: - const BaseInstance& m_base_instance; - private: QString m_debugName; QString m_metaEntryBase; diff --git a/launcher/ui/pages/modplatform/ResourcePackPage.cpp b/launcher/ui/pages/modplatform/ResourcePackPage.cpp index 3d81f4a14..ffa8ffb08 100644 --- a/launcher/ui/pages/modplatform/ResourcePackPage.cpp +++ b/launcher/ui/pages/modplatform/ResourcePackPage.cpp @@ -42,7 +42,7 @@ ResourcePackResourcePage::ResourcePackResourcePage(ResourceDownloadDialog* dialo const ResourceAPI* api) : ResourcePage(dialog, instance, prepareResourcePackDescriptor(), std::move(provider)) { - m_model = new ResourcePackResourceModel(instance, api, debugName(), metaEntryBase()); + m_model = new ResourcePackResourceModel(getDialog()->getBaseModel(), api, debugName(), metaEntryBase()); m_ui->packView->setModel(m_model); addSortings(); diff --git a/launcher/ui/pages/modplatform/ShaderPackModel.cpp b/launcher/ui/pages/modplatform/ShaderPackModel.cpp index 5f2d34f15..503b40a65 100644 --- a/launcher/ui/pages/modplatform/ShaderPackModel.cpp +++ b/launcher/ui/pages/modplatform/ShaderPackModel.cpp @@ -9,11 +9,11 @@ namespace ResourceDownload { -ShaderPackResourceModel::ShaderPackResourceModel(const BaseInstance& baseInst, +ShaderPackResourceModel::ShaderPackResourceModel(ResourceFolderModel* resourceList, const ResourceAPI* api, const QString& debugName, QString metaEntryBase) - : ResourceModel(api), m_baseInstance(baseInst), m_debugName(debugName + " (Model)"), m_metaEntryBase(std::move(metaEntryBase)) + : ResourceModel(resourceList, api), m_debugName(debugName + " (Model)"), m_metaEntryBase(std::move(metaEntryBase)) {} /******** Make data requests ********/ diff --git a/launcher/ui/pages/modplatform/ShaderPackModel.h b/launcher/ui/pages/modplatform/ShaderPackModel.h index 2627b9eaa..09e8151cc 100644 --- a/launcher/ui/pages/modplatform/ShaderPackModel.h +++ b/launcher/ui/pages/modplatform/ShaderPackModel.h @@ -18,7 +18,7 @@ class ShaderPackResourceModel : public ResourceModel { Q_OBJECT public: - ShaderPackResourceModel(const BaseInstance&, const ResourceAPI*, const QString& debugName, QString metaEntryBase); + ShaderPackResourceModel(ResourceFolderModel*, const ResourceAPI*, const QString& debugName, QString metaEntryBase); /* Ask the API for more information */ void searchWithTerm(const QString& term, unsigned int sort); @@ -31,9 +31,6 @@ class ShaderPackResourceModel : public ResourceModel { ResourceAPI::VersionSearchArgs createVersionsArguments(const QModelIndex&) override; ResourceAPI::ProjectInfoArgs createInfoArguments(const QModelIndex&) override; - protected: - const BaseInstance& m_baseInstance; - private: QString m_debugName; QString m_metaEntryBase; diff --git a/launcher/ui/pages/modplatform/ShaderPackPage.cpp b/launcher/ui/pages/modplatform/ShaderPackPage.cpp index ac5150e59..5a40d8a3f 100644 --- a/launcher/ui/pages/modplatform/ShaderPackPage.cpp +++ b/launcher/ui/pages/modplatform/ShaderPackPage.cpp @@ -40,7 +40,7 @@ ShaderPackResourcePage::ShaderPackResourcePage(ResourceDownloadDialog* dialog, const ResourceAPI* api) : ResourcePage(dialog, instance, prepareShaderPackDescriptor(), std::move(provider)) { - m_model = new ShaderPackResourceModel(instance, api, debugName(), metaEntryBase()); + m_model = new ShaderPackResourceModel(getDialog()->getBaseModel(), api, debugName(), metaEntryBase()); m_ui->packView->setModel(m_model); addSortings(); diff --git a/launcher/ui/pages/modplatform/TexturePackModel.cpp b/launcher/ui/pages/modplatform/TexturePackModel.cpp index df167ce7e..ff33c911e 100644 --- a/launcher/ui/pages/modplatform/TexturePackModel.cpp +++ b/launcher/ui/pages/modplatform/TexturePackModel.cpp @@ -14,7 +14,7 @@ static std::vector s_availableVersions = {}; namespace ResourceDownload { -TexturePackResourceModel::TexturePackResourceModel(const BaseInstance& inst, +TexturePackResourceModel::TexturePackResourceModel(ResourceFolderModel* inst, const ResourceAPI* api, const QString& debugName, QString metaEntryBase) diff --git a/launcher/ui/pages/modplatform/TexturePackModel.h b/launcher/ui/pages/modplatform/TexturePackModel.h index 99dc7c17f..18fab7fe6 100644 --- a/launcher/ui/pages/modplatform/TexturePackModel.h +++ b/launcher/ui/pages/modplatform/TexturePackModel.h @@ -13,7 +13,7 @@ class TexturePackResourceModel : public ResourcePackResourceModel { Q_OBJECT public: - TexturePackResourceModel(const BaseInstance& inst, const ResourceAPI* api, const QString& debugName, QString metaEntryBase); + TexturePackResourceModel(ResourceFolderModel* inst, const ResourceAPI* api, const QString& debugName, QString metaEntryBase); inline ::Version maximumTexturePackVersion() const { return { "1.6" }; } diff --git a/launcher/ui/pages/modplatform/TexturePackPage.cpp b/launcher/ui/pages/modplatform/TexturePackPage.cpp index a95276922..4b2a369e5 100644 --- a/launcher/ui/pages/modplatform/TexturePackPage.cpp +++ b/launcher/ui/pages/modplatform/TexturePackPage.cpp @@ -44,7 +44,7 @@ TexturePackResourcePage::TexturePackResourcePage(ResourceDownloadDialog* dialog, { m_model = model; if (!m_model) { - m_model = new TexturePackResourceModel(instance, api, debugName(), metaEntryBase()); + m_model = new TexturePackResourceModel(getDialog()->getBaseModel(), api, debugName(), metaEntryBase()); } m_ui->packView->setModel(m_model); diff --git a/launcher/ui/pages/modplatform/flame/FlameResourceModels.cpp b/launcher/ui/pages/modplatform/flame/FlameResourceModels.cpp index 110b4dab2..f2f385c31 100644 --- a/launcher/ui/pages/modplatform/flame/FlameResourceModels.cpp +++ b/launcher/ui/pages/modplatform/flame/FlameResourceModels.cpp @@ -6,6 +6,7 @@ #include "Json.h" +#include "minecraft/MinecraftInstance.h" #include "minecraft/PackProfile.h" #include "modplatform/flame/FlameAPI.h" #include "ui/pages/modplatform/flame/FlameResourcePages.h" @@ -17,15 +18,15 @@ static bool isOptedOut(const ModPlatform::IndexedVersion& ver) return ver.downloadUrl.isEmpty(); } -FlameTexturePackModel::FlameTexturePackModel(const BaseInstance& base) - : TexturePackResourceModel(base, &FlameAPI::get(), Flame::debugName(), Flame::metaEntryBase()) +FlameTexturePackModel::FlameTexturePackModel(ResourceFolderModel* resourceList) + : TexturePackResourceModel(resourceList, &FlameAPI::get(), Flame::debugName(), Flame::metaEntryBase()) {} ResourceAPI::SearchArgs FlameTexturePackModel::createSearchArguments() { auto args = TexturePackResourceModel::createSearchArguments(); - auto profile = static_cast(m_base_instance).getPackProfile(); + auto profile = static_cast(*m_resourceList->instance()).getPackProfile(); QString instance_minecraft_version = profile->getComponentVersion("net.minecraft"); // Bypass the texture pack logic, because we can't do multiple versions in the API query diff --git a/launcher/ui/pages/modplatform/flame/FlameResourceModels.h b/launcher/ui/pages/modplatform/flame/FlameResourceModels.h index f719aa46d..1218bfccd 100644 --- a/launcher/ui/pages/modplatform/flame/FlameResourceModels.h +++ b/launcher/ui/pages/modplatform/flame/FlameResourceModels.h @@ -12,7 +12,7 @@ class FlameTexturePackModel : public TexturePackResourceModel { Q_OBJECT public: - FlameTexturePackModel(const BaseInstance&); + FlameTexturePackModel(ResourceFolderModel*); ~FlameTexturePackModel() override = default; bool optedOut(const ModPlatform::IndexedVersion& ver) const override; diff --git a/launcher/ui/pages/modplatform/flame/FlameResourcePages.cpp b/launcher/ui/pages/modplatform/flame/FlameResourcePages.cpp index 0e001b75a..a29eeab86 100644 --- a/launcher/ui/pages/modplatform/flame/FlameResourcePages.cpp +++ b/launcher/ui/pages/modplatform/flame/FlameResourcePages.cpp @@ -74,7 +74,8 @@ ResourcePackResourcePage* Flame::createResourcePackResourcePage(ResourceDownload TexturePackResourcePage* Flame::createTexturePackResourcePage(ResourceDownloadDialog* dialog, BaseInstance& instance) { - return new TexturePackResourcePage(dialog, instance, prepareFlame(), &FlameAPI::get(), new FlameTexturePackModel(instance)); + return new TexturePackResourcePage(dialog, instance, prepareFlame(), &FlameAPI::get(), + new FlameTexturePackModel(dialog->getBaseModel())); } ModPage* Flame::createModPage(ResourceDownloadDialog* dialog, BaseInstance& instance)