| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335 |
- import SetGray from "../../component/SetGray";
- import TweenCast from "../../component/tween/TweenCast";
- import { AdFun } from "../../data/AdData";
- import { DataEventId, GameProp, VideoAdType } from "../../data/GameData";
- import CheckButton from "./CheckButton";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class WalletCashOut extends cc.Component {
- @property({ displayName: '公告组件', type: TweenCast })
- private tc: TweenCast = null;
- @property({ displayName: '进度条', type: cc.Sprite })
- private sp_progress: cc.Sprite = null;
- @property({ displayName: '红包币', type: cc.Label })
- private lbl_redMoney: cc.Label = null;
- @property({ displayName: '金额', type: cc.Label })
- private lbl_value: cc.Label = null;
- @property({ displayName: '下提示', type: cc.Label })
- private lbl_tip: cc.Label = null;
- @property({ displayName: '提现按钮文本', type: cc.Label })
- private lbl_cashOut: cc.Label = null;
- @property({ displayName: '新手描述', type: cc.Label })
- private lbl_noviceTitle: cc.Label = null;
- @property({ displayName: '新手金额', type: cc.Label })
- private lbl_noviceValue: cc.Label = null;
- @property({ displayName: '上提示', type: cc.Label })
- private lbl_tipUp: cc.Label = null;
- @property({displayName: '加现金按钮节点', type: cc.Node})
- private node_addCash: cc.Node = null;
- @property(SetGray)
- btn_cashOut: SetGray = null;
- @property(SetGray)
- btn_addProgress: SetGray = null;
- @property({ displayName: '6个选择按钮', type: CheckButton })
- private check_button: CheckButton[] = [];
- private curChooseIndex: number = -1;
- private intV: number = 0;
- private isCanCash = false;
- start() {
- // mk.ad.showNative(4);
- //this.initNoviceUI(true);
- this.initCashOutUI();
- // let data = [{}, {}, {}, {}, {}, {}];
- // for (let i = 0; i != this.check_button.length; ++i) {
- // if (i < data.length) {
- // this.check_button[i].setShowUI(data[i]);
- // } else {
- // this.check_button[i].setShowUI(null);
- // }
- // }
- }
- private initNoviceUI(isInit = false) {
- let data = gData.gameData.playerProp.userNoviceWeFareInfo;
- if (data) {
- this.lbl_noviceTitle.string = data.name + ':';
- this.sp_progress.fillRange = data.progressRate;
- let value = data.cashmoney / 100;
- let v = this.multiply(value, data.progressRate);
- mk.console.logSingle('initNoviceUI=>', v);
- let str = v.toString().split('.');
- if (str.length >= 2 && str[1].length > 4) {
- this.lbl_noviceValue.string = v.toFixed(4) + '元';
- } else {
- this.lbl_noviceValue.string = v.toString() + '元';
- }
- if(!isInit)
- {
- cc.tween(this.lbl_noviceValue.node).to(0.1, {scale: 1.2}).to(0.1, {scale: 1}).start();
- }
- this.intV = Math.round(value);
- this.lbl_tipUp.string = `进度加满后必得${this.intV}元现金`;
- this.lbl_cashOut.string = `满${this.intV}元提现`;
- if (data.progressRate >= 1) {
- this.btn_addProgress.setGray(true, true);
- } else {
- this.btn_addProgress.setGray(false, true);
- }
- }
- }
- private multiply(num1, num2) {
- const num1Changed = Number(num1.toString().replace('.', ''));
- const num2Changed = Number(num2.toString().replace('.', ''));
- const baseNum = this.digitLength(num1) + this.digitLength(num2);
- return num1Changed * num2Changed / Math.pow(10, baseNum);
- }
- private digitLength(num) {
- const eSplit = num.toString().split(/[eE]/);
- const len = (eSplit[0].split('.')[1] || '').length - (+(eSplit[1] || 0));
- return len > 0 ? len : 0;
- }
- private initCashOutUI() {
- let data = gData.gameData.funOpenData;
- if(data[10] == '1')
- {
- let cashTimes = gData.gameData.getProp(GameProp.cashTimes);
- if(!cashTimes){
- cashTimes = 0;
- }
- this.node_addCash.active = cashTimes >= parseInt(gData.gameData.configs.ServerConfig.CashIncrease);
- }else{
- this.node_addCash.active = false;
- }
-
- if (gData.gameData.configs.CashCfg) {
- let arr = [];
- let data = gData.gameData.configs.CashCfg
- for (let i = 0; i != this.check_button.length; ++i) {
- if (i < data.length) {
- let isRemainTimes = this.check_button[i].setShowUI(data[i]);
- arr.push(data[i].money / 100);
- if (isRemainTimes && this.curChooseIndex == -1) {
- this.curChooseIndex = i;
- }
- } else {
- this.check_button[i].setShowUI(null);
- }
- }
- this.tc.setMoneyArr(arr);
- this.initTip();
- }
- }
- private initTip() {
- this.lbl_redMoney.string = (gData.gameData.playerProp.redMoney/100).toString();
- this.lbl_value.string = (gData.gameData.playerProp.redMoney / 1000000).toFixed(3);
- if (this.curChooseIndex != -1) {
- let data = gData.gameData.configs.CashCfg[this.curChooseIndex];
- let isEnough = gData.gameData.playerProp.redMoney - data.redMoney;
- if (isEnough >= 0) {
- if (this.curChooseIndex != -1) {
- this.isCanCash = true;
- this.btn_cashOut.setGray(false, true);
- } else {
- this.isCanCash = false;
- this.btn_cashOut.setGray(true, true);
- }
- let needV = data.money / 100;
- let haveV = (gData.gameData.playerProp.redMoney / 1000000).toFixed(3) + '元';
- this.lbl_tip.string = `需要${needV}元,当前有` + haveV;
- } else {
- this.isCanCash = false;
- this.btn_cashOut.setGray(true, true);
- let needV = data.money / 100;
- let haveV = (gData.gameData.playerProp.redMoney / 1000000).toFixed(3) + '元';
- this.lbl_tip.string = `需要${needV}元,当前只有` + haveV;
- }
- } else {
- this.isCanCash = false;
- this.btn_cashOut.setGray(true, true);
- this.lbl_tip.string = '';
- }
- }
- update(dt) {
- if (gData.walletCashOutData.init_novice) {
- this.initNoviceUI();
- gData.walletCashOutData.init_novice = false;
- }
- if (gData.walletCashOutData.adData) {
- gData.reward.data = gData.walletCashOutData.adData.videoRedMoney.videoRewardList;
- mk.ui.openPanel("module/reward/reward");
- gData.walletCashOutData.adData = null;
- }
- if (gData.gameData.init_wallet_redMoney) {
- this.initTip();
- gData.gameData.init_wallet_redMoney = false;
- }
- if (gData.walletCashOutData.init_cashOut) {
- let isRemainTimes = this.check_button[this.curChooseIndex].setRemaineTimes();
- if (isRemainTimes) {
- this.curChooseIndex = -1;
- this.isCanCash = false;
- this.btn_cashOut.setGray(true, true);
- this.lbl_tip.string = '';
- }
- gData.walletCashOutData.init_cashOut = false;
- }
- }
- private clickChooseBtn(event, customEvenData) {
- mk.audio.playEffect('button');
- let id = parseInt(customEvenData);
- if (id == this.curChooseIndex) {
- return;
- }
- if (this.check_button[id].getIsCanNotChoose()) {
- return;
- }
- this.check_button[id].setIsChoose(true);
- this.check_button[this.curChooseIndex].setIsChoose(false);
- this.curChooseIndex = id;
- this.initTip();
- // for (let i = 0; i != this.check_button.length; ++i) {
- // if (i == this.curChooseIndex) {
- // this.check_button[i].setIsChoose(true);
- // } else {
- // this.check_button[i].setIsChoose(false);
- // }
- // }
- }
- private clickCashOutBtn() {
- mk.audio.playEffect("button");
- if (this.isCanCash) {
- // if (this.checkShowTip()) {
- // mk.tip.pop('请先提现完前一档次数');
- // } else
- {
- if (cc.sys.isNative) {
- if (!gData.loginData.isAuth) {
- // JsbSystem.WxAuth();
- gData.gameData.authUIType = 0;
- mk.ui.openPanel('module/authUI/authUI');
- return;
- }
- }
-
- gData.adData.checkShowFullInter(1);
- //this.check_button[this.curChooseIndex].setIsCanNotChoose();
- gData.walletCashOutData.HttpCashOut2(this.curChooseIndex + 1);
- }
- }else{
- mk.tip.pop('收获农作物可获得红包币');
- }
- }
- private checkShowTip() {
- if (this.curChooseIndex >= 1) {
- let data = gData.gameData.configs.CashCfg[this.curChooseIndex - 1];
- let haveTimes = gData.gameData.playerProp.getRedMoneyCashOutTimesByIndex(data.index);
- if (data.cashFrequency > haveTimes) {
- return true;
- }
- return false;
- }
- return false;
- }
- private clickAddProgressBtn() {
- mk.audio.playEffect("button");
- mk.ad.videoAdType = VideoAdType.video_init_2;
- // 看广告
- mk.ad.watchAd((success: boolean) => {
- mk.console.log("watchAD:" + success);
- if (success) {
- gData.adData.watchVideo(null);
- gData.walletCashOutData.addProgress();
- }
- });
- }
- private clickAddCashBtn() {
- mk.audio.playEffect("button");
- mk.ad.videoAdType = VideoAdType.video_init_3;
- // 看广告
- mk.ad.watchAd((success: boolean) => {
- mk.console.log("watchAD:" + success);
- if (success) {
- gData.adData.watchVideo(AdFun.cashOutAddCash);
- // mk.ad.destroyNativeAd();
- }
- });
- }
- private clickEnoughCashOutBtn() {
- mk.audio.playEffect("button");
- let data = gData.gameData.playerProp.userNoviceWeFareInfo;
- if (data) {
- if (data.progressRate >= 1) {
- let v = Math.round(this.intV * 100);
- gData.walletCashOutData.HttpCashOut(v);
- } else {
- mk.tip.pop(`满${this.intV}元提现`);
- }
- }
- }
- private clickCloseBtn() {
- mk.audio.playEffect("button");
- }
- onDisable() {
- let pop = gData.adData.checkShowFullInter(4);
- if(pop){
- gData.moreGame.openType = 1;
- mk.data.sendDataEvent(DataEventId.htRedBag_scene, "关闭提现界面");
- }
- }
- }
|