|
|
@@ -18,7 +18,7 @@ export class GameBlockSelection extends Component {
|
|
|
type: Node,
|
|
|
tooltip: '拖拽diban/ann001按钮节点到这里'
|
|
|
})
|
|
|
- public addBallButton: Node = null;
|
|
|
+ public addBallButton: Node = null;
|
|
|
|
|
|
@property({
|
|
|
type: Node,
|
|
|
@@ -114,7 +114,6 @@ export class GameBlockSelection extends Component {
|
|
|
private debugGraphics: Graphics = null;
|
|
|
|
|
|
onEnable() {
|
|
|
- console.log('[GameBlockSelection] onEnable() 节点被激活');
|
|
|
// 如果还未初始化,则进行初始化
|
|
|
if (!this.isInitialized) {
|
|
|
this.initializeComponent();
|
|
|
@@ -126,7 +125,6 @@ export class GameBlockSelection extends Component {
|
|
|
}
|
|
|
|
|
|
start() {
|
|
|
- console.log('[GameBlockSelection] start() 被调用');
|
|
|
// 如果还未初始化,则进行初始化
|
|
|
if (!this.isInitialized) {
|
|
|
this.initializeComponent();
|
|
|
@@ -181,7 +179,7 @@ export class GameBlockSelection extends Component {
|
|
|
// 标记为已初始化
|
|
|
this.isInitialized = true;
|
|
|
|
|
|
- console.log('GameBlockSelection.initializeComponent() 初始化完成');
|
|
|
+ // 初始化完成
|
|
|
}
|
|
|
|
|
|
// 设置事件监听器
|
|
|
@@ -203,7 +201,7 @@ export class GameBlockSelection extends Component {
|
|
|
}
|
|
|
// 处理游戏开始事件
|
|
|
private onGameStartEvent() {
|
|
|
- //console.log('[GameBlockSelection] 接收到游戏开始事件,允许生成方块');
|
|
|
+ // 接收到游戏开始事件,允许生成方块
|
|
|
this.shouldGenerateBlocks = true;
|
|
|
}
|
|
|
|
|
|
@@ -226,7 +224,7 @@ export class GameBlockSelection extends Component {
|
|
|
// 重新设置拖拽事件
|
|
|
this.setupBlockDragEvents(block);
|
|
|
} else {
|
|
|
- console.warn('[GameBlockSelection] 跳过无效方块的拖拽事件设置');
|
|
|
+ // 跳过无效方块的拖拽事件设置
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -293,7 +291,7 @@ export class GameBlockSelection extends Component {
|
|
|
// 通过事件系统创建新的小球
|
|
|
const eventBus = EventBus.getInstance();
|
|
|
eventBus.emit(GameEvents.BALL_CREATE_ADDITIONAL);
|
|
|
- console.log(`新增小球成功,扣除${actualCost}金币`);
|
|
|
+ // 新增小球成功
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -322,7 +320,7 @@ export class GameBlockSelection extends Component {
|
|
|
|
|
|
// 扣除金币
|
|
|
if (this.session.spendCoins(actualCost)) {
|
|
|
- console.log(`[GameBlockSelection] 成功扣除 ${actualCost} 金币`);
|
|
|
+ // 成功扣除金币
|
|
|
this.updateCoinDisplay();
|
|
|
|
|
|
// 刷新方块
|
|
|
@@ -332,13 +330,13 @@ export class GameBlockSelection extends Component {
|
|
|
// 找到PlacedBlocks容器
|
|
|
const placedBlocksContainer = find('Canvas/GameLevelUI/PlacedBlocks');
|
|
|
if (placedBlocksContainer) {
|
|
|
- console.log('[GameBlockSelection] 移除已放置方块的标签');
|
|
|
+ // 移除已放置方块的标签
|
|
|
// 移除已放置方块的标签
|
|
|
BlockTag.removeTagsInContainer(placedBlocksContainer);
|
|
|
}
|
|
|
|
|
|
// 刷新方块
|
|
|
- console.log('[GameBlockSelection] 调用 blockManager.refreshBlocks()');
|
|
|
+ // 调用 blockManager.refreshBlocks()
|
|
|
this.blockManager.refreshBlocks();
|
|
|
|
|
|
// 等待一帧确保方块生成完成
|
|
|
@@ -384,7 +382,7 @@ export class GameBlockSelection extends Component {
|
|
|
|
|
|
// 播放diban下滑动画
|
|
|
private playDibanSlideDownAnimation() {
|
|
|
- console.log('[GameBlockSelection] 开始播放diban下滑动画');
|
|
|
+ // 开始播放diban下滑动画
|
|
|
|
|
|
// 使用装饰器属性获取Camera节点上的GameStartMove组件
|
|
|
if (!this.cameraNode) {
|
|
|
@@ -401,7 +399,7 @@ export class GameBlockSelection extends Component {
|
|
|
// 调用GameStartMove的下滑动画方法
|
|
|
(gameStartMove as any).slideDibanDownAndHide(0.3);
|
|
|
|
|
|
- console.log('[GameBlockSelection] 已调用GameStartMove的diban下滑动画');
|
|
|
+ // 已调用GameStartMove的diban下滑动画
|
|
|
}
|
|
|
|
|
|
// 保存已放置的方块(从GameManager迁移)
|
|
|
@@ -433,7 +431,7 @@ export class GameBlockSelection extends Component {
|
|
|
if (label) {
|
|
|
const coins = this.session.getCoins();
|
|
|
label.string = coins.toString();
|
|
|
- console.log(`[GameBlockSelection] 更新金币显示: ${coins}`);
|
|
|
+ // 更新金币显示
|
|
|
} else {
|
|
|
console.warn('[GameBlockSelection] coinLabelNode缺少Label组件');
|
|
|
}
|
|
|
@@ -450,27 +448,22 @@ export class GameBlockSelection extends Component {
|
|
|
duration: 3.0
|
|
|
});
|
|
|
|
|
|
- console.log('金币不足!');
|
|
|
+ // 金币不足
|
|
|
}
|
|
|
|
|
|
// === 公共方法:供GameManager调用 ===
|
|
|
|
|
|
// 生成方块选择(不再控制UI显示,只负责生成方块)
|
|
|
public generateBlockSelection() {
|
|
|
- console.log('[GameBlockSelection] generateBlockSelection开始执行');
|
|
|
-
|
|
|
// 直接生成方块,不再依赖shouldGenerateBlocks标志
|
|
|
if (this.blockManager) {
|
|
|
this.blockManager.refreshBlocks();
|
|
|
- console.log('[GameBlockSelection] 生成新的随机方块');
|
|
|
} else {
|
|
|
console.warn('[GameBlockSelection] BlockManager未找到,无法生成随机方块');
|
|
|
}
|
|
|
|
|
|
// 触发进入备战状态事件
|
|
|
EventBus.getInstance().emit(GameEvents.ENTER_BATTLE_PREPARATION);
|
|
|
-
|
|
|
- console.log('[GameBlockSelection] 方块生成完成');
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -484,8 +477,6 @@ export class GameBlockSelection extends Component {
|
|
|
|
|
|
// 统一的方块占用情况刷新方法
|
|
|
public refreshGridOccupation() {
|
|
|
- console.log('[GameBlockSelection] 刷新方块占用情况');
|
|
|
-
|
|
|
if (this.blockManager) {
|
|
|
this.blockManager.resetGridOccupation();
|
|
|
|
|
|
@@ -494,7 +485,6 @@ export class GameBlockSelection extends Component {
|
|
|
if (placedBlocksContainer) {
|
|
|
for (let i = 0; i < placedBlocksContainer.children.length; i++) {
|
|
|
const block = placedBlocksContainer.children[i];
|
|
|
- console.log(`[GameBlockSelection] 刷新方块占用情况,方块${i}`, block);
|
|
|
|
|
|
// 按照BlockManager.tryPlaceBlockToGrid的正确方法获取位置
|
|
|
let b1Node = block;
|
|
|
@@ -510,21 +500,15 @@ export class GameBlockSelection extends Component {
|
|
|
const b1WorldPos = b1Node.parent.getComponent(UITransform).convertToWorldSpaceAR(b1Node.position);
|
|
|
const gridPos = this.blockManager.gridContainer.getComponent(UITransform).convertToNodeSpaceAR(b1WorldPos);
|
|
|
|
|
|
- console.log(`[GameBlockSelection] B1世界坐标:`, b1WorldPos);
|
|
|
- console.log(`[GameBlockSelection] 网格本地坐标:`, gridPos);
|
|
|
-
|
|
|
// 重新标记方块占用的网格位置
|
|
|
const gridNode = this.blockManager.findNearestGridNode(gridPos);
|
|
|
if (gridNode) {
|
|
|
this.blockManager.markOccupiedPositions(block, gridNode);
|
|
|
- console.log(`[GameBlockSelection] 方块 ${block.name} 重新标记到网格 ${gridNode.name}`);
|
|
|
} else {
|
|
|
console.warn(`[GameBlockSelection] 方块 ${block.name} 未找到对应的网格节点`);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- console.log('[GameBlockSelection] 方块占用情况刷新完成');
|
|
|
} else {
|
|
|
console.warn('[GameBlockSelection] BlockManager未找到,无法刷新占用情况');
|
|
|
}
|
|
|
@@ -534,23 +518,17 @@ export class GameBlockSelection extends Component {
|
|
|
|
|
|
// 重置方块选择状态
|
|
|
public resetSelection() {
|
|
|
- console.log('[GameBlockSelection] 重置方块选择状态');
|
|
|
-
|
|
|
// 重置方块生成标志,等待下次onBattle触发
|
|
|
this.shouldGenerateBlocks = false;
|
|
|
- console.log('[GameBlockSelection] 重置方块生成标志');
|
|
|
|
|
|
// 注意:不再直接调用blockManager.onGameReset(),因为StartGame.clearGameStates()
|
|
|
// 已经通过RESET_BLOCK_MANAGER事件触发了BlockManager的重置,避免重复生成方块
|
|
|
- console.log('[GameBlockSelection] BlockManager将通过事件系统自动重置');
|
|
|
|
|
|
// 清理所有方块标签
|
|
|
BlockTag.clearAllTags();
|
|
|
- console.log('[GameBlockSelection] 方块标签已清理');
|
|
|
|
|
|
// 更新金币显示
|
|
|
this.updateCoinDisplay();
|
|
|
- console.log('[GameBlockSelection] 金币显示已更新');
|
|
|
}
|
|
|
|
|
|
// 检查是否有上阵方块
|
|
|
@@ -573,38 +551,26 @@ export class GameBlockSelection extends Component {
|
|
|
|
|
|
// 显示没有上阵方块的Toast提示
|
|
|
private showNoPlacedBlocksToast() {
|
|
|
- console.log('[GameBlockSelection] 显示未上阵植物提示');
|
|
|
-
|
|
|
// 使用事件机制显示Toast
|
|
|
EventBus.getInstance().emit(GameEvents.SHOW_TOAST, {
|
|
|
message: '请至少上阵一个植物!',
|
|
|
duration: 3.0
|
|
|
});
|
|
|
-
|
|
|
- console.log('[GameBlockSelection] 请至少上阵一个植物!');
|
|
|
}
|
|
|
|
|
|
// 设置方块拖拽事件
|
|
|
public setupBlockDragEvents(block: Node) {
|
|
|
block.on(Node.EventType.TOUCH_START, (event: EventTouch) => {
|
|
|
- console.log('[GameBlockSelection] TOUCH_START - gameStarted:', this.blockManager.gameStarted);
|
|
|
-
|
|
|
// 检查游戏是否已开始
|
|
|
if (!this.blockManager.gameStarted) {
|
|
|
- console.log('[GameBlockSelection] 游戏未开始,拒绝拖拽');
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// 只对grid区域的方块检查移动限制,kuang区域的方块可以自由拖拽
|
|
|
const blockLocation = this.blockManager.blockLocations.get(block);
|
|
|
- console.log('[GameBlockSelection] 方块位置:', blockLocation, '可移动检查:', blockLocation === 'grid' ? this.canMoveBlock(block) : true);
|
|
|
|
|
|
- if (blockLocation === 'grid' && !this.canMoveBlock(block)) {
|
|
|
- console.log('[GameBlockSelection] grid区域方块移动被限制');
|
|
|
- return;
|
|
|
- }
|
|
|
+ // grid区域的方块目前允许自由移动
|
|
|
|
|
|
- console.log('[GameBlockSelection] 开始拖拽方块,位置:', blockLocation);
|
|
|
this.currentDragBlock = block;
|
|
|
this.startPos = event.getUILocation();
|
|
|
this.blockStartPos.set(block.position);
|
|
|
@@ -627,9 +593,8 @@ export class GameBlockSelection extends Component {
|
|
|
|
|
|
// 只对grid区域的方块检查移动限制,kuang区域的方块可以自由拖拽
|
|
|
const blockLocation = this.blockManager.blockLocations.get(block);
|
|
|
- if (blockLocation === 'grid' && !this.canMoveBlock(block)) {
|
|
|
- return;
|
|
|
- }
|
|
|
+
|
|
|
+ // grid区域的方块目前允许自由移动
|
|
|
|
|
|
if (!this.currentDragBlock) return;
|
|
|
|
|
|
@@ -642,9 +607,6 @@ export class GameBlockSelection extends Component {
|
|
|
this.blockStartPos.y + deltaY,
|
|
|
this.blockStartPos.z
|
|
|
);
|
|
|
-
|
|
|
- // 更新调试绘制
|
|
|
- // this.updateDebugDraw();
|
|
|
}, this);
|
|
|
|
|
|
block.on(Node.EventType.TOUCH_END, async (event: EventTouch) => {
|
|
|
@@ -655,9 +617,8 @@ export class GameBlockSelection extends Component {
|
|
|
|
|
|
// 只对grid区域的方块检查移动限制,kuang区域的方块可以自由拖拽
|
|
|
const blockLocation = this.blockManager.blockLocations.get(block);
|
|
|
- if (blockLocation === 'grid' && !this.canMoveBlock(block)) {
|
|
|
- return;
|
|
|
- }
|
|
|
+
|
|
|
+ // grid区域的方块目前允许自由移动
|
|
|
|
|
|
if (this.currentDragBlock) {
|
|
|
try {
|
|
|
@@ -675,9 +636,6 @@ export class GameBlockSelection extends Component {
|
|
|
// 拖拽结束时恢复碰撞体
|
|
|
const collider = block.getComponent(Collider2D);
|
|
|
if (collider) collider.enabled = true;
|
|
|
-
|
|
|
- // 更新调试绘制
|
|
|
- // this.updateDebugDraw();
|
|
|
}
|
|
|
}, this);
|
|
|
|
|
|
@@ -693,20 +651,13 @@ export class GameBlockSelection extends Component {
|
|
|
const collider = block.getComponent(Collider2D);
|
|
|
if (collider) collider.enabled = true;
|
|
|
|
|
|
- // 更新调试绘制
|
|
|
- // this.updateDebugDraw();
|
|
|
+
|
|
|
}
|
|
|
}, this);
|
|
|
}
|
|
|
|
|
|
- // 检查方块是否可以移动
|
|
|
- private canMoveBlock(block: Node): boolean {
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
// 处理方块放下
|
|
|
private async handleBlockDrop(event: EventTouch) {
|
|
|
- console.log("事件:处理方块放下");
|
|
|
try {
|
|
|
const touchPos = event.getLocation();
|
|
|
const startLocation = this.currentDragBlock['startLocation'];
|
|
|
@@ -717,16 +668,11 @@ export class GameBlockSelection extends Component {
|
|
|
this.returnBlockToKuang(startLocation);
|
|
|
} else {
|
|
|
// 没有标签的方块不能放回kuang,返回原位置
|
|
|
- console.log(`[GameBlockSelection] 方块 ${this.currentDragBlock.name} 没有标签,不能放回kuang区域`);
|
|
|
this.returnBlockToOriginalPosition();
|
|
|
}
|
|
|
} else if (this.blockManager.tryPlaceBlockToGrid(this.currentDragBlock)) {
|
|
|
await this.handleSuccessfulPlacement(startLocation);
|
|
|
} else {
|
|
|
- console.log(`[GameBlockSelection] 方块 ${this.currentDragBlock.name} 放置到网格失败`);
|
|
|
- console.log(`[GameBlockSelection] 方块标签状态:`, BlockTag.hasTag(this.currentDragBlock));
|
|
|
- console.log(`[GameBlockSelection] 方块UUID:`, this.currentDragBlock.uuid);
|
|
|
-
|
|
|
// 放置失败,尝试直接与重叠方块合成
|
|
|
if (this.blockManager.tryMergeOnOverlap(this.currentDragBlock)) {
|
|
|
// 合成成功时,若来自 kuang 则扣费
|
|
|
@@ -736,7 +682,6 @@ export class GameBlockSelection extends Component {
|
|
|
}
|
|
|
// 当前拖拽块已被销毁(合并时),无需复位
|
|
|
} else {
|
|
|
- console.log(`[GameBlockSelection] 方块 ${this.currentDragBlock.name} 合成也失败,返回原位置`);
|
|
|
this.returnBlockToOriginalPosition();
|
|
|
}
|
|
|
}
|
|
|
@@ -842,7 +787,7 @@ export class GameBlockSelection extends Component {
|
|
|
const weaponNode = b1Node.getChildByName('Weapon');
|
|
|
if (weaponNode) {
|
|
|
weaponNode.setScale(0.45, 0.45, 1);
|
|
|
- console.log(`[GameBlockSelection] 方块返回kuang区域,设置植物图标缩放: 0.45倍`);
|
|
|
+ // 方块返回kuang区域,设置植物图标缩放: 0.45倍
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -852,11 +797,8 @@ export class GameBlockSelection extends Component {
|
|
|
this.currentDragBlock['placedBefore'] = false;
|
|
|
}
|
|
|
|
|
|
- const dbNode = this.currentDragBlock['dbNode'];
|
|
|
- if (dbNode) {
|
|
|
- dbNode.active = true;
|
|
|
- this.currentDragBlock.emit(Node.EventType.TRANSFORM_CHANGED);
|
|
|
- }
|
|
|
+ // 显示对应的db标签节点
|
|
|
+ this.showDbNodeByBlockLocation(this.currentDragBlock);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -864,7 +806,6 @@ export class GameBlockSelection extends Component {
|
|
|
* @param block 方块节点
|
|
|
*/
|
|
|
private attachWeaponInfoToBlock(block: Node): void {
|
|
|
- console.log(`[GameBlockSelection] 添加武器信息`);
|
|
|
try {
|
|
|
// 查找方块中的Weapon节点
|
|
|
const weaponNode = this.findWeaponNodeInBlock(block);
|
|
|
@@ -876,7 +817,6 @@ export class GameBlockSelection extends Component {
|
|
|
// 检查是否已经有WeaponInfo组件
|
|
|
let weaponInfo = weaponNode.getComponent(WeaponInfo);
|
|
|
if (weaponInfo) {
|
|
|
- console.log(`[GameBlockSelection] 武器节点 ${weaponNode.name} 已有WeaponInfo组件,跳过添加`);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
@@ -888,7 +828,6 @@ export class GameBlockSelection extends Component {
|
|
|
if (weaponConfig) {
|
|
|
// 设置武器配置到WeaponInfo组件
|
|
|
weaponInfo.setWeaponConfig(weaponConfig);
|
|
|
- console.log(`[GameBlockSelection] 成功为武器节点 ${weaponNode.name} 添加武器信息组件,武器: ${weaponConfig.name}`);
|
|
|
} else {
|
|
|
console.warn(`[GameBlockSelection] 方块 ${block.name} 没有武器配置,无法设置武器信息`);
|
|
|
// 移除刚添加的组件
|
|
|
@@ -928,6 +867,32 @@ export class GameBlockSelection extends Component {
|
|
|
return findWeaponRecursive(block);
|
|
|
}
|
|
|
|
|
|
+ // 根据方块位置隐藏对应的db标签节点
|
|
|
+ private hideDbNodeByBlockLocation(block: Node) {
|
|
|
+ const originalLocation = this.getBlockOriginalLocation(block);
|
|
|
+
|
|
|
+ if (originalLocation === 'block1' && this.blockManager.block1DbNode) {
|
|
|
+ this.blockManager.block1DbNode.active = false;
|
|
|
+ } else if (originalLocation === 'block2' && this.blockManager.block2DbNode) {
|
|
|
+ this.blockManager.block2DbNode.active = false;
|
|
|
+ } else if (originalLocation === 'block3' && this.blockManager.block3DbNode) {
|
|
|
+ this.blockManager.block3DbNode.active = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 根据方块位置显示对应的db标签节点
|
|
|
+ private showDbNodeByBlockLocation(block: Node) {
|
|
|
+ const originalLocation = this.getBlockOriginalLocation(block);
|
|
|
+
|
|
|
+ if (originalLocation === 'block1' && this.blockManager.block1DbNode) {
|
|
|
+ this.blockManager.block1DbNode.active = true;
|
|
|
+ } else if (originalLocation === 'block2' && this.blockManager.block2DbNode) {
|
|
|
+ this.blockManager.block2DbNode.active = true;
|
|
|
+ } else if (originalLocation === 'block3' && this.blockManager.block3DbNode) {
|
|
|
+ this.blockManager.block3DbNode.active = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 处理成功放置
|
|
|
private async handleSuccessfulPlacement(startLocation: string) {
|
|
|
try {
|
|
|
@@ -936,12 +901,9 @@ export class GameBlockSelection extends Component {
|
|
|
if (startLocation === 'grid') {
|
|
|
this.blockManager.clearTempStoredOccupiedGrids(this.currentDragBlock);
|
|
|
this.blockManager.blockLocations.set(this.currentDragBlock, 'grid');
|
|
|
- this.blockManager.hidePriceLabel(this.currentDragBlock);
|
|
|
|
|
|
- const dbNode = this.currentDragBlock['dbNode'];
|
|
|
- if (dbNode) {
|
|
|
- dbNode.active = false;
|
|
|
- }
|
|
|
+ // 隐藏对应的db标签节点
|
|
|
+ this.hideDbNodeByBlockLocation(this.currentDragBlock);
|
|
|
|
|
|
// 立即将方块移动到PlacedBlocks节点下,不等游戏开始
|
|
|
this.blockManager.moveBlockToPlacedBlocks(this.currentDragBlock);
|
|
|
@@ -952,29 +914,22 @@ export class GameBlockSelection extends Component {
|
|
|
// 如果游戏已开始,添加锁定视觉提示
|
|
|
if (this.blockManager.gameStarted) {
|
|
|
this.blockManager.addLockedVisualHint(this.currentDragBlock);
|
|
|
-
|
|
|
- // 游戏开始后放置的方块移除标签,不能再放回kuang
|
|
|
BlockTag.removeTag(this.currentDragBlock);
|
|
|
}
|
|
|
|
|
|
// 检查并执行合成
|
|
|
try {
|
|
|
- console.log(`[GameBlockSelection] 尝试合成方块 ${this.currentDragBlock.name}`);
|
|
|
await this.blockManager.tryMergeBlock(this.currentDragBlock);
|
|
|
} catch (mergeError) {
|
|
|
console.error('[GameBlockSelection] 方块合成时发生错误:', mergeError);
|
|
|
- // 合成失败不影响方块放置,只记录错误
|
|
|
}
|
|
|
} else {
|
|
|
if (this.blockManager.deductPlayerCoins(price)) {
|
|
|
this.blockManager.clearTempStoredOccupiedGrids(this.currentDragBlock);
|
|
|
this.blockManager.blockLocations.set(this.currentDragBlock, 'grid');
|
|
|
- this.blockManager.hidePriceLabel(this.currentDragBlock);
|
|
|
|
|
|
- const dbNode = this.currentDragBlock['dbNode'];
|
|
|
- if (dbNode) {
|
|
|
- dbNode.active = false;
|
|
|
- }
|
|
|
+ // 隐藏对应的db标签节点
|
|
|
+ this.hideDbNodeByBlockLocation(this.currentDragBlock);
|
|
|
|
|
|
this.currentDragBlock['placedBefore'] = true;
|
|
|
|
|
|
@@ -1025,110 +980,30 @@ export class GameBlockSelection extends Component {
|
|
|
this.currentDragBlock.position = this.blockStartPos.clone();
|
|
|
}
|
|
|
|
|
|
- // 清除拖动状态,恢复价格标签显示
|
|
|
+ // 清除拖动状态,恢复db节点显示
|
|
|
this.currentDragBlock['isDragging'] = false;
|
|
|
|
|
|
- this.blockManager.showPriceLabel(this.currentDragBlock);
|
|
|
+ this.showDbNodeByBlockLocation(this.currentDragBlock);
|
|
|
|
|
|
- const dbNode = this.currentDragBlock['dbNode'];
|
|
|
- if (dbNode) {
|
|
|
- dbNode.active = true;
|
|
|
- this.currentDragBlock.emit(Node.EventType.TRANSFORM_CHANGED);
|
|
|
- }
|
|
|
+ this.currentDragBlock.emit(Node.EventType.TRANSFORM_CHANGED);
|
|
|
}
|
|
|
|
|
|
// === 调试绘制相关方法 ===
|
|
|
|
|
|
- // 初始化调试绘制
|
|
|
private initDebugDraw() {
|
|
|
- // if (!this.debugDrawSnapRange) return;
|
|
|
- //
|
|
|
- // // 创建调试绘制节点
|
|
|
- // this.debugDrawNode = new Node('DebugDraw');
|
|
|
- // this.debugGraphics = this.debugDrawNode.addComponent(Graphics);
|
|
|
- //
|
|
|
- // // 将调试绘制节点添加到场景中
|
|
|
- // if (this.gridContainer && this.gridContainer.parent) {
|
|
|
- // this.gridContainer.parent.addChild(this.debugDrawNode);
|
|
|
- // }
|
|
|
- //
|
|
|
- // console.log('[GameBlockSelection] 调试绘制初始化完成');
|
|
|
+ // 调试绘制功能已禁用
|
|
|
}
|
|
|
|
|
|
- // 绘制网格吸附范围
|
|
|
private drawGridSnapRanges() {
|
|
|
- // if (!this.debugDrawSnapRange || !this.debugGraphics || !this.blockManager) return;
|
|
|
- //
|
|
|
- // this.debugGraphics.strokeColor = Color.GREEN;
|
|
|
- // this.debugGraphics.lineWidth = 2;
|
|
|
- //
|
|
|
- // // 通过BlockManager获取网格信息来绘制吸附范围
|
|
|
- // const gridSpacing = this.blockManager.getGridSpacing(); // 动态获取网格间距
|
|
|
- // const snapRange = gridSpacing * 0.8; // 吸附范围
|
|
|
- //
|
|
|
- // // 遍历所有网格位置,绘制吸附范围
|
|
|
- // for (let row = 0; row < 6; row++) {
|
|
|
- // for (let col = 0; col < 11; col++) {
|
|
|
- // // 计算网格世界坐标
|
|
|
- // const gridWorldPos = this.blockManager.getGridWorldPosition(row, col);
|
|
|
- // if (!gridWorldPos) continue;
|
|
|
- //
|
|
|
- // // 转换为调试绘制节点的本地坐标
|
|
|
- // const localPos = new Vec3();
|
|
|
- // this.debugDrawNode.getComponent(UITransform).convertToNodeSpaceAR(gridWorldPos, localPos);
|
|
|
- //
|
|
|
- // // 绘制网格吸附范围圆圈
|
|
|
- // this.debugGraphics.circle(localPos.x, localPos.y, snapRange);
|
|
|
- // this.debugGraphics.stroke();
|
|
|
- // }
|
|
|
- // }
|
|
|
+ // 调试绘制功能已禁用
|
|
|
}
|
|
|
|
|
|
- // 绘制方块吸附范围
|
|
|
private drawBlockSnapRange(block: Node) {
|
|
|
- // if (!this.debugDrawSnapRange || !this.debugGraphics || !block || !this.blockManager) return;
|
|
|
- //
|
|
|
- // // 绘制方块吸附点
|
|
|
- // this.debugGraphics.strokeColor = Color.RED;
|
|
|
- // this.debugGraphics.fillColor = Color.RED;
|
|
|
- // this.debugGraphics.lineWidth = 3;
|
|
|
- //
|
|
|
- // const blockParts = this.blockManager.getBlockParts(block);
|
|
|
- // const gridSpacing = this.blockManager.getGridSpacing(); // 动态获取网格间距
|
|
|
- // const snapRange = gridSpacing * 0.6; // 吸附范围
|
|
|
- //
|
|
|
- // blockParts.forEach(part => {
|
|
|
- // const worldPos = part.node.getWorldPosition();
|
|
|
- // const localPos = new Vec3();
|
|
|
- // this.debugDrawNode.getComponent(UITransform).convertToNodeSpaceAR(worldPos, localPos);
|
|
|
- //
|
|
|
- // // 绘制红色十字标记吸附点
|
|
|
- // const crossSize = 10;
|
|
|
- // this.debugGraphics.moveTo(localPos.x - crossSize, localPos.y);
|
|
|
- // this.debugGraphics.lineTo(localPos.x + crossSize, localPos.y);
|
|
|
- // this.debugGraphics.moveTo(localPos.x, localPos.y - crossSize);
|
|
|
- // this.debugGraphics.lineTo(localPos.x, localPos.y + crossSize);
|
|
|
- // this.debugGraphics.stroke();
|
|
|
- //
|
|
|
- // // 绘制吸附范围圆圈
|
|
|
- // this.debugGraphics.circle(localPos.x, localPos.y, snapRange);
|
|
|
- // this.debugGraphics.stroke();
|
|
|
- // });
|
|
|
+ // 调试绘制功能已禁用
|
|
|
}
|
|
|
|
|
|
- // 更新调试绘制
|
|
|
private updateDebugDraw() {
|
|
|
- // if (!this.debugDrawSnapRange || !this.debugGraphics) return;
|
|
|
- //
|
|
|
- // this.debugGraphics.clear();
|
|
|
- //
|
|
|
- // // 绘制网格吸附范围
|
|
|
- // this.drawGridSnapRanges();
|
|
|
- //
|
|
|
- // // 如果有正在拖拽的方块,绘制其吸附范围
|
|
|
- // if (this.currentDragBlock) {
|
|
|
- // this.drawBlockSnapRange(this.currentDragBlock);
|
|
|
- // }
|
|
|
+ // 调试绘制功能已禁用
|
|
|
}
|
|
|
|
|
|
// 清理调试绘制
|
|
|
@@ -1140,17 +1015,9 @@ export class GameBlockSelection extends Component {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 设置调试绘制开关
|
|
|
public setDebugDrawSnapRange(enabled: boolean) {
|
|
|
this.debugDrawSnapRange = enabled;
|
|
|
-
|
|
|
- // if (enabled) {
|
|
|
- // this.initDebugDraw();
|
|
|
- // } else {
|
|
|
- // this.cleanupDebugDraw();
|
|
|
- // }
|
|
|
-
|
|
|
- console.log(`[GameBlockSelection] 调试绘制已${enabled ? '开启' : '关闭'}`);
|
|
|
+ // 调试绘制功能已禁用
|
|
|
}
|
|
|
|
|
|
onDisable() {
|
|
|
@@ -1170,4 +1037,42 @@ export class GameBlockSelection extends Component {
|
|
|
eventBus.off(GameEvents.GAME_START, this.onGameStartEvent, this);
|
|
|
eventBus.off(GameEvents.SETUP_BLOCK_DRAG_EVENTS, this.onSetupBlockDragEventsEvent, this);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取方块的原始位置
|
|
|
+ * @param block 方块节点
|
|
|
+ * @returns 原始位置标识符
|
|
|
+ */
|
|
|
+ private getBlockOriginalLocation(block: Node): string | null {
|
|
|
+ // 检查方块是否在block1Container中
|
|
|
+ if (this.blockManager.block1Container && this.isBlockInContainer(block, this.blockManager.block1Container)) {
|
|
|
+ return 'block1';
|
|
|
+ }
|
|
|
+ // 检查方块是否在block2Container中
|
|
|
+ if (this.blockManager.block2Container && this.isBlockInContainer(block, this.blockManager.block2Container)) {
|
|
|
+ return 'block2';
|
|
|
+ }
|
|
|
+ // 检查方块是否在block3Container中
|
|
|
+ if (this.blockManager.block3Container && this.isBlockInContainer(block, this.blockManager.block3Container)) {
|
|
|
+ return 'block3';
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检查方块是否在指定容器中
|
|
|
+ * @param block 方块节点
|
|
|
+ * @param container 容器节点
|
|
|
+ * @returns 是否在容器中
|
|
|
+ */
|
|
|
+ private isBlockInContainer(block: Node, container: Node): boolean {
|
|
|
+ let parent = block.parent;
|
|
|
+ while (parent) {
|
|
|
+ if (parent === container) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ parent = parent.parent;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|