123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- const GameModule = require("../utils/GameModule");
- const DWTool = require("../utils/DWTool");
- const StarApi = require('../net/StarApi');
- const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
- cc.Class({
- extends: cc.Component,
- properties: {
- nameLabel: cc.Label,
- conditionLabel: cc.Label,
- figure: cc.Sprite, //明星图片
- defaultFigureSpriteFrame: cc.SpriteFrame,
- countLabel: cc.Label,
- roomCountLabel: cc.Label,
- restCountLabel: cc.Label
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad () {
- this.isDoing = false;
- },
- start () {
- },
- configData(starInfo) {
- this.starInfo = starInfo;
- //获取到配置表的明星数据
- let imageId = 50000 + starInfo.starId;
- this.figure.spriteFrame = this.defaultFigureSpriteFrame;
- DWTool.loadResSpriteFrame(`./textures/star_stand/stand_${imageId}`)
- .then((spriteFrame) => {
- this.figure.spriteFrame = spriteFrame;
- }).catch((err) => {
- console.log(err);
- });
- let star = GameGlobal.BuildingManager.getStarInfo(starInfo.starId);
- this.nameLabel.string = star.name;
- if (star.starDesc) {
- this.conditionLabel.string = star.starDesc;
- } else {
- let roomName = GameGlobal.BuildingManager.getRoomName(star.roomId);
- if (roomName) {
- var descString = `需要 开启${roomName}`;
- }
- let buyStarCount = GameModule.userInfo.buyStarCount;
- let needStarCount = starInfo.itemCount;
- if (needStarCount > 0) {
- descString += `\n需要 ${star.desc}`;
- }
- if (descString) {
- this.conditionLabel.string = descString;
- } else {
- this.conditionLabel.string = '';
- }
- }
- this.countLabel.string = `${starInfo.starCount}人`;
- this.roomCountLabel.string = `${starInfo.starRoomCount}人`;
- let restCount = starInfo.starCount - starInfo.starRoomCount;
- if (restCount > 0) {
- this.restCountLabel.string = `${restCount}人`;
- } else {
- this.restCountLabel.string = "0人";
- }
- },
- refreshStarCount() {
- this.roomCountLabel.string = `${this.starInfo.starRoomCount}人`;
- let restCount = this.starInfo.starCount - this.starInfo.starRoomCount;
- if (restCount > 0) {
- this.restCountLabel.string = `${restCount}人`;
- } else {
- this.restCountLabel.string = "0人";
- }
- },
- dispatchToRoom() {
- if (this.isDoing) { return; }
- if (this.starInfo.starRoomCount >= this.starInfo.starCount) { return; } //判断没有可派出明星数量
- StarApi.dispatchStar(this.starInfo.starId, (respondData) => {
- this.isDoing = false;
- if (respondData.roomId > 0) {
- this.starInfo.starRoomCount += 1;
- this.refreshStarCount();
- GameEvent.fire(GameNotificationKey.StarEnterRoom, respondData.starId, respondData.roomId);
- } else {
- GameGlobal.commonAlert.showCommonErrorAlert("派出失败 \n没有空余的房间");
- }
- }, (code, msg) => {
- this.isDoing = false;
- GameGlobal.commonAlert.showCommonErrorAlert(`派出失败 \n${msg}`);
- })
- },
- recallFromRoom() {
- if (this.isDoing) { return; }
- if (this.starInfo.starRoomCount <= 0) { return; } //判断没有可召回明星数量
- StarApi.recallStar(this.starInfo.starId, (respondData) => {
- this.isDoing = false;
- this.starInfo.starRoomCount -= 1;
- this.refreshStarCount();
- GameEvent.fire(GameNotificationKey.StarLeaveRoom, respondData.starId, respondData.roomId);
- }, (code, msg) => {
- this.isDoing = false;
- GameGlobal.commonAlert.showCommonErrorAlert(`召回失败 \n${msg}`);
- })
- }
- // update (dt) {},
- });
|