feat(ui): 添加卡槽自动布局并禁用角色控制器节点

- 在 CardComp 中新增 setSlotPosition 方法,支持动态设置卡槽位置
- 在 MissionCardComp 中实现 layoutCardSlots 方法,根据卡槽数量自动水平居中布局
- 在任务开始、抽卡等关键时机调用布局更新,确保卡槽位置正确
- 禁用角色控制器预制件中的节点,防止其干扰UI交互
This commit is contained in:
walkpan
2026-03-14 09:42:20 +08:00
parent b32cea1c00
commit b630a97f8b
3 changed files with 28 additions and 1 deletions

View File

@@ -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;