DreamMain.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. let ButtonSelect1 = require('ButtonSelect1')
  2. let ViewBase = require('ViewBase')
  3. cc.Class({
  4. extends: ViewBase,
  5. properties: {
  6. button1: {
  7. default: null,
  8. type: ButtonSelect1,
  9. serializable: true,
  10. },
  11. button2: {
  12. default: null,
  13. type: ButtonSelect1,
  14. serializable: true,
  15. },
  16. button3: {
  17. default: null,
  18. type: ButtonSelect1,
  19. serializable: true,
  20. },
  21. button4: {
  22. default: null,
  23. type: ButtonSelect1,
  24. serializable: true,
  25. },
  26. viewContent: {
  27. default: null,
  28. type: cc.Node,
  29. serializable: true,
  30. }
  31. },
  32. onLoad () {
  33. this.buttons = [
  34. this.button1,
  35. this.button2,
  36. this.button3,
  37. this.button4,
  38. ];
  39. this.views = [
  40. {type:JMC.UIEnum.DreamPopular, view:null, initing:false},
  41. {type:JMC.UIEnum.DreamBrilliant, view:null, initing:false},
  42. {type:JMC.UIEnum.DreamDropRecord, view:null, initing:false},
  43. {type:JMC.UIEnum.DreamStatistics, view:null, initing:false},
  44. ];
  45. this.curViewType = null
  46. this.onClickTitle(null, "0")
  47. },
  48. onClickTitle(event, customEventData) {
  49. let index = parseInt(customEventData)
  50. this.updateButtonSelect(index);
  51. this.curViewType = index;
  52. this.createOrShowView(this.curViewType)
  53. },
  54. updateButtonSelect(index) {
  55. for (let i = 0; i < this.buttons.length; i++) {
  56. const b = this.buttons[i];
  57. b.setSelect(index == i)
  58. }
  59. },
  60. createOrShowView(type) {
  61. let viewData = this.views[type]
  62. for (let vd of this.views) {
  63. if (vd.view == null) {
  64. continue
  65. }
  66. vd.view.active = false;
  67. }
  68. if (viewData.initing) {
  69. return
  70. }
  71. if (viewData.view != null) {
  72. viewData.view.active = true;
  73. return
  74. }
  75. viewData.initing = true
  76. let self = this
  77. this.createComponent(viewData.type, this.viewContent, null, function(node, status) {
  78. if (status != 'ok') {
  79. return
  80. }
  81. viewData.view = node
  82. viewData.initing = false
  83. node.active = self.curViewType == type
  84. })
  85. }
  86. // update (dt) {},
  87. });