|
|
@@ -576,6 +576,13 @@ export class GameBlockSelection extends Component {
|
|
|
this.blockStartPos.set(block.position);
|
|
|
this.currentDragBlock['startLocation'] = blockLocation;
|
|
|
|
|
|
+ // 如果方块在grid区域,拿起时清除其占用状态
|
|
|
+ if (blockLocation === 'grid') {
|
|
|
+ this.blockManager.clearOccupiedPositions(block);
|
|
|
+ // 输出更新后的占用情况
|
|
|
+ this.blockManager.printGridOccupationMatrix();
|
|
|
+ }
|
|
|
+
|
|
|
// 设置拖动状态,隐藏价格标签
|
|
|
block['isDragging'] = true;
|
|
|
|
|
|
@@ -983,6 +990,8 @@ export class GameBlockSelection extends Component {
|
|
|
// 返回方块到原位置
|
|
|
private returnBlockToOriginalPosition() {
|
|
|
const currentLocation = this.blockManager.blockLocations.get(this.currentDragBlock);
|
|
|
+ const startLocation = this.currentDragBlock['startLocation'];
|
|
|
+
|
|
|
if (currentLocation === 'kuang') {
|
|
|
const originalPos = this.blockManager.originalPositions.get(this.currentDragBlock);
|
|
|
if (originalPos) {
|
|
|
@@ -990,6 +999,27 @@ export class GameBlockSelection extends Component {
|
|
|
}
|
|
|
} else {
|
|
|
this.currentDragBlock.position = this.blockStartPos.clone();
|
|
|
+
|
|
|
+ // 如果方块原本在grid区域,返回原位置后需要重新标记占用状态
|
|
|
+ if (startLocation === 'grid') {
|
|
|
+ // 获取方块当前位置对应的网格节点
|
|
|
+ let b1Node = this.currentDragBlock;
|
|
|
+ if (this.currentDragBlock.name !== 'B1') {
|
|
|
+ b1Node = this.currentDragBlock.getChildByName('B1');
|
|
|
+ }
|
|
|
+
|
|
|
+ if (b1Node) {
|
|
|
+ const b1WorldPos = b1Node.parent.getComponent(UITransform).convertToWorldSpaceAR(b1Node.position);
|
|
|
+ const gridPos = this.blockManager.gridContainer.getComponent(UITransform).convertToNodeSpaceAR(b1WorldPos);
|
|
|
+ const gridNode = this.blockManager.findNearestGridNode(gridPos);
|
|
|
+
|
|
|
+ if (gridNode) {
|
|
|
+ this.blockManager.markOccupiedPositions(this.currentDragBlock, gridNode);
|
|
|
+ // 输出更新后的占用情况
|
|
|
+ this.blockManager.printGridOccupationMatrix();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 清除拖动状态,恢复db节点显示
|