const ListViewAdapter = require('../utils/TapTapScrollViewAdapter'); const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey; const TapTapTool = require("../utils/TapTapTool"); cc.Class({ extends: cc.Component, properties: { content: cc.Node, item: cc.Prefab, }, // LIFE-CYCLE CALLBACKS: onLoad () {}, start () { }, init(starData) { let buyGold = starData.buyGold; let starTypeCount = starData.starTypeCount; this._userStars = starData.userStars; this.listAdapter = new ListViewAdapter(this); this.listAdapter.buyGold = buyGold; this.listAdapter.start = starTypeCount; this.listAdapter.updateItems(this._userStars, this.item, 'StarItem'); // for(let i = 0; i < userStars.length; ++i) { // let starItem = cc.instantiate(this.item); // starItem.getComponent('StarItem').init(userStars[i], buyGold, starTypeCount); // this.content.addChild(starItem); // } this.listAdapter.isBuying = false; GameEvent.on("Star_Buy_success", this, (areaType, buyGold, starTypeCount) => { this.listAdapter.buyGold = buyGold; this.listAdapter.starTypeCount = starTypeCount; // ///说明满足明星和房间的条件 已经解锁 那么只需要判断金币进行预约了 // if (this._isStarLocked == false && this._isRoomLocked == false) { // /// 如果金币满足 // this.setUpUseBtnBg(TapTapTool.compare(GameModule.userInfo.gold, this._buyGold)); // this.starUseTitleRichText.string = `签约
${TapTapTool.parseToString(this._buyGold)}`; // } /// 如果是明星所需种类 for (let i = 0; i < this._userStars.length; ++ i) { let starData = this._userStars[i]; if (starData.itemId == 102) { this.listAdapter.starTypeCount = starTypeCount; /// 如果是明星需要个数 } else if (starData.itemId == 101) { /// 地区需要明星多少个 } else { /// 如果该地区与需要的这个地区匹配 if (starData.itemId == areaType) { starData.areaStarCount += 1; } } } GameEvent.fire('StarItem_updateUI'); }); //// 明星放入房间 GameEvent.on(GameNotificationKey.StarEnterRoom, this, (starId, roomId) => { for (let i = 0; i < this._userStars.length; ++ i) { let starData = this._userStars[i]; if (starData.starId == starId) { starData.starRoomCount += 1; break; } } GameEvent.fire('StarItem_updateUI'); }); /// 单个明星离开的id GameEvent.on(GameNotificationKey.StarLeaveRoom, this, (starId) => { for (let i = 0; i < this._userStars.length; ++ i) { let starData = this._userStars[i]; if (starData.starId == starId) { starData.starRoomCount -= 1; break; } } GameEvent.fire('StarItem_updateUI'); }); /// 所有的明星都收回 GameEvent.on (GameNotificationKey.AllStarLeaveRoom, this, () => { for (let i = 0; i < this._userStars.length; ++ i) { let starData = this._userStars[i]; starData.starRoomCount = 0; } GameEvent.fire('StarItem_updateUI'); }); GameEvent.on(GameNotificationKey.GameUpdateStarContentBuyGold, this, () => { this.listAdapter.buyGold = TapTapTool.multiple(this.listAdapter.buyGold, {'n': 0.5, 'e': 0}); GameEvent.fire('StarItem_updateUI'); }); }, onDestroy() { GameEvent.off(GameNotificationKey.AllStarLeaveRoom, this); GameEvent.off(GameNotificationKey.StarLeaveRoom, this); GameEvent.off(GameNotificationKey.StarEnterRoom, this); GameEvent.off('Star_Buy_success', this); GameEvent.off(GameNotificationKey.GameUpdateStarContentBuyGold, this); }, onScroll() { if (this.listAdapter != undefined) { this.listAdapter.update(); } }, // update (dt) { // if (this.listAdapter != undefined) { // this.listAdapter.update(dt); // } // }, });