From 74311a54cf2f423a160ce0999bd5ad7e5c62f243 Mon Sep 17 00:00:00 2001 From: Jamie Mansfield Date: Fri, 28 May 2021 15:03:14 +0100 Subject: NOISSUE Support ATLauncher optional mods --- .../modplatform/atlauncher/ATLPackInstallTask.cpp | 21 ++++++++++++++++++--- .../modplatform/atlauncher/ATLPackInstallTask.h | 5 +++++ .../modplatform/atlauncher/ATLPackManifest.cpp | 3 +++ api/logic/modplatform/atlauncher/ATLPackManifest.h | 3 +++ 4 files changed, 29 insertions(+), 3 deletions(-) (limited to 'api/logic/modplatform/atlauncher') diff --git a/api/logic/modplatform/atlauncher/ATLPackInstallTask.cpp b/api/logic/modplatform/atlauncher/ATLPackInstallTask.cpp index 89c4dfd3..89829c05 100644 --- a/api/logic/modplatform/atlauncher/ATLPackInstallTask.cpp +++ b/api/logic/modplatform/atlauncher/ATLPackInstallTask.cpp @@ -457,16 +457,31 @@ void PackInstallTask::extractConfigs() void PackInstallTask::downloadMods() { qDebug() << "PackInstallTask::installMods: " << QThread::currentThreadId(); + + QVector optionalMods; + for (const auto& mod : m_version.mods) { + if (mod.optional) { + optionalMods.push_back(mod); + } + } + + // Select optional mods, if pack contains any + QVector selectedMods; + if (!optionalMods.isEmpty()) { + setStatus(tr("Selecting optional mods...")); + selectedMods = m_support->chooseOptionalMods(optionalMods); + } + setStatus(tr("Downloading mods...")); jarmods.clear(); jobPtr.reset(new NetJob(tr("Mod download"))); for(const auto& mod : m_version.mods) { // skip non-client mods - if (!mod.client) continue; + if(!mod.client) continue; - // skip optional mods for now - if(mod.optional) continue; + // skip optional mods that were not selected + if(mod.optional && !selectedMods.contains(mod.name)) continue; QString url; switch(mod.download) { diff --git a/api/logic/modplatform/atlauncher/ATLPackInstallTask.h b/api/logic/modplatform/atlauncher/ATLPackInstallTask.h index 3647e471..8233c376 100644 --- a/api/logic/modplatform/atlauncher/ATLPackInstallTask.h +++ b/api/logic/modplatform/atlauncher/ATLPackInstallTask.h @@ -18,6 +18,11 @@ namespace ATLauncher { class MULTIMC_LOGIC_EXPORT UserInteractionSupport { public: + /** + * Requests a user interaction to select which optional mods should be installed. + */ + virtual QVector chooseOptionalMods(QVector mods) = 0; + /** * Requests a user interaction to select a component version from a given version list * and constrained to a given Minecraft version. diff --git a/api/logic/modplatform/atlauncher/ATLPackManifest.cpp b/api/logic/modplatform/atlauncher/ATLPackManifest.cpp index 57cc52b6..149cb9c1 100644 --- a/api/logic/modplatform/atlauncher/ATLPackManifest.cpp +++ b/api/logic/modplatform/atlauncher/ATLPackManifest.cpp @@ -143,7 +143,10 @@ static void loadVersionMod(ATLauncher::VersionMod & p, QJsonObject & obj) { p.decompFile = Json::requireString(obj, "decompFile"); } + p.description = Json::ensureString(obj, QString("description"), ""); p.optional = Json::ensureBoolean(obj, QString("optional"), false); + p.recommended = Json::ensureBoolean(obj, QString("recommended"), false); + p.selected = Json::ensureBoolean(obj, QString("selected"), false); p.client = Json::ensureBoolean(obj, QString("client"), false); } diff --git a/api/logic/modplatform/atlauncher/ATLPackManifest.h b/api/logic/modplatform/atlauncher/ATLPackManifest.h index 937106a5..48e1d344 100644 --- a/api/logic/modplatform/atlauncher/ATLPackManifest.h +++ b/api/logic/modplatform/atlauncher/ATLPackManifest.h @@ -86,7 +86,10 @@ struct VersionMod QString decompType_raw; QString decompFile; + QString description; bool optional; + bool recommended; + bool selected; bool client; }; -- cgit From 4ba0c9c2986d9fb133db923d2da60de9272ccc0a Mon Sep 17 00:00:00 2001 From: Jamie Mansfield Date: Fri, 28 May 2021 23:10:02 +0100 Subject: NOISSUE Support mod grouping and dependencies --- .../modplatform/atlauncher/ATLPackManifest.cpp | 13 ++++ api/logic/modplatform/atlauncher/ATLPackManifest.h | 8 +++ .../atlauncher/AtlOptionalModDialog.cpp | 83 ++++++++++++++++++++-- .../modplatform/atlauncher/AtlOptionalModDialog.h | 6 ++ 4 files changed, 103 insertions(+), 7 deletions(-) (limited to 'api/logic/modplatform/atlauncher') diff --git a/api/logic/modplatform/atlauncher/ATLPackManifest.cpp b/api/logic/modplatform/atlauncher/ATLPackManifest.cpp index 149cb9c1..f28fd35c 100644 --- a/api/logic/modplatform/atlauncher/ATLPackManifest.cpp +++ b/api/logic/modplatform/atlauncher/ATLPackManifest.cpp @@ -147,7 +147,20 @@ static void loadVersionMod(ATLauncher::VersionMod & p, QJsonObject & obj) { p.optional = Json::ensureBoolean(obj, QString("optional"), false); p.recommended = Json::ensureBoolean(obj, QString("recommended"), false); p.selected = Json::ensureBoolean(obj, QString("selected"), false); + p.hidden = Json::ensureBoolean(obj, QString("hidden"), false); + p.library = Json::ensureBoolean(obj, QString("library"), false); + p.group = Json::ensureString(obj, QString("group"), ""); + if(obj.contains("depends")) { + auto dependsArr = Json::requireArray(obj, "depends"); + for (const auto depends : dependsArr) { + p.depends.append(Json::requireString(depends)); + } + } + p.client = Json::ensureBoolean(obj, QString("client"), false); + + // computed + p.effectively_hidden = p.hidden || p.library; } void ATLauncher::loadVersion(PackVersion & v, QJsonObject & obj) diff --git a/api/logic/modplatform/atlauncher/ATLPackManifest.h b/api/logic/modplatform/atlauncher/ATLPackManifest.h index 48e1d344..376587b0 100644 --- a/api/logic/modplatform/atlauncher/ATLPackManifest.h +++ b/api/logic/modplatform/atlauncher/ATLPackManifest.h @@ -90,7 +90,15 @@ struct VersionMod bool optional; bool recommended; bool selected; + bool hidden; + bool library; + QString group; + QVector depends; + bool client; + + // computed + bool effectively_hidden; }; struct PackVersion diff --git a/application/pages/modplatform/atlauncher/AtlOptionalModDialog.cpp b/application/pages/modplatform/atlauncher/AtlOptionalModDialog.cpp index 129d9fed..cffe5d55 100644 --- a/application/pages/modplatform/atlauncher/AtlOptionalModDialog.cpp +++ b/application/pages/modplatform/atlauncher/AtlOptionalModDialog.cpp @@ -4,8 +4,16 @@ AtlOptionalModListModel::AtlOptionalModListModel(QWidget *parent, QVector mods) : QAbstractListModel(parent), m_mods(mods) { - for (const auto& mod : mods) { - m_selection[mod.name] = mod.selected; + // fill mod index + for (int i = 0; i < m_mods.size(); i++) { + auto mod = m_mods.at(i); + m_index[mod.name] = i; + } + // set initial state + for (int i = 0; i < m_mods.size(); i++) { + auto mod = m_mods.at(i); + m_selection[mod.name] = false; + setMod(mod, i, mod.selected, false); } } @@ -61,11 +69,7 @@ bool AtlOptionalModListModel::setData(const QModelIndex &index, const QVariant & auto row = index.row(); auto mod = m_mods.at(row); - // toggle the state - m_selection[mod.name] = !m_selection[mod.name]; - - emit dataChanged(AtlOptionalModListModel::index(index.row(), EnabledColumn), - AtlOptionalModListModel::index(index.row(), EnabledColumn)); + toggleMod(mod, row); return true; } @@ -113,6 +117,71 @@ void AtlOptionalModListModel::clearAll() { AtlOptionalModListModel::index(m_mods.size() - 1, EnabledColumn)); } +void AtlOptionalModListModel::toggleMod(ATLauncher::VersionMod mod, int index) { + setMod(mod, index, !m_selection[mod.name]); +} + +void AtlOptionalModListModel::setMod(ATLauncher::VersionMod mod, int index, bool enable, bool shouldEmit) { + if (m_selection[mod.name] == enable) return; + + m_selection[mod.name] = enable; + + // disable other mods in the group, if applicable + if (enable && !mod.group.isEmpty()) { + for (int i = 0; i < m_mods.size(); i++) { + if (index == i) continue; + auto other = m_mods.at(i); + + if (mod.group == other.group) { + setMod(other, i, false, shouldEmit); + } + } + } + + for (const auto& dependencyName : mod.depends) { + auto dependencyIndex = m_index[dependencyName]; + auto dependencyMod = m_mods.at(dependencyIndex); + + // enable/disable dependencies + if (enable) { + setMod(dependencyMod, dependencyIndex, true, shouldEmit); + } + + // if the dependency is 'effectively hidden', then track which mods + // depend on it - so we can efficiently disable it when no more dependents + // depend on it. + auto dependants = m_dependants[dependencyName]; + + if (enable) { + dependants.append(mod.name); + } + else { + dependants.removeAll(mod.name); + + // if there are no longer any dependents, let's disable the mod + if (dependencyMod.effectively_hidden && dependants.isEmpty()) { + setMod(dependencyMod, dependencyIndex, false, shouldEmit); + } + } + } + + // disable mods that depend on this one, if disabling + if (!enable) { + auto dependants = m_dependants[mod.name]; + for (const auto& dependencyName : dependants) { + auto dependencyIndex = m_index[dependencyName]; + auto dependencyMod = m_mods.at(dependencyIndex); + + setMod(dependencyMod, dependencyIndex, false, shouldEmit); + } + } + + if (shouldEmit) { + emit dataChanged(AtlOptionalModListModel::index(index, EnabledColumn), + AtlOptionalModListModel::index(index, EnabledColumn)); + } +} + AtlOptionalModDialog::AtlOptionalModDialog(QWidget *parent, QVector mods) : QDialog(parent), ui(new Ui::AtlOptionalModDialog) { diff --git a/application/pages/modplatform/atlauncher/AtlOptionalModDialog.h b/application/pages/modplatform/atlauncher/AtlOptionalModDialog.h index 8b0dbdb6..a1df43f6 100644 --- a/application/pages/modplatform/atlauncher/AtlOptionalModDialog.h +++ b/application/pages/modplatform/atlauncher/AtlOptionalModDialog.h @@ -37,9 +37,15 @@ public slots: void selectRecommended(); void clearAll(); +private: + void toggleMod(ATLauncher::VersionMod mod, int index); + void setMod(ATLauncher::VersionMod mod, int index, bool enable, bool shouldEmit = true); + private: QVector m_mods; QMap m_selection; + QMap m_index; + QMap> m_dependants; }; class AtlOptionalModDialog : public QDialog { -- cgit