diff --git a/launcher/minecraft/mod/Resource.cpp b/launcher/minecraft/mod/Resource.cpp index 64bf14b6c..8cffa378e 100644 --- a/launcher/minecraft/mod/Resource.cpp +++ b/launcher/minecraft/mod/Resource.cpp @@ -113,22 +113,38 @@ void Resource::setMetadata(std::shared_ptr&& metadata) m_metadata = metadata; } -void Resource::determineCompat(const BaseInstance* inst) { +QStringList Resource::issues() const +{ + QStringList result; + result.reserve(m_issues.length()); + + for (const char* issue : m_issues) { + result.append(tr(issue)); + } + + return result; +} + +void Resource::updateIssues(const BaseInstance* inst) +{ + m_issues.clear(); + if (m_metadata == nullptr) { - m_isCompatible = true; return; } auto mcInst = dynamic_cast(inst); if (mcInst == nullptr) { - m_isCompatible = true; return; } auto profile = mcInst->getPackProfile(); QString mcVersion = profile->getComponentVersion("net.minecraft"); - m_isCompatible = m_metadata->mcVersions.contains(mcVersion); + if (!m_metadata->mcVersions.empty() && !m_metadata->mcVersions.contains(mcVersion)) { + // delay translation until issues() is called + m_issues.append(QT_TR_NOOP("Not marked as compatible with the instance's game version.")); + } } int Resource::compare(const Resource& other, SortType type) const diff --git a/launcher/minecraft/mod/Resource.h b/launcher/minecraft/mod/Resource.h index 7121a8a6b..646ee65dd 100644 --- a/launcher/minecraft/mod/Resource.h +++ b/launcher/minecraft/mod/Resource.h @@ -122,11 +122,12 @@ class Resource : public QObject { void setMetadata(const Metadata::ModStruct& metadata) { setMetadata(std::make_shared(metadata)); } /** - * Returns whether the resource is compatible with the instance. - * This is initially true, and may be updated when calling determineCompat with an instance. + * Returns compatibility issues with the resource and the instance. + * This is initially empty, and may be updated when calling updateIssues. */ - bool isCompatible() const { return m_isCompatible; } - void determineCompat(const BaseInstance* inst); + QStringList issues() const; + void updateIssues(const BaseInstance* inst); + bool hasIssues() const { return !m_issues.empty(); } /** Compares two Resources, for sorting purposes, considering a ascending order, returning: * > 0: 'this' comes after 'other' @@ -197,7 +198,7 @@ class Resource : public QObject { /* Whether the resource is enabled (e.g. shows up in the game) or not. */ bool m_enabled = true; - bool m_isCompatible = true; + QList m_issues; /* Used to keep trach of pending / concluded actions on the resource. */ bool m_is_resolving = false; diff --git a/launcher/minecraft/mod/ResourceFolderModel.cpp b/launcher/minecraft/mod/ResourceFolderModel.cpp index 11ef81dbc..ed0e07574 100644 --- a/launcher/minecraft/mod/ResourceFolderModel.cpp +++ b/launcher/minecraft/mod/ResourceFolderModel.cpp @@ -503,7 +503,7 @@ bool ResourceFolderModel::validateIndex(const QModelIndex& index) const // and they only delegate to the superclass for compatible columns QBrush ResourceFolderModel::rowBackground(int row) const { - if (!m_resources[row]->isCompatible()) { + if (m_resources[row]->hasIssues()) { return { QColor(255, 0, 0, 40) }; } else { return {}; @@ -538,8 +538,8 @@ QVariant ResourceFolderModel::data(const QModelIndex& index, int role) const QString tooltip = m_resources[row]->internal_id(); if (column == NameColumn) { - if (!at(row).isCompatible()) { - tooltip += tr("\nResource is not marked as compatible with the instance."); + for (const QString& issue : at(row).issues()) { + tooltip += "\n" + issue; } if (at(row).isSymLinkUnder(instDirPath())) { @@ -559,7 +559,7 @@ QVariant ResourceFolderModel::data(const QModelIndex& index, int role) const } case Qt::DecorationRole: { if (column == NameColumn) { - if (!at(row).isCompatible()) { + if (at(row).hasIssues()) { return QIcon::fromTheme("status-bad"); } else if (at(row).isSymLinkUnder(instDirPath()) || at(row).isMoreThanOneHardLink()) { return QIcon::fromTheme("status-yellow"); @@ -836,10 +836,10 @@ void ResourceFolderModel::applyUpdates(QSet& current_set, QSet if (new_resource->dateTimeChanged() == current_resource->dateTimeChanged()) { // no significant change - bool oldCompat = current_resource->isCompatible(); - current_resource->determineCompat(m_instance); + bool hadIssues = !current_resource->hasIssues(); + current_resource->updateIssues(m_instance); - if (current_resource->isCompatible() != oldCompat) { + if (hadIssues != current_resource->hasIssues()) { emit dataChanged(index(row, 0), index(row, columnCount({}) - 1)); } continue; @@ -856,7 +856,7 @@ void ResourceFolderModel::applyUpdates(QSet& current_set, QSet } m_resources[row].reset(new_resource); - new_resource->determineCompat(m_instance); + new_resource->updateIssues(m_instance); resolveResource(m_resources.at(row)); emit dataChanged(index(row, 0), index(row, columnCount(QModelIndex()) - 1)); @@ -905,7 +905,7 @@ void ResourceFolderModel::applyUpdates(QSet& current_set, QSet for (auto& added : added_set) { auto res = new_resources[added]; - res->determineCompat(m_instance); + res->updateIssues(m_instance); m_resources.append(res); resolveResource(m_resources.last()); }