|
|
@@ -1,4 +1,4 @@
|
|
|
-import { _decorator, Component, Node, Prefab, instantiate, Vec3, EventTouch, Color, Vec2, UITransform, find, Rect, Label, Size, Sprite, SpriteFrame, resources, Button, Collider2D, Material } from 'cc';
|
|
|
+import { _decorator, Component, Node, Prefab, instantiate, Vec3, EventTouch, Color, Vec2, UITransform, find, Rect, Label, Size, Sprite, SpriteFrame, resources, Button, Collider2D, Material, tween } from 'cc';
|
|
|
import { ConfigManager, WeaponConfig } from '../Core/ConfigManager';
|
|
|
import { SaveDataManager } from '../LevelSystem/SaveDataManager';
|
|
|
import { LevelSessionManager } from '../Core/LevelSessionManager';
|
|
|
@@ -68,7 +68,7 @@ export class BlockManager extends Component {
|
|
|
// 存储网格节点信息
|
|
|
private gridNodes: Node[][] = [];
|
|
|
// 网格间距
|
|
|
- private gridSpacing = 54;
|
|
|
+ private gridSpacing = 54; // 默认值,将在initGridInfo中动态计算
|
|
|
// 不参与占用的节点名称列表
|
|
|
private readonly NON_BLOCK_NODES: string[] = ['Weapon', 'Price'];
|
|
|
// 临时保存方块的原始占用格子
|
|
|
@@ -301,16 +301,44 @@ export class BlockManager extends Component {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 动态计算网格间距,适应不同分辨率
|
|
|
+ this.calculateGridSpacing();
|
|
|
+
|
|
|
+ this.gridInitialized = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 动态计算网格间距
|
|
|
+ private calculateGridSpacing() {
|
|
|
+ // 优先使用相邻行之间的距离计算间距
|
|
|
if (this.GRID_ROWS > 1 && this.GRID_COLS > 0) {
|
|
|
if (this.gridNodes[0][0] && this.gridNodes[1][0]) {
|
|
|
const pos1 = this.gridNodes[0][0].position;
|
|
|
const pos2 = this.gridNodes[1][0].position;
|
|
|
this.gridSpacing = Math.abs(pos2.y - pos1.y);
|
|
|
+ console.log(`动态计算网格间距(行间距): ${this.gridSpacing}`);
|
|
|
+ return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- this.gridInitialized = true;
|
|
|
- }
|
|
|
+ // 如果行间距计算失败,尝试使用相邻列之间的距离
|
|
|
+ if (this.GRID_COLS > 1 && this.GRID_ROWS > 0) {
|
|
|
+ if (this.gridNodes[0][0] && this.gridNodes[0][1]) {
|
|
|
+ const pos1 = this.gridNodes[0][0].position;
|
|
|
+ const pos2 = this.gridNodes[0][1].position;
|
|
|
+ this.gridSpacing = Math.abs(pos2.x - pos1.x);
|
|
|
+ console.log(`动态计算网格间距(列间距): ${this.gridSpacing}`);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果都失败了,保持默认值
|
|
|
+ console.warn(`无法动态计算网格间距,使用默认值: ${this.gridSpacing}`);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取当前网格间距
|
|
|
+ public getGridSpacing(): number {
|
|
|
+ return this.gridSpacing;
|
|
|
+ }
|
|
|
|
|
|
// 初始化网格占用情况
|
|
|
initGridOccupationMap() {
|
|
|
@@ -475,6 +503,12 @@ export class BlockManager extends Component {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ // 检查方块是否正在被拖动,如果是则隐藏价格标签
|
|
|
+ if (block['isDragging']) {
|
|
|
+ dbNode.active = false;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
dbNode.active = true;
|
|
|
|
|
|
const worldPos = block.parent.getComponent(UITransform).convertToWorldSpaceAR(block.position);
|
|
|
@@ -536,6 +570,45 @@ export class BlockManager extends Component {
|
|
|
return success;
|
|
|
}
|
|
|
|
|
|
+ // 显示金币不足时的价格标签闪烁效果
|
|
|
+ showInsufficientCoinsEffect(block: Node) {
|
|
|
+ const priceNode = this.blockPriceMap.get(block);
|
|
|
+ if (!priceNode) {
|
|
|
+ console.warn('[BlockManager] 找不到方块对应的价格标签');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const label = priceNode.getComponent(Label);
|
|
|
+ if (!label) {
|
|
|
+ console.warn('[BlockManager] 价格节点缺少Label组件');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 保存原始颜色
|
|
|
+ const originalColor = label.color.clone();
|
|
|
+
|
|
|
+ // 设置红色
|
|
|
+ const redColor = new Color(255, 0, 0, 255);
|
|
|
+
|
|
|
+ // 创建闪烁动画:变红 -> 恢复原色,重复3次,总时长2秒
|
|
|
+ tween(label)
|
|
|
+ .to(0.2, { color: redColor })
|
|
|
+ .to(0.2, { color: originalColor })
|
|
|
+ .to(0.2, { color: redColor })
|
|
|
+ .to(0.2, { color: originalColor })
|
|
|
+ .to(0.2, { color: redColor })
|
|
|
+ .to(1.0, { color: originalColor })
|
|
|
+ .start();
|
|
|
+
|
|
|
+ // 发送显示Toast事件
|
|
|
+ EventBus.getInstance().emit(GameEvents.SHOW_TOAST, {
|
|
|
+ message: '金币不足',
|
|
|
+ duration: 2.0
|
|
|
+ });
|
|
|
+
|
|
|
+ console.log('[BlockManager] 显示金币不足效果');
|
|
|
+ }
|
|
|
+
|
|
|
// 归还玩家金币
|
|
|
refundPlayerCoins(amount: number) {
|
|
|
this.session.addCoins(amount);
|