StoreDiamond.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. item: cc.Prefab,
  6. content: cc.Node
  7. },
  8. // LIFE-CYCLE CALLBACKS:
  9. // onLoad () {},
  10. start () {
  11. },
  12. init(content) {
  13. if (this._shops != undefined) {
  14. return;
  15. }
  16. this._shops = {};
  17. let contentWidth = this.content.width;
  18. let itemWith = Math.floor((contentWidth - 75) / 2);
  19. this._items = [];
  20. this._content = content;
  21. content.getShopsByType(2).then( (respondData) => {
  22. this._shops = respondData.shops;
  23. for (let i = 0; i < this._shops.length; ++ i) {
  24. let diamondItem = cc.instantiate(this.item);
  25. // let diamondItemWidth = diamondItem.width;
  26. // let diamondItemHeight = diamondItem.height;
  27. // let radio = diamondItemHeight / diamondItemWidth;
  28. diamondItem.width = itemWith;
  29. // diamondItem.height = diamondItemHeight * radio;
  30. this._shops[i].isBuyDiamond = respondData.isBuyDiamond;
  31. diamondItem.getComponent('StoreSmallItem').init(this._shops[i], 2, i);
  32. this.content.addChild(diamondItem);
  33. this._items.push(diamondItem);
  34. }
  35. }).catch((code, msg) => {
  36. console.log(code, msg);
  37. })
  38. GameEvent.on(GameNotificationKey.GameShowNotificationKey, this, this.updateData);
  39. },
  40. updateData() {
  41. this._content.getShopsByType(2).then( (respondData) => {
  42. this._shops = respondData.shops;
  43. for (let i = 0; i < this._items.length; ++ i) {
  44. let item = this._items[i].getComponent('StoreSmallItem');
  45. item._shopData = this._shops[i];
  46. item.updateTime();
  47. }
  48. }).catch((code, msg) => {
  49. console.log(code, msg);
  50. })
  51. },
  52. onDestroy() {
  53. GameEvent.off(GameNotificationKey.GameShowNotificationKey, this);
  54. },
  55. // update (dt) {},
  56. });