refactor(common): 抽离卡牌图标处理逻辑为通用工具类
1. 新建CardIconHelper工具类统一处理卡牌图标解析和设置逻辑 2. 移除SkillBoxComp、SCardComp、EquipListComp、ItemListComp中的重复图标处理代码 3. 统一所有卡牌组件的图标加载优先级和处理流程 4. 新增卡牌背景颜色随等级切换的通用逻辑
This commit is contained in:
@@ -30,16 +30,17 @@
|
||||
* - smc.mission —— 游戏运行状态
|
||||
*/
|
||||
import { mLogger } from "../common/Logger";
|
||||
import { _decorator, Node, Prefab, Sprite, Label, Vec3, resources, SpriteAtlas, tween, v3, Tween, NodeEventType } from "cc";
|
||||
import { _decorator, Node, Sprite, Label, Vec3, tween, v3, Tween, NodeEventType } 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 { CardTriggerType } from "../common/config/CardSet";
|
||||
import { CardTriggerType, CardConfig } from "../common/config/CardSet";
|
||||
import { SkillCardList } from "../common/config/SCardSet";
|
||||
import { SkillSet, SkillOverrides, FieldSkillSet } from "../common/config/SkillSet";
|
||||
import { SkillOverrides } from "../common/config/SkillSet";
|
||||
import { oops } from "db://oops-framework/core/Oops";
|
||||
import { GameEvent } from "../common/config/GameEvent";
|
||||
import { smc } from "../common/SingletonModuleComp";
|
||||
import { UIID } from "../common/config/GameUIConfig";
|
||||
import { getCardIconId, setSpriteFrame } from "../common/CardIconHelper";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/**
|
||||
@@ -370,27 +371,16 @@ export class SkillBoxComp extends CCComp {
|
||||
// 按技能等级切换背景颜色节点(与 getLvColor 等级配色一致)
|
||||
this.updateBgNode();
|
||||
|
||||
// 加载技能图标
|
||||
if (this.icon_node) {
|
||||
// 优先使用卡牌自定义 icon;未定义则按 trigger_type 自动取
|
||||
let iconId: string | undefined = this.card_icon;
|
||||
if (!iconId) {
|
||||
if (this.trigger_type === CardTriggerType.Interval) {
|
||||
iconId = this.s_uuid ? SkillSet[this.s_uuid]?.icon : undefined;
|
||||
} else if (this.trigger_type === CardTriggerType.Field) {
|
||||
const fieldUuid = this.field?.[0];
|
||||
iconId = fieldUuid ? FieldSkillSet[fieldUuid]?.icon : undefined;
|
||||
}
|
||||
}
|
||||
if (this.icon_node && this.icon_node.isValid) {
|
||||
let sprite = this.icon_node.getComponent(Sprite) || this.icon_node.addComponent(Sprite);
|
||||
if (smc.uiconsAtlas && iconId) {
|
||||
const frame = smc.uiconsAtlas.getSpriteFrame(iconId);
|
||||
sprite.spriteFrame = frame || null; // 取不到时清空,避免残留
|
||||
} else {
|
||||
sprite.spriteFrame = null;
|
||||
}
|
||||
}
|
||||
// 加载技能图标(共享工具解析:cardData.icon → FieldSkillSet → SkillSet)
|
||||
if (this.icon_node && this.icon_node.isValid) {
|
||||
const cardData = {
|
||||
uuid: this.s_uuid,
|
||||
skill: this.s_uuid,
|
||||
icon: this.card_icon,
|
||||
field: this.field,
|
||||
} as CardConfig;
|
||||
const iconId = getCardIconId(cardData);
|
||||
setSpriteFrame(this.icon_node, iconId);
|
||||
}
|
||||
|
||||
// 是否需要展示剩余次数
|
||||
|
||||
Reference in New Issue
Block a user