Kaynağa Gözat

补充拖动出售

甘艺伟 9 saat önce
ebeveyn
işleme
62d35cd6b7

BIN
assets/bundle/FGUI/Home/Home.bin


BIN
assets/bundle/FGUI/Home/Home_atlas0.png


+ 2 - 2
assets/bundle/FGUI/Home/Home_atlas0.png.meta

@@ -21,11 +21,11 @@
       "trimThreshold": 1,
       "rotated": false,
       "offsetX": 0,
-      "offsetY": 185.5,
+      "offsetY": 185,
       "trimX": 1,
       "trimY": 1,
       "width": 1022,
-      "height": 651,
+      "height": 652,
       "rawWidth": 1024,
       "rawHeight": 1024,
       "borderTop": 0,

+ 3 - 3
assets/script/data/model/GridMap/GridMapModel.ts

@@ -122,10 +122,10 @@ export default class GridMapModel extends GridMapModelData {
     public async TryMergeItems(fromCell: UECell, toCell: UECell) {
         //检测目标格子物品是否可以拖动
         if (toCell.IsEmpty() || toCell.GetCube().CanDrag()) {
-            let ret = await this.sendHcMerge({ gzid1: fromCell.GetZIndex().toString(), gzid2: toCell.GetZIndex().toString() })
+            let ret = await this.sendHcMerge({ gzid1: fromCell.GetIdx().toString(), gzid2: toCell.GetIdx().toString() })
             if (ret && ret.res) {
-                let fCube = ret.res?.list[fromCell.GetZIndex()];
-                let tCube = ret.res.list[toCell.GetZIndex()];
+                let fCube = ret.res?.list[fromCell.GetIdx()];
+                let tCube = ret.res.list[toCell.GetIdx()];
                 if (toCell.IsEmpty()) {
                     //格子上没有物品
                     fromCell.MoveCubeToCell(toCell);

+ 7 - 0
assets/script/logic/fgui/Home/Home/HomeMergeSellCom.ts

@@ -19,7 +19,9 @@ export default class HomeMergeSellCom {
     private SellBtn: fgui.GButton;
     private QualityLabel: fgui.GTextField;
     data: MergeSellData;
+    static instance: HomeMergeSellCom;
     public constructor(vm: fgui.GComponent) {
+        HomeMergeSellCom.instance = this;
         this._vm = vm;
         this.sp_item = vm.getChild('IconLoad').node.addComponent(ResSprite);
         this.QualityLoad = vm.getChild('QualityLoad').asLoader;
@@ -42,6 +44,11 @@ export default class HomeMergeSellCom {
         GameDataCenter.gridMap.sendHcSell(this.data.item.idx);
     }
 
+    /** 获取售卖按钮 */
+    public GetSellBtn(): cc.Node {
+        return this.SellBtn.node;
+    }
+
 
     private OnHcMergeSell(data: MergeSellData): void {
         this.data = data;

+ 2 - 2
assets/script/logic/fgui/Home/Home/HomeVM.ts

@@ -33,12 +33,12 @@ export class HomeVM extends FguiViewModel {
     readonly BtnMore: fgui.GButton;
     readonly ChatCom: fgui.GComponent;
     readonly Bottom: fgui.GGroup;
+    readonly HomeMergeBottom: fgui.GComponent;
     readonly GridRoot: fgui.GComponent;
     readonly HeadTopCom: fgui.GComponent;
     readonly HdList: fgui.GList;
     readonly BtnHdKaiFu: fgui.GButton;
     readonly Top: fgui.GGroup;
-    readonly HomeMergeBottom: fgui.GComponent;
     readonly EffectComp: fgui.GComponent;
 
     constructor(panel: fgui.GComponent) {
@@ -67,12 +67,12 @@ export class HomeVM extends FguiViewModel {
         this.BtnMore = panel.getChild("BtnMore") as fgui.GButton;
         this.ChatCom = panel.getChild("ChatCom") as fgui.GComponent;
         this.Bottom = panel.getChild("bottom") as fgui.GGroup;
+        this.HomeMergeBottom = panel.getChild("HomeMergeBottom") as fgui.GComponent;
         this.GridRoot = panel.getChild("gridRoot") as fgui.GComponent;
         this.HeadTopCom = panel.getChild("HeadTopCom") as fgui.GComponent;
         this.HdList = panel.getChild("hdList") as fgui.GList;
         this.BtnHdKaiFu = panel.getChild("BtnHdKaiFu") as fgui.GButton;
         this.Top = panel.getChild("top") as fgui.GGroup;
-        this.HomeMergeBottom = panel.getChild("HomeMergeBottom") as fgui.GComponent;
         this.EffectComp = panel.getChild("EffectComp") as fgui.GComponent;
 
     }

+ 1 - 1
assets/script/logic/gridMap/UECell.ts

@@ -110,7 +110,7 @@ export default class UECell extends UEBase {
 
     }
 
-    GetZIndex() {
+    GetIdx() {
         return this.cellData.idx;
     }
 

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

@@ -8,6 +8,8 @@ import EventMng from "../../manager/EventMng";
 import { HcInfoGeziInfo, ResHcInfo } from "../../shared/hc/PtlHcInfo";
 import { ResHcMerge } from "../../shared/hc/PtlHcMerge";
 import AssetMgr from "../../utils/AssetMgr";
+import { uiCommon } from "../../utils/UICommon";
+import HomeMergeSellCom from "../fgui/Home/Home/HomeMergeSellCom";
 import { GridConstant } from "./GridConstant";
 import { GridEvent } from "./GridEvent";
 import UECell, { I_CellData } from "./UECell";
@@ -149,7 +151,7 @@ export default class UEGridMap extends UEBase {
         mergeCube.Init({
             type: data.cube.type,
             id: data.cube.correlationId,
-            idx: data.cell.GetZIndex(),
+            idx: data.cell.GetIdx(),
         });
         //播放经验爆炸飞行动画
 
@@ -186,7 +188,7 @@ export default class UEGridMap extends UEBase {
                 }
                 this.selectedCell = cell;
                 // cell.SetSelect(true);
-                EventMng.emit(GridEvent.HC_CELL_SELECT, cell.GetZIndex());
+                EventMng.emit(GridEvent.HC_CELL_SELECT, cell.GetIdx());
                 EventMng.emit(GridEvent.HC_MERGE_SELL, { isShow: true, item: cell.GetCube().GetCubeData() });
             } else {
                 this.selectedCell = null;
@@ -225,16 +227,16 @@ export default class UEGridMap extends UEBase {
             this.lastMoveCell = targetCell;
             if (targetCell && !targetCell.IsLock()) {
                 // targetCell.SetSelect(true);
-                EventMng.emit(GridEvent.HC_CELL_SELECT, targetCell.GetZIndex());
+                EventMng.emit(GridEvent.HC_CELL_SELECT, targetCell.GetIdx());
             }
             if (targetCell && targetCell != this.selectedCell) {
                 if (!targetCell.IsEmpty() && GameDataCenter.gridMap.CellCanPut(this.selectedCell, targetCell)) {
                     this.ueMergeTip.node.setPosition(targetCell.node.getPosition());
                     this.ueMergeTip.Init({
-                        idx: targetCell.GetZIndex(),
+                        idx: targetCell.GetIdx(),
                         ueCube1: this.selectedCell.GetCube(),
                         ueCube2: targetCell.GetCube(),
-                        dir: targetCell.GetZIndex() % 10 > 4 ? 2 : 1
+                        dir: targetCell.GetIdx() % 10 > 4 ? 2 : 1
                     });
                 } else {
                     this.ueMergeTip.Hide();
@@ -268,10 +270,9 @@ export default class UEGridMap extends UEBase {
                 GameDataCenter.gridMap.TryMergeItems(this.selectedCell, targetCell);
                 // this.selectedCell.SetSelect(false);
                 // targetCell.SetSelect(true);
-                EventMng.emit(GridEvent.HC_CELL_SELECT, targetCell.GetZIndex());
+                EventMng.emit(GridEvent.HC_CELL_SELECT, targetCell.GetIdx());
             } else {
                 this.CheckSell();
-                this.selectedCell.GetCube().BackToOriginalPos(true);
             }
             this.isDragging = false;
             this.selectedCell = targetCell;
@@ -281,13 +282,22 @@ export default class UEGridMap extends UEBase {
 
     /** 检测物品是否拖动到售卖区域售卖 */
     private CheckSell() {
-        let sellPos = cc.v2(0, 0);
-        let sellSize = cc.size(GridConstant.CELL_WIDTH, GridConstant.CELL_WIDTH);
-        let sellRect = cc.rect(sellPos.x, sellPos.y, sellSize.width, sellSize.height);
+        let sellSize = cc.size(200, 200);
+        let sellBtn = HomeMergeSellCom.instance.GetSellBtn();
+        let sellPos = uiCommon.transPos(sellBtn, this.cubeLayer);
+        // 创建以sellPos为中心点的矩形
+        let sellRect = cc.rect(
+            sellPos.x - sellSize.width / 2,  // 左边界 = 中心点x - 宽度/2
+            sellPos.y - sellSize.height / 2, // 下边界 = 中心点y - 高度/2
+            sellSize.width,
+            sellSize.height
+        );
         let cubePos = this.selectedCell.GetCube().node.getPosition();
-        // if (cc.rectContainsPoint(sellRect, cubePos)) {
-        //     this.selectedCell.GetCube().PlayJellyAnim();
-        // }
+        if (sellRect.contains(cubePos)) {
+            GameDataCenter.gridMap.sendHcSell(this.selectedCell.GetIdx());
+        } else {
+            this.selectedCell.GetCube().BackToOriginalPos(true);
+        }
     }
 
     /** 根据像素坐标获取格子 */
@@ -333,8 +343,9 @@ export default class UEGridMap extends UEBase {
         const distanceFactor = totalDistance / 300; // 假设300是标准距离
         const duration = Math.min(baseDuration + distanceFactor * 0.3, 1.2); // 限制最大时间为1.2秒
 
-        // 设置最大高度(向上弹跳的高度)
-        const maxHeight = 400;
+        // 根据距离动态计算最大高度
+        const baseHeight = 200; // 基础高度
+        const maxHeight = Math.min(baseHeight + totalDistance * 0.5, 600); // 根据距离增加高度,但限制最大值
 
         // 计算最后弹跳的起点(在终点前20%距离处)
         const bounceStartPos = cc.v3(
@@ -346,7 +357,7 @@ export default class UEGridMap extends UEBase {
         // 创建第一段抛物线(抛向空中然后落到弹跳起点)
         const bezier1 = [];
         const midPoint1 = cc.v3(
-            startWorldPos.x + moveVec.x * 0.3,
+            startWorldPos.x + moveVec.x * 0.35, // 调整为0.35,让第一段抛物线更自然
             Math.max(startWorldPos.y, bounceStartPos.y) + maxHeight,
             0
         );
@@ -356,40 +367,40 @@ export default class UEGridMap extends UEBase {
 
         // 创建第二段弹跳(第一次弹跳)
         const bezier2 = [];
-        const bounceHeight = totalDistance * 0.15; // 弹跳高度设为总距离的15%
+        const bounceHeight = totalDistance * 0.2; // 增加弹跳高度为总距离的20%,让弹跳更明显
 
         // 计算第一次弹跳的最高点和落点
         const firstBounceTop = cc.v2(
-            (bounceStartPos.x + endWorldPos.x) / 2,  // 水平位置在中间
-            endWorldPos.y + bounceHeight  // 垂直高度为弹跳高度
+            bounceStartPos.x + (endWorldPos.x - bounceStartPos.x) * 0.3, // 调整水平位置,让弹跳更自然
+            endWorldPos.y + bounceHeight
         );
 
         // 计算第二段距离(从bounceStartPos到终点的距离)
-        const secondDistance = totalDistance * 0.2; // 最后20%的距离
+        const secondDistance = totalDistance * 0.2;
         const firstBounceEnd = cc.v2(
-            bounceStartPos.x + normalizedDir.x * (secondDistance * 0.5), // 前进一半
-            bounceStartPos.y + normalizedDir.y * (secondDistance * 0.5)
+            bounceStartPos.x + normalizedDir.x * (secondDistance * 0.6), // 增加到0.6,让第二次弹跳的起点更靠近终点
+            bounceStartPos.y + normalizedDir.y * (secondDistance * 0.6)
         );
 
-        bezier2.push(cc.v2(bounceStartPos.x, bounceStartPos.y)); // 起跳点
-        bezier2.push(firstBounceTop); // 最高点
-        bezier2.push(firstBounceEnd); // 第一次落点
+        bezier2.push(cc.v2(bounceStartPos.x, bounceStartPos.y));
+        bezier2.push(firstBounceTop);
+        bezier2.push(firstBounceEnd);
 
         // 创建第三段弹跳(最后一次弹跳到终点)
         const bezier3 = [];
         const secondBounceTop = cc.v2(
-            (firstBounceEnd.x + endWorldPos.x) / 2,
-            endWorldPos.y + bounceHeight * 0.6  // 第二次弹跳高度为第一次的60%
+            firstBounceEnd.x + (endWorldPos.x - firstBounceEnd.x) * 0.5,
+            endWorldPos.y + bounceHeight * 0.4  // 降低为40%,让最后的弹跳更轻盈
         );
 
-        bezier3.push(firstBounceEnd); // 起跳点
-        bezier3.push(secondBounceTop); // 最高点
-        bezier3.push(cc.v2(endWorldPos.x, endWorldPos.y)); // 终点
+        bezier3.push(firstBounceEnd);
+        bezier3.push(secondBounceTop);
+        bezier3.push(cc.v2(endWorldPos.x, endWorldPos.y));
 
         // 创建动作序列
-        const bezierAction1 = cc.bezierTo(duration * 0.7, bezier1);
-        const bezierAction2 = cc.bezierTo(duration * 0.18, bezier2);
-        const bezierAction3 = cc.bezierTo(duration * 0.12, bezier3);
+        const bezierAction1 = cc.bezierTo(duration * 0.65, bezier1); // 缩短第一段时间
+        const bezierAction2 = cc.bezierTo(0.2, bezier2);
+        const bezierAction3 = cc.bezierTo(0.15, bezier3);
 
         const seq = cc.sequence(
             bezierAction1,

+ 3 - 3
fgui-project/assets/Home/Home.xml

@@ -52,6 +52,9 @@
     <group id="n11_miq9" name="bottom" xy="0,927" size="750,407" advanced="true">
       <relation target="" sidePair="bottom-bottom"/>
     </group>
+    <component id="n30_tt6a" name="HomeMergeBottom" src="j5c83q" fileName="Components/HomeMergeBottom.xml" xy="375,1183" pivot="0.5,0.5" anchor="true">
+      <relation target="" sidePair="center-center,bottom-bottom"/>
+    </component>
     <component id="n27_qj2k" name="gridRoot" src="e0jk8c" fileName="Components/EmptyCom.xml" pkg="rd135cfr" xy="375,596" pivot="0.5,0.5" anchor="true">
       <relation target="" sidePair="center-center,middle-middle"/>
     </component>
@@ -67,9 +70,6 @@
     <group id="n26_miq9" name="top" xy="0,0" size="750,262" advanced="true">
       <relation target="" sidePair="top-top"/>
     </group>
-    <component id="n30_tt6a" name="HomeMergeBottom" src="j5c83q" fileName="Components/HomeMergeBottom.xml" xy="375,1183" pivot="0.5,0.5" anchor="true">
-      <relation target="" sidePair="center-center,bottom-bottom"/>
-    </component>
     <component id="n37_tt6a" name="EffectComp" src="e0jk8c" fileName="Components/EmptyCom.xml" pkg="rd135cfr" xy="375,667" pivot="0.5,0.5" anchor="true" size="750,1334" touchable="false">
       <relation target="" sidePair="width-width,height-height"/>
     </component>