123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- const GameModule = require("../utils/GameModule");
- const DWTool = require("../utils/DWTool");
- const StarApi = require('../net/StarApi');
- const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
- const TapTapTool = require("../utils/TapTapTool");
- const ArtistManager = require('../utils/ArtistManager');
- cc.Class({
- extends: cc.Component,
- properties: {
- starIcon: cc.Sprite,
- starNameLabel: cc.Label,
- subTitleRichText: cc.RichText,
- subTitleRichText1: cc.RichText,
- starUseTitleRichText: cc.RichText,
- starUseBtn: cc.Button,
- starUserSprite: cc.Sprite,
- countLabel: cc.Label,
- countNode: cc.Node,
- starIconBlackBg: cc.Node,
- lightSpriteFrame: cc.SpriteFrame,
- graySpriteFrame: cc.SpriteFrame,
- lockedSpriteFrame: cc.SpriteFrame,
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad () {
-
- GameEvent.on('StarItem_updateUI', this, () => {
- this._buyGold = this._listViewAdapter.buyGold;
- this._starTypeCount = this._listViewAdapter.starTypeCount;
- this.updateData();
- });
- // GameEvent.on("Star_Buy_success", this, (areaType, buyGold, starTypeCount) => {
- // this._buyGold = buyGold;
- // ///说明满足明星和房间的条件 已经解锁 那么只需要判断金币进行预约了
- // if (this._isStarLocked == false && this._isRoomLocked == false) {
- // /// 如果金币满足
- // this.setUpUseBtnBg(TapTapTool.compare(GameModule.userInfo.gold, this._buyGold));
- // this.starUseTitleRichText.string = `<color=#ffffff>签约</c><br/><img src='coin_small'/><color=#ffffff>${TapTapTool.parseToString(this._buyGold)}</c>`;
- // }
- // /// 如果是明星所需种类
- // if (this._starData.itemId == 102) {
- // if (this._starTypeCount != starTypeCount) {
- // this._starTypeCount = starTypeCount;
- // this.setUpIsCanSign();
- // }
- // /// 如果是明星需要个数
- // } else if (this._starData.itemId == 101) {
- // this.setUpIsCanSign();
- // /// 地区需要明星多少个
- // } else {
- // /// 如果该地区与需要的这个地区匹配
- // if (this._starData.itemId == areaType) {
- // this._starData.areaStarCount += 1;
- // this.setUpIsCanSign();
- // }
- // }
- // });
- },
- start () {
- this._isAcion = false;
- },
- onDestroy() {
- GameEvent.off("Star_Buy_success", this);
- GameEvent.off('StarItem_updateUI', this);
- },
- update (dt) {
- /// 如果是锁住的 那就什么都不做嘛 这里就是更新金币
- if (this._isRoomLocked == false && this._isStarLocked == false && this._isAcion == false) {
- /// 如果是没反应的 说明金币不够
- if (this.starUseBtn.interactable == false) {
- if (TapTapTool.compare(GameModule.userInfo.gold, this._buyGold)) {
- this.setUpUseBtnBg(true);
- }
- }
- }
- },
- setListViewAdapter (listViewAdapter) {
- this._listViewAdapter = listViewAdapter;
- this._buyGold = listViewAdapter.buyGold;
- this._starTypeCount = listViewAdapter.starTypeCount;
- },
- updateItem(userInfo, itemId) {
- this._itemId = itemId;
- this._starData = userInfo;
- // console.log(this._starData.itemId);
- this._starInfo = Global.BuildingManager.getStarInfo(this._starData.starId);
- this.updateData();
- this.starNameLabel.string = this._starInfo.name;
- let imageId = 50000 + this._starData.starId;
- ArtistManager.loadStarAvatarSpriteFrame(imageId, this.starIcon);
- },
- deleteItem() {
- this._listViewAdapter.removeItem(this);
- },
- /// 实时更新数据
- updateData() {
- this.setUpIsCanSign();
- this.undateStarCount();
- },
- undateStarCount() {
- if (this._starData.starCount > 0) {
- this.countNode.active = true;
- this.countLabel.string = this._starData.starRoomCount + '/' + this._starData.starCount;
- } else {
- this.countNode.active = false;
- }
- },
- /// 设置是否能签约
- setUpIsCanSign() {
- if (this._starData.type === 3) {
- this._isRoomLocked = false;
- this._isStarLocked = false;
- this.subTitleRichText1.string = "";
- this.subTitleRichText.string = '';
- } else {
- let buyStarCount = GameModule.userInfo.buyStarCount;
- let roomId = this._starData.signRoomId;
- let isUnlocked = Global.BuildingManager.getRoomIsUnlocked(roomId);
- let roomName = Global.BuildingManager.getRoomName(roomId);
-
- this._isRoomLocked = false;
- this._isStarLocked = false;
- /// 需要的房间锁住的。
- if (isUnlocked == 0) {
- this.subTitleRichText.string = "<img src='star_false'/><color=#2E2E2E> 开启 " + roomName + "</c>";
- this._isRoomLocked = true;
- } else {
- this.subTitleRichText.string = "<img src='star_true'/><color=#2E2E2E> 开启 " + roomName + "</c>";
- }
-
- let needCount = this._starData.itemCount;
- if (needCount > 0) {
- /// 如要明星的个数为解锁条件
- if (this._starData.itemId == 101) {
- /// 如果明星数量足够
- if (buyStarCount >= needCount) {
- this.subTitleRichText1.string = "<img src='star_true'/><color=#2E2E2E>" + this._starInfo.desc + " (" + buyStarCount + "/" + needCount + ")" + "</c>";
- } else {
- this._isStarLocked = true;
- this.subTitleRichText1.string = "<img src='star_false'/><color=#2E2E2E>" + this._starInfo.desc + " (" + buyStarCount + "/" + needCount + ")" + "</c>";
- }
- } else if (this._starData.itemId == 102) {
- if (this._starTypeCount >= needCount) {
- this.subTitleRichText1.string = "<img src='star_true'/><color=#2E2E2E>" + this._starInfo.desc + " (" + this._starTypeCount + "/" + needCount + ")" + "</c>";
- } else {
- this._isStarLocked = true;
- this.subTitleRichText1.string = "<img src='star_fale'/><color=#2E2E2E>" + this._starInfo.desc + " (" + this._starTypeCount + "/" + needCount + ")" + "</c>";
- }
- } else {
- if (this._starData.areaStarCount >= needCount) {
- this.subTitleRichText1.string = "<img src='star_true'/><color=#2E2E2E>" + this._starInfo.desc + " (" + this._starData.areaStarCount + "/" + needCount + ")" + "</c>";
- } else {
- this._isStarLocked = true;
- this.subTitleRichText1.string = "<img src='star_false'/><color=#2E2E2E>" + this._starInfo.desc + " (" + this._starData.areaStarCount + "/" + needCount + ")" + "</c>";
- }
- }
- } else {
- this.subTitleRichText1.string = "";
- }
- }
- ///说明满足明星和房间的条件 已经解锁 那么只需要判断金币进行预约了
- if (this._isStarLocked == false && this._isRoomLocked == false) {
- /// 如果金币满足
- this.starUseTitleRichText.node.active = true;
- this.setUpUseBtnBg(TapTapTool.compare(GameModule.userInfo.gold, this._buyGold));
- this.starUseTitleRichText.string = `<color=#ffffff>签约</c><br/><img src='coin_small'/><color=#ffffff>${TapTapTool.parseToString(this._buyGold)}</c>`;
- this.starIconBlackBg.active = false;
- } else {
- this.starUseTitleRichText.node.active = false;
- this.starUseBtn.interactable = false;
- this.starUserSprite.spriteFrame = this.lockedSpriteFrame;
- this.starIconBlackBg.active = true;
- }
- },
- /// 设置签约的button是否能点击
- setUpUseBtnBg(isActive) {
- this.starUseBtn.interactable = isActive;
- this.starUserSprite.spriteFrame = isActive ? this.lightSpriteFrame : this.graySpriteFrame;
- },
- // 签约明星
- signUseBtnAction() {
- /// 只能同时买一个
- if (this._listViewAdapter.isBuying) {
- return;
- }
- this._listViewAdapter.isBuying = true;
- GameModule.audioMng.playClickButton();
- this.starUseBtn.interactable = false;
- this._isAcion = true;
- this.buyStar().then((respondData) => {
- this.starUseBtn.interactable = true;
- this._isAcion = false;
- GameModule.userInfo.gold = TapTapTool.sub(GameModule.userInfo.gold, this._buyGold);
- /// 本地购买的明星数量加1
- GameModule.userInfo.buyStarCount += 1;
- this._starData.starCount += 1;
- GameModule.userInfo.perpetualClickMt = respondData.clickMt;
- GameModule.userInfo.perpetualMt = respondData.mt;
- Global._buyStarGold = respondData.buyGold;
- this.undateStarCount();
- this._listViewAdapter.isBuying = false;
- GameEvent.fire(GameNotificationKey.StarEnterRoom, this._starData.starId, respondData.roomId);
- GameEvent.fire("Star_Buy_success", this._starInfo.areaType, respondData.buyGold, respondData.starTypeCount);
- GameEvent.fire('Star_Buy_success_Alert', this._starInfo.starId, this._starInfo.name);
- }).catch((error) => {
- this.starUseBtn.interactable = true;
- this._isAcion = false;
- Global.commonAlert.showCommonErrorAlert("签约明星失败");
- console.error(error);
- });
- },
- buyStar() {
- return new Promise((resolve, reject) => {
- //// 购买明星
- StarApi.buyStar(this._starData.starId, (respondData) => {
- resolve(respondData);
- }, (code, msg) => {
- reject({code, msg});
- });
- });
- },
- });
|