1. 将原天赋系统页面重构成驻场技能信息展示页 2. 移除升级、重置等旧功能,仅保留基础数据展示逻辑 3. 新增数值格式化工具函数,兼容百分比与整数加成显示 4. 简化组件依赖,仅保留必要的配置与UI渲染逻辑 5. 统一组件命名与注释,明确职责边界
91 lines
3.2 KiB
TypeScript
91 lines
3.2 KiB
TypeScript
/**
|
||
* @file TalentsComp.ts
|
||
* @description 驻场技能信息展示页组件(UI 视图层)
|
||
*
|
||
* 职责:
|
||
* 1. 展示当前所有 FieldSkillSet 配置项的名称、基础值、当前场上总加成。
|
||
* 2. 通过 FieldSkillHelper 实时聚合英雄驻场数据并下发给每个 TalentItemComp。
|
||
* 3. 兼容旧的 `@ecs.register('Talents')` 资源引用。
|
||
*
|
||
* 依赖:
|
||
* - SkillSet(FieldSkillSet / FieldSkillConfig)—— 驻场技能配置
|
||
* - FieldSkillHelper —— 场上英雄驻场技能聚合
|
||
* - 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 { FieldSkillSet, FieldSkillConfig } from "../common/config/SkillSet";
|
||
import { FieldSkillHelper } from "../hero/FieldSkillHelper";
|
||
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: FieldSkillConfig[] = [];
|
||
|
||
protected onEnable(): void {
|
||
this.refreshUI();
|
||
}
|
||
|
||
/** 重新拉取最新数据并刷新所有子项 */
|
||
public refreshUI(): void {
|
||
if (!this.talents_content || !this.prefab_talent_item) return;
|
||
|
||
// 第一次:实例化所有子节点;之后只更新数据
|
||
if (!this.rendered) {
|
||
this.cachedConfigs = Object.values(FieldSkillSet)
|
||
.sort((a, b) => 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, 0);
|
||
}
|
||
});
|
||
this.rendered = true;
|
||
}
|
||
|
||
// 按相同顺序回填最新场上聚合值
|
||
this.cachedConfigs.forEach((cfg, index) => {
|
||
const child = this.talents_content.children[index];
|
||
if (!child) return;
|
||
const comp = child.getComponent(TalentItemComp);
|
||
if (!comp) return;
|
||
const total = FieldSkillHelper.getFieldSkillTotalValue(cfg.type);
|
||
comp.updateItem(cfg, total);
|
||
});
|
||
}
|
||
|
||
/** ECS 组件移除时销毁节点 */
|
||
reset() {
|
||
this.rendered = false;
|
||
this.cachedConfigs = [];
|
||
this.node.destroy();
|
||
}
|
||
|
||
protected onDestroy(): void {
|
||
super.onDestroy();
|
||
mLogger.log(this.debugMode, 'TalentsComp', "释放界面");
|
||
}
|
||
}
|