|
|
@@ -394,6 +394,8 @@ export class GameBlockSelection extends Component {
|
|
|
// 监听敌人数量更新与新波次开始,精确在第二波结束时解禁按钮
|
|
|
eventBus.on(GameEvents.ENEMY_UPDATE_COUNT, this.updateGuideButtonStates, this);
|
|
|
eventBus.on(GameEvents.ENEMY_START_WAVE, this.updateGuideButtonStates, this);
|
|
|
+ // 监听:全局强制结束所有拖拽(用于教程自动放置期间收敛拖拽状态)
|
|
|
+ eventBus.on(GameEvents.FORCE_END_ALL_DRAGS, this.onForceEndAllDrags, this);
|
|
|
}
|
|
|
|
|
|
// 处理重置方块选择事件
|
|
|
@@ -1578,6 +1580,38 @@ export class GameBlockSelection extends Component {
|
|
|
eventBus.off(GameEvents.ENEMY_UPDATE_COUNT, this.updateGuideButtonStates, this);
|
|
|
eventBus.off(GameEvents.ENEMY_START_WAVE, this.updateGuideButtonStates, this);
|
|
|
eventBus.off(GameEvents.SETUP_BLOCK_DRAG_EVENTS, this.onSetupBlockDragEventsEvent, this);
|
|
|
+ eventBus.off(GameEvents.FORCE_END_ALL_DRAGS, this.onForceEndAllDrags, this);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 强制结束当前拖拽:用于教程自动放置发生时,立即清空拖拽上下文
|
|
|
+ private onForceEndAllDrags() {
|
|
|
+ if (!this.currentDragBlock || !this.currentDragBlock.isValid) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ // 清除拖拽标记并恢复碰撞
|
|
|
+ (this.currentDragBlock as any)['isDragging'] = false;
|
|
|
+ const rootCol = this.currentDragBlock.getComponent(Collider2D);
|
|
|
+ if (rootCol && !rootCol.enabled) rootCol.enabled = true;
|
|
|
+ const b1 = this.currentDragBlock.getChildByName('B1');
|
|
|
+ if (b1) {
|
|
|
+ const b1Col = b1.getComponent(Collider2D);
|
|
|
+ if (b1Col && !b1Col.enabled) b1Col.enabled = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 根据方块原始位置决定是否需要回到kuang容器
|
|
|
+ const startLocation = this.blockManager.blockLocations.get(this.currentDragBlock);
|
|
|
+ if (startLocation && startLocation !== 'grid') {
|
|
|
+ this.returnBlockToKuang(startLocation);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 统一抛出拖拽结束事件,维持各模块状态一致
|
|
|
+ EventBus.getInstance().emit(GameEvents.BLOCK_DRAG_END, { block: this.currentDragBlock });
|
|
|
+ } catch (e) {
|
|
|
+ console.warn('[GameBlockSelection] 强制结束拖拽失败:', e);
|
|
|
+ } finally {
|
|
|
+ this.currentDragBlock = null;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|