QuestPopup.js 5.4 KB

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