mirror of
https://github.com/MultiMC/MultiMC5.git
synced 2024-09-03 21:49:13 +00:00
Merge pull request #4943 from jamierocks/atl-messages
Display ATLauncher mod warnings and pack messages
This commit is contained in:
commit
301b44d1c4
@ -96,6 +96,10 @@ void PackInstallTask::onDownloadSucceeded()
|
||||
}
|
||||
m_version = version;
|
||||
|
||||
// Display install message if one exists
|
||||
if (!m_version.messages.install.isEmpty())
|
||||
m_support->displayMessage(m_version.messages.install);
|
||||
|
||||
auto vlist = APPLICATION->metadataIndex()->get("net.minecraft");
|
||||
if(!vlist)
|
||||
{
|
||||
@ -526,7 +530,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..."));
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2020-2021 Jamie Mansfield <jmansfield@cadixdev.org>
|
||||
* Copyright 2020-2022 Jamie Mansfield <jmansfield@cadixdev.org>
|
||||
* Copyright 2021 Petr Mrazek <peterix@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -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(ATLauncher::PackVersion version, QVector<ATLauncher::VersionMod> mods) = 0;
|
||||
|
||||
/**
|
||||
* Requests a user interaction to select a component version from a given version list
|
||||
@ -45,6 +45,11 @@ public:
|
||||
*/
|
||||
virtual QString chooseVersion(Meta::VersionListPtr vlist, QString minecraftVersion) = 0;
|
||||
|
||||
/**
|
||||
* Requests a user interaction to display a message.
|
||||
*/
|
||||
virtual void displayMessage(QString message) = 0;
|
||||
|
||||
};
|
||||
|
||||
class PackInstallTask : public InstanceTask
|
||||
|
@ -178,6 +178,7 @@ static void loadVersionMod(ATLauncher::VersionMod & p, QJsonObject & obj) {
|
||||
p.depends.append(Json::requireValueString(depends));
|
||||
}
|
||||
}
|
||||
p.warning = Json::ensureString(obj, QString("warning"), "");
|
||||
|
||||
p.client = Json::ensureBoolean(obj, QString("client"), false);
|
||||
|
||||
@ -197,6 +198,12 @@ static void loadVersionExtraArguments(ATLauncher::PackVersionExtraArguments & a,
|
||||
a.depends = Json::ensureString(obj, "depends", "");
|
||||
}
|
||||
|
||||
static void loadVersionMessages(ATLauncher::VersionMessages & m, QJsonObject & obj)
|
||||
{
|
||||
m.install = Json::ensureString(obj, "install", "");
|
||||
m.update = Json::ensureString(obj, "update", "");
|
||||
}
|
||||
|
||||
void ATLauncher::loadVersion(PackVersion & v, QJsonObject & obj)
|
||||
{
|
||||
v.version = Json::requireString(obj, "version");
|
||||
@ -244,4 +251,17 @@ void ATLauncher::loadVersion(PackVersion & v, QJsonObject & obj)
|
||||
auto configsObj = Json::requireObject(obj, "configs");
|
||||
loadVersionConfigs(v.configs, configsObj);
|
||||
}
|
||||
|
||||
if(obj.contains("warnings")) {
|
||||
auto warningsObj = Json::requireObject(obj, "warnings");
|
||||
|
||||
for (const auto &key : warningsObj.keys()) {
|
||||
v.warnings[key] = Json::requireValueString(warningsObj.value(key), "warning");
|
||||
}
|
||||
}
|
||||
|
||||
if(obj.contains("messages")) {
|
||||
auto messages = Json::requireObject(obj, "messages");
|
||||
loadVersionMessages(v.messages, messages);
|
||||
}
|
||||
}
|
||||
|
@ -109,6 +109,7 @@ struct VersionMod
|
||||
bool library;
|
||||
QString group;
|
||||
QVector<QString> depends;
|
||||
QString warning;
|
||||
|
||||
bool client;
|
||||
|
||||
@ -134,6 +135,12 @@ struct PackVersionExtraArguments
|
||||
QString depends;
|
||||
};
|
||||
|
||||
struct VersionMessages
|
||||
{
|
||||
QString install;
|
||||
QString update;
|
||||
};
|
||||
|
||||
struct PackVersion
|
||||
{
|
||||
QString version;
|
||||
@ -146,6 +153,9 @@ struct PackVersion
|
||||
QVector<VersionLibrary> libraries;
|
||||
QVector<VersionMod> mods;
|
||||
VersionConfigs configs;
|
||||
|
||||
QMap<QString, QString> warnings;
|
||||
VersionMessages messages;
|
||||
};
|
||||
|
||||
void loadVersion(PackVersion & v, QJsonObject & obj);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2021 Jamie Mansfield <jmansfield@cadixdev.org>
|
||||
* Copyright 2021-2022 Jamie Mansfield <jmansfield@cadixdev.org>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -17,8 +17,10 @@
|
||||
#include "AtlOptionalModDialog.h"
|
||||
#include "ui_AtlOptionalModDialog.h"
|
||||
|
||||
AtlOptionalModListModel::AtlOptionalModListModel(QWidget *parent, QVector<ATLauncher::VersionMod> mods)
|
||||
: QAbstractListModel(parent), m_mods(mods) {
|
||||
#include <QMessageBox>
|
||||
|
||||
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++) {
|
||||
@ -134,7 +136,21 @@ void AtlOptionalModListModel::clearAll() {
|
||||
}
|
||||
|
||||
void AtlOptionalModListModel::toggleMod(ATLauncher::VersionMod mod, int index) {
|
||||
setMod(mod, index, !m_selection[mod.name]);
|
||||
auto enable = !m_selection[mod.name];
|
||||
|
||||
// If there is a warning for the mod, display that first (if we would be enabling the mod)
|
||||
if (enable && !mod.warning.isEmpty() && m_version.warnings.contains(mod.warning)) {
|
||||
auto message = QString("%1<br><br>%2")
|
||||
.arg(m_version.warnings[mod.warning], tr("Are you sure that you want to enable this mod?"));
|
||||
|
||||
// fixme: avoid casting here
|
||||
auto result = QMessageBox::warning((QWidget*) this->parent(), tr("Warning"), message, QMessageBox::Yes | QMessageBox::No);
|
||||
if (result != QMessageBox::Yes) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
setMod(mod, index, enable);
|
||||
}
|
||||
|
||||
void AtlOptionalModListModel::setMod(ATLauncher::VersionMod mod, int index, bool enable, bool shouldEmit) {
|
||||
@ -199,11 +215,11 @@ void AtlOptionalModListModel::setMod(ATLauncher::VersionMod mod, int index, bool
|
||||
}
|
||||
|
||||
|
||||
AtlOptionalModDialog::AtlOptionalModDialog(QWidget *parent, QVector<ATLauncher::VersionMod> mods)
|
||||
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);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2021 Jamie Mansfield <jmansfield@cadixdev.org>
|
||||
* Copyright 2021-2022 Jamie Mansfield <jmansfield@cadixdev.org>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -36,7 +36,7 @@ public:
|
||||
DescriptionColumn,
|
||||
};
|
||||
|
||||
AtlOptionalModListModel(QWidget *parent, QVector<ATLauncher::VersionMod> mods);
|
||||
AtlOptionalModListModel(QWidget *parent, ATLauncher::PackVersion version, QVector<ATLauncher::VersionMod> mods);
|
||||
|
||||
QVector<QString> getResult();
|
||||
|
||||
@ -58,7 +58,9 @@ private:
|
||||
void setMod(ATLauncher::VersionMod mod, int index, bool enable, bool shouldEmit = true);
|
||||
|
||||
private:
|
||||
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;
|
||||
@ -68,7 +70,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() {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2020-2021 Jamie Mansfield <jmansfield@cadixdev.org>
|
||||
* Copyright 2020-2022 Jamie Mansfield <jmansfield@cadixdev.org>
|
||||
* Copyright 2021 Philip T <me@phit.link>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -26,6 +26,8 @@
|
||||
|
||||
#include <BuildConfig.h>
|
||||
|
||||
#include <QMessageBox>
|
||||
|
||||
AtlPage::AtlPage(NewInstanceDialog* dialog, QWidget *parent)
|
||||
: QWidget(parent), ui(new Ui::AtlPage), dialog(dialog)
|
||||
{
|
||||
@ -145,8 +147,8 @@ 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();
|
||||
}
|
||||
@ -186,3 +188,8 @@ QString AtlPage::chooseVersion(Meta::VersionListPtr vlist, QString minecraftVers
|
||||
vselect.exec();
|
||||
return vselect.selectedVersion()->descriptor();
|
||||
}
|
||||
|
||||
void AtlPage::displayMessage(QString message)
|
||||
{
|
||||
QMessageBox::information(this, tr("Installing"), message);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2020-2021 Jamie Mansfield <jmansfield@cadixdev.org>
|
||||
* Copyright 2020-2022 Jamie Mansfield <jmansfield@cadixdev.org>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -64,7 +64,8 @@ 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;
|
||||
void displayMessage(QString message) override;
|
||||
|
||||
private slots:
|
||||
void triggerSearch();
|
||||
|
Loading…
Reference in New Issue
Block a user