| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- // Learn TypeScript:
- // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
- // Learn Attribute:
- // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
- // Learn life-cycle callbacks:
- // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
- import { EVENT_TYPE } from "../../game/data/GameData";
- import GameConst from "../data/GameConst";
- import PlayerConst from "../data/PlayerConst";
- import EffectMgr from "../mgr/EffectMgr";
- import GameMgr, { UI_NAME } from "../mgr/GameMgr";
- import HttpMgr from "../mgr/HttpMgr";
- import GameLogic from "../util/GameLogic";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class DailyCashOutUI extends cc.Component {
- @property(cc.Node)
- node_rectBg: cc.Node = null;
- @property(cc.Label)
- label_videoTaskTip: cc.Label = null;
- @property(cc.Label)
- label_videoTaskProgress: cc.Label = null;
- @property(cc.ProgressBar)
- bar_videoTaskProgress: cc.ProgressBar = null;
- @property(cc.Label)
- label_timeTaskTip: cc.Label = null;
- @property(cc.Label)
- @property(cc.Label)
- label_timeTaskProgress: cc.Label = null;
- @property(cc.ProgressBar)
- bar_timeTaskProgress: cc.ProgressBar = null;
- @property(cc.Label)
- label_passTaskTip: cc.Label = null;
- @property(cc.Label)
- label_passTaskProgress: cc.Label = null;
- @property(cc.ProgressBar)
- bar_passTaskProgress: cc.ProgressBar = null;
- @property(cc.Node)
- node_closeBtn: cc.Node = null;
- @property(cc.Node)
- node_cashOutBtn: cc.Node = null;
- @property(cc.Node)
- node_cashOutBtn_on: cc.Node = null;
- @property(cc.Node)
- node_cashOutBtn_off: cc.Node = null;
- public videoNum: number = 30;
- public onlineTime: number = 30;
- public passNum: number = 20;
- // LIFE-CYCLE CALLBACKS:
- // onLoad () {}
- onEnable() {
- GameMgr.Inst.sendEvent(UI_NAME.DailyCashOutUI, "进入每日打卡界面");
- this.initView();
- }
- start() {
- this.node_rectBg.setContentSize(cc.winSize.width, cc.winSize.height);
- this.initEvent();
- }
- initView() {
- this.initLabelTip();
- this.initWatchVideoNum();
- this.initOnlineTime();
- this.initPassNum();
- this.initCashOutState();
- }
- initLabelTip() {
- if (PlayerConst.loginDay == 1) {
- this.videoNum = 10;
- this.onlineTime = 5;
- this.passNum = 3;
- }
- else {
- this.videoNum = GameLogic.getVideoNumByEcpm();
- this.onlineTime = 15;
- this.passNum = 15;
- }
- this.label_videoTaskTip.string = `观看视频${this.videoNum}次`;
- this.label_timeTaskTip.string = `在线时长达到${this.onlineTime}分钟`;
- this.label_passTaskTip.string = `通关${this.passNum}关`;
- }
- initWatchVideoNum() {
- this.label_videoTaskProgress.string = `${PlayerConst.watchVideoNum}/${this.videoNum}`;
- let progress = PlayerConst.watchVideoNum / this.videoNum;
- progress = progress >= 1 ? 1 : progress;
- this.bar_videoTaskProgress.progress = progress;
- }
- initOnlineTime() {
- let onlineTime = Math.floor(PlayerConst.onlineTime / 60);
- this.label_timeTaskProgress.string = `${onlineTime}/${this.onlineTime}`;
- let progress = onlineTime / this.onlineTime;
- progress = progress >= 1 ? 1 : progress;
- this.bar_timeTaskProgress.progress = progress;
- }
- initPassNum() {
- this.label_passTaskProgress.string = `${PlayerConst.passNum}/${this.passNum}`;
- let progress = PlayerConst.passNum / this.passNum;
- progress = progress >= 1 ? 1 : progress;
- this.bar_passTaskProgress.progress = progress;
- }
- /**初始化提现状态 */
- initCashOutState() {
- if (this.bar_videoTaskProgress.progress != 1 || this.bar_timeTaskProgress.progress != 1 || this.bar_passTaskProgress.progress != 1) {
- this.node_cashOutBtn_off.active = true;
- this.node_cashOutBtn_on.active = !this.node_cashOutBtn_off.active;
- }
- else {
- this.node_cashOutBtn_on.active = !PlayerConst.ifDailyCashOut;
- this.node_cashOutBtn_off.active = PlayerConst.ifDailyCashOut;
- }
- }
- /**初始化事件 */
- initEvent() {
- this.node_cashOutBtn.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
- this.node_closeBtn.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
- //如果未授权则添加监听
- if (!GameConst.isAuth) {
- mk.event.register(EVENT_TYPE.BACK_WxAuth, this.onWxAuthBack, this);
- }
- }
- /**点击按钮 */
- onClickBtn(event: cc.Event.EventTouch) {
- // AudioMgr.Inst.playEffect(AUDIO_CLIP_NAME.buttonClick);
- mk.audio.playEffect("ef_button_click");
- switch (event.currentTarget) {
- case this.node_cashOutBtn:
- this.onClickCashOutBtn();
- break;
- case this.node_closeBtn:
- this.onClickCloseBtn();
- break;
- }
- }
- // update (dt) {}
- //点击提现按钮
- onClickCashOutBtn() {
- GameMgr.Inst.sendEvent(UI_NAME.DailyCashOutUI, "点击提现按钮");
- if (!GameConst.isAuth) {
- EffectMgr.Inst.addTip("授权才能提现哦");
- mk.ui.openPanel("game/prefab/uiPanel/GuideAuthUI");
- return;
- }
- if (!this.node_cashOutBtn_on.active) {
- if (PlayerConst.ifDailyCashOut) {
- EffectMgr.Inst.addTip(`今天已提现啦,明天再来哦~`);
- }
- else {
- EffectMgr.Inst.addTip(`完成任务才可提现哦`);
- }
- return;
- }
- let cashNum = 0.3;
- HttpMgr.Inst.cash(cashNum, 2).then(() => {
- PlayerConst.ifDailyCashOut = true;
- this.initCashOutState();
- EffectMgr.Inst.addTip("提现成功,请等待微信到账");
- GameMgr.Inst.sendEvent(UI_NAME.DailyCashOutUI, "每日提现成功");
- GameMgr.Inst.sendEventCp(UI_NAME.DailyCashOutUI, "每日提现成功");
- //提现操作
- }).catch((err) => {
- mk.console.log("[DailyCashOut] cash err", err);
- EffectMgr.Inst.addTip(err.errmsg);
- // EffectMgr.Inst.addTip(`后台维护中,请稍后再试`)
- });
- }
- //点击继续按钮
- onClickCloseBtn() {
- GameMgr.Inst.sendEvent(UI_NAME.DailyCashOutUI, "点击关闭按钮");
-
- mk.ui.closePanel("DailyCashOutUI")
- }
- //自定义事件---------------------------------------------------------------------
- /**微信授权返回 */
- onWxAuthBack() {
- this.initView();
- mk.event.register(EVENT_TYPE.BACK_WxAuth, this.onWxAuthBack, this);
- }
- }
|