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 (GameGlobal.isCheck) {
this.videoBtn.active = false;
this.shareBtn.active = false;
this.normalBtn.active = true;
} else {
let url = GameGlobal.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 || CC_QQPLAY) {
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 = ` ${coin}`;
},
///2倍
setWatchVideoRichText(coin) {
this.watchVideoRichText.string = ` ${coin}`;
},
/// 2倍
setShareVideoRichText(coin) {
this.shareRichText.string = ` ${coin}`;
},
// update (dt) {},
});