import { AdFun } from "../../data/AdData"; import { BannerAdType, VideoAdType } from "../../data/GameData"; const { ccclass, property } = cc._decorator; @ccclass export default class SpeedUpUI extends cc.Component { @property(cc.Label) private lbl_reward_value: cc.Label = null; @property(cc.Sprite) private spr_cash_out: cc.Sprite = null; @property(cc.Label) private lbl_progress: cc.Label = null; @property(cc.Animation) private node_cash: cc.Animation = null; @property(cc.Label) private lbl_remainTimes: cc.Label = null; start() { this.initCashOutStyle(gData.gameData.playerProp.redMoney); this.lbl_remainTimes.string = `今日剩余次数:${gData.gameData.playerProp.speedUpLeftTimes}`; mk.event.register("refreshCoin", this.initCashOutStyle.bind(this), this); } onEnable() { mk.ad.showBanner(BannerAdType.banner_click_5); } onDisable() { mk.event.remove('refreshCoin', this); mk.ad.destoryBanner(); } update(dt) { if (gData.reward.add_redbag_value) { this.initCashOutStyle(gData.gameData.playerProp.redMoney + gData.reward.add_redbag_value); } if (gData.gameData.init_speedup) { gData.gameData.init_speedup = false; this.lbl_remainTimes.string = `今日剩余次数:${gData.gameData.playerProp.speedUpLeftTimes}`; } } /** * 底部提现相关样式 */ private initCashOutStyle(redMoney: number = 0) { if (redMoney == 0) { redMoney = gData.gameData.playerProp.redMoney; } 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.spr_cash_out.fillRange = fillRange; cc.tween(this.spr_cash_out).to(fillRange, { fillRange: fillRange }).start(); if (redMoney >= cash_data.redMoney) { this.node_cash.play(); } else { this.node_cash.stop(); } } /** * 提现操作 */ private clickCashOut() { mk.audio.playEffect("button"); gData.reward.addReward(); mk.ui.closePanel(this.node.name); // let path = 'module/redBagCash/redBagCash'; // mk.ui.openPanel(path); } private clickWatchVideoBtn() { mk.audio.playEffect("button"); if (gData.gameData.playerProp.speedUpLeftTimes <= 0) { mk.tip.pop('今日加速次数已用完'); return; } if (gData.gameData.checkCanSpeedUp()) { mk.ui.closePanel(this.node.name); mk.ad.videoAdType = VideoAdType.video_init_14; mk.ad.watchAd(async (success) => { if (success) { gData.adData.watchVideo(AdFun.farmSpeedUp); let response = await mk.http.sendData('farmSpeedUp', {}); if (response && response.errcode == 0) { gData.gameData.playerProp.speedUpLeftTimes = response.data.speedUpLeftTimes; gData.gameData.init_speedup = true; } gData.gameData.setHarvest(); mk.tip.pop('加速成功!'); //gData.gameData.popTableScreenADLogic(12); } }) } else { mk.tip.pop('没有可加速的物品'); } } private clickCloseBtn() { mk.audio.playEffect("button"); } onDestroy(){ //gData.adData.checkPopInter(InterAdType.interstitial1_click_9); gData.gameData.popTableScreenADLogic(8); } }