| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293 |
- import GamePlay from "../../../before/GamePlay";
- import Util from "../../../before/util/Util";
- import JsbSystem from "../../../mk/system/JsbSystem";
- import { AdFun } from "../../data/AdData";
- import { BannerAdType, DataEventId, InterFullAdType } from "../../data/GameData";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class NewOpenRedBag extends cc.Component {
- @property({ type: cc.Label, displayName: '标题' })
- labTitle: cc.Label = null;
- @property({ displayName: '数字组', type: cc.Label })
- private lbl_value: cc.Label[] = [];
- @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.Sprite)
- private sp_icon: cc.Sprite = null;
- @property(cc.Node)
- private node_openBtn: cc.Node = null;
- @property(cc.Node)
- private node_getBtn: cc.Node = null;
- @property(cc.Node)
- private node_cashOut: cc.Node = null;
- data = null
- private showNativeAd = false;
- onLoad() {
- this.showNativeAd = gData.gameData.init_hideRedBag;
- }
- start() {
- if (gData.moreGame.init_newOpenRedBag) {
- gData.moreGame.init_newOpenRedBag = false;
- this.showElectUI();
- this.labTitle.string = '恭喜发财';
- }
- else {
- if (gData.adData.curRedBagAdFun == AdFun.harvest) {
- this.labTitle.string = '收获红包';
- }
- else if (gData.adData.curRedBagAdFun == AdFun.bubble) {
- this.labTitle.string = '气泡红包';
- }
- else if (gData.adData.curRedBagAdFun == AdFun.settlement) {
- this.labTitle.string = '通关红包';
- }
- }
- this.showChangePart();
- this.initCashOutStyle(gData.gameData.playerProp.redMoney);
- mk.event.register("refreshCoin", this.initCashOutStyle.bind(this), this);
- }
- showElectUI() {
- this.sendRecommendList();
- }
- async sendRecommendList() {
- 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) {
- cc.loader.load(this.data.icon, (err, res) => {
- if (err) {
- console.log('err:', err);
- return;
- }
- let tex: cc.Texture2D = res as cc.Texture2D;
- this.sp_icon.spriteFrame = new cc.SpriteFrame(tex);
- })
- }
- }
- this.node_openBtn.active = false;
- this.node_getBtn.active = true;
- }
- onEnable() {
- //gData.adData.checkPopInter(InterAdType.interstitial1_click_1);
- gData.gameData.popTableScreenADLogic(0);
- if (this.showNativeAd) {
- mk.ad.showNative();
- } else {
- mk.ad.showBanner(BannerAdType.banner_click_3);
- }
- }
- onDisable() {
- mk.event.remove('refreshCoin', this);
- if (this.showNativeAd) {
- mk.ad.destroyNativeAd();
- } else {
- mk.ad.destoryBanner();
- }
- }
- /**
- * 底部提现相关样式
- */
- private initCashOutStyle(redMoney: number = 0) {
- if (gData.gameData.init_hideRedBag) {
- this.node_cashOut.active = false;
- gData.gameData.init_hideRedBag = false;
- return;
- }
- 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 showWatchAdReward() {
- if (gData.reward.adData) {
- this.unschedule(this.onChangeSchedule);
- let v = '0.30';
- v = v.replace('.', '');
- let c = v.split('');
- for (let i = 0; i != this.lbl_value.length; ++i) {
- if (i < c.length) {
- this.lbl_value[i].string = c[i];
- } else {
- this.lbl_value[i].string = '0';
- }
- }
- }
- }
- // update() {
- // if (gData.harvestData.init_reward) {
- // gData.harvestData.init_reward = false;
- // //奖励弹窗
- // gData.reward.adData = gData.harvestData.adData;
- // mk.ui.openPanel('module/reward/reward');
- // }
- // }
- showChangePart() {
- //this.changePart.active = true
- this.schedule(this.onChangeSchedule, 0.1)
- }
- onChangeSchedule() {
- let len = this.lbl_value.length;
- for (var i = 0; i < len; i++) {
- let ran = Util.rnd(0, 9);
- this.lbl_value[i].string = `${ran}`;
- }
- }
- private async clickOpenBtn() {
- mk.audio.playEffect("button");
- if (this.sp_icon.node.active) {
- this.creatorDownLoadTask();
- switch (gData.moreGame.openType) {
- case 0:
- mk.data.sendDataEvent(DataEventId.htRedBag_eject, "点击可收获-领取");
- break;
- case 1:
- mk.data.sendDataEvent(DataEventId.htRedBag_eject, "关闭提现界面-领取");
- break;
- case 2:
- mk.data.sendDataEvent(DataEventId.htRedBag_eject, "关闭福利界面-领取");
- break;
- case 3:
- mk.data.sendDataEvent(DataEventId.htRedBag_eject, "关闭农场等级奖励界面-领取");
- break;
- }
- gData.moreGame.openType = -1;
- mk.ui.closePanel(this.name);
- }
- else {
- if (gData.adData.curRedBagAdFun == AdFun.harvest) {
- //第一次免费领取红包
- if (gData.gameData.playerProp.isFirstRedMoney == 1) {
- gData.gameData.playerProp.isFirstRedMoney = 0;
- let response = await mk.http.sendData('getFreeRedMoney', {});
- if (response.errcode != 0) {
- mk.tip.pop(response.errmsg);
- return;
- }
- gData.reward.adData = {};
- gData.reward.adData.videoRedMoney = {};
- gData.reward.adData.videoRedMoney.videoRewardList = [{ rewardType: 1, rewardNum: response.data.freeRedMoney }];
- gData.reward.callback = gData.harvestData.call;
- // gData.gameData.gameStyle.doCropFlyLogic(gData.harvestData.plantID);
- mk.ui.openPanel('module/reward/reward');
- mk.ui.closePanel(this.node.name);
- return;
- }
- }
- mk.ad.watchAd(async (success: boolean) => {
- mk.console.log("watchAD:" + success);
- if (success) {
- await gData.adData.watchVideo(gData.adData.curRedBagAdFun, (data) => {
- if (gData.adData.curRedBagAdFun == AdFun.bubble || gData.adData.curRedBagAdFun == AdFun.settlement) {
- gData.reward.adData = data;
- mk.ui.openPanel('module/reward/reward');
- }
- //广告类型在界面打开时赋值
- mk.ui.closePanel(this.node.name);
- });
- }
- else {
- if (gData.adData.curRedBagAdFun == AdFun.settlement) {
- GamePlay.Inst.nextLevel();
- }
- gData.adData.curRedBagAdFun = null;
- mk.ui.closePanel(this.node.name);
- }
- });
- }
- }
- private clickCloseBtn() {
- gData.adData.checkShowFullInter(1, InterFullAdType.interstitial2_init_1);
- if (gData.adData.curRedBagAdFun == AdFun.settlement) {
- GamePlay.Inst.nextLevel();
- }
- gData.adData.curRedBagAdFun = null;
- mk.ui.closePanel(this.node.name);
- }
- cool = false
- creatorDownLoadTask() {
- if (!CC_JSB) {
- gData.moreGame.popNodeGetRedBag();
- mk.ui.closePanel(this.node.name);
- return;
- }
- if (this.cool) {
- return
- }
- this.cool = true
- mk.data.sendDataEvent(DataEventId.hutuiFunction, "互推插屏下载");
- if (this.data.appType == 1) {
- if (!JsbSystem.ifCanStartGame(this.data.packageName, true)) {
- gData.moreGame.createNewTask(this.data, 1)
- }
- }
- else if (this.data.appType == 2) {
- cc.sys.openURL(this.data.recommendLink);
- }
- mk.ui.closePanel(this.node.name);
- gData.moreGame.popNodeGetRedBag();
- }
- }
|