/** * @description 福袋界面类 * @author kaka */ import SetGray from "../../component/SetGray"; import TableView from "../../component/TableView"; import { DataEventId, VideoAdType } from "../../data/GameData"; const { ccclass, property } = cc._decorator; @ccclass export default class BlessingBag extends cc.Component { @property(cc.RichText) txtRemaindAdNum: cc.RichText = null; @property(cc.Prefab) blassingBagItem: cc.Prefab = null; @property(cc.Node) itemContent: cc.Node = null; @property(cc.Node) btnAd: cc.Node = null; @property(cc.Node) adIcon: cc.Node = null; @property(cc.Node) node_xiabiao: cc.Node = null; @property(TableView) tableview: TableView = null; @property(cc.Button) video_btn: cc.Button = null; private scroll_view: cc.ScrollView = null!; /**红包页面类型 1 大额 2 任务*/ private rbPanelType: number = 0; private adrbArray = []; private isPlayInitAni = true; onLoad() { } onEnable() { this.isPlayAni = false; this.isPlayInitAni = true; gData.blessingBag.isPlayAniUpdate = false; gData.blessingBag.init_videoRbData = true; } update(dt) { this.PlayMoneyAniUpdate(dt); if (gData.blessingBag.init_videoRbData) { this.UpdateInfo(); } if (gData.blessingBag.init_openRb) { //this.OpenRbPanel(gData.blessingBag.taskRbId, gData.blessingBag.rbNum); if (cc.sys.isNative && !gData.loginData.isAuth) { // JsbSystem.WxAuth(); mk.ui.openPanel('module/authUI/authUI'); return; } gData.blessingBag.HttpCashTask(); } } lateUpdate() { gData.blessingBag.init_videoRbData = false; gData.blessingBag.init_openRb = false; } UpdateInfo() { let data = gData.blessingBag.videoRbData; if (!data) { return } let isAllComplete = true; for (let i = 0; i != data.welFareTaskList.length; ++i) { if (data.welFareTaskList[i].progressRate < 1) { isAllComplete = false; break; } } //if(isAllComplete || data.leftVideoTimes <= 0) if (isAllComplete) { this.video_btn.interactable = false; let cmp = this.video_btn.getComponent(SetGray); if (cmp) { cmp.setGray(true); } } { if (!isAllComplete && !this.video_btn.interactable) { this.video_btn.interactable = true; let cmp = this.video_btn.getComponent(SetGray); if (cmp) { cmp.setGray(false); } } } this.txtRemaindAdNum.string = "今日剩余次数:" + data.leftVideoTimes + ""; //this.adIcon.active = data.isVideo != 1; if (this.adrbArray.length < 4) { this.adrbArray = []; for (let i = 0; i < data.welFareTaskList.length; i++) { let obj = { data: data.welFareTaskList[i], isPlayAniUpdate: gData.blessingBag.isPlayAniUpdate, isPlayInitAni: this.isPlayInitAni } this.adrbArray.push(obj); } this.itemContent.emit('srollview-init', this.adrbArray); this.scroll_view = this.itemContent.getComponent(cc.ScrollView); this.scroll_view.vertical = false; cc.tween(this.node).delay(0.1).call(() => { let allItem = this.tableview.getFrontPositionItemByCount(5); for (let i = 0; i != allItem.length; ++i) { //allItem[i].active = true; let posY = allItem[i].position.y allItem[i].y = posY - 600; cc.tween(allItem[i]).delay(i * 0.1).to(0.3, { y: posY }, cc.easeSineOut()).start(); } }).start(); } else { this.adrbArray = []; for (let i = 0; i < data.welFareTaskList.length; i++) { let obj = { data: data.welFareTaskList[i], isPlayAniUpdate: gData.blessingBag.isPlayAniUpdate, isPlayInitAni: this.isPlayInitAni } this.adrbArray.push(obj); } //刷新 this.itemContent.emit('srollview-update', this.adrbArray); } this.isPlayInitAni = false; gData.blessingBag.isPlayAniUpdate = false; } private isPlayAni = false; targetProgress: number = 0; delta: number = 0; curValue: number = 0; curTime: number = 0; totalTime: number = 0; lastNum: number = 0; PlayMoneyAni(time) { this.totalTime = time; this.delta = (this.targetProgress - this.lastNum) / time; this.curValue = this.lastNum; this.curTime = 0; this.isPlayAni = true; } PlayMoneyAniUpdate(dt) { if (this.isPlayAni) { if (this.curTime < this.totalTime) { this.curTime += dt; this.curValue += this.delta * dt; if (this.curValue >= this.targetProgress) { this.isPlayAni = false; this.curValue = this.targetProgress; this.lastNum = this.targetProgress; } } else { this.isPlayAni = false; this.curTime = this.totalTime; this.curValue = this.targetProgress; this.lastNum = this.targetProgress; } } } Click_AdProgressBtn() { mk.audio.playEffect("button"); // if (gData.blessingBag.videoRbData.isVideo == 1) { // //免费加进度 // gData.blessingBag.addProgress(); // } else { // if (cc.sys.isNative && !gData.loginData.isAuth) { // // JsbSystem.WxAuth(); // mk.ui.openPanel('module/authUI/authUI'); // return; // } if (gData.blessingBag.videoRbData.leftVideoTimes > 0) { mk.ad.videoAdType = VideoAdType.video_init_15; mk.ad.watchAd(async (success: boolean) => { mk.console.log("watchAD:" + success); if (success) { await gData.adData.watchVideo(null); gData.blessingBag.addProgress(); } }); } else { mk.tip.pop('今日观看次数已用完'); } } } /** * 打开红包页面 * @param type 打开红包类型 1 大额红包 2 任务红包 * @param num 红包金额 */ OpenRbPanel(type: number, num: number) { //this.rbPanelType = type; // this.txtRbNum.string = num + "元"; // this.nodeRb.active = true; // this.rbOpenBtn.active = true; //把打开原来的红包界面操作取消掉,直接提现 gData.blessingBag.HttpCashTask(); } CheckCashRedCode() { let data = gData.blessingBag.videoRbData; if (data.redMoneyCode.length > 0) { for (let i = 0; i < data.redMoneyCode.length; i++) { if (data.preLargeAmountCashId == data.redMoneyCode[i].RedMoneyId) { if (data.redMoneyCode[i].RedMoneyCode != "") { gData.redCodeData.openRedCode(data.redMoneyCode[i].VideoCashBig, data.redMoneyCode[i].RedMoneyCode); } else { mk.tip.pop('提现成功'); } return; } } } mk.tip.pop('请先完成提现任务'); } async Click_CashBtn() { mk.audio.playEffect("button"); if (gData.blessingBag.videoRbData.cumulativeAmount >= gData.blessingBag.videoRbData.requestAmount) { let response = await gData.blessingBag.HttpCashBig(); if (response && response.data.code == 1) { //弹红包码界面 this.CheckCashRedCode(); gData.cashNormal.getRecord();// 请求新的提现记录 } else { mk.tip.pop('请先完成提现任务'); } } else { mk.tip.pop("累计到" + gData.blessingBag.videoRbData.requestAmount + "元才可提现"); } } /** 点击帮助回调 */ clickHelpCallBack() { let des = "1、观看大量视频可以快速增加提现进度。\n\n2、提现进度到100%,可以提现对应档位的红包。\n\n3、余额累计满一定金额,可以申请大额提现。"; gData.help.des = des; } Click_InitData() { mk.audio.playEffect("button"); gData.blessingBag.HttpInitAdRbData(); } /** 点击关闭 */ onClickClose() { } onDisable() { let pop = gData.adData.checkShowFullInter(4); if(pop){ gData.moreGame.openType = 2; mk.data.sendDataEvent(DataEventId.htRedBag_scene, "关闭福利界面"); } } onDestroy(){ //gData.adData.checkPopInter(InterAdType.interstitial1_click_10); gData.gameData.popTableScreenADLogic(9); } }