QuestPopup.js 5.0 KB

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