1
0

UserPack.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. packPagePrefab: cc.Prefab,
  5. pageView: cc.PageView,
  6. indicatorLayout: cc.Layout,
  7. indicatorPrefab: cc.Prefab,
  8. },
  9. // LIFE-CYCLE CALLBACKS:
  10. onLoad () {
  11. this.pageViewSize = this.pageView.node._contentSize;
  12. },
  13. start () {
  14. },
  15. init() {
  16. this.node.parent = cc.find("Canvas");
  17. this.node.setContentSize(cc.view.getVisibleSize());
  18. this.node.active = false;
  19. },
  20. onDisable() {
  21. for (let child of this.pageView.content.children) {
  22. if (cc.isValid(child)) {
  23. child.destroy();
  24. }
  25. }
  26. for (let child of this.indicatorLayout.node.children) {
  27. if (cc.isValid(child)) {
  28. child.destroy();
  29. }
  30. }
  31. this.pageView.removeAllPages();
  32. },
  33. showPack() {
  34. this.node.zIndex += 1;
  35. this.node.active = true;
  36. for (var i = 0; i < 3; i++) {
  37. let item = cc.instantiate(this.packPagePrefab);
  38. item = item.getComponent('UserPackPage');
  39. item.init();
  40. item.node.setContentSize(this.pageViewSize);
  41. this.pageView.addPage(item.node);
  42. let indicatorItem = cc.instantiate(this.indicatorPrefab);
  43. this.indicatorLayout.node.addChild(indicatorItem);
  44. let indicatorItemMng = indicatorItem.getComponent('UserPackIndicator');
  45. indicatorItemMng.pageLabel.string = (i + 1).toString();
  46. indicatorItemMng.indicatorIndex = i;
  47. if (i === 0) {
  48. indicatorItemMng.isSelected = true;
  49. }
  50. }
  51. },
  52. closeNodeAction() {
  53. this.node.active = false;
  54. },
  55. pageScrollEnd() {
  56. let selectedIndex = this.pageView.getCurrentPageIndex();
  57. for (let child of this.indicatorLayout.node.children) {
  58. if (child.getComponent('UserPackIndicator') != undefined) {
  59. let indicatorItemMng = child.getComponent('UserPackIndicator');
  60. if (selectedIndex == indicatorItemMng.indicatorIndex) {
  61. indicatorItemMng.isSelected = true;
  62. } else {
  63. indicatorItemMng.isSelected = false;
  64. }
  65. }
  66. }
  67. }
  68. // update (dt) {},
  69. });