UserPackPage.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. const dataItemInfo = require('../data/item');
  2. const GameModule = require('../utils/GameModule');
  3. cc.Class({
  4. extends: cc.Component,
  5. properties: {
  6. packItemPrefab: cc.Prefab,
  7. pageLayout: cc.Layout,
  8. },
  9. // LIFE-CYCLE CALLBACKS:
  10. onLoad () {
  11. GameModule.homeGuide.on('Fire_state33', this.showPackEquipe, this);
  12. },
  13. init(array,page) {
  14. this.page = page;
  15. for (var i = 0; i < 20; i++) {
  16. let item = cc.instantiate(this.packItemPrefab);
  17. item = item.getComponent('UserPackItem');
  18. if (i < array.length) {
  19. let itemInfo = array[i];
  20. let count = itemInfo.count;
  21. for (let info of dataItemInfo) {
  22. if (info.id == itemInfo.itemId) {
  23. itemInfo = info;
  24. break;
  25. }
  26. }
  27. itemInfo.count = count;
  28. item.init(i,page,itemInfo);
  29. } else {
  30. item.init(i,page);
  31. }
  32. this.pageLayout.node.addChild(item.node);
  33. }
  34. },
  35. onDisable () {
  36. for (let child of this.pageLayout.node.children) {
  37. if (cc.isValid(child)) {
  38. child.destroy();
  39. }
  40. }
  41. },
  42. start () {
  43. },
  44. showPackEquipe() {
  45. if (this.page == 0) {
  46. for (let child of this.pageLayout.node.children) {
  47. let item = child.getComponent('UserPackItem');
  48. if (item && item.itemIndex == 0) {
  49. item.selectItem();
  50. this.scheduleOnce(function() {
  51. GameModule.homeGuide.getComponent('HomeGuide').handleGuideStateNext('state33', 'state37');
  52. }, 0.1);
  53. break;
  54. }
  55. }
  56. }
  57. }
  58. // update (dt) {},
  59. });