Allow multiple compat issues to be displayed, make game version incompat clearer

Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
TheKodeToad 2026-02-12 20:38:43 +00:00
parent 9cb33b519f
commit b664846030
No known key found for this signature in database
GPG key ID: 5E39D70B4C93C38E
3 changed files with 35 additions and 18 deletions

View file

@ -113,22 +113,38 @@ void Resource::setMetadata(std::shared_ptr<Metadata::ModStruct>&& 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<const MinecraftInstance*>(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

View file

@ -122,11 +122,12 @@ class Resource : public QObject {
void setMetadata(const Metadata::ModStruct& metadata) { setMetadata(std::make_shared<Metadata::ModStruct>(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<const char*> m_issues;
/* Used to keep trach of pending / concluded actions on the resource. */
bool m_is_resolving = false;

View file

@ -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<QString>& current_set, QSet<QString>
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<QString>& current_set, QSet<QString>
}
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<QString>& current_set, QSet<QString>
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());
}