From f10772bfd84bab64197e082add48a33cf51378be Mon Sep 17 00:00:00 2001 From: panFD Date: Fri, 31 Jul 2026 20:30:30 +0800 Subject: [PATCH] =?UTF-8?q?refactor(missionCard):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E8=8B=B1=E9=9B=84=E6=A7=BD=E4=BD=8D=E5=8A=A0=E8=BD=BD=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E5=B9=B6=E6=B8=85=E7=90=86=E5=BA=9F=E5=BC=83=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 移除不再需要的showCards节点和heroPrefab引用 2. 简化ensureHeroBoxSlots方法,改为直接缓存预放置的槽位 3. 更新对应注释说明当前槽位由编辑器预创建 4. 新增装备数量显示节点的属性声明 --- assets/script/game/map/MissionCardComp.ts | 42 ++++++----------------- 1 file changed, 11 insertions(+), 31 deletions(-) diff --git a/assets/script/game/map/MissionCardComp.ts b/assets/script/game/map/MissionCardComp.ts index d7b91576..ca61b3f8 100644 --- a/assets/script/game/map/MissionCardComp.ts +++ b/assets/script/game/map/MissionCardComp.ts @@ -86,8 +86,6 @@ export class MissionCardComp extends CCComp { /** 英雄抽卡面板(战斗阶段收起,准备阶段展开) */ @property(Node) - showCards: Node = null! - @property(Node) cardPanNode: Node = null! @property(Node) cards_node: Node = null! @@ -108,8 +106,6 @@ export class MissionCardComp extends CCComp { herosPanNode: Node = null! @property(Node) herosBoxNode: Node = null! - @property(Prefab) - heroPrefab: Prefab = null! /** 装备面板显示按钮 */ @property(Node) @@ -160,6 +156,9 @@ export class MissionCardComp extends CCComp { /** 英雄数量显示节点(含 icon + num 子节点) */ @property(Node) hero_num_node: Node = null! + /** 装备数量显示节点(含 icon + num 子节点) */ + @property(Node) + refresh_stone_num_node: Node = null! // ======================== 运行时状态 ======================== @@ -240,9 +239,6 @@ export class MissionCardComp extends CCComp { if (this.showHeros && this.showHeros.isValid) { this.showHeros.off(NodeEventType.TOUCH_END, this.onShowHerosClick, this); } - if (this.showCards && this.showCards.isValid) { - this.showCards.off(NodeEventType.TOUCH_END, this.onShowCardsClick, this); - } if (this.closeCards && this.closeCards.isValid) { this.closeCards.off(NodeEventType.TOUCH_END, this.onCloseCardsClick, this); } @@ -391,8 +387,7 @@ export class MissionCardComp extends CCComp { this.cards_chou?.on(NodeEventType.TOUCH_END, this.onDrawTouchEnd, this); this.cards_chou?.on(NodeEventType.TOUCH_CANCEL, this.onDrawTouchCancel, this); - /** 显示卡牌面板按钮 */ - this.showCards?.on(NodeEventType.TOUCH_END, this.onShowCardsClick, this); + /** 隐藏卡牌面板按钮 */ this.closeCards?.on(NodeEventType.TOUCH_END, this.onCloseCardsClick, this); @@ -641,9 +636,7 @@ export class MissionCardComp extends CCComp { if (this.showHeros && this.showHeros.isValid) { this.showHeros.off(NodeEventType.TOUCH_END, this.onShowHerosClick, this); } - if (this.showCards && this.showCards.isValid) { - this.showCards.off(NodeEventType.TOUCH_END, this.onShowCardsClick, this); - } + if (this.closeCards && this.closeCards.isValid) { this.closeCards.off(NodeEventType.TOUCH_END, this.onCloseCardsClick, this); } @@ -968,7 +961,7 @@ export class MissionCardComp extends CCComp { /** * 同步英雄信息盒槽位与场上英雄: - * 1. 确保 herosBoxNode 下存在 3 个 HeroBoxComp 槽位(复用 + 实例化补充)。 + * 1. 刷新 herosBoxNode 下 HeroBoxComp 槽位缓存(编辑器已预放 3 个)。 * 2. 查询当前存活英雄列表,按序绑定到槽位。 * 3. 多余槽位显示空英雄信息。 * @@ -977,7 +970,7 @@ export class MissionCardComp extends CCComp { private refreshHeroBoxSlots() { if (!this.herosBoxNode || !this.herosBoxNode.isValid) return; - this.ensureHeroBoxSlots(3); + this.ensureHeroBoxSlots(); // 查询场上存活英雄(含复活中的实体,按 eid 升序保证稳定顺序) const actors: Array<{ eid: number, model: HeroAttrsComp }> = []; @@ -1005,28 +998,15 @@ export class MissionCardComp extends CCComp { } /** - * 确保英雄信息盒槽位数量足够。 - * 优先复用 herosBoxNode 现有子节点,不足时从 heroPrefab 实例化补充。 + * 缓存英雄信息盒槽位组件引用。 + * 槽位已在编辑器中预先放置(herosBoxNode 下挂 HeroBoxComp), + * 运行时仅刷新缓存,不再动态实例化。 */ - private ensureHeroBoxSlots(targetCount: number) { + 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); - - // 补充实例化不足的槽位 - while (this.heroBoxComps.length < targetCount) { - if (!this.heroPrefab) break; - const node = instantiate(this.heroPrefab); - // 先禁用根节点 Widget 再挂到父节点,避免 lateUpdate 覆盖 position - const widget = node.getComponent(Widget); - if (widget) widget.enabled = false; - this.herosBoxNode.addChild(node); - const comp = node.getComponent(HeroBoxComp) || node.addComponent(HeroBoxComp); - this.heroBoxComps.push(comp); - } } /**