feat(talents): 重构驻场技能页面为天赋图鉴页面
- 调整天赋预制体布局参数,包含容器宽度、边距和间距 - 移除旧的驻场技能相关UI节点引用 - 替换数据来源为卡牌池技能卡,重构列表渲染与排序逻辑 - 更新UI展示逻辑,显示天赋名称、描述、图标和对应品质背景 - 优化组件注释与属性描述,统一代码风格
This commit is contained in:
@@ -1,61 +1,85 @@
|
||||
/**
|
||||
* @file TalentItemComp.ts
|
||||
* @description 驻场技能项组件(UI 视图层)
|
||||
* @description 天赋图鉴项组件(UI 视图层)
|
||||
*
|
||||
* 职责:
|
||||
* 1. 接收 TalentsComp 下发的 FieldSkillConfig 与当前场上总加成值。
|
||||
* 2. 渲染名称 / 基础值 / 当前值 / 描述四段信息。
|
||||
* 3. 兼容旧的 `@ecs.register('TalentItem')` 资源引用。
|
||||
* 1. 接收 TalentsComp 下发的天赋卡配置(技能卡)。
|
||||
* 2. 渲染名称、描述、图标和背景。
|
||||
* 3. 背景颜色根据 wave 映射为对应的 poolLv。
|
||||
*
|
||||
* 依赖:
|
||||
* - SkillSet.FieldSkillConfig —— 单条驻场技能配置
|
||||
* - CardSet.CardConfig —— 单条卡牌配置
|
||||
* - SkillSet —— 获取技能图标
|
||||
*/
|
||||
import { _decorator, Label } from "cc";
|
||||
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 { FieldSkillConfig } from "../common/config/SkillSet";
|
||||
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;
|
||||
|
||||
/**
|
||||
* 将驻场配置值统一格式化为可读字符串。
|
||||
* 兼容"小数"(0.1 表示 10%)与"整数百分点"(10 表示 10%)两种口径。
|
||||
*/
|
||||
function formatBuffValue(value: number): string {
|
||||
if (Math.abs(value) < 1) {
|
||||
return `${(value * 100).toFixed(0)}%`;
|
||||
}
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
/** TalentItemComp —— 驻场技能项组件 */
|
||||
/** TalentItemComp —— 天赋图鉴项组件 */
|
||||
@ccclass('TalentItemComp')
|
||||
@ecs.register('TalentItem', false)
|
||||
export class TalentItemComp extends CCComp {
|
||||
|
||||
@property({ type: Label, tooltip: "驻场技能名称" })
|
||||
@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: "驻场技能描述" })
|
||||
@property({ type: Label, tooltip: "天赋说明" })
|
||||
lbl_info: Label = null!;
|
||||
|
||||
@property({ type: Sprite, tooltip: "天赋图标" })
|
||||
icon: Sprite = null!;
|
||||
|
||||
@property({ type: CardBgComp, tooltip: "卡牌背景组件" })
|
||||
bg: CardBgComp = null!;
|
||||
|
||||
/**
|
||||
* 刷新单条驻场技能展示
|
||||
* @param config FieldSkillSet 中的单条配置
|
||||
* @param currentTotal 当前场上同 type 累加值(实时聚合)
|
||||
* 刷新单条天赋展示
|
||||
* @param config CardPoolList 中的天赋卡(技能卡)配置
|
||||
*/
|
||||
public updateItem(config: FieldSkillConfig, currentTotal: number): void {
|
||||
public updateItem(config: CardConfig): 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 ?? "";
|
||||
|
||||
// 根据 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 抽象方法实现) */
|
||||
|
||||
Reference in New Issue
Block a user