/** * 货币类型,游戏币为默认 */ var CurrencyType = cc.Enum({ GAME: 0, CNT: 1, SNB: 2 }); cc.Class({ extends: cc.Component, properties: { Name: { default: '', tooltip: '建筑名称', }, Price: { default: '', tooltip: '需要金币的价格', }, DiamondPrice: { default: 1, type: cc.Integer, tooltip: '需要钻石的价格', }, CNT: { default: '', tooltip: '需要CNT货币的价格', }, SNB: { default: '', tooltip: '需要SNB货币的价格', }, Synopsis: { default: '', tooltip: '简介', }, //消耗的货币类型,默认是游戏币 consumeType: { default: CurrencyType.GAME, type: cc.Enum(CurrencyType), tooltip: '需要消耗的货币类型', }, bgSprite:{ default:null, type:cc.Sprite, }, NumLabel:{ default:null, type:cc.Label, }, NameLabel:{ default:null, type:cc.Label, }, clickEvents: { default: [], type: cc.Component.EventHandler, tooltip: CC_DEV && 'i18n:COMPONENT.button.click_events', } }, onPressed() { //建筑数量为零,也不需要提示购买 let NameNode = this.node.getChildByName('Name'); if (NameNode) { let Num = NameNode.getChildByName('Num'); if (Num) { let NumLabel = Num.getComponent(cc.Label); if (parseInt(NumLabel.string) < 1) { switch (this.consumeType) { /** * todo 目前只有特殊购买开放购买 */ case CurrencyType.CNT: case CurrencyType.SNB: console.warn("Content_Button 不需要购买!"); // GlobalD.game._ManageUIScript.onPurchaseTips(this); break; default: console.warn("Content_Button 不需要购买!"); break; } // GlobalD.game._ManageUIScript.onPurchaseTips(this); return; } } } let item = { Name: this.Name, Price: this.Price, Synopsis: this.Synopsis }; switch (this.consumeType) { case CurrencyType.CNT: item.Price = this.CNT; break; case CurrencyType.SNB: item.Price = this.SNB; break; default: item.Price = this.Price; break; } GlobalD.game._ManageUIScript.onSetButtonState({ Target: this },item); }, onPressedInfo(event, customEventData) { let item = { Name: this.Name, Price: this.Price, Synopsis: this.Synopsis }; switch (this.consumeType) { case CurrencyType.CNT: item.Price = this.CNT; break; case CurrencyType.SNB: item.Price = this.SNB; break; default: item.Price = this.Price; break; } GlobalD.game._ManageUIScript.onSetButtonInfoState({ Target: this }, item ); } });