浏览代码

拖动处理

甘艺伟 1 周之前
父节点
当前提交
d128e640dd

+ 10 - 10
assets/json/chapterLayout.json

@@ -9,16 +9,16 @@
   {"id":10008,"infoId":1,"grid":25,"type":3,"correlationId":10008,"unlock":0},
   {"id":10009,"infoId":1,"grid":26,"type":3,"correlationId":10009,"unlock":0},
   {"id":10010,"infoId":1,"grid":31,"type":3,"correlationId":10010,"unlock":0},
-  {"id":10011,"infoId":1,"grid":32,"type":3,"correlationId":10011,"unlock":0},
-  {"id":10012,"infoId":1,"grid":34,"type":3,"correlationId":10012,"unlock":0},
-  {"id":10013,"infoId":1,"grid":36,"type":3,"correlationId":10013,"unlock":0},
-  {"id":10014,"infoId":1,"grid":41,"type":3,"correlationId":10014,"unlock":0},
-  {"id":10015,"infoId":1,"grid":42,"type":3,"correlationId":10015,"unlock":0},
-  {"id":10016,"infoId":1,"grid":43,"type":3,"correlationId":10016,"unlock":0},
-  {"id":10017,"infoId":1,"grid":44,"type":3,"correlationId":10017,"unlock":0},
-  {"id":10018,"infoId":1,"grid":46,"type":3,"correlationId":10018,"unlock":0},
-  {"id":10019,"infoId":1,"grid":53,"type":3,"correlationId":10019,"unlock":0},
-  {"id":20001,"infoId":2,"grid":11,"type":3,"correlationId":10020,"unlock":0},
+  {"id":10011,"infoId":1,"grid":32,"type":3,"correlationId":10001,"unlock":0},
+  {"id":10012,"infoId":1,"grid":34,"type":3,"correlationId":10002,"unlock":0},
+  {"id":10013,"infoId":1,"grid":36,"type":3,"correlationId":10003,"unlock":0},
+  {"id":10014,"infoId":1,"grid":41,"type":3,"correlationId":10004,"unlock":0},
+  {"id":10015,"infoId":1,"grid":42,"type":3,"correlationId":10005,"unlock":0},
+  {"id":10016,"infoId":1,"grid":43,"type":3,"correlationId":10006,"unlock":0},
+  {"id":10017,"infoId":1,"grid":44,"type":3,"correlationId":10007,"unlock":0},
+  {"id":10018,"infoId":1,"grid":46,"type":3,"correlationId":10008,"unlock":0},
+  {"id":10019,"infoId":1,"grid":53,"type":3,"correlationId":10009,"unlock":0},
+  {"id":20001,"infoId":2,"grid":11,"type":3,"correlationId":10010,"unlock":0},
   {"id":20002,"infoId":2,"grid":12,"type":3,"correlationId":10001,"unlock":0},
   {"id":20003,"infoId":2,"grid":13,"type":3,"correlationId":10002,"unlock":0},
   {"id":20004,"infoId":2,"grid":15,"type":3,"correlationId":10003,"unlock":0},

+ 7 - 7
assets/script/common/xlsConfig.ts

@@ -37,20 +37,20 @@ export type xlsPingbiciInfo = {}
 // type for shop.excel
 
 export class XlsConfig {
-    xlsChapterInfo: xlsChapterInfo[]
-    xlsChapterLayout: xlsChapterLayout[]
     xlsKaiqiInfo: xlsKaiqiInfo[]
+    xlsAudioInfo: xlsAudioInfo[]
     xlsEmitterInfo: xlsEmitterInfo[]
+    xlsChapterInfo: xlsChapterInfo[]
+    xlsChapterLayout: xlsChapterLayout[]
     xlsAttrAttr: xlsAttrAttr[]
-    xlsAudioInfo: xlsAudioInfo[]
+    xlsNameName: xlsNameName[]
     xlsLanguageClientText: xlsLanguageClientText[]
-    xlsGuideInfo: xlsGuideInfo[]
-    xlsLanguageSeverHouduan: xlsLanguageSeverHouduan[]
     xlsPackageInfo: xlsPackageInfo[]
     xlsMergePropInfo: xlsMergePropInfo[]
-    xlsMathInfo: xlsMathInfo[]
+    xlsGuideInfo: xlsGuideInfo[]
     xlsPingbiciInfo: xlsPingbiciInfo[]
-    xlsNameName: xlsNameName[]
+    xlsLanguageSeverHouduan: xlsLanguageSeverHouduan[]
+    xlsMathInfo: xlsMathInfo[]
     xlsItemKind: xlsItemKind[]
     xlsItemMoney: xlsItemMoney[]
     xlsLanguageLang: xlsLanguageLang[]

+ 10 - 0
assets/script/logic/gridMap/UECell.ts

@@ -30,6 +30,10 @@ export default class UECell extends UEBase {
         }
     }
 
+    GetZIndex() {
+        return this.cellData.zIndex;
+    }
+
 
     SetSelect(isSelect: boolean) {
         this.node_select.active = isSelect;
@@ -49,6 +53,12 @@ export default class UECell extends UEBase {
         return this.cellData.ueCube == null;
     }
 
+    /** 清空棋格里的棋子 */
+    ClearCube() {
+        this.cellData.ueCube.unUse();
+        this.cellData.ueCube = null;
+    }
+
     MoveCubeToCell(toCell: UECell) {
         this.cellData.ueCube.MoveToNewPos(toCell.node.position.clone());
     }

+ 4 - 0
assets/script/logic/gridMap/UECube.ts

@@ -125,4 +125,8 @@ export default class UECube extends UEBase {
             // TODO: 更新物品的具体显示效果
         }
     }
+
+    public unUse() {
+        this.node.destroy();
+    }
 }

+ 36 - 14
assets/script/logic/gridMap/UEGridMap.ts

@@ -50,8 +50,6 @@ export default class UEGridMap extends UEBase {
         layoutCfg.forEach(element => {
             layoutGridMap[element.grid] = element;
         });
-        const startX = -(GridConstant.ROW * GridConstant.CELL_WIDTH) / 2;
-        const startY = (GridConstant.COL * GridConstant.CELL_HEIGHT) / 2;
         this.cellMap = {};
         for (let i = 0; i < GridConstant.COL; i++) {
             let rowCells = [];
@@ -64,15 +62,8 @@ export default class UEGridMap extends UEBase {
                     let cellCfg: xlsChapterLayout = layoutGridMap[idx];
                     let cube = null;
                     if (cellCfg) {
-                        cube = cc.instantiate(this.cubePrefab).getComponent(UECube);
+                        cube = this.CreateCube(i, j);
                         rowCubes.push(cube);
-                        this.cubeLayer.addChild(cube.node);
-                        cube.node.width = GridConstant.CELL_WIDTH;
-                        cube.node.height = GridConstant.CELL_HEIGHT;
-                        cube.node.setPosition(cc.v2(
-                            startX + j * GridConstant.CELL_WIDTH + GridConstant.CELL_WIDTH / 2,
-                            startY - i * GridConstant.CELL_HEIGHT - GridConstant.CELL_HEIGHT / 2
-                        ));
                         cube.Init({
                             type: cellCfg.type,
                             id: cellCfg.correlationId,
@@ -106,6 +97,21 @@ export default class UEGridMap extends UEBase {
         return cell;
     }
 
+    /** 创建棋子 */
+    private CreateCube(i: number, j: number) {
+        const startX = -(GridConstant.ROW * GridConstant.CELL_WIDTH) / 2;
+        const startY = (GridConstant.COL * GridConstant.CELL_HEIGHT) / 2;
+        let cube = cc.instantiate(this.cubePrefab).getComponent(UECube);
+        this.cubeLayer.addChild(cube.node);
+        cube.node.width = GridConstant.CELL_WIDTH;
+        cube.node.height = GridConstant.CELL_HEIGHT;
+        cube.node.setPosition(cc.v2(
+            startX + j * GridConstant.CELL_WIDTH + GridConstant.CELL_WIDTH / 2,
+            startY - i * GridConstant.CELL_HEIGHT - GridConstant.CELL_HEIGHT / 2
+        ));
+        return cube;
+    }
+
     private OnTouchStart(event: cc.Event.EventTouch): void {
         const touchPos = this.gridLayer.convertToNodeSpaceAR(event.getLocation());
         const cell = this.GetCellByPos(touchPos);
@@ -146,6 +152,7 @@ export default class UEGridMap extends UEBase {
     }
 
     private OnTouchEnd(event: cc.Event.EventTouch): void {
+        this.dragStartPos = null;
         if (!this.selectedCell) return;
         const touchPos = this.gridLayer.convertToNodeSpaceAR(event.getLocation());
         const targetCell = this.GetCellByPos(touchPos);
@@ -161,7 +168,7 @@ export default class UEGridMap extends UEBase {
             }
         } else {
             if (!this.isDragging) return;
-            if (targetCell) {
+            if (targetCell && targetCell != this.selectedCell) {
                 this.TryMergeItems(this.selectedCell, targetCell);
                 this.selectedCell.SetSelect(false);
                 targetCell.SetSelect(true);
@@ -197,15 +204,30 @@ export default class UEGridMap extends UEBase {
             fromCell.SetCube(null);
         } else if (this.CanMergeItems(fromCell, toCell)) {
             toCell.GetCube().PlayMergeAnim();
+            fromCell.ClearCube();
+            toCell.ClearCube();
+            let vec = this.TranIdxToPos(toCell.GetZIndex());
+            let mergeCube = this.CreateCube(vec.y, vec.x);
+            mergeCube.Init({
+                type: 3,
+                id: 10022,
+                zIndex: toCell.GetZIndex(),
+                unlock: 0
+            });
+            toCell.SetCube(mergeCube);
         } else {
             this.SwitchCell(fromCell, toCell);
         }
     }
 
+    private TranIdxToPos(idx: number): cc.Vec2 {
+        let row = idx % 10;
+        let col = Math.floor(idx / 10);
+        return cc.v2(row - 1, col - 1);
+    }
+
     private CanMergeItems(fromCell: UECell, toCell: UECell): boolean {
-        if (fromCell.GetCube().getCubeData().type == toCell.GetCube().getCubeData().type
-            && fromCell.GetCube().getCubeData().id != fromCell.GetCube().getCubeData().id
-        ) {
+        if (fromCell.GetCube().getCubeData().type == toCell.GetCube().getCubeData().type) {
             return true;
         }