Browse Source

自定义事件统一用EventSystem类

kaka 4 years ago
parent
commit
6eb0da5d5f

+ 1 - 1
assets/script/game/data/GameData.ts

@@ -1254,7 +1254,7 @@ class PlayerProp {
         gData.gameData.init_coin = true;
         //gData.gameData.init_red_point = true;
         gData.gameData.init_wallet_redMoney = true;
-        mk.ui.invokeRefreshEventByName("refreshCoin");
+        mk.event.emit('refreshCoin');
 
         mk.data.setTAEventUser(0, 'current_redmoney_stock', this._redMoney);
     }

+ 1 - 1
assets/script/game/data/HttpData.ts

@@ -5,7 +5,7 @@
 export class HttpData {
 
     /** 服务器类型 0测试服 1正式服 2李扬服 3悍国服 */
-    public serverType: number = 1;
+    public serverType: number = 0;
 
     public getServerUrl(): string {
         switch (this.serverType) {

+ 19 - 24
assets/script/game/module/newOpenRedBag/NewOpenRedBag.ts

@@ -33,11 +33,11 @@ export default class NewOpenRedBag extends cc.Component {
     data = null
 
     private showNativeAd = false;
-    onLoad(){
+    onLoad() {
         this.showNativeAd = gData.gameData.init_hideRedBag;
     }
     start() {
-        
+
         if (gData.moreGame.init_newOpenRedBag) {
             gData.moreGame.init_newOpenRedBag = false;
             this.showElectUI();
@@ -45,18 +45,17 @@ export default class NewOpenRedBag extends cc.Component {
         this.showChangePart();
 
         this.initCashOutStyle(gData.gameData.playerProp.redMoney);
-        
-        mk.ui.registerRefreshEvent(this, this.initCashOutStyle.bind(this), "refreshCoin");
+
+        mk.event.register("refreshCoin", this.initCashOutStyle.bind(this), this);
     }
-    
+
 
     showElectUI() {
         this.sendRecommendList();
     }
 
     async sendRecommendList() {
-        if( this.sp_icon)
-        {
+        if (this.sp_icon) {
             this.sp_icon.node.active = true;
             this.data = gData.moreGame.getRandomNormal();
             if (this.data && cc.sys.os != cc.sys.OS_WINDOWS) {
@@ -70,7 +69,7 @@ export default class NewOpenRedBag extends cc.Component {
                 })
             }
         }
-    
+
         this.node_openBtn.active = false;
         this.node_getBtn.active = true;
     }
@@ -78,24 +77,22 @@ export default class NewOpenRedBag extends cc.Component {
     onEnable() {
         gData.adData.checkPopInter(InterAdType.interstitial1_click_1);
 
-        if(this.showNativeAd)
-        {
+        if (this.showNativeAd) {
             mk.ad.showNative();
-        }else{
+        } else {
             mk.ad.showBanner(BannerAdType.banner_click_3);
         }
-        
+
     }
 
     onDisable() {
-        mk.ui.removeRefreshEvent(this);
-        if(this.showNativeAd)
-        {
+        mk.event.remove('refreshCoin', this);
+        if (this.showNativeAd) {
             mk.ad.destroyNativeAd();
-        }else{
+        } else {
             mk.ad.destoryBanner();
         }
-        
+
     }
 
     /**
@@ -103,26 +100,24 @@ export default class NewOpenRedBag extends cc.Component {
      */
     private initCashOutStyle(redMoney: number = 0) {
 
-        if(gData.gameData.init_hideRedBag)
-        {
+        if (gData.gameData.init_hideRedBag) {
             this.node_cashOut.active = false;
             gData.gameData.init_hideRedBag = false;
             return;
 
         }
 
-        if(redMoney == 0)
-        {
+        if (redMoney == 0) {
             redMoney = gData.gameData.playerProp.redMoney;
         }
-        redMoney = redMoney/100;
+        redMoney = redMoney / 100;
         const cash_bar = gData.redBagCash.cash_bar;
         let cash_data = gData.redBagCash.getItemDataByIndex(cash_bar);
         if (!cash_data) return;
         const newRedMoney = redMoney > cash_data.redMoney ? cash_data.redMoney : redMoney;
         this.lbl_reward_value.string = cash_data.money / 100 + '元';
-        this.lbl_progress.string = newRedMoney + '/' + cash_data.redMoney/100;
-        const fillRange = newRedMoney / cash_data.redMoney >= 1 ? 1 : newRedMoney / (cash_data.redMoney/100);
+        this.lbl_progress.string = newRedMoney + '/' + cash_data.redMoney / 100;
+        const fillRange = newRedMoney / cash_data.redMoney >= 1 ? 1 : newRedMoney / (cash_data.redMoney / 100);
         // this.spr_cash_out.fillRange = fillRange;
         cc.tween(this.spr_cash_out).to(fillRange, { fillRange: fillRange }).start();
         if (redMoney >= cash_data.redMoney) {

+ 2 - 2
assets/script/game/module/redBagTask/RedBagTask.ts

@@ -72,7 +72,7 @@ export default class RedBagTask extends cc.Component {
 
 
         this.initCashOutStyle(gData.gameData.playerProp.redMoney);
-        mk.ui.registerRefreshEvent(this, this.initCashOutStyle.bind(this), "refreshCoin");
+        mk.event.register("refreshCoin", this.initCashOutStyle.bind(this), this);
 
     }
 
@@ -94,7 +94,7 @@ export default class RedBagTask extends cc.Component {
     }
 
     onDisable() {
-        mk.ui.removeRefreshEvent(this);
+        mk.event.remove('refreshCoin', this);
         //mk.ad.destoryBanner();
         mk.ad.destroyNativeAd();
     }

+ 5 - 6
assets/script/game/module/speedUpUI/SpeedUpUI.ts

@@ -22,7 +22,7 @@ export default class SpeedUpUI extends cc.Component {
         this.initCashOutStyle(gData.gameData.playerProp.redMoney);
         this.lbl_remainTimes.string = `今日剩余次数:${gData.gameData.playerProp.speedUpLeftTimes}`;
 
-        mk.ui.registerRefreshEvent(this, this.initCashOutStyle.bind(this), "refreshCoin");
+        mk.event.register("refreshCoin", this.initCashOutStyle.bind(this), this);
     }
 
     onEnable() {
@@ -30,7 +30,7 @@ export default class SpeedUpUI extends cc.Component {
     }
 
     onDisable() {
-        mk.ui.removeRefreshEvent(this);
+        mk.event.remove('refreshCoin', this);
         mk.ad.destoryBanner();
     }
 
@@ -49,8 +49,7 @@ export default class SpeedUpUI extends cc.Component {
      * 底部提现相关样式
      */
     private initCashOutStyle(redMoney: number = 0) {
-        if(redMoney == 0)
-        {
+        if (redMoney == 0) {
             redMoney = gData.gameData.playerProp.redMoney;
         }
         redMoney = redMoney / 100;
@@ -59,8 +58,8 @@ export default class SpeedUpUI extends cc.Component {
         if (!cash_data) return;
         const newRedMoney = redMoney > cash_data.redMoney ? cash_data.redMoney : redMoney;
         this.lbl_reward_value.string = cash_data.money / 100 + '元';
-        this.lbl_progress.string = newRedMoney + '/' + cash_data.redMoney/100;
-        const fillRange = newRedMoney / cash_data.redMoney >= 1 ? 1 : newRedMoney / (cash_data.redMoney/100);
+        this.lbl_progress.string = newRedMoney + '/' + cash_data.redMoney / 100;
+        const fillRange = newRedMoney / cash_data.redMoney >= 1 ? 1 : newRedMoney / (cash_data.redMoney / 100);
         // this.spr_cash_out.fillRange = fillRange;
         cc.tween(this.spr_cash_out).to(fillRange, { fillRange: fillRange }).start();
         if (redMoney >= cash_data.redMoney) {

+ 7 - 8
assets/script/game/module/turntable/Turnablerule.ts

@@ -25,7 +25,7 @@ export default class Turnablerule extends cc.Component {
         mk.ad.showBanner(BannerAdType.banner_click_9);
 
         this.initCashOutStyle(gData.gameData.playerProp.redMoney);
-        mk.ui.registerRefreshEvent(this, this.initCashOutStyle.bind(this), "refreshCoin");
+        mk.event.register("refreshCoin", this.initCashOutStyle.bind(this), this);
     }
 
     update(dt) {
@@ -39,18 +39,17 @@ export default class Turnablerule extends cc.Component {
      * 底部提现相关样式
      */
     private initCashOutStyle(redMoney: number = 0) {
-        if(redMoney == 0)
-        {
+        if (redMoney == 0) {
             redMoney = gData.gameData.playerProp.redMoney;
         }
-        redMoney = redMoney/100;
+        redMoney = redMoney / 100;
         const cash_bar = gData.redBagCash.cash_bar;
         let cash_data = gData.redBagCash.getItemDataByIndex(cash_bar);
         if (!cash_data) return;
         const newRedMoney = redMoney > cash_data.redMoney ? cash_data.redMoney : redMoney;
         this.lbl_reward_value.string = cash_data.money / 100 + '元';
-        this.lbl_progress.string = newRedMoney + '/' + cash_data.redMoney/100;
-        const fillRange = newRedMoney / cash_data.redMoney >= 1 ? 1 : newRedMoney / (cash_data.redMoney/100);
+        this.lbl_progress.string = newRedMoney + '/' + cash_data.redMoney / 100;
+        const fillRange = newRedMoney / cash_data.redMoney >= 1 ? 1 : newRedMoney / (cash_data.redMoney / 100);
         // this.spr_cash_out.fillRange = fillRange;
         cc.tween(this.spr_cash_out).to(fillRange, { fillRange: fillRange }).start();
         if (redMoney >= cash_data.redMoney) {
@@ -71,8 +70,8 @@ export default class Turnablerule extends cc.Component {
         // mk.ui.openPanel(path);
     }
 
-    onDisable(){
-        mk.ui.removeRefreshEvent(this);
+    onDisable() {
+        mk.event.remove('refreshCoin', this);
     }
     private onClickClose() {
         mk.audio.playEffect("button");

+ 0 - 37
assets/script/mk/system/UISystem.ts

@@ -18,11 +18,8 @@ export default class UISystem extends cc.Component {
     /** 上一个打开的界面名称 */
     private lastOpenPanelName: string = "";
 
-    private registerCallBack: Map<any, Map<string, Function>> = new Map<any, Map<string,Function>>();
-        
     onLoad() {
         mk.ui = this;
-        this.registerCallBack.clear();
     }
 
     start() {
@@ -179,40 +176,6 @@ export default class UISystem extends cc.Component {
         mk.ad.destroyNativeAd()
         mk.ad.destoryBanner()
     }
-
-    registerRefreshEvent(target:any, callBack: Function = null, name: string = "default")
-    {
-        let value = this.registerCallBack.get(target);
-        if(value)
-        {
-            value.set(name, callBack);
-        }else{
-            let m = new Map<string, Function>();
-            m.set(name, callBack);
-            this.registerCallBack.set(target, m);
-        }
-    }
-
-    invokeRefreshEventByName(name: string)
-    {
-        this.registerCallBack.forEach((value, key)=>{
-            value.forEach((callBack, k)=>{
-                if(k === name)
-                {
-                    callBack && callBack();
-                }          
-            })
-        });
-    }
-
-    removeRefreshEvent(target: any)
-    {
-        let value = this.registerCallBack.get(target);
-        if(value)
-        {
-            this.registerCallBack.delete(target);
-        }
-    }
 }
 
 /** 界面打开操作 */