QuestPopup.js 5.1 KB

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