const SkillApi = require('../net/SkillApi'); const DWTool = require("../utils/DWTool"); const GameModule = require("../utils/GameModule"); const buildingLevel = require('../data/buildingLevel'); const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey; const TapTapTool = require("../utils/TapTapTool"); cc.Class({ extends: cc.Component, properties: { button100: cc.Button, sprite100: cc.Sprite, richText100: cc.RichText, button10: cc.Button, sprite10: cc.Sprite, richText10: cc.RichText, lightSprite: cc.SpriteFrame, graySprite: cc.SpriteFrame, }, // LIFE-CYCLE CALLBACKS: onLoad () {}, start () { }, updateData(gold10, gold100, item) { this._item = item; this._gold10 = gold10; this._gold100 = gold100; this.button10.interactable = false; this.button100.interactable = false; this.richText10.string = '升级 x10' + `
${TapTapTool.parseToString(this._gold10)}`; this.richText100.string = '升级 x100' + `
${TapTapTool.parseToString(this._gold100)}`; }, /// 是否是100 setupGrayBg(isActive, is100) { let spriteFrame = isActive ? this.lightSprite : this.graySprite; if (is100) { this.button100.interactable = isActive; if (this.sprite100 != spriteFrame) { this.sprite100.spriteFrame = spriteFrame; } } else { if (this.sprite10 != spriteFrame) { this.sprite10.spriteFrame = spriteFrame; } this.button10.interactable = isActive; } }, update(dt) { let gold = GameModule.userInfo.gold; let is10 = TapTapTool.compare(gold, this._gold10); let is100 = TapTapTool.compare(gold, this._gold100); this.setupGrayBg(is10, false); this.setupGrayBg(is100, true); }, buttonAction(eventTarget, eventData) { GameModule.audioMng.playClickButton(); if (eventData == 10) { this.button10.interactable = false; } else { this.button100.interactable = false; } this.upBuildingLevel(eventData).then((respondData) => { let upGold = {}; if (eventData == 10) { this.button10.interactable = true; upGold = this._gold10; } else { this.button100.interactable = true; upGold = this._gold100; } GameModule.userInfo.buildingLevel = respondData.level; GameModule.userInfo.gold = TapTapTool.sub(GameModule.userInfo.gold, upGold); this._item.hiddenSkillBuidingAlert(respondData.gold10, respondData.gold100); GameEvent.fire(GameNotificationKey.UpBuildingLevel); }).catch(({code, msg}) => { console.log(code, msg); if (eventData == 10) { this.button10.interactable = true; } else { this.button100.interactable = true; } }); }, /// 升级建筑 upBuildingLevel(upLevel) { return new Promise((resolve, reject) => { // 获取目标用户的建筑 SkillApi.upBuildingLevel(upLevel, (respondData) => { resolve(respondData); }, (code, msg) => { reject({code, msg}); }); }); }, // update (dt) {}, });