refactor(TalentItemComp): 优化天赋卡牌UI显示逻辑
1. 复用CardConfig中的pool_lv统一卡牌背景色,与技能卡保持一致 2. 新增对驻场天赋卡的图标显示支持,使用FieldSkillSet获取图标 3. 重构图标获取逻辑,与SCardComp保持对齐避免显示异常 4. 移除冗余的wave映射背景色代码
This commit is contained in:
@@ -15,7 +15,7 @@ import { _decorator, Label, Sprite, SpriteFrame } 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 { CardConfig } from "../common/config/CardSet";
|
||||
import { SkillSet } from "../common/config/SkillSet";
|
||||
import { FieldSkillSet, SkillSet } from "../common/config/SkillSet";
|
||||
import { CardBgComp } from "./CardBgComp";
|
||||
import { smc } from "../common/SingletonModuleComp";
|
||||
import { oops } from "db://oops-framework/core/Oops";
|
||||
@@ -45,38 +45,35 @@ export class TalentItemComp extends CCComp {
|
||||
*/
|
||||
public updateItem(config: CardConfig): void {
|
||||
if (!config) return;
|
||||
|
||||
|
||||
if (this.lbl_name) this.lbl_name.string = config.name ?? "";
|
||||
if (this.lbl_info) this.lbl_info.string = config.info ?? "";
|
||||
|
||||
// 根据 wave 映射背景颜色
|
||||
// 1=绿色(poolLv=1) 5=蓝色(poolLv=2) 10=紫色(poolLv=3) 15=黄色(poolLv=4) 20=红色(poolLv=5)
|
||||
|
||||
// 直接复用 CardSet 中已映射好的 pool_lv,保证与技能卡牌背景一致
|
||||
// CardSet 通过 waveToPoolLv[wave] 由 SKILL_CARD_WAVES 索引推导(wave 1→1, 5→2, 8→3)
|
||||
if (this.bg) {
|
||||
let poolLv = 1;
|
||||
const wave = config.wave || 1;
|
||||
if (wave >= 20) poolLv = 5;
|
||||
else if (wave >= 15) poolLv = 4;
|
||||
else if (wave >= 10) poolLv = 3;
|
||||
else if (wave >= 5) poolLv = 2;
|
||||
else poolLv = 1;
|
||||
|
||||
this.bg.apply(poolLv);
|
||||
this.bg.apply(config.pool_lv || 1);
|
||||
}
|
||||
|
||||
// 设置图标
|
||||
if (this.icon && config.skill) {
|
||||
const skillData = SkillSet[config.skill];
|
||||
if (skillData && skillData.icon) {
|
||||
// 设置图标:驻场卡(skill=undefined 但有 field)走 FieldSkillSet,否则走 SkillSet
|
||||
// 与 SCardComp 保持一致,避免驻场卡无 icon 显示
|
||||
if (this.icon) {
|
||||
let iconId: string | undefined;
|
||||
if (!config.skill && config.field && config.field.length > 0) {
|
||||
// 驻场卡:用 FieldSkillSet[field[0]].icon
|
||||
const fieldUuid = config.field[0];
|
||||
iconId = FieldSkillSet[fieldUuid]?.icon || `${fieldUuid}`;
|
||||
} else if (config.skill) {
|
||||
// 技能卡:用 SkillSet[skill].icon
|
||||
iconId = SkillSet[config.skill]?.icon;
|
||||
}
|
||||
if (iconId) {
|
||||
if (smc.uiconsAtlas) {
|
||||
const frame = smc.uiconsAtlas.getSpriteFrame(skillData.icon);
|
||||
if (frame) {
|
||||
this.icon.spriteFrame = frame;
|
||||
}
|
||||
const frame = smc.uiconsAtlas.getSpriteFrame(iconId);
|
||||
if (frame) this.icon.spriteFrame = frame;
|
||||
} else {
|
||||
const sf = oops.res.get("game/heros/cards/" + skillData.icon, SpriteFrame) as SpriteFrame;
|
||||
if (sf) {
|
||||
this.icon.spriteFrame = sf;
|
||||
}
|
||||
const sf = oops.res.get("game/heros/cards/" + iconId, SpriteFrame) as SpriteFrame;
|
||||
if (sf) this.icon.spriteFrame = sf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user