123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- 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");
- var Promise = require('../lib/es6-promise').Promise;
- 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 = '<color=#ffffff>升级 x10</c>' + `<br/><img src='coin_small'/><color=#ffffff>${TapTapTool.parseToString(this._gold10)}</c>`;
- this.richText100.string = '<color=#ffffff>升级 x100</c>' + `<br/><img src='coin_small'/><color=#ffffff>${TapTapTool.parseToString(this._gold100)}</c>`;
- },
- /// 是否是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) {},
- });
|