|
|
@@ -1,8 +1,7 @@
|
|
|
-import { _decorator, Component, Node, Button, Label, find, UITransform, Sprite, Color, tween, Tween, Prefab, instantiate } from 'cc';
|
|
|
+import { _decorator, Component, Node, Button, Label, find, UITransform, Sprite, Color, Prefab, instantiate, Vec3 } from 'cc';
|
|
|
import { LevelSessionManager } from '../../Core/LevelSessionManager';
|
|
|
import { BallController } from '../BallController';
|
|
|
import { BlockManager } from '../BlockManager';
|
|
|
-import { GameStartMove } from '../../Animations/GameStartMove';
|
|
|
|
|
|
import { BlockTag } from './BlockTag';
|
|
|
import { SkillManager } from '../SkillSelection/SkillManager';
|
|
|
@@ -15,19 +14,19 @@ export class GameBlockSelection extends Component {
|
|
|
|
|
|
@property({
|
|
|
type: Node,
|
|
|
- tooltip: '拖拽BlockSelectionUI/diban/ann001按钮节点到这里'
|
|
|
+ tooltip: '拖拽diban/ann001按钮节点到这里'
|
|
|
})
|
|
|
public addBallButton: Node = null;
|
|
|
|
|
|
@property({
|
|
|
type: Node,
|
|
|
- tooltip: '拖拽BlockSelectionUI/diban/ann002按钮节点到这里'
|
|
|
+ tooltip: '拖拽diban/ann002按钮节点到这里'
|
|
|
})
|
|
|
public addCoinButton: Node = null;
|
|
|
|
|
|
@property({
|
|
|
type: Node,
|
|
|
- tooltip: '拖拽BlockSelectionUI/diban/ann003按钮节点到这里'
|
|
|
+ tooltip: '拖拽diban/ann003按钮节点到这里'
|
|
|
})
|
|
|
public refreshButton: Node = null;
|
|
|
|
|
|
@@ -55,12 +54,6 @@ export class GameBlockSelection extends Component {
|
|
|
})
|
|
|
public blockManagerNode: Node = null;
|
|
|
|
|
|
- @property({
|
|
|
- type: Node,
|
|
|
- tooltip: '拖拽Canvas/Camera节点到这里'
|
|
|
- })
|
|
|
- public cameraNode: Node = null;
|
|
|
-
|
|
|
@property({
|
|
|
type: Node,
|
|
|
tooltip: '拖拽Canvas/GameLevelUI/GameArea/GridContainer节点到这里'
|
|
|
@@ -75,15 +68,15 @@ export class GameBlockSelection extends Component {
|
|
|
|
|
|
@property({
|
|
|
type: Node,
|
|
|
- tooltip: '拖拽BlockSelectionUI根节点到这里'
|
|
|
+ tooltip: '拖拽Canvas/GameLevelUI/InGameManager节点到这里'
|
|
|
})
|
|
|
- public blockSelectionUINode: Node = null;
|
|
|
+ public inGameManagerNode: Node = null;
|
|
|
|
|
|
@property({
|
|
|
type: Node,
|
|
|
- tooltip: '拖拽BlockSelectionUI/diban节点到这里'
|
|
|
+ tooltip: '拖拽Canvas/Camera节点到这里'
|
|
|
})
|
|
|
- public dibanNode: Node = null;
|
|
|
+ public cameraNode: Node = null;
|
|
|
|
|
|
// 按钮费用配置
|
|
|
private readonly ADD_BALL_COST = 80;
|
|
|
@@ -93,7 +86,6 @@ export class GameBlockSelection extends Component {
|
|
|
private session: LevelSessionManager = null;
|
|
|
private ballController: BallController = null;
|
|
|
private blockManager: BlockManager = null;
|
|
|
- private gameStartMove: GameStartMove = null;
|
|
|
|
|
|
// 回调函数,用于通知GameManager
|
|
|
public onConfirmCallback: () => void = null;
|
|
|
@@ -128,21 +120,7 @@ export class GameBlockSelection extends Component {
|
|
|
// 获取管理器实例
|
|
|
this.session = LevelSessionManager.inst;
|
|
|
|
|
|
- // 如果组件挂载在BlockSelectionUI节点上,则将该节点设为blockSelectionUINode
|
|
|
- if (!this.blockSelectionUINode && this.node.name === 'BlockSelectionUI') {
|
|
|
- this.blockSelectionUINode = this.node;
|
|
|
- console.log('[GameBlockSelection] 组件挂载在BlockSelectionUI节点上,设置为blockSelectionUINode:', this.blockSelectionUINode.name);
|
|
|
- }
|
|
|
-
|
|
|
- // 如果dibanNode未绑定,尝试在当前节点下查找
|
|
|
- if (!this.dibanNode && this.blockSelectionUINode) {
|
|
|
- this.dibanNode = this.blockSelectionUINode.getChildByName('diban');
|
|
|
- if (this.dibanNode) {
|
|
|
- console.log('[GameBlockSelection] 找到diban节点:', this.dibanNode.name);
|
|
|
- } else {
|
|
|
- console.error('[GameBlockSelection] 无法找到diban节点');
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
// 获取BallController
|
|
|
if (this.ballControllerNode) {
|
|
|
@@ -158,33 +136,7 @@ export class GameBlockSelection extends Component {
|
|
|
console.warn('BlockManager节点未绑定,请在Inspector中拖拽Canvas/GameLevelUI/BlockController节点');
|
|
|
}
|
|
|
|
|
|
- // 获取GameStartMove组件
|
|
|
- if (this.cameraNode) {
|
|
|
- this.gameStartMove = this.cameraNode.getComponent(GameStartMove);
|
|
|
- console.log('GameStartMove组件获取结果:', !!this.gameStartMove);
|
|
|
-
|
|
|
- // 如果GameStartMove存在,设置BlockSelectionUI和diban引用,并更新原始位置
|
|
|
- if (this.gameStartMove && this.blockSelectionUINode && this.dibanNode) {
|
|
|
- this.gameStartMove.blockSelectionUI = this.blockSelectionUINode;
|
|
|
- this.gameStartMove.dibanNode = this.dibanNode;
|
|
|
- this.gameStartMove.updateDibanOriginalPosition();
|
|
|
-
|
|
|
- console.log('GameStartMove引用设置完成:', {
|
|
|
- blockSelectionUISet: !!this.gameStartMove.blockSelectionUI,
|
|
|
- dibanNodeSet: !!this.gameStartMove.dibanNode,
|
|
|
- blockSelectionUINodeName: this.blockSelectionUINode.name,
|
|
|
- dibanNodeName: this.dibanNode.name
|
|
|
- });
|
|
|
- } else {
|
|
|
- console.warn('GameStartMove引用设置失败:', {
|
|
|
- gameStartMove: !!this.gameStartMove,
|
|
|
- blockSelectionUINode: !!this.blockSelectionUINode,
|
|
|
- dibanNode: !!this.dibanNode
|
|
|
- });
|
|
|
- }
|
|
|
- } else {
|
|
|
- console.warn('Camera节点未绑定,请在Inspector中拖拽Canvas/Camera节点');
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
// 如果没有指定coinLabelNode,尝试找到它
|
|
|
if (!this.coinLabelNode) {
|
|
|
@@ -217,8 +169,7 @@ export class GameBlockSelection extends Component {
|
|
|
console.log('[GameBlockSelection] RESET_BLOCK_SELECTION事件监听器已设置');
|
|
|
|
|
|
// 监听显示方块选择事件
|
|
|
- eventBus.on(GameEvents.SHOW_BLOCK_SELECTION, this.onShowBlockSelectionEvent, this);
|
|
|
- console.log('[GameBlockSelection] SHOW_BLOCK_SELECTION事件监听器已设置');
|
|
|
+
|
|
|
|
|
|
// 监听游戏开始事件,用于标记可以开始生成方块
|
|
|
eventBus.on(GameEvents.GAME_START, this.onGameStartEvent, this);
|
|
|
@@ -234,14 +185,7 @@ export class GameBlockSelection extends Component {
|
|
|
this.resetSelection();
|
|
|
}
|
|
|
|
|
|
- // 处理显示方块选择事件
|
|
|
- private onShowBlockSelectionEvent() {
|
|
|
- console.log('[GameBlockSelection] ===== 接收到显示方块选择事件 =====');
|
|
|
- console.log('[GameBlockSelection] 当前组件节点:', this.node.name, '状态:', this.node.active);
|
|
|
- console.log('[GameBlockSelection] blockSelectionUINode:', this.blockSelectionUINode?.name, '状态:', this.blockSelectionUINode?.active);
|
|
|
- this.showBlockSelection(true); // false表示不是下一波,而是游戏开始
|
|
|
- console.log('[GameBlockSelection] ===== 显示方块选择事件处理完成 =====');
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
// 处理游戏开始事件
|
|
|
private onGameStartEvent() {
|
|
|
@@ -369,7 +313,7 @@ export class GameBlockSelection extends Component {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 确认按钮点击(从GameManager迁移的onConfirmButtonClicked)
|
|
|
+ // 确认按钮点击
|
|
|
public onConfirmButtonClicked() {
|
|
|
// 检查是否有上阵方块
|
|
|
const hasBlocks = this.hasPlacedBlocks();
|
|
|
@@ -382,14 +326,42 @@ export class GameBlockSelection extends Component {
|
|
|
|
|
|
// 保存已放置的方块
|
|
|
this.preservePlacedBlocks();
|
|
|
+
|
|
|
+ // 清理kuang区域的方块(用户期望的行为)
|
|
|
+ if (this.blockManager) {
|
|
|
+ this.blockManager.clearBlocks();
|
|
|
+ console.log('[GameBlockSelection] 已清理kuang区域的方块');
|
|
|
+ }
|
|
|
|
|
|
// 先回调通知GameManager,让它处理波次逻辑
|
|
|
if (this.onConfirmCallback) {
|
|
|
this.onConfirmCallback();
|
|
|
}
|
|
|
|
|
|
- // 然后隐藏UI并恢复游戏
|
|
|
- this.hideBlockSelection();
|
|
|
+ // 播放下滑diban动画,结束备战进入playing状态
|
|
|
+ this.playDibanSlideDownAnimation();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 播放diban下滑动画
|
|
|
+ private playDibanSlideDownAnimation() {
|
|
|
+ console.log('[GameBlockSelection] 开始播放diban下滑动画');
|
|
|
+
|
|
|
+ // 使用装饰器属性获取Camera节点上的GameStartMove组件
|
|
|
+ if (!this.cameraNode) {
|
|
|
+ console.warn('[GameBlockSelection] Camera节点未设置,请在Inspector中拖拽Canvas/Camera节点');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const gameStartMove = this.cameraNode.getComponent('GameStartMove');
|
|
|
+ if (!gameStartMove) {
|
|
|
+ console.warn('[GameBlockSelection] GameStartMove组件未找到');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 调用GameStartMove的下滑动画方法
|
|
|
+ (gameStartMove as any).slideDibanDownAndHide(300, 0.3);
|
|
|
+
|
|
|
+ console.log('[GameBlockSelection] 已调用GameStartMove的diban下滑动画');
|
|
|
}
|
|
|
|
|
|
// 保存已放置的方块(从GameManager迁移)
|
|
|
@@ -467,142 +439,27 @@ export class GameBlockSelection extends Component {
|
|
|
|
|
|
// === 公共方法:供GameManager调用 ===
|
|
|
|
|
|
- // 显示方块选择UI(用于游戏开始或下一波)
|
|
|
- public showBlockSelection(isNextWave: boolean = false) {
|
|
|
- console.log('[GameBlockSelection] showBlockSelection开始执行');
|
|
|
- console.log('[GameBlockSelection] 节点状态检查:', {
|
|
|
- node: !!this.node,
|
|
|
- nodeActive: this.node?.active,
|
|
|
- nodeName: this.node?.name,
|
|
|
- gridContainer: !!this.gridContainer,
|
|
|
- gridContainerActive: this.gridContainer?.active,
|
|
|
- blockSelectionUINode: !!this.blockSelectionUINode,
|
|
|
- blockSelectionUINodeActive: this.blockSelectionUINode?.active,
|
|
|
- blockSelectionUINodeName: this.blockSelectionUINode?.name
|
|
|
- });
|
|
|
-
|
|
|
- // 通过事件系统暂停游戏
|
|
|
- const eventBus = EventBus.getInstance();
|
|
|
- eventBus.emit(GameEvents.GAME_PAUSE);
|
|
|
- console.log('[GameBlockSelection] 显示方块选择UI,确保游戏暂停');
|
|
|
+ // 生成方块选择(不再控制UI显示,只负责生成方块)
|
|
|
+ public generateBlockSelection() {
|
|
|
+ console.log('[GameBlockSelection] generateBlockSelection开始执行');
|
|
|
|
|
|
- // BlockSelectionUI节点现在默认就是激活状态,无需手动设置
|
|
|
- // 只需要确认节点状态用于调试
|
|
|
- if (this.blockSelectionUINode) {
|
|
|
- console.log('[GameBlockSelection] BlockSelectionUI节点状态:', this.blockSelectionUINode.active, this.blockSelectionUINode.name);
|
|
|
- } else {
|
|
|
- console.log('[GameBlockSelection] 组件节点状态:', this.node.active, this.node.name);
|
|
|
- }
|
|
|
-
|
|
|
- if (this.gridContainer) {
|
|
|
- this.gridContainer.active = true;
|
|
|
- console.log('[GameBlockSelection] gridContainer已激活:', this.gridContainer.active);
|
|
|
- } else {
|
|
|
- console.warn('[GameBlockSelection] gridContainer未找到');
|
|
|
- }
|
|
|
-
|
|
|
- // 只有在onBattle触发后才生成方块
|
|
|
- if (this.shouldGenerateBlocks && this.blockManager) {
|
|
|
+ // 直接生成方块,不再依赖shouldGenerateBlocks标志
|
|
|
+ if (this.blockManager) {
|
|
|
this.blockManager.refreshBlocks();
|
|
|
console.log('[GameBlockSelection] 生成新的随机方块');
|
|
|
- } else if (!this.shouldGenerateBlocks) {
|
|
|
- console.log('[GameBlockSelection] 等待onBattle触发后才生成方块');
|
|
|
} else {
|
|
|
console.warn('[GameBlockSelection] BlockManager未找到,无法生成随机方块');
|
|
|
}
|
|
|
|
|
|
- // 播放BlockSelectionUI出现动画
|
|
|
- console.log('[GameBlockSelection] 准备播放显示动画');
|
|
|
- this.playShowAnimation();
|
|
|
-
|
|
|
// 触发进入备战状态事件
|
|
|
EventBus.getInstance().emit(GameEvents.ENTER_BATTLE_PREPARATION);
|
|
|
-
|
|
|
- // 派发事件
|
|
|
- EventBus.getInstance().emit(GameEvents.BLOCK_SELECTION_OPEN);
|
|
|
-
|
|
|
- console.log(`[GameBlockSelection] ${isNextWave ? '显示下一波方块选择UI' : '显示游戏开始方块选择UI'} 完成`);
|
|
|
+
|
|
|
+ console.log('[GameBlockSelection] 方块生成完成');
|
|
|
}
|
|
|
|
|
|
- // 隐藏方块选择UI
|
|
|
- public hideBlockSelection() {
|
|
|
- // 播放隐藏动画,动画完成后隐藏UI
|
|
|
- this.playHideAnimation(() => {
|
|
|
- this.node.active = false;
|
|
|
-
|
|
|
- // 派发事件
|
|
|
- EventBus.getInstance().emit(GameEvents.BLOCK_SELECTION_CLOSE);
|
|
|
-
|
|
|
- // 发送游戏开始事件,确保GamePause正确设置isInGameMode状态
|
|
|
- console.log('[GameBlockSelection] 隐藏方块选择UI、发送游戏开始事件');
|
|
|
- EventBus.getInstance().emit(GameEvents.GAME_START);
|
|
|
-
|
|
|
- // 通过事件系统恢复游戏状态
|
|
|
- console.log('[GameBlockSelection] 恢复游戏状态');
|
|
|
- EventBus.getInstance().emit(GameEvents.GAME_RESUME);
|
|
|
-
|
|
|
- // 移除这里的波次提示调用,让GameManager统一控制波次提示的显示时机
|
|
|
- // 显示波次提示Toast并开始敌人生成
|
|
|
- // const enemyController = EnemyController.getInstance();
|
|
|
- // if (enemyController) {
|
|
|
- // enemyController.showStartWavePromptUI(2); // 显示2秒Toast提示
|
|
|
- // }
|
|
|
- });
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
- // 播放显示动画
|
|
|
- private playShowAnimation() {
|
|
|
- console.log('播放显示动画playShowAnimation');
|
|
|
- if (this.gameStartMove && this.blockSelectionUINode && this.dibanNode) {
|
|
|
- // 设置GameStartMove的blockSelectionUI和dibanNode引用
|
|
|
- this.gameStartMove.blockSelectionUI = this.blockSelectionUINode;
|
|
|
- this.gameStartMove.dibanNode = this.dibanNode;
|
|
|
-
|
|
|
- // 使用GameStartMove的进入方块选择模式动画
|
|
|
- this.gameStartMove.enterBlockSelectionMode(300, 0.3);
|
|
|
- console.log('进入方块选择模式动画已启动');
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- // 播放隐藏动画
|
|
|
- private playHideAnimation(onComplete?: () => void) {
|
|
|
- console.log('播放隐藏动画playHideAnimation');
|
|
|
- console.log('GameBlockSelection 引用检查:', {
|
|
|
- gameStartMove: !!this.gameStartMove,
|
|
|
- blockSelectionUINode: !!this.blockSelectionUINode,
|
|
|
- dibanNode: !!this.dibanNode,
|
|
|
- blockSelectionUINodeName: this.blockSelectionUINode?.name,
|
|
|
- dibanNodeName: this.dibanNode?.name
|
|
|
- });
|
|
|
-
|
|
|
- if (this.gameStartMove && this.blockSelectionUINode && this.dibanNode) {
|
|
|
- // 设置GameStartMove的blockSelectionUI和dibanNode引用
|
|
|
- this.gameStartMove.blockSelectionUI = this.blockSelectionUINode;
|
|
|
- this.gameStartMove.dibanNode = this.dibanNode;
|
|
|
-
|
|
|
- console.log('GameStartMove 引用设置后检查:', {
|
|
|
- gameStartMoveBlockSelectionUI: !!this.gameStartMove.blockSelectionUI,
|
|
|
- gameStartMoveDibanNode: !!this.gameStartMove.dibanNode
|
|
|
- });
|
|
|
-
|
|
|
- // 使用GameStartMove的退出方块选择模式动画
|
|
|
- this.gameStartMove.exitBlockSelectionMode(300, 0.3);
|
|
|
- console.log('退出方块选择模式动画已启动');
|
|
|
-
|
|
|
- // 由于slideDibanDownAndHide会自动隐藏blockSelectionUI和重置位置,我们需要在动画完成后执行回调
|
|
|
- if (onComplete) {
|
|
|
- this.scheduleOnce(() => {
|
|
|
- onComplete();
|
|
|
- }, 0.3); // 与动画时长一致
|
|
|
- }
|
|
|
- } else {
|
|
|
- console.log('GameBlockSelection 条件检查失败,无法播放动画');
|
|
|
- if (onComplete) {
|
|
|
- // 如果没有动画组件,直接执行回调
|
|
|
- onComplete();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
// 设置确认回调
|
|
|
public setConfirmCallback(callback: () => void) {
|
|
|
@@ -701,7 +558,7 @@ export class GameBlockSelection extends Component {
|
|
|
// 清理事件监听
|
|
|
const eventBus = EventBus.getInstance();
|
|
|
eventBus.off(GameEvents.RESET_BLOCK_SELECTION, this.onResetBlockSelectionEvent, this);
|
|
|
- eventBus.off(GameEvents.SHOW_BLOCK_SELECTION, this.onShowBlockSelectionEvent, this);
|
|
|
+
|
|
|
eventBus.off(GameEvents.GAME_START, this.onGameStartEvent, this);
|
|
|
}
|
|
|
}
|