feat(ui): 新增天赋详情弹窗功能
重构天赋加点逻辑:将卡片点击校验与加点弹窗逻辑内聚到TIBoxComp中,TalentsComp仅负责打开弹窗。新增天赋详情弹窗,支持展示天赋信息、前置条件校验,并根据玩家状态动态控制加点按钮显隐。
This commit is contained in:
@@ -5,41 +5,30 @@
|
||||
* 职责:
|
||||
* 1. 页头展示:可用天赋点 / 天赋等级(Lv.x)/ 当前等级经验进度。
|
||||
* 2. 收集子树内全部 TalentItemComp(编辑器静态摆放),TALENT_UPDATE 事件驱动全量刷新。
|
||||
* 3. 卡片点击统一校验(层位解锁 → 软前置 → 满级 → 点数),不满足走 smalltip 气泡;
|
||||
* 满足则弹出 CommonPrompt 确认加点(smc.upgradeTalent)。
|
||||
* 3. 卡片点击统一打开 TIBox 天赋详情弹窗;加点校验(层位/前置/满级/点数)由 TIBoxComp 内聚,
|
||||
* 不满足条件时弹窗隐藏加点按钮,仅作详情查看。
|
||||
* 4. 看广告重置入口:CommonPrompt 二次确认后调 smc.resetTalents() 退还全部点数。
|
||||
*
|
||||
* 依赖:
|
||||
* - TalentSet(TalentTier/isTalentTierUnlocked/isTalentPrereqMet/getTalentTierInvestedPoints)—— 配置与层位校验
|
||||
* - TalentSet(getTalentTierInvestedPoints/getTalentLevelExp)—— 配置与统计
|
||||
* - TalentItemComp —— 单张迷你升级卡(编辑器静态摆放,按 uuid 自驱动渲染)
|
||||
* - TIBoxComp —— 天赋详情弹窗(UIID.TIBox)
|
||||
* - smc —— 天赋等级表/点数/升级/重置
|
||||
*/
|
||||
import { _decorator, Label, Node, NodeEventType, ProgressBar } 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 {
|
||||
TalentSet,
|
||||
TALENT_TIER_UNLOCK_THRESHOLD,
|
||||
getTalentDisplayText, getTalentLevelExp, getTalentTierInvestedPoints, getTalentUpgradeCost,
|
||||
isTalentPrereqMet, isTalentTierUnlocked,
|
||||
getTalentLevelExp, getTalentTierInvestedPoints,
|
||||
} from "../common/config/TalentSet";
|
||||
import { GameEvent } from "../common/config/GameEvent";
|
||||
import { UIID } from "../common/config/GameUIConfig";
|
||||
import { SmallTipComp } from "./SmallTipComp";
|
||||
import { TalentItemComp } from "./TalentItemComp";
|
||||
import { smc } from "../common/SingletonModuleComp";
|
||||
import { oops } from "db://oops-framework/core/Oops";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/** 层位序号展示文案(提示文案用) */
|
||||
const TIER_NAMES: Record<number, string> = {
|
||||
1: "第 1 层", 2: "第 2 层", 3: "第 3 层", 4: "第 4 层", 5: "第 5 层",
|
||||
};
|
||||
|
||||
/** 页签/卡片上的 smalltip 气泡节点名 */
|
||||
const SMALL_TIP_CHILD = "smalltip";
|
||||
|
||||
/** TalentsComp —— 天赋加点页组件(最小容器:页头 + 编辑器静态卡片收集) */
|
||||
@ccclass('TalentsComp')
|
||||
@ecs.register('Talents', false)
|
||||
@@ -123,80 +112,11 @@ export class TalentsComp extends CCComp {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取挂载点下的 smalltip 气泡组件(节点缺失或组件未挂时返回 null 并静默跳过提示)
|
||||
* @param parent 气泡挂载的父节点
|
||||
*/
|
||||
private getSmallTip(parent: Node | null): SmallTipComp | null {
|
||||
const tipNode = parent?.getChildByName(SMALL_TIP_CHILD);
|
||||
return tipNode ? (tipNode.getComponent(SmallTipComp) ?? tipNode.addComponent(SmallTipComp)) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 在指定节点下弹出 smalltip 气泡提示
|
||||
* @param anchor 气泡挂载的父节点
|
||||
* @param text 提示文案
|
||||
*/
|
||||
private showSmallTip(anchor: Node | null, text: string): void {
|
||||
const tip = this.getSmallTip(anchor);
|
||||
tip?.show(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按 uuid 找到对应的天赋卡节点(气泡锚点用)
|
||||
* 卡片点击统一入口:任何状态均打开 TIBox 天赋详情弹窗,加点按钮显隐由 TIBoxComp 校验
|
||||
* @param uuid 天赋 uuid
|
||||
*/
|
||||
private findItemNode(uuid: number): Node | null {
|
||||
for (const item of this.talent_items) {
|
||||
if (item.talent_uuid === uuid) return item.node;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** 卡片点击统一入口:层位未解锁/前置未满足/已满级/点数不足走 smalltip 气泡;其余弹出 CommonPrompt 确认加点,成功后事件驱动刷新 */
|
||||
private onTalentTap(uuid: number): void {
|
||||
const cfg = TalentSet[uuid];
|
||||
if (!cfg) return;
|
||||
const levels = smc.getTalentLevels();
|
||||
const anchor = this.findItemNode(uuid);
|
||||
|
||||
// 层位解锁:第 N 层要求第 N-1 层累计投入 ≥ 阈值
|
||||
if (!isTalentTierUnlocked(levels, cfg.tier)) {
|
||||
this.showSmallTip(anchor, `${TIER_NAMES[cfg.tier - 1]}投入${TALENT_TIER_UNLOCK_THRESHOLD} 点解锁`);
|
||||
return;
|
||||
}
|
||||
// 软前置:前置天赋等级需达标
|
||||
if (!isTalentPrereqMet(levels, cfg)) {
|
||||
const preCfg = TalentSet[cfg.prereq_uuid!];
|
||||
const preName = preCfg ? preCfg.name : `天赋${cfg.prereq_uuid}`;
|
||||
this.showSmallTip(anchor, `需「${preName}」达到 Lv.${cfg.prereq_lv}`);
|
||||
return;
|
||||
}
|
||||
const lv = smc.getTalentLv(uuid);
|
||||
if (lv >= cfg.max_lv) {
|
||||
this.showSmallTip(anchor, "该天赋已满级");
|
||||
return;
|
||||
}
|
||||
const cost = getTalentUpgradeCost(cfg.tier);
|
||||
if (cost <= 0) return;
|
||||
if (smc.getTalentPoints() < cost) {
|
||||
this.showSmallTip(anchor, "天赋点不足");
|
||||
return;
|
||||
}
|
||||
|
||||
// CommonPrompt 确认加点(UIID.Window)
|
||||
oops.gui.open(UIID.Window, {
|
||||
title: "天赋加点",
|
||||
content: `${cfg.name} Lv.${lv} → Lv.${lv + 1}\n消耗 <color=#E0A93D>${cost}</color> 点天赋点,获得 ${getTalentDisplayText(cfg, 1)}。是否加点?`,
|
||||
okWord: "加点",
|
||||
cancelWord: "取消",
|
||||
needCancel: true,
|
||||
maskClose: true,
|
||||
okFunc: () => {
|
||||
if (!smc.upgradeTalent(uuid)) {
|
||||
this.showSmallTip(anchor, "天赋点不足");
|
||||
}
|
||||
},
|
||||
});
|
||||
oops.gui.open(UIID.TIBox, { uuid });
|
||||
}
|
||||
|
||||
/** 看广告重置入口:CommonPrompt 二次确认(广告接入前先直接确认重置) */
|
||||
|
||||
Reference in New Issue
Block a user