1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- // Learn cc.Class:
- 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._content = content;
- this._shops = {};
- let contentWidth = this.content.width;
- let itemWith = Math.floor((contentWidth - 75) / 2);
- this._items = []
- content.getShopsByType(3).then( (respondData) => {
- this._shops = respondData.shops;
- for (let i = 0; i < this._shops.length; ++ i) {
- let coinItem = cc.instantiate(this.item);
- // let coinItemWidth = coinItem.width;
- // let coinItemHeight = coinItem.height;
- // let radio = coinItemHeight / coinItemWidth;
- coinItem.width = itemWith;
- // coinItem.height = coinItemHeight * radio;
- coinItem.getComponent('StoreSmallItem').init(this._shops[i], 3, i);
- this.content.addChild(coinItem);
- this._items.push(coinItem);
- }
- }).catch((code, msg) => {
- console.log(code, msg);
- })
- GameEvent.on(GameNotificationKey.GameShowNotificationKey, this, this.updateInitData);
- },
- updateInitData() {
- this._content.getShopsByType(3).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) {},
- });
|