|
@@ -1,8 +1,10 @@
|
|
|
-import { _decorator, Component, Node, Button, Label, find, UITransform, Sprite, Color } from 'cc';
|
|
|
|
|
|
|
+import { _decorator, Component, Node, Button, Label, find, UITransform, Sprite, Color, tween, Tween } from 'cc';
|
|
|
import { LevelSessionManager } from '../../Core/LevelSessionManager';
|
|
import { LevelSessionManager } from '../../Core/LevelSessionManager';
|
|
|
import { BallController } from '../BallController';
|
|
import { BallController } from '../BallController';
|
|
|
import { BlockManager } from '../BlockManager';
|
|
import { BlockManager } from '../BlockManager';
|
|
|
import { GameStartMove } from '../../Animations/GameStartMove';
|
|
import { GameStartMove } from '../../Animations/GameStartMove';
|
|
|
|
|
+import { GameManager } from '../../LevelSystem/GameManager';
|
|
|
|
|
+import { GamePause } from '../GamePause';
|
|
|
const { ccclass, property } = _decorator;
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
|
|
@ccclass('GameBlockSelection')
|
|
@ccclass('GameBlockSelection')
|
|
@@ -68,6 +70,18 @@ export class GameBlockSelection extends Component {
|
|
|
})
|
|
})
|
|
|
public confirmButton: Node = null;
|
|
public confirmButton: Node = null;
|
|
|
|
|
|
|
|
|
|
+ @property({
|
|
|
|
|
+ type: Node,
|
|
|
|
|
+ tooltip: '拖拽BlockSelectionUI根节点到这里'
|
|
|
|
|
+ })
|
|
|
|
|
+ public blockSelectionUINode: Node = null;
|
|
|
|
|
+
|
|
|
|
|
+ @property({
|
|
|
|
|
+ type: Node,
|
|
|
|
|
+ tooltip: '拖拽BlockSelectionUI/diban节点到这里'
|
|
|
|
|
+ })
|
|
|
|
|
+ public dibanNode: Node = null;
|
|
|
|
|
+
|
|
|
// 按钮费用配置
|
|
// 按钮费用配置
|
|
|
private readonly ADD_BALL_COST = 80;
|
|
private readonly ADD_BALL_COST = 80;
|
|
|
private readonly ADD_COIN_AMOUNT = 80;
|
|
private readonly ADD_COIN_AMOUNT = 80;
|
|
@@ -77,11 +91,14 @@ export class GameBlockSelection extends Component {
|
|
|
private ballController: BallController = null;
|
|
private ballController: BallController = null;
|
|
|
private blockManager: BlockManager = null;
|
|
private blockManager: BlockManager = null;
|
|
|
private gameStartMove: GameStartMove = null;
|
|
private gameStartMove: GameStartMove = null;
|
|
|
|
|
+ private gameManager: GameManager = null;
|
|
|
|
|
|
|
|
// 回调函数,用于通知GameManager
|
|
// 回调函数,用于通知GameManager
|
|
|
public onConfirmCallback: () => void = null;
|
|
public onConfirmCallback: () => void = null;
|
|
|
|
|
|
|
|
start() {
|
|
start() {
|
|
|
|
|
+ console.log('GameBlockSelection.start() 开始初始化');
|
|
|
|
|
+
|
|
|
// 获取管理器实例
|
|
// 获取管理器实例
|
|
|
this.session = LevelSessionManager.inst;
|
|
this.session = LevelSessionManager.inst;
|
|
|
|
|
|
|
@@ -102,6 +119,29 @@ export class GameBlockSelection extends Component {
|
|
|
// 获取GameStartMove组件
|
|
// 获取GameStartMove组件
|
|
|
if (this.cameraNode) {
|
|
if (this.cameraNode) {
|
|
|
this.gameStartMove = this.cameraNode.getComponent(GameStartMove);
|
|
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,尝试找到它
|
|
// 如果没有指定coinLabelNode,尝试找到它
|
|
@@ -109,8 +149,16 @@ export class GameBlockSelection extends Component {
|
|
|
this.coinLabelNode = find('Canvas-001/TopArea/CoinNode/CoinLabel');
|
|
this.coinLabelNode = find('Canvas-001/TopArea/CoinNode/CoinLabel');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 获取GameManager实例
|
|
|
|
|
+ const gameManagerNode = find('Canvas/GameManager');
|
|
|
|
|
+ if (gameManagerNode) {
|
|
|
|
|
+ this.gameManager = gameManagerNode.getComponent(GameManager);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// 绑定按钮事件
|
|
// 绑定按钮事件
|
|
|
this.bindButtonEvents();
|
|
this.bindButtonEvents();
|
|
|
|
|
+
|
|
|
|
|
+ console.log('GameBlockSelection.start() 初始化完成');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 绑定按钮事件
|
|
// 绑定按钮事件
|
|
@@ -207,23 +255,8 @@ export class GameBlockSelection extends Component {
|
|
|
|
|
|
|
|
// 确认按钮点击(从GameManager迁移的onConfirmButtonClicked)
|
|
// 确认按钮点击(从GameManager迁移的onConfirmButtonClicked)
|
|
|
public onConfirmButtonClicked() {
|
|
public onConfirmButtonClicked() {
|
|
|
- // 执行相机动画和UI关闭
|
|
|
|
|
- if (this.gameStartMove) {
|
|
|
|
|
- this.gameStartMove.slideDibanDownAndHide();
|
|
|
|
|
- } else {
|
|
|
|
|
- // Fallback: 若未挂载 GameStartMove,直接关闭
|
|
|
|
|
- this.node.active = false;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Camera move back up with smooth animation
|
|
|
|
|
- if (this.gameStartMove) {
|
|
|
|
|
- this.gameStartMove.moveUpSmooth();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 显示GridContainer
|
|
|
|
|
- if (this.gridContainer) {
|
|
|
|
|
- this.gridContainer.active = true;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 使用统一的隐藏方法,包含动画
|
|
|
|
|
+ this.hideBlockSelection();
|
|
|
|
|
|
|
|
// 保存已放置的方块
|
|
// 保存已放置的方块
|
|
|
this.preservePlacedBlocks();
|
|
this.preservePlacedBlocks();
|
|
@@ -232,6 +265,12 @@ export class GameBlockSelection extends Component {
|
|
|
if (this.onConfirmCallback) {
|
|
if (this.onConfirmCallback) {
|
|
|
this.onConfirmCallback();
|
|
this.onConfirmCallback();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // 恢复游戏
|
|
|
|
|
+ const gamePause = GamePause.getInstance();
|
|
|
|
|
+ if (gamePause) {
|
|
|
|
|
+ gamePause.resumeGame();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 保存已放置的方块(从GameManager迁移)
|
|
// 保存已放置的方块(从GameManager迁移)
|
|
@@ -280,24 +319,111 @@ export class GameBlockSelection extends Component {
|
|
|
|
|
|
|
|
// 显示方块选择UI(用于游戏开始或下一波)
|
|
// 显示方块选择UI(用于游戏开始或下一波)
|
|
|
public showBlockSelection(isNextWave: boolean = false) {
|
|
public showBlockSelection(isNextWave: boolean = false) {
|
|
|
|
|
+ // 检查游戏是否已结束(胜利或失败),如果是则不显示方块选择UI
|
|
|
|
|
+ if (this.gameManager && this.gameManager.isGameOver()) {
|
|
|
|
|
+ console.warn('[GameBlockSelection] 游戏已经结束(胜利或失败),不显示方块选择UI');
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 首先显示UI节点
|
|
|
this.node.active = true;
|
|
this.node.active = true;
|
|
|
|
|
|
|
|
if (this.gridContainer) {
|
|
if (this.gridContainer) {
|
|
|
this.gridContainer.active = true;
|
|
this.gridContainer.active = true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- console.log(isNextWave ? '显示下一波方块选择UI' : '显示游戏开始方块选择UI');
|
|
|
|
|
|
|
+ // 如果有BlockSelectionUI节点,确保它可见
|
|
|
|
|
+ if (this.blockSelectionUINode) {
|
|
|
|
|
+ this.blockSelectionUINode.active = true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 每次显示方块选择UI时,生成新的随机方块
|
|
|
|
|
+ if (this.blockManager) {
|
|
|
|
|
+ this.blockManager.refreshBlocks();
|
|
|
|
|
+ console.log('[GameBlockSelection] 生成新的随机方块');
|
|
|
|
|
+ } else {
|
|
|
|
|
+ console.warn('[GameBlockSelection] BlockManager未找到,无法生成随机方块');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 播放BlockSelectionUI出现动画
|
|
|
|
|
+ this.playShowAnimation();
|
|
|
|
|
+
|
|
|
|
|
+ console.log(`[GameBlockSelection] ${isNextWave ? '显示下一波方块选择UI' : '显示游戏开始方块选择UI'}`);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 隐藏方块选择UI
|
|
// 隐藏方块选择UI
|
|
|
public hideBlockSelection() {
|
|
public hideBlockSelection() {
|
|
|
- this.node.active = false;
|
|
|
|
|
-
|
|
|
|
|
- if (this.gridContainer) {
|
|
|
|
|
- this.gridContainer.active = false;
|
|
|
|
|
|
|
+ // 播放隐藏动画,动画完成后隐藏UI
|
|
|
|
|
+ this.playHideAnimation(() => {
|
|
|
|
|
+ this.node.active = false;
|
|
|
|
|
+
|
|
|
|
|
+ // 移除隐藏GridContainer的代码,因为GridContainer应该在游戏过程中保持可见
|
|
|
|
|
+ // if (this.gridContainer) {
|
|
|
|
|
+ // this.gridContainer.active = false;
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
|
|
+ console.log('隐藏方块选择UI');
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 播放显示动画
|
|
|
|
|
+ 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;
|
|
|
|
|
+
|
|
|
|
|
+ // 每次显示BlockSelectionUI时,摄像头下移182px
|
|
|
|
|
+ this.gameStartMove.moveDownInstant();
|
|
|
|
|
+ console.log('摄像头下移182px');
|
|
|
|
|
+
|
|
|
|
|
+ // 使用GameStartMove的上滑入场动画
|
|
|
|
|
+ this.gameStartMove.slideUpFromBottom(300, 0.3);
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- console.log('隐藏方块选择UI');
|
|
|
|
|
|
|
+ // 播放隐藏动画
|
|
|
|
|
+ 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
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // 每次隐藏BlockSelectionUI时,摄像头上移182px
|
|
|
|
|
+ this.gameStartMove.moveUpSmooth();
|
|
|
|
|
+ console.log('摄像头上移182px');
|
|
|
|
|
+
|
|
|
|
|
+ // 播放下滑隐藏动画,动画完成后执行回调
|
|
|
|
|
+ this.gameStartMove.slideDibanDownAndHide(300, 0.3);
|
|
|
|
|
+
|
|
|
|
|
+ // 由于slideDibanDownAndHide会自动隐藏blockSelectionUI和重置位置,我们需要在动画完成后执行回调
|
|
|
|
|
+ if (onComplete) {
|
|
|
|
|
+ this.scheduleOnce(() => {
|
|
|
|
|
+ onComplete();
|
|
|
|
|
+ }, 0.3); // 与动画时长一致
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ console.log('GameBlockSelection 条件检查失败,无法播放动画');
|
|
|
|
|
+ if (onComplete) {
|
|
|
|
|
+ // 如果没有动画组件,直接执行回调
|
|
|
|
|
+ onComplete();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 设置确认回调
|
|
// 设置确认回调
|