const DWTool = require("../utils/DWTool"); const GameModule = require("../utils/GameModule"); const ArtistManager = require('../utils/ArtistManager'); cc.Class({ extends: cc.Component, properties: { iconSprite: cc.Sprite, titleRichText: cc.RichText, descRichText: cc.RichText, /// 增加钻石的 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.titleRichText.string = `${title}`; 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 () { }, sureAction() { if (this.diamond > 0) { GameModule.userInfo.diamond += this.diamond; } GameModule.audioMng.playClickButton(); let notificationStr = this._isBuyStar ? 'commAlert_BuyStar_hidden' : 'commAlert_hidden'; GameEvent.fire(notificationStr); this.node.destroy(); } // update (dt) {}, });