QuestPopup.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. questDaily: {
  5. tooltip: '每日任务容器',
  6. default: null,
  7. type: cc.Node
  8. },
  9. questMain: {
  10. tooltip: '主线任务容器',
  11. default: null,
  12. type: cc.Node
  13. },
  14. tab: [cc.Node],
  15. tabFade: cc.Node,
  16. tabIndex: {
  17. tooltip: '默认显示的Tab',
  18. default: 0,
  19. type: cc.Integer
  20. }
  21. },
  22. onLoad () {
  23. this._initDaily()
  24. this._initMain()
  25. this._initTab()
  26. },
  27. start () {
  28. let space = 50;
  29. let upAction = cc.moveTo(0.25, cc.v2(0, space));
  30. let downAction = cc.moveBy(0.1, cc.v2(0, -space));
  31. let bouncesActionArray = [upAction, downAction];
  32. this.node.runAction(cc.sequence(bouncesActionArray));
  33. },
  34. /**
  35. * 初始化Tab
  36. */
  37. _initTab () {
  38. for(let i = 0; i < this.tab.length; i++) {
  39. this.tab[i] = this.tab[i].getComponent('QuestTab')
  40. this.tab[i].init(this)
  41. }
  42. this.tabFade.zIndex = 20
  43. this.tabList = [this.questMain, this.questDaily]
  44. this.handleTab(null, this.tabIndex)
  45. },
  46. /**
  47. * 初始化每日任务
  48. */
  49. _initDaily () {
  50. this.questDaily = this.questDaily.getComponent('QuestDaily')
  51. this.questDaily.init(this)
  52. },
  53. /**
  54. * 初始化主线任务
  55. */
  56. _initMain () {
  57. this.questMain = this.questMain.getComponent('QuestMain')
  58. this.questMain.init(this)
  59. },
  60. /**
  61. * Tab切换
  62. * @param {number} tabIndex [1: 每日任务, 0: 完成目标]
  63. */
  64. handleTab(event, tabIndex) {
  65. this.tab.forEach((item, index) => {
  66. if(tabIndex == index) {
  67. item.show()
  68. item.node.zIndex = 30
  69. this.tabList[index].node.active = true
  70. } else {
  71. item.hide()
  72. item.node.zIndex = 10
  73. this.tabList[index].node.active = false
  74. }
  75. })
  76. },
  77. close() {
  78. this.node.destroy();
  79. }
  80. });