From 9cb33b519fb16ee70cfd5a724bc62161b4461fa0 Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Thu, 12 Feb 2026 18:51:27 +0000 Subject: [PATCH] Render incompatibility highlight and warning Signed-off-by: TheKodeToad --- .../minecraft/mod/DataPackFolderModel.cpp | 2 + launcher/minecraft/mod/ModFolderModel.cpp | 5 +- .../minecraft/mod/ResourceFolderModel.cpp | 49 ++++++++++++++----- launcher/minecraft/mod/ResourceFolderModel.h | 1 + .../minecraft/mod/ResourcePackFolderModel.cpp | 2 + .../minecraft/mod/TexturePackFolderModel.cpp | 2 + 6 files changed, 48 insertions(+), 13 deletions(-) diff --git a/launcher/minecraft/mod/DataPackFolderModel.cpp b/launcher/minecraft/mod/DataPackFolderModel.cpp index a975b742e..b934e451e 100644 --- a/launcher/minecraft/mod/DataPackFolderModel.cpp +++ b/launcher/minecraft/mod/DataPackFolderModel.cpp @@ -64,6 +64,8 @@ QVariant DataPackFolderModel::data(const QModelIndex& index, int role) const int column = index.column(); switch (role) { + case Qt::BackgroundRole: + return rowBackground(row); case Qt::DisplayRole: switch (column) { case PackFormatColumn: { diff --git a/launcher/minecraft/mod/ModFolderModel.cpp b/launcher/minecraft/mod/ModFolderModel.cpp index cf3219918..50b8985c8 100644 --- a/launcher/minecraft/mod/ModFolderModel.cpp +++ b/launcher/minecraft/mod/ModFolderModel.cpp @@ -88,6 +88,8 @@ QVariant ModFolderModel::data(const QModelIndex& index, int role) const int column = index.column(); switch (role) { + case Qt::BackgroundRole: + return rowBackground(row); case Qt::DisplayRole: switch (column) { case VersionColumn: { @@ -96,8 +98,9 @@ QVariant ModFolderModel::data(const QModelIndex& index, int role) const return tr("Folder"); case ResourceType::SINGLEFILE: return tr("File"); + default: + return at(row).version(); } - return at(row).version(); } case SideColumn: { return at(row).side(); diff --git a/launcher/minecraft/mod/ResourceFolderModel.cpp b/launcher/minecraft/mod/ResourceFolderModel.cpp index 532eb8d66..11ef81dbc 100644 --- a/launcher/minecraft/mod/ResourceFolderModel.cpp +++ b/launcher/minecraft/mod/ResourceFolderModel.cpp @@ -499,6 +499,17 @@ bool ResourceFolderModel::validateIndex(const QModelIndex& index) const return true; } +// HACK: all subclasses need to call this to have the whole row painted +// and they only delegate to the superclass for compatible columns +QBrush ResourceFolderModel::rowBackground(int row) const +{ + if (!m_resources[row]->isCompatible()) { + return { QColor(255, 0, 0, 40) }; + } else { + return {}; + } +} + QVariant ResourceFolderModel::data(const QModelIndex& index, int role) const { if (!validateIndex(index)) @@ -508,6 +519,8 @@ QVariant ResourceFolderModel::data(const QModelIndex& index, int role) const int column = index.column(); switch (role) { + case Qt::BackgroundRole: + return rowBackground(row); case Qt::DisplayRole: switch (column) { case NameColumn: @@ -521,25 +534,37 @@ QVariant ResourceFolderModel::data(const QModelIndex& index, int role) const default: return {}; } - case Qt::ToolTipRole: + case Qt::ToolTipRole: { + QString tooltip = m_resources[row]->internal_id(); + if (column == NameColumn) { - if (at(row).isSymLinkUnder(instDirPath())) { - return m_resources[row]->internal_id() + - tr("\nWarning: This resource is symbolically linked from elsewhere. Editing it will also change the original." - "\nCanonical Path: %1") - .arg(at(row).fileinfo().canonicalFilePath()); - ; + if (!at(row).isCompatible()) { + tooltip += tr("\nResource is not marked as compatible with the instance."); } + + if (at(row).isSymLinkUnder(instDirPath())) { + tooltip += + m_resources[row]->internal_id() + + tr("\nWarning: This resource is symbolically linked from elsewhere. Editing it will also change the original." + "\nCanonical Path: %1") + .arg(at(row).fileinfo().canonicalFilePath()); + } + if (at(row).isMoreThanOneHardLink()) { - return m_resources[row]->internal_id() + - tr("\nWarning: This resource is hard linked elsewhere. Editing it will also change the original."); + tooltip += tr("\nWarning: This resource is hard linked elsewhere. Editing it will also change the original."); } } - return m_resources[row]->internal_id(); + return tooltip; + } case Qt::DecorationRole: { - if (column == NameColumn && (at(row).isSymLinkUnder(instDirPath()) || at(row).isMoreThanOneHardLink())) - return QIcon::fromTheme("status-yellow"); + if (column == NameColumn) { + if (!at(row).isCompatible()) { + return QIcon::fromTheme("status-bad"); + } else if (at(row).isSymLinkUnder(instDirPath()) || at(row).isMoreThanOneHardLink()) { + return QIcon::fromTheme("status-yellow"); + } + } return {}; } diff --git a/launcher/minecraft/mod/ResourceFolderModel.h b/launcher/minecraft/mod/ResourceFolderModel.h index b6343a807..81bc6f5fc 100644 --- a/launcher/minecraft/mod/ResourceFolderModel.h +++ b/launcher/minecraft/mod/ResourceFolderModel.h @@ -153,6 +153,7 @@ class ResourceFolderModel : public QAbstractListModel { [[nodiscard]] bool validateIndex(const QModelIndex& index) const; + QBrush rowBackground(int row) const; QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override; diff --git a/launcher/minecraft/mod/ResourcePackFolderModel.cpp b/launcher/minecraft/mod/ResourcePackFolderModel.cpp index c83f90e2a..fd59d5765 100644 --- a/launcher/minecraft/mod/ResourcePackFolderModel.cpp +++ b/launcher/minecraft/mod/ResourcePackFolderModel.cpp @@ -65,6 +65,8 @@ QVariant ResourcePackFolderModel::data(const QModelIndex& index, int role) const int column = index.column(); switch (role) { + case Qt::BackgroundRole: + return rowBackground(row); case Qt::DisplayRole: switch (column) { case PackFormatColumn: { diff --git a/launcher/minecraft/mod/TexturePackFolderModel.cpp b/launcher/minecraft/mod/TexturePackFolderModel.cpp index e5f3eef88..d96b768db 100644 --- a/launcher/minecraft/mod/TexturePackFolderModel.cpp +++ b/launcher/minecraft/mod/TexturePackFolderModel.cpp @@ -63,6 +63,8 @@ QVariant TexturePackFolderModel::data(const QModelIndex& index, int role) const int column = index.column(); switch (role) { + case Qt::BackgroundRole: + return rowBackground(row); case Qt::DecorationRole: { if (column == ImageColumn) { return at(row).image({ 32, 32 }, Qt::AspectRatioMode::KeepAspectRatioByExpanding);