| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352 |
- import Util from "../../../before/util/Util";
- import JsbSystem from "../../../mk/system/JsbSystem";
- import SetGray from "../../component/SetGray";
- import { BannerAdType, DataEventId, GameProp } from "../../data/GameData";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class RedBagTask extends cc.Component {
- @property({ displayName: '数字组', type: cc.Label })
- private lbl_value: cc.Label[] = [];
- @property({ displayName: '任务进度条', type: cc.Sprite })
- private sp_taskProgress: cc.Sprite = null;
- @property({ displayName: '任务进度文本', type: cc.Label })
- private lbl_taskProgress: cc.Label = null;
- @property({ displayName: '按钮动画', type: cc.Animation })
- private openBtn_ani: cc.Animation = null;
- @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({ type: cc.Node, displayName: '显示金额节点' })
- private node_value: cc.Node = null;
- @property({ type: cc.Node, displayName: '任务节点' })
- private node_task: cc.Node = null;
- @property({ type: cc.Label, displayName: '动画显示文字' })
- private lbl_Ani: cc.Label = null;
- @property({ type: cc.Label, displayName: '任务数量' })
- private lbl_taskNum: cc.Label = null;
- @property(cc.Node)
- private node_videoIcon: cc.Node = null;
- @property(cc.Node)
- private node_hand: cc.Node = null;
- private isShowNewTask = false;
- private num = 0;
- private delayTime = 0;
- private times = 0;
- private maxNum = 14;
- private isCanCash = false;
- private isRefreshTask = false;
- private btnCD = 0;
- private startTimes = false;
- start() {
- mk.console.logSingle('redBagTask=>', gData.gameData.playerProp.userFarmTaskInfo);
- if (!gData.gameData.playerProp.userFarmTaskInfo) {
- return;
- }
- gData.gameData.init_redBagTask = false;
- this.maxNum = gData.gameData.playerProp.userFarmTaskInfo.taskCount;
- //this.isShowNewTask = gData.gameData.init_redBagTask;
- if (this.isShowNewTask) {
- this.showNewTaskUI();
- } else {
- //this.node_value.active = true;
- //this.node_task.active = true;
- //this.node_cash.node.active = true;
- this.initTaskProgressUI();
- this.showChangePart();
- }
- this.initCashOutStyle(gData.gameData.playerProp.redMoney);
- mk.event.register("refreshCoin", this.initCashOutStyle.bind(this), this);
- }
- private showNewTaskUI() {
- this.node_value.active = false;
- this.node_task.active = false;
- this.openBtn_ani.node.active = false;
- this.lbl_Ani.node.active = true;
- //gData.gameData.init_redBagTask = false;
- gData.gameData.init_task = true;
- this.node_hand.active = false;
- //gData.gameData.setProp(GameProp.redBagTaskRefresh, gData.gameData.init_redBagTask)
- }
- onEnable() {
- //mk.ad.showBanner(BannerAdType.banner_click_2);
- mk.ad.showNative();
- }
- onDisable() {
- mk.event.remove('refreshCoin', this);
- //mk.ad.destoryBanner();
- mk.ad.destroyNativeAd();
- }
- update(dt) {
- if (gData.reward.add_redbag_value) {
- this.initCashOutStyle(gData.gameData.playerProp.redMoney + gData.reward.add_redbag_value);
- }
- if (this.isShowNewTask) {
- if (this.delayTime <= 0.6) {
- this.delayTime += dt;
- } else {
- this.times += 1;
- if (this.times == 2) {
- this.times = 0;
- this.num += 1;
- let randNum = mk.math.random(1, this.maxNum);
- this.lbl_Ani.string = randNum.toString();
- if (this.num == 14) {
- this.lbl_Ani.string = this.maxNum.toString();
- this.isShowNewTask = false;
- this.lbl_Ani.node.color = new cc.Color(255, 218, 49);
- let clone = cc.instantiate(this.lbl_Ani.node);
- clone.parent = this.lbl_Ani.node.parent;
- cc.tween(clone).to(0.8, { scale: 4.0, opacity: 0 }).call(() => {
- clone.active = false;
- let worldPos = this.lbl_taskNum.node.parent.convertToWorldSpaceAR(this.lbl_taskNum.node.position);
- let pos = this.lbl_taskNum.node.parent.parent.convertToNodeSpaceAR(worldPos);
- cc.tween(this.lbl_Ani).to(0.6, { fontSize: 40 }).start();
- cc.tween(this.lbl_Ani.node).to(0.6, { position: pos }, cc.easeSineOut()).call(() => {
- this.lbl_Ani.node.active = false;
- this.node_task.active = true;
- cc.tween(this.node_task).by(0.16, { y: -6 }).by(0.1, { y: 6 }).start();
- }).start();
- this.node_value.active = true;
- this.node_value.scale = 0;
- cc.tween(this.node_value).to(0.5, { scale: 1.3 }, cc.easeSineOut()).to(0.1, { scale: 1 }).call(() => {
- this.openBtn_ani.node.active = true;
- // mk.guide.open(2);
- this.initTaskProgressUI();
- this.showChangePart();
- }).start();
- }).start();
- }
- }
- }
- }
- if (gData.gameData.init_redBagTask) {
- gData.gameData.init_redBagTask = false;
- gData.gameData.init_productTask = true;
- this.isRefreshTask = true;
- this.showNewTaskUI();
- this.isShowNewTask = true;
- }
- if(this.startTimes)
- {
- this.btnCD += dt;
- if(this.btnCD >= 2)
- {
- this.startTimes = false;
- this.btnCD = 0;
- }
- }
- }
- private initTaskProgressUI() {
- if (gData.gameData.playerProp.userFarmTaskInfo) {
- let com = gData.gameData.playerProp.userFarmTaskInfo.completeCount;
- let count = gData.gameData.playerProp.userFarmTaskInfo.taskCount;
- let per = com / count;
- if (!this.isRefreshTask) {
- cc.tween(this.sp_taskProgress).delay(0.2).to(0.2, { fillRange: per }, {
- onUpdate: () => {
- let num = Math.round(this.sp_taskProgress.fillRange * count);
- this.lbl_taskProgress.string = `${num}/${count}`;
- }
- }).call(() => {
- this.lbl_taskProgress.string = `${com}/${count}`;
- }).start();
- } else {
- this.sp_taskProgress.fillRange = per;
- this.lbl_taskProgress.string = `${com}/${count}`;
- }
- this.lbl_taskNum.string = count.toString();
- let gray = this.openBtn_ani.getComponent(SetGray);
- if (gray && com < count) {
- gray.setGray(true, true);
- //this.openBtn_ani.getComponent(cc.Button).interactable = true;
- }
- this.isCanCash = com >= count;
- this.node_hand.active = this.isCanCash;
- if (this.isCanCash && gData.adData.checkShowVideoIcon()) {
- this.node_videoIcon.active = true;
- } else {
- this.node_videoIcon.active = false;
- }
- }
- }
- showChangePart() {
- //this.changePart.active = true
- let len = this.lbl_value.length;
- this.schedule(() => {
- for (var i = 0; i < len; i++) {
- let ran = Util.rnd(0, 9);
- this.lbl_value[i].string = `${ran}`;
- }
- }, 0.1)
- }
- /**
- * 底部提现相关样式
- */
- 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 clickVideoBtn() {
- }
- private clickGetRewardBtn() {
- //gData.receiptNotice.receip_rmb = gData.blessingBag.rbNum;
- //mk.ui.openPanel('module/newNotice/newNotice');
- if(!this.startTimes)
- {
- this.startTimes = true;
- this.btnCD = 0;
- }else{
- return;
- }
- mk.audio.playEffect("button");
- if (this.isCanCash) {
- if (cc.sys.isNative) {
- if (!gData.loginData.isAuth) {
- // JsbSystem.WxAuth();
- gData.gameData.authUIType = 0;
- mk.ui.openPanel('module/authUI/authUI');
- return;
- }
- }
- this.httpCashOut();
- } else {
- mk.tip.pop('完成任务即可提现');
- }
- }
- private async httpCashOut() {
- // gData.cashPro.openCashPro(0);
- let data = {};
- let response = await mk.http.sendData('farmTask/farmTaskCash', data);
- mk.console.logSingle('redBagTask=>', response);
- if (response.errcode != 0) {
- // gData.cashPro.init_fail = true;
- if(response.errcode == 405)
- {
- mk.tip.pop("今日提现额度已到上限,请明天再提现");
- mk.data.sendDataEvent(DataEventId.cashLimit, "提现触发上限");
- }
- return;
- }
- mk.console.logSingle('redBagTaskhttpCashOut=>', response.data.userFarmTaskInfo);
- gData.gameData.playerProp.userFarmTaskInfo = response.data.userFarmTaskInfo;
- gData.gameData.playerProp.completeFarmTaskTimes = response.data.completeFarmTaskTimes;
- mk.event.emit("refreshBubble");
-
- mk.data.setTAEventUser(0, 'Cumulative_task', gData.gameData.playerProp.completeFarmTaskTimes);
- //gData.gameData.init_redBagTask = true;
- gData.gameData.checkTaskFinishUnLock();
- gData.gameData.init_task = true;
- this.maxNum = gData.gameData.playerProp.userFarmTaskInfo.taskCount;
- this.num = 0;
- this.delayTime = 0;
- this.times = 0;
- //this.showNewTaskUI();
- //this.isShowNewTask = true;
- // gData.cashPro.cashPro_money = response.data.cashMoney;
- // gData.cashPro.init_success = true;
-
- gData.receiptNotice.receip_rmb = response.data.cashMoney;
- mk.ui.openPanel('module/newNotice/newNotice');
- mk.data.sendDataEvent(DataEventId.Sundry, '任务红包提现成功');
- let value = mk.storage.getStorage('guide_harvest');
- if (!value) {
- mk.storage.setStorage('guide_harvest', 1);
- mk.data.sendXYEvent('guide_harvest', '首次领取任务红包');
- }
- gData.gameData.doPointToXYLogic();
- //gData.gameData.addCashOutTimes();
- gData.adData.checkPopCashFull();
- //gData.safeDepositBoxData.updateQipao();
- gData.cashNormal.getRecord();
- }
- /**
- * 提现操作
- */
- private clickCashOut() {
- mk.audio.playEffect("button");
- gData.reward.addReward();
- //mk.ui.closePanel(this.node.name);
- let path = 'module/newCashUI/walletCashOut';
- mk.ui.openPanel(path);
- }
- private clickCloseBtn() {
- mk.audio.playEffect("button");
- }
- onDestroy(){
- //gData.adData.checkPopInter(InterAdType.interstitial1_click_5);
- gData.gameData.popTableScreenADLogic(4);
- }
- }
|