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");
const ADVideo = require('../utils/ADVideo');
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);
GameEvent.off(GameNotificationKey.AdUpdateStateNotification, 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 {
this.initAd();
}
} 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};
GameEvent.on(GameNotificationKey.AdUpdateStateNotification, this, (adState, callBack) => {
if (callBack != undefined && callBack == 'offlineIncome') {
if (adState === 3) {
this.addIncome(taptapTool.multiple(this._grossIncome, {'n':2, 'e': 0}));
this.dismiss();
} else {
this.addIncome(this._grossIncome);
this.dismiss();
}
}
if (adState === 0 || adState === 1) {
this.initAd();
}
this.videoBtn.getComponent(cc.Button).interactable = true;
});
},
initAd() {
if (!CC_WECHATGAME) {
return;
}
//// 说明有广告
if (GameGlobal._adVideoState == 0) {
this.videoBtn.active = true;
this.shareBtn.active = false;
} else if (GameGlobal._adVideoState === 1) {
this.videoBtn.active = false;
this.shareBtn.active = true;
}
},
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) {
GameModule.userInfo.gold = taptapTool.add(GameModule.userInfo.gold, value);
// 添加金币后立刻上报
GameModule.userInfo.doReport();
},
/**
* 看视频获取更多离线收益
*/
watchVideo() {
GameModule.audioMng.playClickButton();
this.videoBtn.getComponent(cc.Button).interactable = false;
GameGlobal._adVideo.showVideo('offlineIncome');
},
/**
* 调起微信分享及后续分享逻辑
*/
share() {
GameModule.audioMng.playClickButton();
if (CC_WECHATGAME || CC_QQPLAY) {
this.shareBtn.getComponent(cc.Button).interactable = false;
GameEvent.on(GameNotificationKey.ShowShareAction, this, (type, isOk) => {
if (type == WechatShareType.OfflineIncome) {
if (isOk) {
this.shareActionCallback();
} else {
this.shareBtn.getComponent(cc.Button).interactable = true;
}
GameEvent.off(GameNotificationKey.ShowShareAction, this);
}
});
WeChat.shareAction(WechatShareType.OfflineIncome, () => {
}, () => {
console.log('分享失败或取消');
});
} else {
this.addIncome(taptapTool.multiple(this._grossIncome, {'n': 2, 'e': 0}));
this.dismiss();
}
},
shareActionCallback() {
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) {},
});