refactor(ui): 移除英雄信息盒组件并重构弹窗逻辑

1. 删除 HeroBoxComp 组件及其相关缓存、调用逻辑
2. 简化 HeroMoreCom 职责说明与关闭逻辑
3. 为英雄技能配置添加图标字段
4. 移除 MissionCardComp 对英雄盒的相关依赖与事件监听
This commit is contained in:
panFD
2026-09-08 00:18:01 +08:00
parent dc0e873523
commit f52488f3fb
7 changed files with 1189 additions and 2112 deletions

View File

@@ -47,7 +47,6 @@ import { drawItemCards } from "../common/config/ICardSet";
import { drawSkillCards } from "../common/config/SCardSet";
import { CHeroComp } from "./CHeroComp";
import { EquipListComp } from "./EquipListComp";
import { HeroBoxComp } from "./HeroBoxComp";
import { SCardComp } from "./SCardComp";
import { MissEquipComp } from "./MissEquipComp";
import { MissSkillsComp } from "./MissSkillsComp";
@@ -189,8 +188,6 @@ export class MissionCardComp extends CCComp {
/** 三个槽位对应的 CHeroComp 控制器缓存(有序数组) */
private cardComps: CHeroComp[] = [];
/** 英雄面板 HeroBoxComp 控制器缓存(与场上英雄一一对应,最多 3 个) */
private heroBoxComps: HeroBoxComp[] = [];
/** 装备卡槽控制器缓存 */
private equipCardComps: EquipListComp[] = [];
/** 技能卡槽控制器缓存 */
@@ -266,7 +263,6 @@ export class MissionCardComp extends CCComp {
onLoad() {
this.bindEvents();
this.cacheCardComps();
this.hideAllHeroBoxSlots();
this.initCardsPanelPos();
this.initPanelLayout();
// 初始即永久隐藏手动插卡按钮,任何阶段都不再激活
@@ -378,17 +374,12 @@ export class MissionCardComp extends CCComp {
mLogger.log(this.debugMode, "MissionCardComp", "mission start");
}
/** 任务结束:清空 3 槽 + 装备商店 + 技能卡槽 + 英雄面板并隐藏整个节点 */
/** 任务结束:清空 3 槽 + 装备商店 + 技能卡槽并隐藏整个节点 */
onMissionEnd() {
this.clearAllCards();
this.clearEquipments();
this.clearSkillCards();
this.clearShopItems();
for (const comp of this.heroBoxComps) {
if (comp && comp.node && comp.node.isValid) {
comp.applyEmpty();
}
}
// 任务结束清理:停止新手卡牌引导动画
this.stopCardsGuideAnim();
this.unscheduleAllCallbacks();
@@ -439,8 +430,6 @@ export class MissionCardComp extends CCComp {
oops.message.on(GameEvent.UseSpecialCard, this.onUseSpecialCard, this);
oops.message.on(GameEvent.ShowSmallTip, this.onShowSmallTip, this);
oops.message.on(GameEvent.CardUsed, this.onCardUsed, this);
oops.message.on(GameEvent.HeroBoxEmptyClick, this.onHeroBoxEmptyClick, this);
oops.message.on(GameEvent.HeroUpgrade, this.onHeroUpgrade, this);
/** 按钮触控事件:抽卡 */
this.cards_refresh?.on(NodeEventType.TOUCH_START, this.onDrawTouchStart, this);
@@ -698,8 +687,6 @@ export class MissionCardComp extends CCComp {
oops.message.off(GameEvent.UseSpecialCard, this.onUseSpecialCard, this);
oops.message.off(GameEvent.ShowSmallTip, this.onShowSmallTip, this);
oops.message.off(GameEvent.CardUsed, this.onCardUsed, this);
oops.message.off(GameEvent.HeroBoxEmptyClick, this.onHeroBoxEmptyClick, this);
oops.message.off(GameEvent.HeroUpgrade, this.onHeroUpgrade, this);
if (this.cards_refresh && this.cards_refresh.isValid) {
this.cards_refresh.off(NodeEventType.TOUCH_START, this.onDrawTouchStart, this);
this.cards_refresh.off(NodeEventType.TOUCH_END, this.onDrawTouchEnd, this);
@@ -756,56 +743,20 @@ export class MissionCardComp extends CCComp {
this.hasCalledHero = true;
this.updatePanelButtonsInteractable();
}
// 英雄登场后同步英雄信息盒
// 暂不启用 herobox 同步(后续可能恢复)
// this.refreshHeroBoxSlots();
}
/** 英雄死亡事件回调:刷新面板列表并更新英雄数量 UI */
/** 英雄死亡事件回调:更新英雄数量 UI */
private onHeroDead() {
this.updateHeroNumUI(true, false);
// 暂不启用 herobox 同步(后续可能恢复)
// this.refreshHeroBoxSlots();
}
/** 英雄被出售事件回调:更新英雄数量 UI 并清空对应英雄信息盒 */
/** 英雄被出售事件回调:更新英雄数量 UI */
private onHeroSell() {
this.updateHeroNumUI(true, false);
// 暂不启用 herobox 同步(后续可能恢复)
// this.refreshHeroBoxSlots();
}
/**
* 英雄面板升级请求回调(由 HeroBoxComp 确认弹窗后派发)。
* 扣费成功后按 eid 精确升级;金币不足或不可升级时 toast 提示。
*/
private onHeroUpgrade(event: string, args: any) {
const payload = args ?? event;
const eid: number = payload?.eid ?? 0;
if (!eid) return;
const actor = this.queryAliveHeroActors().find(item => item.eid === eid);
if (!actor) return;
// 无限升级:不再拦截满级,仅校验金币
// 统一经济管理入口:按当前等级扣费
if (!MissionEconomy.executeUpgradeCost(actor.model.lv)) {
oops.gui.toast(`金币不足`);
return;
}
this.tryUpgradeHeroByEid(eid);
}
/** 英雄升级事件回调:刷新英雄信息盒显示 */
/** 英雄升级事件回调 */
private onHeroLvUp() {
// 暂不启用 herobox 同步(后续可能恢复)
// this.refreshHeroBoxSlots();
}
/** 英雄面板空槽位点击回调:展示英雄卡池选择界面 */
private onHeroBoxEmptyClick() {
this.onShowCardsClick();
}
/**
@@ -1169,76 +1120,6 @@ export class MissionCardComp extends CCComp {
this.showHeros.active = false;
}
// ======================== 英雄信息盒(herosBoxNode) ========================
/**
* 同步英雄信息盒槽位与场上英雄:
* 1. 刷新 herosBoxNode 下 HeroBoxComp 槽位缓存(编辑器已预放 3 个)。
* 2. 查询当前存活英雄列表,按序绑定到槽位(bindHero 内部激活节点)。
* 3. 多余槽位清空数据并隐藏(默认全部隐藏,召唤一个激活一个)。
*
* Why: 英雄召唤 / 死亡 / 卖出 / 升级后调用,保证面板与场上一一对应。
*
* 备注:当前版本暂不启用 herobox 同步显示英雄信息(后续可能恢复),
* 方法体已整体注释,所有调用点也已注释。恢复时取消方法体与调用点注释。
*/
private refreshHeroBoxSlots() {
/* 暂不启用 herobox 同步,保留实现备查
if (!this.herosBoxNode || !this.herosBoxNode.isValid) return;
this.ensureHeroBoxSlots();
// 查询场上存活英雄(含复活中的实体,按 eid 升序保证稳定顺序)
const actors: Array<{ eid: number, model: HeroAttrsComp }> = [];
ecs.query(ecs.allOf(HeroAttrsComp)).forEach((entity: ecs.Entity) => {
const model = entity.get(HeroAttrsComp);
if (!model) return;
if (model.fac !== FacSet.HERO) return;
if (model.is_dead) return;
actors.push({ eid: entity.eid, model });
});
actors.sort((a, b) => a.eid - b.eid);
for (let i = 0; i < this.heroBoxComps.length; i++) {
const comp = this.heroBoxComps[i];
if (!comp || !comp.node || !comp.node.isValid) continue;
const actor = actors[i];
if (actor) {
comp.bindHero(actor.eid, actor.model);
} else {
// 空槽位默认隐藏:召唤一个英雄才激活一个槽位
comp.applyEmpty();
comp.node.active = false;
}
}
// 列表高度只按可见槽位(存活英雄数)计算,空槽位已隐藏不再占位
this.resizeListBox(this.herosBoxNode, actors.length);
*/
}
/**
* 缓存英雄信息盒槽位组件引用。
* 槽位已在编辑器中预先放置(herosBoxNode 下挂 HeroBoxComp),
* 运行时仅刷新缓存,不再动态实例化。
*/
private ensureHeroBoxSlots() {
if (!this.herosBoxNode || !this.herosBoxNode.isValid) return;
this.heroBoxComps = this.herosBoxNode.children
.map(node => node.getComponent(HeroBoxComp))
.filter((comp): comp is HeroBoxComp => !!comp);
}
/** 英雄信息盒槽位默认全部隐藏,召唤一个英雄再激活一个 */
private hideAllHeroBoxSlots() {
this.ensureHeroBoxSlots();
for (const comp of this.heroBoxComps) {
if (comp && comp.node && comp.node.isValid) {
comp.node.active = false;
}
}
}
/**
* 支付抽卡面板开启费用:
* 金币足够则扣除当前费用,并将该面板费用递增 PANEL_OPEN_COST_STEP;
@@ -2316,7 +2197,6 @@ export class MissionCardComp extends CCComp {
// 关键:在 reset/销毁 时将 Map 置空,彻底切断引用
this.cardComps = [];
this.heroBoxComps = [];
this.skillCardComps = [];
if (this.node && this.node.isValid) {