Files
pixelheros/assets/script/game/map/TalentItemComp.ts
pan 9adff47e6a refactor(map): 重构天赋系统为驻场技能展示组件
1.  将原天赋系统页面重构成驻场技能信息展示页
2.  移除升级、重置等旧功能,仅保留基础数据展示逻辑
3.  新增数值格式化工具函数,兼容百分比与整数加成显示
4.  简化组件依赖,仅保留必要的配置与UI渲染逻辑
5.  统一组件命名与注释,明确职责边界
2026-06-03 10:27:55 +08:00

66 lines
2.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 TalentItemComp.ts
* @description 驻场技能项组件UI 视图层)
*
* 职责:
* 1. 接收 TalentsComp 下发的 FieldSkillConfig 与当前场上总加成值。
* 2. 渲染名称 / 基础值 / 当前值 / 描述四段信息。
* 3. 兼容旧的 `@ecs.register('TalentItem')` 资源引用。
*
* 依赖:
* - SkillSet.FieldSkillConfig —— 单条驻场技能配置
*/
import { _decorator, Label } 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 { FieldSkillConfig } from "../common/config/SkillSet";
const { ccclass, property } = _decorator;
/**
* 将驻场配置值统一格式化为可读字符串。
* 兼容"小数"0.1 表示 10%)与"整数百分点"10 表示 10%)两种口径。
*/
function formatBuffValue(value: number): string {
if (Math.abs(value) < 1) {
return `${(value * 100).toFixed(0)}%`;
}
return value.toString();
}
/** 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_base: Label = null!;
@property({ type: Label, tooltip: "当前场上总加成(实时聚合)" })
lbl_current: Label = null!;
@property({ type: Label, tooltip: "驻场技能描述" })
lbl_info: Label = null!;
/**
* 刷新单条驻场技能展示
* @param config FieldSkillSet 中的单条配置
* @param currentTotal 当前场上同 type 累加值(实时聚合)
*/
public updateItem(config: FieldSkillConfig, currentTotal: number): void {
if (!config) return;
if (this.lbl_name) this.lbl_name.string = config.name ?? "";
if (this.lbl_base) this.lbl_base.string = `基础 +${formatBuffValue(config.value)}`;
if (this.lbl_current) this.lbl_current.string = `当前 +${formatBuffValue(currentTotal)}`;
if (this.lbl_info) this.lbl_info.string = config.info ?? "";
}
/** ECS 组件移除时销毁节点CCComp 抽象方法实现) */
reset() {
this.node.destroy();
}
}