瀏覽代碼

【优化】完善游戏二倍速的时候自动暂停逻辑

mojunshou 7 月之前
父節點
當前提交
e490543b22

文件差異過大導致無法顯示
+ 1330 - 1148
assets/bundle/gui/eliminate/eliminate.prefab


+ 1 - 1
assets/bundle/gui/eliminate/prefab/cashRebate.prefab

@@ -207,7 +207,7 @@
     "__prefab": {
       "__id__": 8
     },
-    "playOnLoad": false,
+    "playOnLoad": true,
     "_clips": [
       {
         "__uuid__": "62c95173-1005-48b0-bef6-f49a73db295c",

+ 2 - 2
assets/script/game/common/config/GameUIConfig.ts

@@ -1,7 +1,7 @@
 /*
  * @Date: 2021-08-12 09:33:37
  * @LastEditors: mojunshou 1637302775@qq.com
- * @LastEditTime: 2025-04-21 19:10:15
+ * @LastEditTime: 2025-04-23 11:58:45
  */
 import { LayerType, UIConfig } from "../../../../../extensions/oops-plugin-framework/assets/core/gui/layer/LayerManager";
 
@@ -83,7 +83,7 @@ export var UIConfigData: { [key: number]: UIConfig } = {
     [UIID.Verify]: { layer: LayerType.PopUp, prefab: "gui/eliminate/prefab/popup/VerifyPopup", vacancy: true, mask: true },
     [UIID.WithdrawRecord]: { layer: LayerType.UI, prefab: "gui/eliminate/prefab/WithdrawalRecord" },
     [UIID.WechatWithdraw]: { layer: LayerType.UI, prefab: "gui/eliminate/prefab/WechatWithdrawal" },
-    [UIID.WithSussce]: { layer: LayerType.PopUp, prefab: "gui/eliminate/prefab/CashWithdrawal" },
+    [UIID.WithSussce]: { layer: LayerType.PopUp, prefab: "gui/eliminate/prefab/CashWithdrawal", vacancy: true, mask: true },
     [UIID.KeepSpeed]: { layer: LayerType.PopUp, prefab: "gui/eliminate/prefab/popup/KeepDoubleSpeed", vacancy: true, mask: true },
     [UIID.WarmReminder]: { layer: LayerType.PopUp, prefab: "gui/eliminate/prefab/popup/WarmReminder", vacancy: true, mask: true },
     [UIID.WelfareOne]: { layer: LayerType.PopUp, prefab: "gui/eliminate/prefab/popup/WelfareOne", vacancy: true, mask: true },

+ 9 - 5
assets/script/game/common/manager/ADHandler.ts

@@ -1,3 +1,10 @@
+/*
+ * @Author: mojunshou 1637302775@qq.com
+ * @Date: 2025-04-11 10:14:44
+ * @LastEditors: mojunshou 1637302775@qq.com
+ * @LastEditTime: 2025-04-23 15:03:22
+ * @Description: 
+ */
 // ADHandler.ts
 import { CocosHandlerType, CocosHandler } from './CocosHandler';
 import { AD_TYPE } from '../config/GameDefine';
@@ -101,7 +108,7 @@ export class ADHandler {
 
     adRewardLoadFailed = (str: string) => {
         smc.game.GameModel.isShowAd = false;
-        console.log('[广告] 激励视频展示失败', str);
+        oops.message.dispatchEvent(GameEvent.updateGameState, "playing");
         //展示失败
         if (smc.game.GameModel.viewType === "revive_reward") {
             const score = smc.game.GameModel.curScore;
@@ -109,16 +116,14 @@ export class ADHandler {
             smc.game.GameModel.curScore = Math.floor(score / 2);
             oops.message.dispatchEvent(GameEvent.RestartGame);
         }
-        oops.message.dispatchEvent(GameEvent.updateGameState, "playing");
     };
 
     adRewardClose = (state: boolean) => {
         smc.game.GameModel.isShowAd = false;
         console.log("[广告] 激励视频关闭", state)
         smc.game.GameModel.isDone = state;
+        oops.message.dispatchEvent(GameEvent.updateGameState, "playing");
         if (state) {
-            //如果是二倍速,就加速就好,不用发放奖励
-            console.log("激励视频关闭", smc.game.GameModel.viewType)
             if (smc.game.GameModel.viewType === "speed_reward") {
                 //直接成功-增加时长
                 oops.message.dispatchEvent(GameEvent.DoubleSpeedOpenSuccess);
@@ -133,7 +138,6 @@ export class ADHandler {
             }
             ServerHandler.inst.getVideorReward();
         }
-        oops.message.dispatchEvent(GameEvent.updateGameState, "playing");
     };
 }
 window["ADHandler"] = ADHandler;

+ 30 - 0
assets/script/game/common/manager/DCHandler.ts

@@ -0,0 +1,30 @@
+import { CocosHandler } from "./CocosHandler";
+
+//数据上报
+
+export class DCHandler {
+    private static _inst: DCHandler;
+
+    public static get inst(): DCHandler {
+        if (!this._inst) {
+            this._inst = new DCHandler();
+        }
+        return this._inst;
+    }
+
+    //数据上报
+    async reportData(eventId: number) {
+        const param = {
+            eventId: eventId
+        }
+        const data = {
+            method: 'analysis.event',
+            param: JSON.stringify(param)
+        };
+        const result = await CocosHandler.inst.sendMessageToAndroid(data, '获取数据上报状态');
+        return JSON.parse(result);
+    }
+}
+
+
+window["DCHandler"] = DCHandler;

+ 9 - 0
assets/script/game/common/manager/DCHandler.ts.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "4.0.24",
+  "importer": "typescript",
+  "imported": true,
+  "uuid": "ae1f384b-04c0-4859-a08c-8709422adbea",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 1 - 3
assets/script/game/common/manager/ServerHandler.ts

@@ -2,7 +2,7 @@
  * @Author: mojunshou 1637302775@qq.com
  * @Date: 2025-04-11 10:16:41
  * @LastEditors: mojunshou 1637302775@qq.com
- * @LastEditTime: 2025-04-23 10:28:35
+ * @LastEditTime: 2025-04-23 14:51:53
  * @Description: 
  */
 // ServerHandler.ts
@@ -11,8 +11,6 @@ import { GameEvent } from '../config/GameEvent';
 import { oops } from 'db://oops-framework/core/Oops';
 import { CocosHandler, CocosHandlerType } from './CocosHandler';
 import { ProtocolEvent } from './ProtocolEvent';
-import { url } from 'inspector';
-import { Game } from 'cc';
 
 export class ServerHandler {
     private static _inst: ServerHandler;

+ 3 - 1
assets/script/game/common/setting/SettingViewComp.ts

@@ -2,7 +2,7 @@
  * @Author: mojunshou 1637302775@qq.com
  * @Date: 2025-03-20 15:40:20
  * @LastEditors: mojunshou 1637302775@qq.com
- * @LastEditTime: 2025-04-21 18:47:35
+ * @LastEditTime: 2025-04-23 11:57:18
  * @Description:设置界面 
  */
 import { _decorator } from "cc";
@@ -21,6 +21,7 @@ import { CocosHandler } from "../manager/CocosHandler";
 import { LoginHandler } from "../manager/LoginHandler";
 import { UITransform } from "cc";
 import { Size } from "cc";
+import { GameEvent } from "../config/GameEvent";
 const { ccclass, property } = _decorator;
 
 /** 视图层对象 */
@@ -68,6 +69,7 @@ export class SettingViewComp extends CCVMParentComp {
 
     private btn_close() {
         oops.gui.remove(UIID.Setting);
+        oops.message.dispatchEvent(GameEvent.updateGameState, "playing");
     }
 
 

+ 1 - 3
assets/script/game/initialize/view/LoadingViewComp.ts

@@ -2,7 +2,7 @@
  * @Author: mojunshou 1637302775@qq.com
  * @Date: 2025-03-19 16:23:51
  * @LastEditors: mojunshou 1637302775@qq.com
- * @LastEditTime: 2025-04-22 11:32:32
+ * @LastEditTime: 2025-04-23 14:16:55
  * @Description: loading界面
  */
 import { _decorator, Toggle } from "cc";
@@ -157,9 +157,7 @@ export class LoadingViewComp extends CCVMParentComp {
             oops.gui.toast("请同意隐私政策")
             return;
         }
-        //暂时跳过这个登录
         LoginHandler.inst.wechatLogin();
-        console.log("点击微信登录");
     }
 
     /**

+ 33 - 22
assets/script/game/view/EliminateViewComp.ts

@@ -2,7 +2,7 @@
  * @Author: mojunshou 1637302775@qq.com
  * @Date: 2025-03-20 15:01:09
  * @LastEditors: mojunshou 1637302775@qq.com
- * @LastEditTime: 2025-04-23 11:13:27
+ * @LastEditTime: 2025-04-23 15:13:01
  * @Description: 消除游戏主场景
  */
 import { _decorator, Button, Color, EventTouch, instantiate, JsonAsset, Label, Node, Prefab, randomRangeInt, Sprite, tween, UITransform, Vec2, Vec3, Widget } from "cc";
@@ -225,6 +225,7 @@ export class EliminateViewComp extends CCComp {
 
     private randomList: number[] = [];
 
+    private autoFunction: Function | null = null;
 
 
     /** 视图层逻辑代码分离演示 */
@@ -319,13 +320,10 @@ export class EliminateViewComp extends CCComp {
         if (smc.game.GameModel.curLevelConfig.eliminateScope) {
             this.eliminateInterval = smc.game.GameModel.curLevelConfig.eliminateScope || [];
         }
-
-
         this.score = smc.game.GameModel.curScore;
         this.money = smc.account.AccountModel.wxCoin;
         this.cash = smc.account.AccountModel.hbCoin;
-        // this.targetScore = smc.game.GameModel.targetScore;
-        this.targetScore = 200;
+        this.targetScore = smc.game.GameModel.targetScore;
         this.popupType = smc.game.GameModel.popupType;
         this.lab_score.string = this.score.toString();
         this.lab_wxCoin.string = Format.formatWxCoin(this.money);
@@ -592,7 +590,6 @@ export class EliminateViewComp extends CCComp {
                 }
             );
         }
-        this.updateGameScore();
     }
 
 
@@ -1423,6 +1420,7 @@ export class EliminateViewComp extends CCComp {
                 }
 
                 this.score += score;
+                this.updateGameScore();
                 if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
                     ServerHandler.inst.updateEliminationReward({
                         count: totalEliminationsInThisRound,
@@ -1837,6 +1835,13 @@ export class EliminateViewComp extends CCComp {
         console.log("游戏结束")
         smc.game.GameModel.curScore = this.score;
         oops.gui.open(UIID.GameOver);
+        //如果有自动就要关闭自动
+        if (this.autoFunction) {
+            this.unschedule(this.autoFunction);
+            this.autoFunction = null;
+            this.initButtonState(false);
+            this.autoState = false;
+        }
     }
 
 
@@ -1896,6 +1901,7 @@ export class EliminateViewComp extends CCComp {
     //设置按钮
     private btn_setting() {
         oops.gui.open(UIID.Setting);
+        this.gameState = GameState.PAUSED;
     }
 
     //左边微信按钮
@@ -1905,7 +1911,7 @@ export class EliminateViewComp extends CCComp {
         } else {
             oops.gui.open(UIID.WechatWithdraw);
         }
-
+        this.gameState = GameState.PAUSED;
     }
 
     //顶部红包按钮
@@ -1917,14 +1923,14 @@ export class EliminateViewComp extends CCComp {
         } else {
             oops.gui.open(UIID.RedPacketWithdraw);
         }
-
-
+        this.gameState = GameState.PAUSED;
     }
 
-    //二倍速按钮
+    //二倍速按钮   
     private btn_double() {
         // oops.gui.open(UIID.DoubleSpeed);
         if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
+            this.gameState = GameState.PAUSED;
             ServerHandler.inst.getDoubleSpeedTime();
         } else {
             oops.gui.open(UIID.DoubleSpeed);
@@ -1940,7 +1946,18 @@ export class EliminateViewComp extends CCComp {
         this.autoState = !this.autoState;
         this.initButtonState(this.autoState);
         if (this.autoState) {
+
             this.executeAutoPlace();
+            this.autoFunction = this.executeAutoPlace;
+            this.schedule(this.autoFunction, 1.5);
+        } else {
+            //关闭
+            if (this.autoFunction) {
+                this.unschedule(this.autoFunction);
+                this.autoFunction = null;
+                this.initButtonState(false);
+                this.autoState = false;
+            }
         }
     }
 
@@ -2119,11 +2136,6 @@ export class EliminateViewComp extends CCComp {
                             if (!promptFlag) {
                                 this.autoState = false
                                 this.gameOver()
-                            } else if (this.autoState) {
-                                // 继续自动放置
-                                this.scheduleOnce(() => {
-                                    this.executeAutoPlace()
-                                }, this.autoPlaceInterval)
                             }
                         })
                     })
@@ -2147,11 +2159,9 @@ export class EliminateViewComp extends CCComp {
         //改变按钮时间
         // let time = smc.game.GameModel.doubleSpeedTime;
         this.doubleSpeedTime = smc.game.GameModel.doubleSpeedTime;
-        let time = 15;
-        if (time <= 0) {
+        if (this.doubleSpeedTime <= 0) {
             return
         }
-        console.log("二倍速时间", time);
         if (!this.autoState) {
             this.btn_auto();
             //改按钮状态
@@ -2160,18 +2170,19 @@ export class EliminateViewComp extends CCComp {
         }
         this.callback = function () {
             if (!this.adShowingFlag && this.gameState === GameState.PLAYING) {
-                time--
+                this.doubleSpeedTime--
                 //修改剩余时间,秒格式化成时分10:59
-                const minutes = Math.floor(time / 60);
-                const seconds = time % 60;
+                const minutes = Math.floor(this.doubleSpeedTime / 60);
+                const seconds = this.doubleSpeedTime % 60;
                 const formattedTime = `${minutes}:${seconds < 10 ? '0' : ''}${seconds}`;
                 this.lab_doubleTime.string = formattedTime;
                 //时间到了
-                if (time <= 0) {
+                if (this.doubleSpeedTime <= 0) {
                     this.lab_doubleTime.string = "二倍速";
                     this.isDoubleSpeed = false;
                     this.doubleNum = 1;
                     //再打开继续二倍速页面
+                    this.gameState = GameState.PAUSED;
                     oops.gui.open(UIID.KeepSpeed);
                     this.unschedule(this.callback);
                 }

+ 1 - 0
assets/script/game/view/RedPackeWithdrawalViewComp.ts

@@ -105,6 +105,7 @@ export class RedPackeWithdrawalViewComp extends CCVMParentComp {
 
     private btn_back() {
         oops.gui.remove(UIID.RedPacketWithdraw);
+        oops.message.dispatchEvent(GameEvent.updateGameState, "playing");
     }
 
 

+ 2 - 1
assets/script/game/view/WechatWithdrawalViewComp.ts

@@ -2,7 +2,7 @@
  * @Author: mojunshou 1637302775@qq.com
  * @Date: 2025-03-20 17:00:12
  * @LastEditors: mojunshou 1637302775@qq.com
- * @LastEditTime: 2025-04-22 16:30:02
+ * @LastEditTime: 2025-04-23 11:57:06
  * @Description: 微信提现页面
  */
 import { _decorator, ImageAsset, Label, Node, RichText, Size, Sprite, SpriteFrame, Texture2D, tween, UITransform, Vec3 } from "cc";
@@ -104,6 +104,7 @@ export class WechatWithdrawalViewComp extends CCVMParentComp {
 
     private btn_back() {
         oops.gui.remove(UIID.WechatWithdraw);
+        oops.message.dispatchEvent(GameEvent.updateGameState, "playing");
     }
 
     private btn_record() {

+ 1 - 1
assets/script/game/view/keepDoubleSpeedView.ts

@@ -2,7 +2,7 @@
  * @Author: mojunshou 1637302775@qq.com
  * @Date: 2025-04-15 20:16:16
  * @LastEditors: mojunshou 1637302775@qq.com
- * @LastEditTime: 2025-04-17 10:02:59
+ * @LastEditTime: 2025-04-23 15:13:16
  * @Description: 继续二倍速
  */
 import { _decorator, Component, Node } from 'cc';