ATLauncher: Display warnings when selecting optional mods
This commit is contained in:
parent
305973c0e7
commit
b84d52be3d
@ -198,6 +198,7 @@ static void loadVersionMod(ATLauncher::VersionMod & p, QJsonObject & obj) {
|
||||
}
|
||||
}
|
||||
p.colour = Json::ensureString(obj, QString("colour"), "");
|
||||
p.warning = Json::ensureString(obj, QString("warning"), "");
|
||||
|
||||
p.client = Json::ensureBoolean(obj, QString("client"), false);
|
||||
|
||||
@ -264,6 +265,11 @@ void ATLauncher::loadVersion(PackVersion & v, QJsonObject & obj)
|
||||
v.colours[key] = Json::requireString(colourObj.value(key), "colour");
|
||||
}
|
||||
|
||||
auto warningsObj = Json::ensureObject(obj, "warnings");
|
||||
for (const auto &key : warningsObj.keys()) {
|
||||
v.warnings[key] = Json::requireString(warningsObj.value(key), "warning");
|
||||
}
|
||||
|
||||
auto messages = Json::ensureObject(obj, "messages");
|
||||
loadVersionMessages(v.messages, messages);
|
||||
}
|
||||
|
@ -130,6 +130,7 @@ struct VersionMod
|
||||
QString group;
|
||||
QVector<QString> depends;
|
||||
QString colour;
|
||||
QString warning;
|
||||
|
||||
bool client;
|
||||
|
||||
@ -163,6 +164,7 @@ struct PackVersion
|
||||
VersionConfigs configs;
|
||||
|
||||
QMap<QString, QString> colours;
|
||||
QMap<QString, QString> warnings;
|
||||
VersionMessages messages;
|
||||
};
|
||||
|
||||
|
@ -231,7 +231,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) {
|
||||
|
Loading…
Reference in New Issue
Block a user