123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- 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 = `<color=#540904>${desc}</color>`;
- }
- this.closeButton.active = true;
- this.titleRichText.string = `<b><color=#540904>${title}</c></b>`;
- this.sureRichText.string = `<b><color=#ffffff>炫耀</c></b>`;
- 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 = `<color=#540904>${desc}</color>`;
- }
- this.titleRichText.string = `<b><color=#540904>${title}</c></b>`;
- 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) {},
- });
|