const DWTool = require("../utils/DWTool");
const GameModule = require("../utils/GameModule");
const ArtistManager = require('../utils/ArtistManager');
const {GameNotificationKey, WechatShareType} = require('../utils/GameEnum');
const WeChat = require('../net/WeChat');
cc.Class({
extends: cc.Component,
properties: {
iconSprite: cc.Sprite,
titleRichText: cc.RichText,
descRichText: cc.RichText,
sureRichText: cc.RichText,
sureButton: cc.Button,
closeButton: cc.Node,
/// 增加钻石的
diamond: 0,
},
// LIFE-CYCLE CALLBACKS:
// onLoad () {},
initBuyStar(imageId, desc, title, isRichText = false) {
ArtistManager.loadStarAvatarSpriteFrame(imageId, this.iconSprite);
if (isRichText) {
this.descRichText.string = desc;
} else {
this.descRichText.string = `${desc}`;
}
this.closeButton.active = true;
this.titleRichText.string = `${title}`;
this.sureRichText.string = `炫耀`;
this._isBuyStar = true;
},
init(iconPath, desc, title, isRichText = false) {
DWTool.loadResSpriteFrame(iconPath)
.then((spriteFrame) => {
this.iconSprite.spriteFrame = spriteFrame;
}).catch((err) => {
console.log(err);
});
if (isRichText) {
this.descRichText.string = desc;
} else {
this.descRichText.string = `${desc}`;
}
this.titleRichText.string = `${title}`;
this._isBuyStar = false;
},
/// 初始化上次
initAddDiamond(iconPath, desc, title, diamond) {
this.diamond = diamond;
this.init(iconPath, desc, title);
},
start () {
},
//// 只有购买明星才有关闭按钮
closeAction() {
GameEvent.fire('commAlert_BuyStar_hidden');
this.node.destroy();
},
sureAction() {
if (this.diamond > 0) {
GameModule.userInfo.diamond += this.diamond;
}
GameModule.audioMng.playClickButton();
if (this._isBuyStar) {
this.sureButton.interactable = false;
GameEvent.on(GameNotificationKey.ShowShareAction, this, (type, isOk) => {
if (type != WechatShareType.buyStar) { return; }
if (isOk) {
GameEvent.fire('commAlert_BuyStar_hidden');
this.node.destroy();
} else {
this.sureButton.interactable = true;
}
GameEvent.off(GameNotificationKey.ShowShareAction, this);
});
WeChat.shareAction(WechatShareType.buyStar, () => {
}, () => {
this.sureButton.interactable = true;
console.log('分享失败或取消');
});
} else {
GameEvent.fire('commAlert_hidden');
this.node.destroy();
}
}
// update (dt) {},
});