123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- const DWTool = require('../utils/DWTool');
- const {GameNotificationKey, WechatShareType } = require('../utils/GameEnum');
- const GameModule = require('../utils/GameModule');
- const WeChat = require('../net/WeChat');
- const Api = require('../net/Api');
- const taptapTool = require('../utils/TapTapTool');
- const SkillApi = require("../net/SkillApi");
- 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: {
- get() {
- return this._grossIncome;
- },
- set(value) {
- this._grossIncome = value;
-
- this.setCoinRichText(taptapTool.parseToString(value));
- this.setWatchVideoRichText(taptapTool.parseToString(taptapTool.multiple(value, {"n": 2, "e": 0})));
- this.setShareVideoRichText(taptapTool.parseToString(taptapTool.multiple(value, {"n": 2, "e": 0})));
- }
- },
- zIndex: {
- default: 0,
- notify(oldValue) {
- //减少无效赋值
- if (oldValue === this.zIndex) {
- return;
- }
- this.node.zIndex = this.zIndex;
- }
- }
- },
- // LIFE-CYCLE CALLBACKS:
- onDestroy() {
- GameEvent.off(GameNotificationKey.ShowShareAction, this);
- },
- init(grossIncome) {
- this.grossIncome = grossIncome;
- this._resetBtn();
- if (CC_WECHATGAME) {
- //判断是否是正在审核的版本,是的话将隐藏分享到群的按钮
- if (Global.isCheck) {
- this.videoBtn.active = false;
- this.shareBtn.active = false;
- this.normalBtn.active = true;
- } else {
- let url = Global.debug ? 'https://pub.dwstatic.com/wxgame/taptapstar_test/sheet/offlineIncome.json' : 'https://pub.dwstatic.com/wxgame/taptapstar/sheet/offlineIncome.json';
- wx.request({
- url: url,
- success: (res) => {
- console.log(res.data);
- 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.normalBtn.active = false;
- }
- }
- });
- }
- } else {
- this.videoBtn.active = true;
- this.shareBtn.active = true;
- this.normalBtn.active = false;
- }
- },
- onLoad() {
- this.node.zIndex = this.zIndex;
- this._grossIncome = {"n": 0, "e": 0};
- },
- 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(325, 0)));
- },
- /**
- * 重置按钮状态
- */
- _resetBtn() {
- this.videoBtn.active = false;
- this.shareBtn.active = false;
- this.normalBtn.active = true;
- },
- 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() {
- GameModule.audioMng.playClickButton();
- this.addIncome(this._grossIncome);
- this.dismiss()
- },
- /**
- * 增加金币收入
- * @param {number} value 数量
- */
- addIncome(value) {
- // console.log("addIncome: " + value);
- // GameModule.userInfo.gold += parseInt(value);
- GameModule.userInfo.gold = taptapTool.add(GameModule.userInfo.gold, value);
- // GameEvent.fire(GameNotificationKey.HandleOfflineIncomeAnim)
- // 添加金币后立刻上报
- GameModule.userInfo.doReport();
- },
- /**
- * 看视频获取更多离线收益
- */
- watchVideo() {
- GameModule.audioMng.playClickButton();
- // Todo: 对接微信广告Api
- this.addIncome(taptapTool.multiple(this._grossIncome, {'n':2, 'e': 0}));
- this.dismiss();
- },
- /**
- * 调起微信分享及后续分享逻辑
- */
- share() {
- GameModule.audioMng.playClickButton();
- if (CC_WECHATGAME) {
- GameEvent.on(GameNotificationKey.ShowShareAction, this, (type) => {
- this.shareActionCallback(type);
- });
- WeChat.shareAction(WechatShareType.OfflineIncome, () => {
- }, () => {
- console.log('分享失败或取消');
- });
- } else {
- this.addIncome(taptapTool.multiple(this._grossIncome, {'n': 2, 'e': 0}));
- this.dismiss();
- }
- },
- shareActionCallback(type) {
- if (type != WechatShareType.OfflineIncome) { return; }
- this.addIncome(taptapTool.multiple(this._grossIncome, {'n':2, 'e': 0}))
- this.dismiss();
- GameEvent.off(GameNotificationKey.ShowShareAction, this);
- },
- setCoinRichText(coin) {
- this.coinRichText.string = `<img src='coin_small'/><outline color=#ffffff width=4><b><color=#009227> ${coin}</c></b></outline>`;
- },
- ///2倍
- setWatchVideoRichText(coin) {
- this.watchVideoRichText.string = `<img src='coin_small'/><color=#ffffff> ${coin}</c>`;
- },
- /// 2倍
- setShareVideoRichText(coin) {
- this.shareRichText.string = `<img src='coin_small'/><color=#ffffff> ${coin}</c>`;
- },
- // update (dt) {},
- });
|