甘艺伟 1 hete
szülő
commit
e62fde38be

+ 3 - 3
assets/bundle/commonView/netMask.prefab

@@ -407,7 +407,7 @@
     },
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 92,
+      "width": 140,
       "height": 32.76
     },
     "_anchorPoint": {
@@ -459,8 +459,8 @@
     ],
     "_srcBlendFactor": 770,
     "_dstBlendFactor": 771,
-    "_string": "加载中...",
-    "_N$string": "加载中...",
+    "_string": "网络重连中...",
+    "_N$string": "网络重连中...",
     "_fontSize": 24,
     "_lineHeight": 26,
     "_enableWrapText": true,

+ 26 - 40
assets/script/logic/gridMap/UECell.ts

@@ -3,7 +3,10 @@ import UEBase from "../../frameWork/compment/UEBase";
 const { ccclass, property } = cc._decorator;
 
 export interface I_CellData {
-
+    id: number;
+    type: number;
+    level?: number;
+    zIndex: number;
 }
 @ccclass
 export default class UECell extends UEBase {
@@ -16,63 +19,46 @@ export default class UECell extends UEBase {
     @property(cc.Label)
     private lbt_num: cc.Label = null!;
 
-    private itemType: number = 0; // 物品类型
-    private itemLevel: number = 0; // 物品等级
     private originalPos: cc.Vec3 = cc.v3(0, 0);
-
-    Init(idx: number) {
+    cellData: I_CellData = null!;
+    Init(cellData: I_CellData, idx: number) {
+        this.cellData = cellData;
+        this.node.zIndex = cellData.zIndex;
         this.lbt_num.string = idx.toString();
         this.originalPos = this.node.position;
     }
 
-    hasItem(): boolean {
-        return this.itemType !== 0;
+    /** 是否有物品可以拖动 */
+    CanDrag(): boolean {
+        return true;
     }
 
-    startDrag(): void {
-        if (this.itemNode) {
-            this.itemNode.zIndex = 100;
-            this.itemNode.opacity = 180;
-        }
+    StartDrag(): void {
+        this.node.zIndex = 1000;
     }
 
-    updateDragPosition(pos: cc.Vec3): void {
+    UpdateDragPosition(pos: cc.Vec3): void {
         if (this.itemNode) {
             this.itemNode.position = pos.sub(this.node.position);
         }
     }
 
-    endDrag(): void {
-        if (this.itemNode) {
-            this.itemNode.zIndex = 1;
-            this.itemNode.opacity = 255;
-            this.itemNode.position = cc.Vec3.ZERO;
-        }
-    }
-
-    canMergeWith(other: UECell): boolean {
-        return this.itemType === other.itemType && this.itemLevel === other.itemLevel;
-    }
-
-    mergeFrom(other: UECell): void {
-        if (this.canMergeWith(other)) {
-            this.itemLevel++;
-            // 更新显示
-            this.updateItemDisplay();
-            // 清空原来的格子
-            other.clearItem();
-        }
-    }
-
-    clearItem(): void {
-        this.itemType = 0;
-        this.itemLevel = 0;
+    EndDrag(): void {
         if (this.itemNode) {
-            this.itemNode.active = false;
+            this.node.zIndex = this.cellData.zIndex;
+            cc.tween(this.itemNode)
+                .to(0.15, { position: cc.Vec3.ZERO })
+                .call(() => {
+                    this.itemNode.scale = 1.3;
+                })
+                .to(0.3, { scale: 1 })
+                .to(0.2, { scale: 1.1 })
+                .to(0.2, { scale: 1 })
+                .start();
         }
     }
 
-    private updateItemDisplay(): void {
+    private UpdateItemDisplay(): void {
         // 根据 itemType 和 itemLevel 更新物品显示
         if (this.itemNode) {
             this.itemNode.active = true;

+ 33 - 29
assets/script/logic/gridMap/UEGridMap.ts

@@ -37,65 +37,69 @@ export default class UEGridMap extends UEBase {
                     startY - i * GridConstant.CELL_HEIGHT - GridConstant.CELL_HEIGHT / 2
                 ));
                 row.push(cell);
-                cell.Init(idx);
+                cell.Init({
+                    id: idx, type: 1,
+                    zIndex: idx
+                }, idx);
                 idx++;
             }
             this.gridMap.push(row);
         }
-        this.initEvent();
+        this.InitEvent();
     }
 
-    initEvent(): void {
-        this.gridLayer.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this);
-        this.gridLayer.on(cc.Node.EventType.TOUCH_MOVE, this.onTouchMove, this);
-        this.gridLayer.on(cc.Node.EventType.TOUCH_END, this.onTouchEnd, this);
-        this.gridLayer.on(cc.Node.EventType.TOUCH_CANCEL, this.onTouchEnd, this);
+    InitEvent(): void {
+        this.gridLayer.on(cc.Node.EventType.TOUCH_START, this.OnTouchStart, this);
+        this.gridLayer.on(cc.Node.EventType.TOUCH_MOVE, this.OnTouchMove, this);
+        this.gridLayer.on(cc.Node.EventType.TOUCH_END, this.OnTouchEnd, this);
+        this.gridLayer.on(cc.Node.EventType.TOUCH_CANCEL, this.OnTouchEnd, this);
     }
 
-    private onTouchStart(event: cc.Event.EventTouch): void {
-        const touchPos = this.node.convertToNodeSpaceAR(event.getLocation());
-        const cell = this.getCellByPos(touchPos);
-        if (cell && cell.hasItem()) {
+    private OnTouchStart(event: cc.Event.EventTouch): void {
+        const touchPos = this.gridLayer.convertToNodeSpaceAR(event.getLocation());
+        const cell = this.GetCellByPos(touchPos);
+        if (cell && cell.CanDrag()) {
             this.isDragging = true;
             this.dragStartPos = touchPos;
             this.selectedCell = cell;
-            cell.startDrag();
+            cell.StartDrag();
         }
     }
 
-    private onTouchMove(event: cc.Event.EventTouch): void {
+    private OnTouchMove(event: cc.Event.EventTouch): void {
         if (!this.isDragging || !this.selectedCell) return;
-        const touchPos = this.node.convertToNodeSpaceAR(event.getLocation());
-        this.selectedCell.updateDragPosition(cc.v3(touchPos.x, touchPos.y));
+        const touchPos = this.gridLayer.convertToNodeSpaceAR(event.getLocation());
+        this.selectedCell.UpdateDragPosition(cc.v3(touchPos.x, touchPos.y));
     }
 
-    private onTouchEnd(event: cc.Event.EventTouch): void {
+    private OnTouchEnd(event: cc.Event.EventTouch): void {
         if (!this.isDragging || !this.selectedCell) return;
-        const touchPos = this.node.convertToNodeSpaceAR(event.getLocation());
-        const targetCell = this.getCellByPos(touchPos);
+        const touchPos = this.gridLayer.convertToNodeSpaceAR(event.getLocation());
+        const targetCell = this.GetCellByPos(touchPos);
 
         if (targetCell && targetCell !== this.selectedCell) {
-            this.tryMergeItems(this.selectedCell, targetCell);
+            this.TryMergeItems(this.selectedCell, targetCell);
         }
 
-        this.selectedCell.endDrag();
+        this.selectedCell.EndDrag();
         this.isDragging = false;
         this.selectedCell = null;
     }
 
-    private getCellByPos(pos: cc.Vec2): UECell | null {
-        const row = Math.floor(-pos.y / GridConstant.CELL_HEIGHT);
-        const col = Math.floor(pos.x / GridConstant.CELL_WIDTH);
+    private GetCellByPos(pos: cc.Vec2): UECell | null {
+        const startX = -(GridConstant.ROW * GridConstant.CELL_WIDTH) / 2;
+        const startY = (GridConstant.COL * GridConstant.CELL_HEIGHT) / 2;
+
+        const row = Math.floor((pos.x - startX) / GridConstant.CELL_WIDTH);
+        const col = Math.floor((startY - pos.y) / GridConstant.CELL_HEIGHT);
 
-        if (row >= 0 && row < GridConstant.ROW && col >= 0 && col < GridConstant.COL) {
-            return this.gridMap[row][col];
+        if (col >= 0 && col < GridConstant.COL && row >= 0 && row < GridConstant.ROW) {
+            return this.gridMap[col][row];
         }
         return null;
     }
 
-    private tryMergeItems(fromCell: UECell, toCell: UECell): void {
-        if (fromCell.canMergeWith(toCell)) {
-            toCell.mergeFrom(fromCell);
-        }
+    private TryMergeItems(fromCell: UECell, toCell: UECell): void {
+
     }
 }

+ 4 - 0
assets/script/server/GameServerModel.ts

@@ -8,6 +8,8 @@ import IDataModel from "../data/model/IDataModel";
 import UIHelp, { DialogParams } from "../logic/ui/UIHelp";
 import GameController from "../GameController";
 import { I18n } from "../utils/I18nUtil";
+import { NetworkEvent } from "../data/const/EventConst";
+import EventMng from "../manager/EventMng";
 
 
 /** 游戏服 */
@@ -57,6 +59,7 @@ export class GameServerModel extends IDataModel {
             }, 2000);
             return;
         }
+        EventMng.emit(NetworkEvent.WAIT, -1)
         CC_PREVIEW && console.log("重连服务器成功");
     }
 
@@ -66,6 +69,7 @@ export class GameServerModel extends IDataModel {
             // 非客户端手动断开时处理(例:网络错误、服务器关闭)
             if (!v.isManual) {
                 CC_PREVIEW && console.log("wss断线", v.reason);
+                EventMng.emit(NetworkEvent.WAIT, 1);
                 this.reconnectCnt = 0;
                 // 等待 2 秒后自动重连
                 this.ReConnect();