Kaynağa Gözat

补满逻辑添加

woso_javan 3 ay önce
ebeveyn
işleme
dd2222d7b1

+ 57 - 0
assets/module_take_goblet/Script/Component/ButtonComponent.ts

@@ -0,0 +1,57 @@
+import { Button, Component, Label, Node, NodeEventType, _decorator, find } from 'cc';
+import { GameEvent } from '../Enum/GameEvent';
+import { EventDispatcher } from 'db://assets/core_tgx/easy_ui_framework/EventDispatcher';
+import { GlobalConfig } from 'db://assets/start/Config/GlobalConfig';
+import { AdvertMgr } from 'db://assets/core_tgx/base/ad/AdvertMgr';
+import { TYPE_ITEM } from '../TakeGobletGlobalInstance';
+const { ccclass, property } = _decorator;
+
+/**
+ * 底部按钮控制器
+ */
+@ccclass('ButtonComponent')
+export class ButtonComponent extends Component {
+    @property(Button) btnFillUp: Button = null!;
+    @property(Button) btMoveOut: Button = null!;
+    @property(Button) btRefresh: Button = null!;
+
+    protected start(): void {
+        this.addUIEvent();
+    }
+
+    private addUIEvent(): void {
+        this.btnFillUp.node.on(NodeEventType.TOUCH_END, () => this.onClickHandler(TYPE_ITEM.FillUp), this);
+        this.btMoveOut.node.on(NodeEventType.TOUCH_END, () => this.onClickHandler(TYPE_ITEM.MoveOut), this);
+        this.btRefresh.node.on(NodeEventType.TOUCH_END, () => this.onClickHandler(TYPE_ITEM.Refresh), this);
+    }
+
+    private onClickHandler(type: TYPE_ITEM): void {
+        // CarUnscrewAudioMgr.playOneShot(CarUnscrewAudioMgr.getMusicIdName(3), 1.0);
+        if (type == TYPE_ITEM.FillUp) {
+            if (!GlobalConfig.isDebug) {
+                AdvertMgr.instance.showReawardVideo(() => {
+                    EventDispatcher.instance.emit(GameEvent.EVENT_FILL_UP);
+                })
+            } else {
+                EventDispatcher.instance.emit(GameEvent.EVENT_FILL_UP);
+            }
+        } else if (type == TYPE_ITEM.MoveOut) {
+            if (!GlobalConfig.isDebug) {
+                AdvertMgr.instance.showReawardVideo(() => {
+                    EventDispatcher.instance.emit(GameEvent.EVENT_MOVE_OUT);
+                })
+            } else {
+                EventDispatcher.instance.emit(GameEvent.EVENT_MOVE_OUT);
+            }
+        } else {
+            if (!GlobalConfig.isDebug) {
+                AdvertMgr.instance.showReawardVideo(() => {
+                    EventDispatcher.instance.emit(GameEvent.EVENT_REFRESH_COLOR);
+                })
+            } else {
+                EventDispatcher.instance.emit(GameEvent.EVENT_REFRESH_COLOR);
+            }
+        }
+    }
+
+}

+ 9 - 0
assets/module_take_goblet/Script/Component/ButtonComponent.ts.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "4.0.23",
+  "importer": "typescript",
+  "imported": true,
+  "uuid": "e06e24a5-23e6-49b6-91e5-67db11e57166",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 39 - 1
assets/module_take_goblet/Script/Component/CocktailCup.ts

@@ -1,4 +1,4 @@
-import { _decorator, Color, Component, Enum, Node, Sprite, tween, Vec3 } from 'cc';
+import { _decorator, Color, Component, Enum, Node, Sprite, tween, Vec3, UITransform, view } from 'cc';
 import { CupHeight, WaterColorHex, WaterColors } from '../TakeGobletGlobalInstance';
 import { Water } from './Water';
 import { EventDispatcher } from 'db://assets/core_tgx/easy_ui_framework/EventDispatcher';
@@ -58,6 +58,44 @@ export class CocktailCup extends Component {
         }
     }
 
+    //补满水
+    public async fillUp() {
+        const currentActive = this.waters.children.filter(n => n.active).length;
+        const layersToAdd = this.cupHeight - currentActive;
+
+        for (let i = 0; i < layersToAdd; i++) {
+            const waterIndex = currentActive + i;
+            const waterNode = this.waters.children[waterIndex];
+            const water = waterNode.getComponent(Water)!;
+
+            water.color = this.cupColor;
+            waterNode.active = true;
+            waterNode.scale = Vec3.ZERO;
+
+            await new Promise<void>(resolve => {
+                tween(waterNode)
+                    .to(0.5 / layersToAdd, { scale: Vec3.ONE }, { easing: 'sineOut' })
+                    .call(() => resolve())
+                    .start();
+            });
+        }
+
+        // 补满后执行移动销毁动画
+        const uiTransform = this.node.getComponent(UITransform)!;
+        const screenWidth = view.getVisibleSize().width;
+        const targetX = screenWidth / 2 + uiTransform.width * 1.5;
+
+        await new Promise<void>(resolve => {
+            tween(this.node)
+                .to(0.5, { position: new Vec3(targetX, 0, 0) }, { easing: 'sineIn' })
+                .call(() => {
+                    this.node.destroy();
+                    resolve();
+                })
+                .start();
+        });
+    }
+
     // 清空水层(消除时调用)
     reset() {
         this.waters.children.forEach(water => water.active = false);

+ 35 - 0
assets/module_take_goblet/Script/Component/OutArea.ts

@@ -1,4 +1,7 @@
 import { _decorator, Component, Node, tween, Vec3 } from 'cc';
+import { EventDispatcher } from 'db://assets/core_tgx/easy_ui_framework/EventDispatcher';
+import { GameEvent } from '../Enum/GameEvent';
+import { CocktailCup } from '../Component/CocktailCup';
 const { ccclass, property, executeInEditMode } = _decorator;
 
 @ccclass('OutArea')
@@ -14,7 +17,39 @@ export class OutArea extends Component {
     }
 
     start() {
+        this.registerEvent();
+    }
+
+    protected onDestroy(): void {
+        EventDispatcher.instance.off(GameEvent.EVENT_FILL_UP, this.onFillUp, this);
+    }
+
+    private registerEvent(): void {
+        EventDispatcher.instance.on(GameEvent.EVENT_FILL_UP, this.onFillUp, this);
+    }
+
+    private async onFillUp(): Promise<void> {
+        console.log('补满');
+
+        // 获取所有有效杯子
+        const validCups = this.cups.filter(cup => cup.isValid);
+        if (validCups.length === 0) return;
+
+        // 找到最右边的杯子(x坐标最大的)
+        const rightMostCup = validCups.reduce((prev, current) => {
+            return prev.position.x > current.position.x ? prev : current;
+        });
 
+        const cocktailCup = rightMostCup.getComponent(CocktailCup);
+        if (cocktailCup) {
+            try {
+                // 执行补满动画并等待完成
+                await cocktailCup.fillUp();
+                console.log('最右侧杯子已补满');
+            } catch (e) {
+                console.error('补满操作失败:', e);
+            }
+        }
     }
 
     update(deltaTime: number) {

+ 6 - 0
assets/module_take_goblet/Script/Enum/GameEvent.ts

@@ -13,6 +13,12 @@ export class GameEvent {
     /** 按钮功能 颜色刷新事件*/
     static readonly EVENT_REFRESH_COLOR = 'EVENT_REFRESH_COLOR';
 
+    /** 按钮功能 移出事件*/
+    static readonly EVENT_MOVE_OUT = 'EVENT_MOVE_OUT';
+
+    /** 按钮功能 补满事件*/
+    static readonly EVENT_FILL_UP = 'EVENT_FILL_UP';
+
     /** 检测游戏是否结束*/
     static readonly EVENT_CHECK_GAME_OVER = 'EVENT_CHECK_GAME_OVER';
 

+ 2 - 2
assets/module_take_goblet/Script/TakeGobletGlobalInstance.ts

@@ -90,9 +90,9 @@ export class TakeGobletGlobalInstance {
  * @param Disturb 打乱
 */
 export enum TYPE_ITEM {
-    REVOKE = 1,
+    FillUp = 1,
     MoveOut = 2,
-    Disturb = 3,
+    Refresh = 3,
 }
 
 export enum WaterColors {

+ 66 - 42
assets/module_take_goblet/rooster_takegoblet.scene

@@ -23,7 +23,7 @@
     "_active": true,
     "_components": [],
     "_prefab": {
-      "__id__": 66
+      "__id__": 67
     },
     "_lpos": {
       "__type__": "cc.Vec3",
@@ -54,7 +54,7 @@
     },
     "autoReleaseAssets": false,
     "_globals": {
-      "__id__": 67
+      "__id__": 68
     },
     "_id": "be14c61f-22d8-4bb9-b444-ad9f29740469"
   },
@@ -80,14 +80,11 @@
         "__id__": 12
       },
       {
-        "__id__": 60
+        "__id__": 61
       }
     ],
     "_active": true,
     "_components": [
-      {
-        "__id__": 62
-      },
       {
         "__id__": 63
       },
@@ -96,6 +93,9 @@
       },
       {
         "__id__": 65
+      },
+      {
+        "__id__": 66
       }
     ],
     "_prefab": null,
@@ -486,16 +486,16 @@
         "__id__": 13
       },
       {
-        "__id__": 47
+        "__id__": 48
       }
     ],
     "_active": true,
     "_components": [
       {
-        "__id__": 58
+        "__id__": 59
       },
       {
-        "__id__": 59
+        "__id__": 60
       }
     ],
     "_prefab": null,
@@ -557,6 +557,9 @@
       },
       {
         "__id__": 46
+      },
+      {
+        "__id__": 47
       }
     ],
     "_prefab": null,
@@ -1421,7 +1424,7 @@
   },
   {
     "__type__": "cc.Node",
-    "_name": "BtnDisturb",
+    "_name": "BtnRefresh",
     "_objFlags": 0,
     "__editorExtras__": {},
     "_parent": {
@@ -1918,6 +1921,27 @@
     "_isAlign": false,
     "_id": "e5lNKW+8REapy973XbOiDJ"
   },
+  {
+    "__type__": "e06e2SlI+ZJtpHlZ9sR5XFm",
+    "_name": "",
+    "_objFlags": 0,
+    "__editorExtras__": {},
+    "node": {
+      "__id__": 13
+    },
+    "_enabled": true,
+    "__prefab": null,
+    "btnFillUp": {
+      "__id__": 23
+    },
+    "btMoveOut": {
+      "__id__": 33
+    },
+    "btRefresh": {
+      "__id__": 43
+    },
+    "_id": "c0Qmmo34pE/II8L7R2hCgt"
+  },
   {
     "__type__": "cc.Node",
     "_name": "TopLeft",
@@ -1928,19 +1952,19 @@
     },
     "_children": [
       {
-        "__id__": 48
+        "__id__": 49
       },
       {
-        "__id__": 52
+        "__id__": 53
       }
     ],
     "_active": true,
     "_components": [
       {
-        "__id__": 56
+        "__id__": 57
       },
       {
-        "__id__": 57
+        "__id__": 58
       }
     ],
     "_prefab": null,
@@ -1979,19 +2003,19 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "_parent": {
-      "__id__": 47
+      "__id__": 48
     },
     "_children": [],
     "_active": true,
     "_components": [
-      {
-        "__id__": 49
-      },
       {
         "__id__": 50
       },
       {
         "__id__": 51
+      },
+      {
+        "__id__": 52
       }
     ],
     "_prefab": null,
@@ -2030,7 +2054,7 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 48
+      "__id__": 49
     },
     "_enabled": true,
     "__prefab": null,
@@ -2052,7 +2076,7 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 48
+      "__id__": 49
     },
     "_enabled": true,
     "__prefab": null,
@@ -2091,7 +2115,7 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 48
+      "__id__": 49
     },
     "_enabled": true,
     "__prefab": null,
@@ -2133,7 +2157,7 @@
     "_duration": 0.1,
     "_zoomScale": 1.2,
     "_target": {
-      "__id__": 48
+      "__id__": 49
     },
     "_id": "51Zwo4GTBBT7vNI+1Aij5E"
   },
@@ -2143,19 +2167,19 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "_parent": {
-      "__id__": 47
+      "__id__": 48
     },
     "_children": [],
     "_active": true,
     "_components": [
-      {
-        "__id__": 53
-      },
       {
         "__id__": 54
       },
       {
         "__id__": 55
+      },
+      {
+        "__id__": 56
       }
     ],
     "_prefab": null,
@@ -2194,7 +2218,7 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 52
+      "__id__": 53
     },
     "_enabled": true,
     "__prefab": null,
@@ -2216,7 +2240,7 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 52
+      "__id__": 53
     },
     "_enabled": true,
     "__prefab": null,
@@ -2255,7 +2279,7 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 52
+      "__id__": 53
     },
     "_enabled": true,
     "__prefab": null,
@@ -2297,7 +2321,7 @@
     "_duration": 0.1,
     "_zoomScale": 1.2,
     "_target": {
-      "__id__": 52
+      "__id__": 53
     },
     "_id": "ec3qEoJHVABoxGd3CvrvsV"
   },
@@ -2307,7 +2331,7 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 47
+      "__id__": 48
     },
     "_enabled": true,
     "__prefab": null,
@@ -2329,7 +2353,7 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 47
+      "__id__": 48
     },
     "_enabled": true,
     "__prefab": null,
@@ -2417,7 +2441,7 @@
     "_active": true,
     "_components": [
       {
-        "__id__": 61
+        "__id__": 62
       }
     ],
     "_prefab": null,
@@ -2456,7 +2480,7 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 60
+      "__id__": 61
     },
     "_enabled": true,
     "__prefab": null,
@@ -2558,28 +2582,28 @@
   {
     "__type__": "cc.SceneGlobals",
     "ambient": {
-      "__id__": 68
+      "__id__": 69
     },
     "shadows": {
-      "__id__": 69
+      "__id__": 70
     },
     "_skybox": {
-      "__id__": 70
+      "__id__": 71
     },
     "fog": {
-      "__id__": 71
+      "__id__": 72
     },
     "octree": {
-      "__id__": 72
+      "__id__": 73
     },
     "skin": {
-      "__id__": 73
+      "__id__": 74
     },
     "lightProbeInfo": {
-      "__id__": 74
+      "__id__": 75
     },
     "postSettings": {
-      "__id__": 75
+      "__id__": 76
     },
     "bakedWithStationaryMainLight": false,
     "bakedWithHighpLightmap": false