feat(ui): 新增通用确认弹窗并重构英雄出售逻辑
1. 新增CommonPrompt通用确认弹窗组件,支持富文本内容、自定义按钮与弹窗动画 2. 在UIID配置中新增Window弹窗枚举与对应UI配置 3. 重构HeroBoxComp的出售逻辑,添加二次确认防止误触出售英雄
This commit is contained in:
@@ -23,6 +23,7 @@ import { Hero } from "../hero/Hero";
|
||||
import { getLvColor } from "../common/config/GameSet";
|
||||
import { buildSkillDescRich } from "../common/config/HeroSkillDesc";
|
||||
import { MissionEconomy } from "./MissionEconomy";
|
||||
import { UIID } from "../common/config/GameUIConfig";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@@ -183,19 +184,42 @@ export class HeroBoxComp extends CCComp {
|
||||
}
|
||||
|
||||
/**
|
||||
* 出售按钮点击:移除英雄实体、按等级结算金币并派发 HeroSell 事件。
|
||||
* MissionCardComp 监听该事件后会刷新槽位,本盒自动切为空状态。
|
||||
* 出售按钮点击:弹出公共确认窗口,确认后再执行出售。
|
||||
* Why: 出售不可逆,需二次确认防止误触。
|
||||
*/
|
||||
private onSellHeroClick() {
|
||||
if (!this.eid || !this.model) return;
|
||||
oops.audio.playEffect("music/button");
|
||||
|
||||
const heroName = this.model.hero_name ?? "";
|
||||
const heroLv = Math.max(1, Math.floor(this.model.lv ?? 1));
|
||||
const gold = MissionEconomy.getSellGold(heroLv);
|
||||
|
||||
// oops.gui 公共确认窗口(自定义 CommonPrompt:内容支持富文本高亮)
|
||||
oops.gui.open(UIID.Window, {
|
||||
title: "出售英雄",
|
||||
content: `确定出售 <color=#C0392B>${heroName}</color>(Lv.${heroLv})吗?\n出售后获得 <color=#1E8449>${gold}</color> 金币`,
|
||||
okWord: "出售",
|
||||
cancelWord: "取消",
|
||||
needCancel: true,
|
||||
okFunc: () => this.executeSellHero()
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行出售:移除英雄实体、按等级结算金币并派发 HeroSell 事件。
|
||||
* MissionCardComp 监听该事件后会刷新槽位,本盒自动切为空状态。
|
||||
*/
|
||||
private executeSellHero() {
|
||||
// 确认窗口打开期间英雄可能已死亡/被移除,需二次校验
|
||||
if (!this.eid || !this.model) return;
|
||||
const heroLv = Math.max(1, Math.floor(this.model.lv ?? 1));
|
||||
// 移除 ECS 实体失败(实体已失效)则不做后续结算
|
||||
if (!Hero.removeByEid(this.eid)) return;
|
||||
|
||||
oops.audio.playEffect("music/button");
|
||||
// 统一经济管理入口:按等级计算卖价并加金币
|
||||
const gold = MissionEconomy.executeSellHero(heroLv);
|
||||
mLogger.log(this.debugMode, "HeroBoxComp", "onSellHeroClick", { eid: this.eid, heroLv, gold });
|
||||
mLogger.log(this.debugMode, "HeroBoxComp", "executeSellHero", { eid: this.eid, heroLv, gold });
|
||||
|
||||
// 通知 MissionCardComp 更新场上英雄数量并刷新英雄盒槽位
|
||||
oops.message.dispatchEvent(GameEvent.HeroSell, { eid: this.eid });
|
||||
|
||||
Reference in New Issue
Block a user