From b630a97f8b18ac1559163a82bada4c1e7aab343b Mon Sep 17 00:00:00 2001 From: walkpan Date: Sat, 14 Mar 2026 09:42:20 +0800 Subject: [PATCH] =?UTF-8?q?feat(ui):=20=E6=B7=BB=E5=8A=A0=E5=8D=A1?= =?UTF-8?q?=E6=A7=BD=E8=87=AA=E5=8A=A8=E5=B8=83=E5=B1=80=E5=B9=B6=E7=A6=81?= =?UTF-8?q?=E7=94=A8=E8=A7=92=E8=89=B2=E6=8E=A7=E5=88=B6=E5=99=A8=E8=8A=82?= =?UTF-8?q?=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 CardComp 中新增 setSlotPosition 方法,支持动态设置卡槽位置 - 在 MissionCardComp 中实现 layoutCardSlots 方法,根据卡槽数量自动水平居中布局 - 在任务开始、抽卡等关键时机调用布局更新,确保卡槽位置正确 - 禁用角色控制器预制件中的节点,防止其干扰UI交互 --- assets/resources/gui/role_controller.prefab | 2 +- assets/script/game/map/CardComp.ts | 8 ++++++++ assets/script/game/map/MissionCardComp.ts | 19 +++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/assets/resources/gui/role_controller.prefab b/assets/resources/gui/role_controller.prefab index c3667501..7b7ec2a8 100644 --- a/assets/resources/gui/role_controller.prefab +++ b/assets/resources/gui/role_controller.prefab @@ -8635,7 +8635,7 @@ "node": { "__id__": 342 }, - "_enabled": true, + "_enabled": false, "__prefab": { "__id__": 380 }, diff --git a/assets/script/game/map/CardComp.ts b/assets/script/game/map/CardComp.ts index d78f0447..657e2489 100644 --- a/assets/script/game/map/CardComp.ts +++ b/assets/script/game/map/CardComp.ts @@ -159,6 +159,14 @@ export class CardComp extends CCComp { return this.isLocked; } + setSlotPosition(x: number) { + const current = this.node.position; + this.restPosition = new Vec3(x, current.y, current.z); + if (!this.isDragging && !this.isUsing) { + this.node.setPosition(this.restPosition); + } + } + /** 系统清槽:用于任务开始/结束等强制重置场景 */ clearBySystem() { Tween.stopAllByTarget(this.node); diff --git a/assets/script/game/map/MissionCardComp.ts b/assets/script/game/map/MissionCardComp.ts index 35ce7139..34f11030 100644 --- a/assets/script/game/map/MissionCardComp.ts +++ b/assets/script/game/map/MissionCardComp.ts @@ -14,6 +14,7 @@ const { ccclass, property } = _decorator; @ecs.register('MissionCard', false) export class MissionCardComp extends CCComp { private debugMode: boolean = true; + private readonly cardWidth: number = 175; /** 四个插卡槽位(固定顺序分发:1~4) */ @property(Node) card1:Node = null! @@ -39,6 +40,7 @@ export class MissionCardComp extends CCComp { /** 绑定事件 -> 缓存子控制器 -> 初始化UI状态 */ this.bindEvents(); this.cacheCardComps(); + this.layoutCardSlots(); this.onMissionStart(); mLogger.log(this.debugMode, "MissionCardComp", "onLoad init", { slots: this.cardComps.length, @@ -56,6 +58,7 @@ export class MissionCardComp extends CCComp { /** 任务开始时:重置卡池等级、清空4槽、显示面板 */ onMissionStart() { this.poolLv = CARD_POOL_INIT_LEVEL; + this.layoutCardSlots(); this.clearAllCards(); if (this.cards_up) { this.cards_up.active = true; @@ -113,6 +116,7 @@ export class MissionCardComp extends CCComp { mLogger.log(this.debugMode, "MissionCardComp", "click draw", { poolLv: this.poolLv }); + this.layoutCardSlots(); const cards = this.buildDrawCards(); this.dispatchCardsToSlots(cards); } @@ -163,6 +167,21 @@ export class MissionCardComp extends CCComp { this.cardComps.forEach(comp => comp.clearBySystem()); } + private layoutCardSlots() { + const count = this.cardComps.length; + if (count === 0) return; + const startX = -((count - 1) * this.cardWidth) / 2; + for (let i = 0; i < count; i++) { + const x = startX + i * this.cardWidth; + this.cardComps[i].setSlotPosition(x); + } + mLogger.log(this.debugMode, "MissionCardComp", "layout card slots", { + count, + cardWidth: this.cardWidth, + startX + }); + } + /** 更新升级按钮上的等级文案,反馈当前卡池层级 */ private updatePoolLvUI() { if (!this.cards_up) return;