const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey; cc.Class({ extends: cc.Component, properties: { item: cc.Prefab, content: cc.Node }, // LIFE-CYCLE CALLBACKS: // onLoad () {}, start () { }, init(content) { if (this._shops != undefined) { return; } this._shops = {}; let contentWidth = this.content.width; let itemWith = Math.floor((contentWidth - 75) / 2); this._items = []; this._content = content; content.getShopsByType(2).then( (respondData) => { this._shops = respondData.shops; for (let i = 0; i < this._shops.length; ++ i) { let diamondItem = cc.instantiate(this.item); // let diamondItemWidth = diamondItem.width; // let diamondItemHeight = diamondItem.height; // let radio = diamondItemHeight / diamondItemWidth; diamondItem.width = itemWith; // diamondItem.height = diamondItemHeight * radio; this._shops[i].isBuyDiamond = respondData.isBuyDiamond; diamondItem.getComponent('StoreSmallItem').init(this._shops[i], 2, i); this.content.addChild(diamondItem); this._items.push(diamondItem); } }).catch((code, msg) => { console.log(code, msg); }) GameEvent.on(GameNotificationKey.GameShowNotificationKey, this, this.updateData); }, updateData() { this._content.getShopsByType(2).then( (respondData) => { this._shops = respondData.shops; for (let i = 0; i < this._items.length; ++ i) { let item = this._items[i].getComponent('StoreSmallItem'); item._shopData = this._shops[i]; item.updateTime(); } }).catch((code, msg) => { console.log(code, msg); }) }, onDestroy() { GameEvent.off(GameNotificationKey.GameShowNotificationKey, this); }, // update (dt) {}, });