Files
pixelheros/assets/script/game/map/TalentsComp.ts
pan 12449c8d1d feat(talents): 重构驻场技能页面为天赋图鉴页面
- 调整天赋预制体布局参数,包含容器宽度、边距和间距
- 移除旧的驻场技能相关UI节点引用
- 替换数据来源为卡牌池技能卡,重构列表渲染与排序逻辑
- 更新UI展示逻辑,显示天赋名称、描述、图标和对应品质背景
- 优化组件注释与属性描述,统一代码风格
2026-06-09 10:01:44 +08:00

95 lines
3.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* @file TalentsComp.ts
* @description 天赋图鉴页组件UI 视图层)
*
* 职责:
* 1. 展示当前所有天赋卡(技能卡)的图鉴。
* 2. 从 CardPoolList 获取所有的 type=Skill 卡牌。
* 3. 兼容旧的 `@ecs.register('Talents')` 资源引用。
*
* 依赖:
* - CardPoolListCardSet—— 获取技能卡配置
* - TalentItemComp —— 单条天赋图鉴项视图
*/
import { _decorator, instantiate, Node, Prefab } 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 { mLogger } from "../common/Logger";
import { CardPoolList, CardType, CardConfig } from "../common/config/CardSet";
import { TalentItemComp } from "./TalentItemComp";
const { ccclass, property } = _decorator;
/** TalentsComp —— 天赋图鉴信息页组件 */
@ccclass('TalentsComp')
@ecs.register('Talents', false)
export class TalentsComp extends CCComp {
@property({ type: Node, tooltip: "天赋技能列表容器" })
talents_content: Node = null!;
@property({ type: Prefab, tooltip: "单条天赋项预制" })
prefab_talent_item: Prefab = null!;
/** 调试日志开关 */
debugMode: boolean = false;
/** 首次实例化缓存 */
private rendered: boolean = false;
/** 缓存的稳定配置顺序,避免重复渲染时列表抖动 */
private cachedConfigs: CardConfig[] = [];
protected onEnable(): void {
this.refreshUI();
}
/** 重新拉取最新数据并刷新所有子项 */
public refreshUI(): void {
if (!this.talents_content || !this.prefab_talent_item) return;
// 第一次:实例化所有子节点
if (!this.rendered) {
// 获取所有天赋(技能卡)并按 wave 和 uuid 排序
this.cachedConfigs = CardPoolList.filter(card => card.type === CardType.Skill)
.sort((a, b) => {
const waveA = a.wave || 1;
const waveB = b.wave || 1;
if (waveA !== waveB) return waveA - waveB;
return a.uuid - b.uuid;
});
this.cachedConfigs.forEach((cfg) => {
const itemNode = instantiate(this.prefab_talent_item);
this.talents_content.addChild(itemNode);
const comp = itemNode.getComponent(TalentItemComp);
if (comp) {
comp.updateItem(cfg);
}
});
this.rendered = true;
} else {
// 如果已渲染,则仅更新数据(图鉴一般不会变动,这里做个兜底更新)
this.cachedConfigs.forEach((cfg, index) => {
const child = this.talents_content.children[index];
if (!child) return;
const comp = child.getComponent(TalentItemComp);
if (!comp) return;
comp.updateItem(cfg);
});
}
}
/** ECS 组件移除时销毁节点 */
reset() {
this.rendered = false;
this.cachedConfigs = [];
this.node.destroy();
}
protected onDestroy(): void {
super.onDestroy();
mLogger.log(this.debugMode, 'TalentsComp', "释放界面");
}
}