QuestPopup.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. setTimeout(() => {
  61. this._initTab()
  62. }, 300);
  63. },
  64. start () {
  65. // let space = 50;
  66. // let upAction = cc.moveTo(0.25, cc.v2(0, space));
  67. // let downAction = cc.moveBy(0.1, cc.v2(0, -space));
  68. // let bouncesActionArray = [upAction, downAction];
  69. // this.node.runAction(cc.sequence(bouncesActionArray));
  70. },
  71. /**
  72. * 初始化Tab
  73. */
  74. _initTab () {
  75. for(let i = 0; i < this.tab.length; i++) {
  76. this.tab[i] = this.tab[i].getComponent('QuestTab')
  77. this.tab[i].init(this)
  78. }
  79. this.tabFade.zIndex = 20
  80. this.handleTab(null, this.tabIndex)
  81. },
  82. /**
  83. * 初始化每日任务
  84. */
  85. _initDaily () {
  86. if(!this.initDailyDone) {
  87. this.initDailyDone = true
  88. this.questDaily = this.questDaily.getComponent('QuestDaily')
  89. this.questDaily.init(this)
  90. }
  91. },
  92. /**
  93. * 初始化主线任务
  94. */
  95. _initMain () {
  96. if(!this.initMainDone) {
  97. this.initMainDone = true
  98. this.questMain = this.questMain.getComponent('QuestMain')
  99. this.questMain.init(this)
  100. }
  101. },
  102. /**
  103. * Tab切换
  104. * @param {number} tabIndex [1: 每日任务, 0: 完成目标]
  105. */
  106. handleTab(event, tabIndex) {
  107. this.tab.forEach((item, index) => {
  108. if(tabIndex == index) {
  109. item.show()
  110. item.node.zIndex = 30
  111. this.tabList[index].wrap.active = true
  112. this.tabList[index].init.apply(this)
  113. } else {
  114. item.hide()
  115. item.node.zIndex = 10
  116. this.tabList[index].wrap.active = false
  117. }
  118. })
  119. },
  120. /**
  121. * 更新全局用户数据
  122. * @param {number} coin 金币
  123. * @param {number} diamond 钻石
  124. * @param {number} ticket 艺人券
  125. */
  126. updateUserInfo (coin, diamond, ticket) {
  127. GameModule.userInfo.updateUserRes({
  128. grossIncome: coin,
  129. diamond: diamond,
  130. ticket: ticket
  131. })
  132. },
  133. /**
  134. * 显示领取活跃度奖励动画
  135. * @param {object} giftObj {ticket: 艺人券, diamond: 钻石, coin: 金币}
  136. */
  137. showActGift (giftObj) {
  138. let giftMap = {
  139. diamond: {
  140. showText: '钻石',
  141. count: giftObj.diamond
  142. },
  143. coin: {
  144. showText: '金币',
  145. count: giftObj.coin
  146. },
  147. ticket: {
  148. showText: '艺人券',
  149. count: giftObj.ticket
  150. },
  151. }
  152. let showText, showType
  153. for(let i in giftMap) {
  154. if(giftMap[i].count > 0) {
  155. showText = `${giftMap[i].showText} x ${giftMap[i].count}`
  156. showType = i
  157. }
  158. }
  159. GameModule.audioMng.playGift()
  160. this.mask.zIndex = 12
  161. this.actGift.active = true
  162. this.giftMap.forEach((value, index) => {
  163. if(showType == value) {
  164. cc.find('/gift_sprite', this.actGift).getComponent('cc.Sprite').spriteFrame = this.actGiftFrames[index]
  165. cc.find('/gift_label', this.actGift).getComponent('cc.Label').string = showText
  166. }
  167. })
  168. },
  169. /**
  170. * 显示领取奖励动画
  171. * @param {cc.SpriteFrame} showFrame 图片素材
  172. * @param {string} showText 显示文案
  173. */
  174. showMainGift (showFrame, showText) {
  175. GameModule.audioMng.playGift()
  176. this.mask.zIndex = 12
  177. this.actGift.active = true
  178. cc.find('/gift_sprite', this.actGift).getComponent('cc.Sprite').spriteFrame = showFrame
  179. cc.find('/gift_label', this.actGift).getComponent('cc.Label').string = showText
  180. },
  181. hideActGift () {
  182. this.mask.zIndex = 10
  183. this.actGift.active = false
  184. },
  185. close() {
  186. this.node.destroy();
  187. }
  188. });