feat(ui): 添加任务卡片图标支持并更新配置图标引用

添加任务卡片组件图标显示功能,支持动态加载图集资源
更新属性卡和英雄配置中的图标引用为新的资源ID
This commit is contained in:
panw
2026-01-16 11:05:14 +08:00
parent 5bb3acf385
commit 5af936d9b3
3 changed files with 76 additions and 31 deletions

View File

@@ -1,4 +1,4 @@
import { _decorator, Label, Node, tween, Vec3, Color, Sprite, Tween } from "cc";
import { _decorator, Label, Node, tween, Vec3, Color, Sprite, Tween, SpriteAtlas, resources } from "cc";
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
@@ -50,6 +50,9 @@ export class MissionCardComp extends CCComp {
private isLocked: boolean = true;
// 是否永久解锁(本局)
private isAdUnlocked: boolean = false;
// 图标图集缓存
private uiconsAtlas: SpriteAtlas | null = null;
onLoad() {
if (this.btnClose) {
@@ -360,6 +363,48 @@ export class MissionCardComp extends CCComp {
if (activeTypeNode) activeTypeNode.active = true;
}
}
// 更新图标 (如果存在 icon 节点)
// 注意:根据 Prefab 分析icon 可能在 card/Mask/icon 路径下,也可能在各个分类节点下
// 这里尝试统一查找 icon 节点
let iconNode: Node | null = null;
// 1. 尝试查找通用的 mask/icon (根据之前 card.prefab 分析,有个 Mask/icon 节点)
const maskNode = card.getChildByName("Mask");
if (maskNode) {
iconNode = maskNode.getChildByName("icon");
}
if (iconNode && data.icon) {
this.updateIcon(iconNode, data.icon);
}
}
private updateIcon(node: Node, iconId: string) {
if (!node || !iconId) return;
const sprite = node.getComponent(Sprite);
if (!sprite) return;
if (this.uiconsAtlas) {
const frame = this.uiconsAtlas.getSpriteFrame(iconId);
if (frame) {
sprite.spriteFrame = frame;
}
} else {
// 加载图集
resources.load("gui/uicons", SpriteAtlas, (err, atlas) => {
if (err) {
console.error("[MissionCardComp] Failed to load uicons atlas", err);
return;
}
this.uiconsAtlas = atlas;
const frame = atlas.getSpriteFrame(iconId);
if (frame) {
sprite.spriteFrame = frame;
}
});
}
}
updateCardData(index: number, data: ICardInfo) {