123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- 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 = `<color=#ffffff>签约</c><br/><img src='coin_small'/><color=#ffffff>${TapTapTool.parseToString(this._buyGold)}</c>`;
- // }
- /// 如果是明星所需种类
- 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);
- // }
- // },
- });
|