QuestPopup.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. const GameModule = require("../utils/GameModule");
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. questDaily: {
  6. tooltip: '每日任务容器',
  7. default: null,
  8. type: cc.Node
  9. },
  10. questMain: {
  11. tooltip: '主线任务容器',
  12. default: null,
  13. type: cc.Node
  14. },
  15. tab: [cc.Node],
  16. tabFade: cc.Node,
  17. tabIndex: {
  18. tooltip: '默认显示的Tab',
  19. default: 0,
  20. type: cc.Integer
  21. },
  22. mask: {
  23. tooltip: '遮罩层',
  24. default: null,
  25. type: cc.Node
  26. },
  27. wrap: {
  28. tooltip: '弹窗载体',
  29. default: null,
  30. type: cc.Node
  31. },
  32. actGift: {
  33. tooltip: '活跃度弹出层',
  34. default: null,
  35. type: cc.Node
  36. },
  37. actGiftFrames: {
  38. tooltip: '奖品大图',
  39. default: [],
  40. type: [cc.SpriteFrame]
  41. }
  42. },
  43. onLoad () {
  44. this.giftMap = ['diamond', 'coin', 'ticket']
  45. this.tabList = [{
  46. wrap: this.questMain,
  47. init: () => {
  48. this._initMain()
  49. },
  50. }, {
  51. wrap: this.questDaily,
  52. init: () => {
  53. this._initDaily()
  54. }
  55. }]
  56. this.mask.zIndex = 10
  57. this.wrap.zIndex = 11
  58. this.actGift.zIndex = 15
  59. this.actGift.active = false
  60. this._initTab()
  61. // setTimeout(() => {
  62. // this.showActGift('coin')
  63. // }, 2000);
  64. },
  65. start () {
  66. let space = 50;
  67. let upAction = cc.moveTo(0.25, cc.v2(0, space));
  68. let downAction = cc.moveBy(0.1, cc.v2(0, -space));
  69. let bouncesActionArray = [upAction, downAction];
  70. this.node.runAction(cc.sequence(bouncesActionArray));
  71. },
  72. /**
  73. * 初始化Tab
  74. */
  75. _initTab () {
  76. for(let i = 0; i < this.tab.length; i++) {
  77. this.tab[i] = this.tab[i].getComponent('QuestTab')
  78. this.tab[i].init(this)
  79. }
  80. this.tabFade.zIndex = 20
  81. this.handleTab(null, this.tabIndex)
  82. },
  83. /**
  84. * 初始化每日任务
  85. */
  86. _initDaily () {
  87. if(!this.initDailyDone) {
  88. this.initDailyDone = true
  89. this.questDaily = this.questDaily.getComponent('QuestDaily')
  90. this.questDaily.init(this)
  91. }
  92. },
  93. /**
  94. * 初始化主线任务
  95. */
  96. _initMain () {
  97. if(!this.initMainDone) {
  98. this.initMainDone = true
  99. this.questMain = this.questMain.getComponent('QuestMain')
  100. this.questMain.init(this)
  101. }
  102. },
  103. /**
  104. * Tab切换
  105. * @param {number} tabIndex [1: 每日任务, 0: 完成目标]
  106. */
  107. handleTab(event, tabIndex) {
  108. this.tab.forEach((item, index) => {
  109. if(tabIndex == index) {
  110. item.show()
  111. item.node.zIndex = 30
  112. this.tabList[index].wrap.active = true
  113. this.tabList[index].init.apply(this)
  114. } else {
  115. item.hide()
  116. item.node.zIndex = 10
  117. this.tabList[index].wrap.active = false
  118. }
  119. })
  120. },
  121. /**
  122. * 更新全局用户数据
  123. * @param {number} coin 金币
  124. * @param {number} diamond 钻石
  125. * @param {number} ticket 艺人券
  126. */
  127. updateUserInfo (coin, diamond, ticket) {
  128. GameModule.userInfo.updateUserRes({
  129. grossIncome: coin,
  130. diamond: diamond,
  131. ticket: ticket
  132. })
  133. },
  134. /**
  135. * 显示领取活跃度奖励动画
  136. * @param {object} giftObj {ticket: 艺人券, diamond: 钻石, coin: 金币}
  137. */
  138. showActGift (giftObj) {
  139. let giftMap = {
  140. diamond: {
  141. showText: '钻石',
  142. count: giftObj.diamond
  143. },
  144. coin: {
  145. showText: '金币',
  146. count: giftObj.coin
  147. },
  148. ticket: {
  149. showText: '艺人券',
  150. count: giftObj.ticket
  151. },
  152. }
  153. let showText, showType
  154. for(let i in giftMap) {
  155. if(giftMap[i].count > 0) {
  156. showText = `${giftMap[i].showText} x ${giftMap[i].count}`
  157. showType = i
  158. }
  159. }
  160. GameModule.audioMng.playGift()
  161. this.mask.zIndex = 12
  162. this.actGift.active = true
  163. this.giftMap.forEach((value, index) => {
  164. if(showType == value) {
  165. cc.find('/gift_sprite', this.actGift).getComponent('cc.Sprite').spriteFrame = this.actGiftFrames[index]
  166. cc.find('/gift_label', this.actGift).getComponent('cc.Label').string = showText
  167. }
  168. })
  169. },
  170. hideActGift () {
  171. this.mask.zIndex = 10
  172. this.actGift.active = false
  173. },
  174. close() {
  175. this.node.destroy();
  176. }
  177. });