GameTabbar.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. const AlertManager = require('../utils/AlertManager');
  2. const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
  3. const GameModule = require("../utils/GameModule");
  4. const GameRedDot = require('../utils/GameEnum').GameRedDot;
  5. const TapTapTool = require("../utils/TapTapTool");
  6. cc.Class({
  7. extends: cc.Component,
  8. properties: {
  9. officeNode: cc.Node,
  10. officeCommonNode: cc.Node,
  11. officeSelectedNode: cc.Node,
  12. starNode: cc.Node,
  13. starCommonNode: cc.Node,
  14. starSelectedNode: cc.Node,
  15. catNode: cc.Node,
  16. skillRedNode: cc.Node,
  17. starRedNode: cc.Node,
  18. },
  19. // LIFE-CYCLE CALLBACKS:
  20. onLoad () {
  21. this.isShowOffice = false;
  22. this.isShowStar = false;
  23. this.catMng = this.catNode.getComponent('MoneyCat');
  24. let self = this;
  25. this.handleChangeTab = _.throttle((index) => {
  26. self.handleTabbarClick(index);
  27. }, 500, true);
  28. this.officeNode.on(cc.Node.EventType.TOUCH_END, () => {
  29. self.handleChangeTab(0);
  30. });
  31. this.starNode.on(cc.Node.EventType.TOUCH_END, () => {
  32. self.handleChangeTab(2);
  33. });
  34. GameEvent.on(GameNotificationKey.TabbarClickCat, this, () => {
  35. self.handleChangeTab(1);
  36. });
  37. this.handelShowRedDot();
  38. GameEvent.on(GameNotificationKey.GameRedDotUpdate, this, this.handelShowRedDot);
  39. GameModule.homeGuide.on('Fire_state11', this.handleSkillAction, this);
  40. GameModule.homeGuide.on('Fire_state28', this.handleStarAction, this);
  41. GameModule.homeGuide.getComponent('HomeGuide').handleGuideStateNext('state8', 'state10');
  42. GameModule.homeGuide.getComponent('HomeGuide').handleGuideStateNext('state26', 'state27');
  43. this.schedule(this.updateRedDot, 1);
  44. },
  45. updateRedDot () {
  46. if (Global._gold10 === undefined) {
  47. return;
  48. }
  49. if (TapTapTool.compare(GameModule.userInfo.gold, Global._gold10) && this.skillRedNode.active == false) {
  50. this.skillRedNode.active = true;
  51. } else if (this.skillRedNode == true && Global._redTypes.indexOf(GameRedDot.skill) == -1) {
  52. this.skillRedNode.active = false;
  53. }
  54. if (TapTapTool.compare(GameModule.userInfo.gold, Global._buyStarGold)) {
  55. this.starRedNode.active = true;
  56. } else {
  57. this.starRedNode.active = false;
  58. }
  59. },
  60. start () {
  61. },
  62. handelShowRedDot() {
  63. if (Global._redTypes == null || Global._redTypes == undefined || Global._redTypes.length == 0) {
  64. this.skillRedNode.active = false;
  65. this.starRedNode.active = false;
  66. return;
  67. }
  68. let redTypes = Global._redTypes;
  69. this.skillRedNode.active = (redTypes.indexOf(GameRedDot.skill) != -1 || redTypes.indexOf(GameRedDot.upSKillBuiding) != -1);
  70. let starActive = redTypes.indexOf(GameRedDot.star) != -1
  71. this.starRedNode.active = starActive;
  72. },
  73. handleTabbarClick(index) {
  74. switch (index) {
  75. case 0:
  76. this.handleSkillAction();
  77. break;
  78. case 1:
  79. this.handleCatAction();
  80. break;
  81. case 2:
  82. this.handleStarAction();
  83. break;
  84. default:
  85. break;
  86. }
  87. },
  88. //显示招财猫
  89. handleCatAction() {
  90. if (this.catMng.isHided) {
  91. this.isShowOffice = false;
  92. this.isShowStar = false;
  93. this.officeCommonNode.active = true;
  94. this.officeSelectedNode.active = false;
  95. this.starCommonNode.active = true;
  96. this.starSelectedNode.active = false;
  97. GameEvent.fire("skillAlert_done");
  98. GameEvent.fire("starAlert_done");
  99. this.showCat();
  100. }
  101. },
  102. //显示技能界面
  103. handleSkillAction() {
  104. if (!GameModule.homeGuide.getComponent('HomeGuide').isPassGuideState('state7')) {
  105. return;
  106. }
  107. if (this.isShowOffice) {
  108. this.officeCommonNode.active = true;
  109. this.officeSelectedNode.active = false;
  110. this.showCat();
  111. GameEvent.fire("skillAlert_done");
  112. } else {
  113. //如果已点开明星界面则需要关闭
  114. if (this.isShowStar) {
  115. this.starCommonNode.active = true;
  116. this.starSelectedNode.active = false;
  117. GameEvent.fire("starAlert_done");
  118. this.isShowStar = false;
  119. }
  120. AlertManager.showSkillAlert();
  121. this.officeCommonNode.active = false;
  122. this.officeSelectedNode.active = true;
  123. if (!this.catMng.isHided) {
  124. this.hideCat();
  125. } else {
  126. this.resetCatPosition();
  127. }
  128. }
  129. this.isShowOffice = !this.isShowOffice;
  130. },
  131. //显示明星界面
  132. handleStarAction() {
  133. if (!GameModule.homeGuide.getComponent('HomeGuide').isPassGuideState('state27')) {
  134. return;
  135. }
  136. if (this.isShowStar) {
  137. this.starCommonNode.active = true;
  138. this.starSelectedNode.active = false;
  139. this.showCat();
  140. GameEvent.fire("starAlert_done");
  141. } else {
  142. //如果已点开技能界面则需要关闭
  143. if (this.isShowOffice) {
  144. this.officeCommonNode.active = true;
  145. this.officeSelectedNode.active = false;
  146. GameEvent.fire("skillAlert_done");
  147. this.isShowOffice = false;
  148. }
  149. GameEvent.fire("skillAlert_done");
  150. AlertManager.showStarAlert();
  151. this.starCommonNode.active = false;
  152. this.starSelectedNode.active = true;
  153. if (!this.catMng.isHided) {
  154. this.hideCat();
  155. } else {
  156. this.resetCatPosition();
  157. }
  158. }
  159. this.isShowStar = !this.isShowStar;
  160. },
  161. showCat() {
  162. GameModule.audioMng.playClickButton();
  163. this.catNode.stopAllActions();
  164. let showAction = cc.moveTo(0.2,0,-11);
  165. this.catNode.runAction(showAction);
  166. this.catMng.isHided = false;
  167. GameModule.homeGuide.getComponent('HomeGuide').tabbarShowCat();
  168. },
  169. hideCat() {
  170. this.catNode.stopAllActions();
  171. let hideAction = cc.moveTo(0.2,0,-161);
  172. this.catNode.runAction(hideAction);
  173. this.catMng.isHided = true;
  174. GameModule.homeGuide.getComponent('HomeGuide').tabbarHideCat();
  175. },
  176. resetCatPosition() {
  177. this.catNode.y = -161;
  178. }
  179. // update (dt) {},
  180. });