Browse Source

弱引导添加

薛鸿潇 5 years ago
parent
commit
f4731e84ec

+ 2 - 4
assets/resources/module/guideWeak/GuideWeak.prefab

@@ -159,8 +159,8 @@
     ],
     "_srcBlendFactor": 770,
     "_dstBlendFactor": 771,
-    "_string": "引导运行中",
-    "_N$string": "引导运行中",
+    "_string": "引导运行中",
+    "_N$string": "引导运行中",
     "_fontSize": 40,
     "_lineHeight": 40,
     "_enableWrapText": true,
@@ -223,8 +223,6 @@
       "__id__": 1
     },
     "_enabled": true,
-    "label": null,
-    "text": "hello",
     "_id": ""
   },
   {

+ 272 - 8
assets/scene/MainScene.fire

@@ -90,16 +90,16 @@
     "_active": true,
     "_components": [
       {
-        "__id__": 14
+        "__id__": 22
       },
       {
-        "__id__": 15
+        "__id__": 23
       },
       {
-        "__id__": 16
+        "__id__": 24
       },
       {
-        "__id__": 17
+        "__id__": 25
       }
     ],
     "_prefab": null,
@@ -580,9 +580,17 @@
     "_parent": {
       "__id__": 2
     },
-    "_children": [],
+    "_children": [
+      {
+        "__id__": 14
+      }
+    ],
     "_active": true,
-    "_components": [],
+    "_components": [
+      {
+        "__id__": 21
+      }
+    ],
     "_prefab": null,
     "_opacity": 255,
     "_color": {
@@ -594,8 +602,8 @@
     },
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 0,
-      "height": 0
+      "width": 750,
+      "height": 1334
     },
     "_anchorPoint": {
       "__type__": "cc.Vec2",
@@ -632,6 +640,262 @@
     "_id": "00l+e+JEJA2YTFgORvtX+s"
   },
   {
+    "__type__": "cc.Node",
+    "_name": "GuideWeak",
+    "_objFlags": 0,
+    "_parent": {
+      "__id__": 13
+    },
+    "_children": [
+      {
+        "__id__": 15
+      }
+    ],
+    "_active": true,
+    "_components": [
+      {
+        "__id__": 18
+      },
+      {
+        "__id__": 19
+      }
+    ],
+    "_prefab": {
+      "__id__": 20
+    },
+    "_opacity": 255,
+    "_color": {
+      "__type__": "cc.Color",
+      "r": 255,
+      "g": 255,
+      "b": 255,
+      "a": 255
+    },
+    "_contentSize": {
+      "__type__": "cc.Size",
+      "width": 750,
+      "height": 1334
+    },
+    "_anchorPoint": {
+      "__type__": "cc.Vec2",
+      "x": 0.5,
+      "y": 0.5
+    },
+    "_trs": {
+      "__type__": "TypedArray",
+      "ctor": "Float64Array",
+      "array": [
+        0,
+        0,
+        0,
+        0,
+        0,
+        0,
+        1,
+        1,
+        1,
+        1
+      ]
+    },
+    "_eulerAngles": {
+      "__type__": "cc.Vec3",
+      "x": 0,
+      "y": 0,
+      "z": 0
+    },
+    "_skewX": 0,
+    "_skewY": 0,
+    "_is3DNode": false,
+    "_groupIndex": 0,
+    "groupIndex": 0,
+    "_id": "eanBXyELZLiLKDrC2BLhHQ"
+  },
+  {
+    "__type__": "cc.Node",
+    "_name": "New Label",
+    "_objFlags": 0,
+    "_parent": {
+      "__id__": 14
+    },
+    "_children": [],
+    "_active": true,
+    "_components": [
+      {
+        "__id__": 16
+      }
+    ],
+    "_prefab": {
+      "__id__": 17
+    },
+    "_opacity": 255,
+    "_color": {
+      "__type__": "cc.Color",
+      "r": 255,
+      "g": 255,
+      "b": 255,
+      "a": 255
+    },
+    "_contentSize": {
+      "__type__": "cc.Size",
+      "width": 240,
+      "height": 50.4
+    },
+    "_anchorPoint": {
+      "__type__": "cc.Vec2",
+      "x": 0.5,
+      "y": 0.5
+    },
+    "_trs": {
+      "__type__": "TypedArray",
+      "ctor": "Float64Array",
+      "array": [
+        0,
+        0,
+        0,
+        0,
+        0,
+        0,
+        1,
+        1,
+        1,
+        1
+      ]
+    },
+    "_eulerAngles": {
+      "__type__": "cc.Vec3",
+      "x": 0,
+      "y": 0,
+      "z": 0
+    },
+    "_skewX": 0,
+    "_skewY": 0,
+    "_is3DNode": false,
+    "_groupIndex": 0,
+    "groupIndex": 0,
+    "_id": "e95KcmSUVBkKczggTkotEr"
+  },
+  {
+    "__type__": "cc.Label",
+    "_name": "",
+    "_objFlags": 0,
+    "node": {
+      "__id__": 15
+    },
+    "_enabled": true,
+    "_materials": [
+      {
+        "__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
+      }
+    ],
+    "_srcBlendFactor": 770,
+    "_dstBlendFactor": 771,
+    "_string": "若引导运行中",
+    "_N$string": "若引导运行中",
+    "_fontSize": 40,
+    "_lineHeight": 40,
+    "_enableWrapText": true,
+    "_N$file": null,
+    "_isSystemFontUsed": true,
+    "_spacingX": 0,
+    "_batchAsBitmap": false,
+    "_styleFlags": 0,
+    "_underlineHeight": 0,
+    "_N$horizontalAlign": 1,
+    "_N$verticalAlign": 1,
+    "_N$fontFamily": "Arial",
+    "_N$overflow": 0,
+    "_N$cacheMode": 0,
+    "_id": "a61HIV92JBeYx2JHC9YdSf"
+  },
+  {
+    "__type__": "cc.PrefabInfo",
+    "root": {
+      "__id__": 14
+    },
+    "asset": {
+      "__uuid__": "ba2e33b2-5a64-424b-8b08-247fed4be0f0"
+    },
+    "fileId": "9bpVbHl+FJeqHz4I/c2T/+",
+    "sync": false
+  },
+  {
+    "__type__": "cc.Widget",
+    "_name": "",
+    "_objFlags": 0,
+    "node": {
+      "__id__": 14
+    },
+    "_enabled": true,
+    "alignMode": 1,
+    "_target": null,
+    "_alignFlags": 45,
+    "_left": 0,
+    "_right": 0,
+    "_top": 0,
+    "_bottom": 0,
+    "_verticalCenter": 0,
+    "_horizontalCenter": 0,
+    "_isAbsLeft": true,
+    "_isAbsRight": true,
+    "_isAbsTop": true,
+    "_isAbsBottom": true,
+    "_isAbsHorizontalCenter": true,
+    "_isAbsVerticalCenter": true,
+    "_originalWidth": 0,
+    "_originalHeight": 0,
+    "_id": "b9uTPYnKhElrSn8ZUXnvd9"
+  },
+  {
+    "__type__": "f13f5zT97NMpINpXOCogVAt",
+    "_name": "",
+    "_objFlags": 0,
+    "node": {
+      "__id__": 14
+    },
+    "_enabled": true,
+    "label": null,
+    "text": "hello",
+    "_id": "ab6Xv7F+NPuIRbgFjWiSyj"
+  },
+  {
+    "__type__": "cc.PrefabInfo",
+    "root": {
+      "__id__": 14
+    },
+    "asset": {
+      "__uuid__": "ba2e33b2-5a64-424b-8b08-247fed4be0f0"
+    },
+    "fileId": "",
+    "sync": false
+  },
+  {
+    "__type__": "cc.Widget",
+    "_name": "",
+    "_objFlags": 0,
+    "node": {
+      "__id__": 13
+    },
+    "_enabled": true,
+    "alignMode": 1,
+    "_target": null,
+    "_alignFlags": 45,
+    "_left": 0,
+    "_right": 0,
+    "_top": 0,
+    "_bottom": 0,
+    "_verticalCenter": 0,
+    "_horizontalCenter": 0,
+    "_isAbsLeft": true,
+    "_isAbsRight": true,
+    "_isAbsTop": true,
+    "_isAbsBottom": true,
+    "_isAbsHorizontalCenter": true,
+    "_isAbsVerticalCenter": true,
+    "_originalWidth": 0,
+    "_originalHeight": 0,
+    "_id": "4a5t4pwQtJiI5cavWztbU0"
+  },
+  {
     "__type__": "cc.Canvas",
     "_name": "",
     "_objFlags": 0,

+ 2 - 0
assets/script/game/component/BtnClosePanel.ts

@@ -30,8 +30,10 @@ export default class BtnClosePanel extends cc.Component {
     private async closePanel() {
         mk.audio.playEffect("button");
         if (this.block_click) return;
+        cc.log(111)
         if (this.node_panel) {
             mk.ui.closePanel(this.node_panel.name);
+            mk.event.emit('close-panel', this.node_panel.name);
         }
         const c_count = this.onComplete.length;
         for (let i = 0; i < c_count; i++) {

+ 4 - 1
assets/script/game/data/GData.ts

@@ -22,6 +22,7 @@ import RedeemData from "./module/RedeemData";
 import { MoreGameData } from "./module/MoreGameData";
 import { SettingData } from "./module/SettingData";
 import { GuideData } from "./module/GuideData";
+import GuideWeakData from "./module/GuideWeakData";
 
 /**
  * 数据集合全局类
@@ -40,7 +41,8 @@ class GData {
     public httpData: HttpData;
     public adData: AdData;
     public storageData: StorageData;
-    public guideData:GuideData;
+    public guideData: GuideData;
+    public guideWeakData: GuideWeakData;
 
     //module
     /** 领取红包奖励 */
@@ -79,6 +81,7 @@ class GData {
         this.adData = new AdData();
         this.storageData = new StorageData();
         this.guideData = new GuideData();
+        this.guideWeakData = new GuideWeakData();
 
         this.reward = new RewardData();
         this.help = new HelpData();

+ 3 - 0
assets/script/game/data/GameData.ts

@@ -1,3 +1,4 @@
+import FunBtns from "../game/FunBtns";
 import Game from "../game/Game";
 
 /**
@@ -37,6 +38,8 @@ export class GameData {
 
     /** 主页样式脚本 */
     public gameStyle: Game = null;
+    /** 入口按钮 */
+    public funBtns: FunBtns = null;
 
     /**
      * 初始化游戏数据:网络配置信息,用户信息

+ 48 - 3
assets/script/game/data/module/GuideWeakData.ts

@@ -1,11 +1,17 @@
 import { Data } from "../../../mk/data/Data";
-
-const { ccclass, property } = cc._decorator;
+import GuideWeak from "../../module/guideWeak/GuideWeak";
 /**
  * 弱引导数据
+ * - 主界面-弱引导
+    1. 弱引导启动:用户在主界面超过10秒未操作【配置】。
+    2. 弱引导效果:自动弹出以下界面中的一种:气泡红包界面、福袋界面、互推界面……【配置】
+    3. 配置需支持配置界面ID和对应的弹出概率。
+    - 关卡界面-弱引导
+    1. 弱引导启动:用户在关卡界面超过10秒未操作【配置】。
+    2. 弱引导效果:自动弹出以下界面中的一种:气泡红包界面、福袋界面、互推界面……【配置】
+    3. 配置需支持配置界面ID和对应的弹出概率。
  * @author 薛鸿潇
  */
-@ccclass
 export default class GuideWeakData extends Data {
 
     /**
@@ -14,4 +20,43 @@ export default class GuideWeakData extends Data {
     public init() {
 
     }
+    /** 测试配置 */
+    public test_config = [1, 2, 3]
+    /** 功能是否启动 */
+    public enable: boolean = false;
+    /** 引导正在运行 */
+
+    /** 样式类 */
+    public guideStyle: GuideWeak = null;
+
+    /**
+     * 玩家静默时间
+     * - 即:未进行任何操作的时间
+     */
+    public silent_time: number = 0;
+
+    /** 弱引导触发时间 */
+    public check_time: number = 10;
+
+    /** 当前打开的界面id */
+    public cur_guide_id: number = 0;
+    /** 当前打开的界面名字 */
+    public cur_guide_panel: string = null;
+
+    public initGuideId() {
+        gData.guideWeakData.cur_guide_id = 1 + 1;
+    }
+    public openPanelByBtn() {
+        const panel_id = gData.guideWeakData.cur_guide_id
+        gData.gameData.funBtns['btn' + panel_id].emit('click')
+    }
+    public panel_name_config = {
+        moreGame: 1,
+        turnable: 2,
+        none: 3,
+        pigBank: 4,
+        blessingBag: 5,
+        sign: 6,
+        redBagCash: 7,
+    }
 }

+ 1 - 1
assets/script/game/game/FunBtns.ts

@@ -22,7 +22,7 @@ export default class FunBtns extends cc.Component {
     btn_redeem: cc.Node = null;
 
     onLoad() {
-
+        gData.gameData.funBtns = this;
     }
 
     start() {

+ 7 - 0
assets/script/game/game/Game.ts

@@ -50,6 +50,7 @@ export default class Game extends cc.Component {
         this.initQiPaos();
         this.initInfo();
         this.autoOpenPanel();
+        this.runGuideWeak();
 
         // if(gData.gameData.isNewPlayer()){
         //     this.initGuide();
@@ -131,6 +132,12 @@ export default class Game extends cc.Component {
             gData.gameData.setProp(GameProp.isAutoOpenPanel, 1)
         }
     }
+    /**
+     * 开始运行弱引导
+     */
+    private runGuideWeak() {
+        gData.guideWeakData.enable = true;
+    }
 
     //测试道具获取效果
     private testFly() {

+ 64 - 19
assets/script/game/module/guideWeak/GuideWeak.ts

@@ -1,28 +1,73 @@
-// Learn TypeScript:
-//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
-// Learn Attribute:
-//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
-// Learn life-cycle callbacks:
-//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
-
-const {ccclass, property} = cc._decorator;
 
+const { ccclass, property } = cc._decorator;
+/**
+ * @author 薛鸿潇
+ */
 @ccclass
-export default class NewClass extends cc.Component {
-
-    @property(cc.Label)
-    label: cc.Label = null;
-
-    @property
-    text: string = 'hello';
+export default class GuideWeak extends cc.Component {
 
-    // LIFE-CYCLE CALLBACKS:
+    onLoad() {
+        gData.guideWeakData.guideStyle = this;
+        this.InitTouch();
+        mk.event.register('close-panel', this.onClosePanel, this);
+    }
 
-    // onLoad () {}
+    update(dt) {
+        if (!gData.guideWeakData.enable) return;
+        if (gData.guideWeakData.cur_guide_id) return;
 
-    start () {
+        gData.guideWeakData.silent_time += dt;
+        if (gData.guideWeakData.silent_time >= gData.guideWeakData.check_time) {
+            gData.guideWeakData.initGuideId();
+            gData.guideWeakData.openPanelByBtn();
+        }
+    }
 
+    /**
+     * 界面关闭
+     */
+    public onClosePanel(panel_name: string = '') {
+        cc.log(panel_name)
+        if (gData.guideWeakData.panel_name_config[panel_name] == gData.guideWeakData.cur_guide_id) {
+            gData.guideWeakData.cur_guide_id = 0;
+        }
+    }
+    /** 玩家的屏幕触摸操作 */
+    private onClickCall(touch) {
+        cc.log('弱引导计时重置');
+        gData.guideWeakData.silent_time = 0;
+    }
+    
+    ///////////////// 自定义触摸监听 /////////////////
+    private _eventManager = cc["internal"]["eventManager"];
+    private _touchListener: any;
+    private InitTouch() {
+        const EventListener = cc["EventListener"];
+        this._touchListener = EventListener.create({
+            event: EventListener.TOUCH_ONE_BY_ONE,
+            swallowTouches: false,//是否吞噬touch事件
+            owner: this.node,
+            mask: null,
+            onTouchBegan: this.onTouchStart.bind(this),
+            onTouchMoved: null,
+            onTouchEnded: this.onTouchEnded.bind(this),
+            onTouchCancelled: null,
+        });
+        this._eventManager.addListener(this._touchListener, this.node);
     }
 
-    // update (dt) {}
+    private onTouchStart(touch: cc.Touch, event: cc.Event.EventTouch): boolean {
+        // cc.log("touch start");
+        //此处必须返回true(表示接触到了节点),否则TOUCH_MOVE,TOUCH_END,TOUCH_CANCEL不触发。
+        return true;
+    }
+    private onTouchEnded(touch: cc.Touch, event: cc.Event.EventTouch): void {
+        // cc.log("touch end");
+        this.onClickCall(touch);
+    }
+    protected onDestroy(): void {
+        // super.onDestroy();
+        this._eventManager.removeListener(this._touchListener, this.node);
+        mk.event.remove('close-panel', this.onClosePanel, this);
+    }
 }