123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- const DWTool = require('../utils/DWTool')
- const { GameNotificationKey } = require("../utils/GameEnum");
- const GameModule = require('../utils/GameModule')
- const WeChat = require('../net/WeChat');
- const Api = require('../net/Api');
- cc.Class({
- extends: cc.Component,
- properties: {
-
- content: cc.Node,
- coinRichText: cc.RichText,
-
- watchVideoRichText: cc.RichText,
-
- shareRichText: cc.RichText,
- secretarySprite: cc.Node,
- videoBtn: {
- tooltip: '观看视频按钮',
- default: null,
- type: cc.Node
- },
- shareBtn: {
- tooltip: '分享按钮',
- default: null,
- type: cc.Node
- },
- normalBtn: {
- tooltip: '普通确认按钮',
- default: null,
- type: cc.Node
- },
- _grossIncome: 0,
- grossIncome: {
- get() {
- return this._grossIncome;
- },
- set (value) {
- this._grossIncome = value;
- this.setCoinRichText(value);
- this.setWatchVideoRichText(value);
- this.setShareVideoRichText(value);
- }
- }
- },
- // LIFE-CYCLE CALLBACKS:
- init(grossIncome) {
- this.grossIncome = grossIncome;
-
- this._resetBtn();
- if(CC_WECHATGAME) {
- wx.request({
- url: "https://pub.dwstatic.com/wxgame/allstar/sheet/offlineIncome.json",
- success: (res) => {
- if(res.data.video) {
- this.videoBtn.active = true;
- }
- if(res.data.share) {
- this.shareBtn.active = true;
- }
- if(res.data.normal) {
- this.normalBtn.active = true;
- }
- }
- })
- } else {
- this.videoBtn.active = true;
- this.shareBtn.active = true;
- }
- },
- onLoad () {
- },
- start () {
- this.content.scaleX = 0;
- this.content.scaleY = 0;
- this.content.runAction(cc.scaleTo(0.35, 1, 1).easing(cc.easeBackOut()));
- this.secretarySprite.runAction(cc.moveBy(0.3, cc.v2(400, 0)));
- },
- /**
- * 重置按钮状态
- */
- _resetBtn () {
- this.videoBtn.active = false;
- this.shareBtn.active = false;
- this.normalBtn.active = false;
- },
- dismiss() {
- let finish = cc.callFunc(() => {
- this.node.destroy();
- }, this);
- let sequence = cc.sequence(cc.scaleTo(0.2, 0, 0).easing(cc.easeBackIn()), finish)
- this.content.runAction(sequence);
- },
- /**
- * 普通关闭,获得正常收益x1
- */
- close() {
- this.addIncome(this._grossIncome)
- this.dismiss()
- },
- /**
- * 增加金币收入
- * @param {number} value 数量
- */
- addIncome(value) {
- console.log("addIncome: " + value);
- GameModule.userInfo.grossIncome = parseInt(GameModule.userInfo.grossIncome) + parseInt(value)
- GameEvent.fire(GameNotificationKey.HandleOfflineIncomeAnim)
- },
- /**
- * 看视频获取更多离线收益
- */
- watchVideo() {
- // Todo: 对接微信广告Api
- this.addIncome(this._grossIncome * 2)
- this.dismiss();
- },
- /**
- * 调起微信分享及后续分享逻辑
- */
- share() {
- if(CC_WECHATGAME) {
- // this.shareFlag = 1
- wx.shareAppMessage({
- title: '偷偷分享给你一个小程序,福利满满,你懂的',
- imageUrl: 'https://pub.dwstatic.com/wxgame/allstar/share/share1.jpg',
- // query: 'uid=' + Global.user.uid + '&shareType=' + ShareAction.ADD_FRIEND
- success: (res) => {
- console.log('分享成功');
- this.addIncome(this._grossIncome * 3)
- this.dismiss();
- // this.shareFlag = 0;
- },
- fail: (res) => {
- console.log('分享失败或取消');
- }
- });
- // 微信分享api无法正确回调时候的备用方案
- // wx.onShow(res => {
- // if(this.shareFlag == 1) {
- // GameModule.userInfo.grossIncome += this.grossIncome * 2;
- // this.shareFlag = 0;
- // this.dismiss();
- // }
- // })
- } else {
- this.addIncome(this._grossIncome * 3)
- this.dismiss();
- }
- },
- setCoinRichText(coin) {
- this.coinRichText.string = `<img src='alert_coin'/><outline color=#ffffff width=4><b><color=#009227> ${DWTool.coinParse(coin)}</c></b></outline>`;
- },
- setWatchVideoRichText(coin) {
- this.watchVideoRichText.string = `<img src='alert_coin'/><color=#ffffff> ${DWTool.coinParse(coin * 2)}</c>`;
- },
- setShareVideoRichText(coin) {
- this.shareRichText.string = `<img src='alert_coin'/><color=#ffffff> ${DWTool.coinParse(coin * 3)}</c>`;
- },
- // update (dt) {},
- });
|