ATLauncher: Display mod colours in optional mod dialog

This commit is contained in:
Jamie Mansfield 2022-05-02 20:27:20 +01:00
parent f5f59203a2
commit 7c251efc47
No known key found for this signature in database
GPG Key ID: 36F61598F39F67B0
8 changed files with 36 additions and 14 deletions

View File

@ -556,7 +556,7 @@ void PackInstallTask::downloadMods()
QVector<QString> selectedMods;
if (!optionalMods.isEmpty()) {
setStatus(tr("Selecting optional mods..."));
selectedMods = m_support->chooseOptionalMods(optionalMods);
selectedMods = m_support->chooseOptionalMods(m_version, optionalMods);
}
setStatus(tr("Downloading mods..."));

View File

@ -37,7 +37,7 @@ public:
/**
* Requests a user interaction to select which optional mods should be installed.
*/
virtual QVector<QString> chooseOptionalMods(QVector<ATLauncher::VersionMod> mods) = 0;
virtual QVector<QString> chooseOptionalMods(PackVersion version, QVector<ATLauncher::VersionMod> mods) = 0;
/**
* Requests a user interaction to select a component version from a given version list

View File

@ -178,6 +178,7 @@ static void loadVersionMod(ATLauncher::VersionMod & p, QJsonObject & obj) {
p.depends.append(Json::requireString(depends));
}
}
p.colour = Json::ensureString(obj, QString("colour"), "");
p.client = Json::ensureBoolean(obj, QString("client"), false);
@ -232,4 +233,9 @@ void ATLauncher::loadVersion(PackVersion & v, QJsonObject & obj)
auto configsObj = Json::requireObject(obj, "configs");
loadVersionConfigs(v.configs, configsObj);
}
auto colourObj = Json::ensureObject(obj, "colours");
for (const auto &key : colourObj.keys()) {
v.colours[key] = Json::requireString(colourObj.value(key), "colour");
}
}

View File

@ -16,9 +16,10 @@
#pragma once
#include <QJsonObject>
#include <QMap>
#include <QString>
#include <QVector>
#include <QJsonObject>
namespace ATLauncher
{
@ -109,6 +110,7 @@ struct VersionMod
bool library;
QString group;
QVector<QString> depends;
QString colour;
bool client;
@ -134,6 +136,8 @@ struct PackVersion
QVector<VersionLibrary> libraries;
QVector<VersionMod> mods;
VersionConfigs configs;
QMap<QString, QString> colours;
};
void loadVersion(PackVersion & v, QJsonObject & obj);

View File

@ -43,8 +43,11 @@
#include "modplatform/atlauncher/ATLShareCode.h"
#include "Application.h"
AtlOptionalModListModel::AtlOptionalModListModel(QWidget *parent, QVector<ATLauncher::VersionMod> mods)
: QAbstractListModel(parent), m_mods(mods) {
AtlOptionalModListModel::AtlOptionalModListModel(QWidget* parent, ATLauncher::PackVersion version, QVector<ATLauncher::VersionMod> mods)
: QAbstractListModel(parent)
, m_version(version)
, m_mods(mods)
{
// fill mod index
for (int i = 0; i < m_mods.size(); i++) {
auto mod = m_mods.at(i);
@ -97,6 +100,11 @@ QVariant AtlOptionalModListModel::data(const QModelIndex &index, int role) const
return mod.description;
}
}
else if (role == Qt::ForegroundRole) {
if (!mod.colour.isEmpty() && m_version.colours.contains(mod.colour)) {
return QColor(QString("#%1").arg(m_version.colours[mod.colour]));
}
}
else if (role == Qt::CheckStateRole) {
if (index.column() == EnabledColumn) {
return m_selection[mod.name] ? Qt::Checked : Qt::Unchecked;
@ -287,12 +295,13 @@ void AtlOptionalModListModel::setMod(ATLauncher::VersionMod mod, int index, bool
}
}
AtlOptionalModDialog::AtlOptionalModDialog(QWidget *parent, QVector<ATLauncher::VersionMod> mods)
: QDialog(parent), ui(new Ui::AtlOptionalModDialog) {
AtlOptionalModDialog::AtlOptionalModDialog(QWidget* parent, ATLauncher::PackVersion version, QVector<ATLauncher::VersionMod> mods)
: QDialog(parent)
, ui(new Ui::AtlOptionalModDialog)
{
ui->setupUi(this);
listModel = new AtlOptionalModListModel(this, mods);
listModel = new AtlOptionalModListModel(this, version, mods);
ui->treeView->setModel(listModel);
ui->treeView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

View File

@ -56,7 +56,7 @@ public:
DescriptionColumn,
};
AtlOptionalModListModel(QWidget *parent, QVector<ATLauncher::VersionMod> mods);
AtlOptionalModListModel(QWidget *parent, ATLauncher::PackVersion version, QVector<ATLauncher::VersionMod> mods);
QVector<QString> getResult();
@ -86,7 +86,9 @@ private:
NetJob::Ptr m_jobPtr;
QByteArray m_response;
ATLauncher::PackVersion m_version;
QVector<ATLauncher::VersionMod> m_mods;
QMap<QString, bool> m_selection;
QMap<QString, int> m_index;
QMap<QString, QVector<QString>> m_dependants;
@ -96,7 +98,7 @@ class AtlOptionalModDialog : public QDialog {
Q_OBJECT
public:
AtlOptionalModDialog(QWidget *parent, QVector<ATLauncher::VersionMod> mods);
AtlOptionalModDialog(QWidget *parent, ATLauncher::PackVersion version, QVector<ATLauncher::VersionMod> mods);
~AtlOptionalModDialog() override;
QVector<QString> getResult() {

View File

@ -169,8 +169,9 @@ void AtlPage::onVersionSelectionChanged(QString data)
suggestCurrent();
}
QVector<QString> AtlPage::chooseOptionalMods(QVector<ATLauncher::VersionMod> mods) {
AtlOptionalModDialog optionalModDialog(this, mods);
QVector<QString> AtlPage::chooseOptionalMods(ATLauncher::PackVersion version, QVector<ATLauncher::VersionMod> mods)
{
AtlOptionalModDialog optionalModDialog(this, version, mods);
optionalModDialog.exec();
return optionalModDialog.getResult();
}

View File

@ -84,7 +84,7 @@ private:
void suggestCurrent();
QString chooseVersion(Meta::VersionListPtr vlist, QString minecraftVersion) override;
QVector<QString> chooseOptionalMods(QVector<ATLauncher::VersionMod> mods) override;
QVector<QString> chooseOptionalMods(ATLauncher::PackVersion version, QVector<ATLauncher::VersionMod> mods) override;
private slots:
void triggerSearch();