- 调整天赋预制体布局参数,包含容器宽度、边距和间距 - 移除旧的驻场技能相关UI节点引用 - 替换数据来源为卡牌池技能卡,重构列表渲染与排序逻辑 - 更新UI展示逻辑,显示天赋名称、描述、图标和对应品质背景 - 优化组件注释与属性描述,统一代码风格
90 lines
3.1 KiB
TypeScript
90 lines
3.1 KiB
TypeScript
/**
|
||
* @file TalentItemComp.ts
|
||
* @description 天赋图鉴项组件(UI 视图层)
|
||
*
|
||
* 职责:
|
||
* 1. 接收 TalentsComp 下发的天赋卡配置(技能卡)。
|
||
* 2. 渲染名称、描述、图标和背景。
|
||
* 3. 背景颜色根据 wave 映射为对应的 poolLv。
|
||
*
|
||
* 依赖:
|
||
* - CardSet.CardConfig —— 单条卡牌配置
|
||
* - SkillSet —— 获取技能图标
|
||
*/
|
||
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 { CardBgComp } from "./CardBgComp";
|
||
import { smc } from "../common/SingletonModuleComp";
|
||
import { oops } from "db://oops-framework/core/Oops";
|
||
|
||
const { ccclass, property } = _decorator;
|
||
|
||
/** TalentItemComp —— 天赋图鉴项组件 */
|
||
@ccclass('TalentItemComp')
|
||
@ecs.register('TalentItem', false)
|
||
export class TalentItemComp extends CCComp {
|
||
|
||
@property({ type: Label, tooltip: "天赋名称" })
|
||
lbl_name: Label = null!;
|
||
|
||
@property({ type: Label, tooltip: "天赋说明" })
|
||
lbl_info: Label = null!;
|
||
|
||
@property({ type: Sprite, tooltip: "天赋图标" })
|
||
icon: Sprite = null!;
|
||
|
||
@property({ type: CardBgComp, tooltip: "卡牌背景组件" })
|
||
bg: CardBgComp = null!;
|
||
|
||
/**
|
||
* 刷新单条天赋展示
|
||
* @param config CardPoolList 中的天赋卡(技能卡)配置
|
||
*/
|
||
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)
|
||
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);
|
||
}
|
||
|
||
// 设置图标
|
||
if (this.icon && config.skill) {
|
||
const skillData = SkillSet[config.skill];
|
||
if (skillData && skillData.icon) {
|
||
if (smc.uiconsAtlas) {
|
||
const frame = smc.uiconsAtlas.getSpriteFrame(skillData.icon);
|
||
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;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/** ECS 组件移除时销毁节点(CCComp 抽象方法实现) */
|
||
reset() {
|
||
this.node.destroy();
|
||
}
|
||
}
|