|
|
@@ -501,18 +501,39 @@ export class GameBlockSelection extends Component {
|
|
|
console.log('[GameBlockSelection] 刷新方块占用情况');
|
|
|
|
|
|
if (this.blockManager) {
|
|
|
- // 不重置网格占用状态,只重新计算已放置方块的占用情况
|
|
|
- // 这样可以保留refreshBlocks中恢复的占用信息
|
|
|
+ this.blockManager.resetGridOccupation();
|
|
|
|
|
|
// 重新计算所有已放置方块的占用情况
|
|
|
const placedBlocksContainer = find('Canvas/GameLevelUI/PlacedBlocks');
|
|
|
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;
|
|
|
+ if (block.name !== 'B1') {
|
|
|
+ b1Node = block.getChildByName('B1');
|
|
|
+ if (!b1Node) {
|
|
|
+ console.warn(`[GameBlockSelection] 方块 ${block.name} 没有B1子节点`);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取B1节点的世界坐标,然后转换为网格本地坐标
|
|
|
+ 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(block.worldPosition);
|
|
|
+ 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} 未找到对应的网格节点`);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -521,6 +542,8 @@ export class GameBlockSelection extends Component {
|
|
|
} else {
|
|
|
console.warn('[GameBlockSelection] BlockManager未找到,无法刷新占用情况');
|
|
|
}
|
|
|
+
|
|
|
+ this.blockManager.printGridOccupationMatrix();
|
|
|
}
|
|
|
|
|
|
// 重置方块选择状态
|
|
|
@@ -538,10 +561,7 @@ export class GameBlockSelection extends Component {
|
|
|
// 清理所有方块标签
|
|
|
BlockTag.clearAllTags();
|
|
|
console.log('[GameBlockSelection] 方块标签已清理');
|
|
|
-
|
|
|
- // 刷新方块占用情况
|
|
|
- this.refreshGridOccupation();
|
|
|
-
|
|
|
+
|
|
|
// 更新金币显示
|
|
|
this.updateCoinDisplay();
|
|
|
console.log('[GameBlockSelection] 金币显示已更新');
|
|
|
@@ -593,7 +613,6 @@ export class GameBlockSelection extends Component {
|
|
|
this.currentDragBlock['startLocation'] = this.blockManager.blockLocations.get(block);
|
|
|
|
|
|
block.setSiblingIndex(block.parent.children.length - 1);
|
|
|
- this.blockManager.tempStoreBlockOccupiedGrids(block);
|
|
|
// 拖拽开始时禁用碰撞体
|
|
|
const collider = block.getComponent(Collider2D);
|
|
|
if (collider) collider.enabled = false;
|
|
|
@@ -669,6 +688,7 @@ export class GameBlockSelection extends Component {
|
|
|
|
|
|
// 处理方块放下
|
|
|
private async handleBlockDrop(event: EventTouch) {
|
|
|
+ console.log("事件:处理方块放下");
|
|
|
try {
|
|
|
const touchPos = event.getLocation();
|
|
|
const startLocation = this.currentDragBlock['startLocation'];
|
|
|
@@ -677,25 +697,13 @@ export class GameBlockSelection extends Component {
|
|
|
// 检查是否有标签,只有有标签的方块才能放回kuang
|
|
|
if (BlockTag.hasTag(this.currentDragBlock)) {
|
|
|
this.returnBlockToKuang(startLocation);
|
|
|
- // 返回kuang后输出格子占用情况
|
|
|
- this.blockManager.printGridOccupationMatrix();
|
|
|
- // 刷新方块占用情况
|
|
|
- this.refreshGridOccupation();
|
|
|
} else {
|
|
|
// 没有标签的方块不能放回kuang,返回原位置
|
|
|
console.log(`[GameBlockSelection] 方块 ${this.currentDragBlock.name} 没有标签,不能放回kuang区域`);
|
|
|
this.returnBlockToOriginalPosition();
|
|
|
- // 返回原位置后输出格子占用情况
|
|
|
- this.blockManager.printGridOccupationMatrix();
|
|
|
- // 刷新方块占用情况
|
|
|
- this.refreshGridOccupation();
|
|
|
}
|
|
|
} else if (this.blockManager.tryPlaceBlockToGrid(this.currentDragBlock)) {
|
|
|
await this.handleSuccessfulPlacement(startLocation);
|
|
|
- // 放置成功后输出格子占用情况
|
|
|
- this.blockManager.printGridOccupationMatrix();
|
|
|
- // 刷新方块占用情况
|
|
|
- this.refreshGridOccupation();
|
|
|
} else {
|
|
|
console.log(`[GameBlockSelection] 方块 ${this.currentDragBlock.name} 放置到网格失败`);
|
|
|
console.log(`[GameBlockSelection] 方块标签状态:`, BlockTag.hasTag(this.currentDragBlock));
|
|
|
@@ -709,17 +717,9 @@ export class GameBlockSelection extends Component {
|
|
|
this.blockManager.deductPlayerCoins(price);
|
|
|
}
|
|
|
// 当前拖拽块已被销毁(合并时),无需复位
|
|
|
- // 合成成功后输出格子占用情况
|
|
|
- this.blockManager.printGridOccupationMatrix();
|
|
|
- // 刷新方块占用情况
|
|
|
- this.refreshGridOccupation();
|
|
|
} else {
|
|
|
console.log(`[GameBlockSelection] 方块 ${this.currentDragBlock.name} 合成也失败,返回原位置`);
|
|
|
this.returnBlockToOriginalPosition();
|
|
|
- // 放置失败后输出格子占用情况
|
|
|
- this.blockManager.printGridOccupationMatrix();
|
|
|
- // 刷新方块占用情况
|
|
|
- this.refreshGridOccupation();
|
|
|
}
|
|
|
}
|
|
|
} catch (error) {
|
|
|
@@ -728,6 +728,8 @@ export class GameBlockSelection extends Component {
|
|
|
this.returnBlockToOriginalPosition();
|
|
|
throw error; // 重新抛出错误,让上层处理
|
|
|
}
|
|
|
+ // 刷新方块占用情况
|
|
|
+ this.refreshGridOccupation();
|
|
|
}
|
|
|
|
|
|
// 检查是否在kuang区域内
|
|
|
@@ -760,7 +762,6 @@ export class GameBlockSelection extends Component {
|
|
|
this.currentDragBlock.position = originalPos.clone();
|
|
|
}
|
|
|
|
|
|
- this.blockManager.restoreBlockOccupiedGrids(this.currentDragBlock);
|
|
|
this.blockManager.blockLocations.set(this.currentDragBlock, 'kuang');
|
|
|
this.blockManager.showPriceLabel(this.currentDragBlock);
|
|
|
|
|
|
@@ -865,7 +866,6 @@ export class GameBlockSelection extends Component {
|
|
|
this.currentDragBlock.position = this.blockStartPos.clone();
|
|
|
}
|
|
|
|
|
|
- this.blockManager.restoreBlockOccupiedGrids(this.currentDragBlock);
|
|
|
this.blockManager.showPriceLabel(this.currentDragBlock);
|
|
|
|
|
|
const dbNode = this.currentDragBlock['dbNode'];
|
|
|
@@ -873,9 +873,6 @@ export class GameBlockSelection extends Component {
|
|
|
dbNode.active = true;
|
|
|
this.currentDragBlock.emit(Node.EventType.TRANSFORM_CHANGED);
|
|
|
}
|
|
|
-
|
|
|
- // 刷新方块占用情况
|
|
|
- this.refreshGridOccupation();
|
|
|
}
|
|
|
|
|
|
// === 调试绘制相关方法 ===
|