From 1bddb6f8f0f6c88a5c3bdafdb1797fd053ac7e17 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sat, 20 Apr 2024 15:11:02 -0400 Subject: [PATCH] Armoury: Add gear icons --- armoury/include/gearview.h | 1 + armoury/src/gearlistmodel.cpp | 36 ++++++++++++++++++++++++++++++----- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/armoury/include/gearview.h b/armoury/include/gearview.h index 8b73a06..f0f7147 100644 --- a/armoury/include/gearview.h +++ b/armoury/include/gearview.h @@ -18,6 +18,7 @@ struct GearInfo { std::string name; Slot slot; ModelInfo modelInfo; + uint16_t icon; std::string getMtrlPath(const std::string_view material_name) const { diff --git a/armoury/src/gearlistmodel.cpp b/armoury/src/gearlistmodel.cpp index aaeaa17..bb6c69b 100644 --- a/armoury/src/gearlistmodel.cpp +++ b/armoury/src/gearlistmodel.cpp @@ -111,15 +111,40 @@ QVariant GearListModel::data(const QModelIndex &index, int role) const if (!index.isValid()) return {}; - if (role != Qt::DisplayRole) - return {}; - auto item = static_cast(index.internalPointer()); if (item->type == TreeType::Category) { - return QLatin1String(magic_enum::enum_name(*item->slotType).data()); + if (role == Qt::DisplayRole) { + return QLatin1String(magic_enum::enum_name(*item->slotType).data()); + } } else if (item->type == TreeType::Item) { - return QLatin1String(item->gear->name.data()); + if (role == Qt::DisplayRole) { + return QLatin1String(item->gear->name.data()); + } else if (role == Qt::DecorationRole) { + // TODO: cache these images in memory + const QString iconName = QString::number(item->gear->icon); + const QString iconBaseNum = QString::number(item->gear->icon).left(2).leftJustified(iconName.length(), QLatin1Char('0')); + + const QString iconFolder = QStringLiteral("ui/icon/%1").arg(iconBaseNum, 6, QLatin1Char('0')); + const QString iconFile = QStringLiteral("%1.tex").arg(iconName, 6, QLatin1Char('0')); + + const std::string iconFilename = iconFolder.toStdString() + "/" + iconFile.toStdString(); + + auto texFile = physis_gamedata_extract_file(gameData, iconFilename.c_str()); + if (texFile.data != nullptr) { + auto tex = physis_texture_parse(texFile); + if (tex.rgba != nullptr) { + QImage image(tex.rgba, tex.width, tex.height, QImage::Format_RGBA8888); + + QPixmap pixmap; + pixmap.convertFromImage(image); + + return pixmap.scaled(32, 32, Qt::KeepAspectRatio, Qt::SmoothTransformation); + } + } + + return QIcon::fromTheme(QStringLiteral("unknown")); + } } return {}; @@ -159,6 +184,7 @@ void GearListModel::exdFinished(int index) GearInfo info = {}; info.name = row.column_data[9].string._0; + info.icon = row.column_data[10].u_int16._0; info.slot = physis_slot_from_id(row.column_data[17].u_int8._0); info.modelInfo.primaryID = parts[0];