GameTabbar.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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.handelHomeTabbarShowRedDot();
  38. GameEvent.on(GameNotificationKey.GameRedDotUpdate, this, this.handelHomeTabbarShowRedDot);
  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 (GameGlobal._gold10 === undefined) {
  47. return;
  48. }
  49. if (TapTapTool.compare(GameModule.userInfo.gold, GameGlobal._gold10)) {
  50. this.skillRedNode.active = true;
  51. /// 如果是小于 说明金币不满足
  52. } else if (this.skillRedNode.active == true) {
  53. this.skillRedNode.active = false;
  54. }
  55. if (TapTapTool.compare(GameModule.userInfo.gold, GameGlobal._buyStarGold)) {
  56. this.starRedNode.active = true;
  57. } else {
  58. this.starRedNode.active = false;
  59. }
  60. },
  61. start () {
  62. },
  63. handelHomeTabbarShowRedDot() {
  64. if (GameGlobal._redTypes == null || GameGlobal._redTypes == undefined || GameGlobal._redTypes.length == 0) {
  65. this.skillRedNode.active = false;
  66. this.starRedNode.active = false;
  67. return;
  68. }
  69. let redTypes = GameGlobal._redTypes;
  70. // this.skillRedNode.active = redTypes.indexOf(GameRedDot.skill) != -1;
  71. let starActive = redTypes.indexOf(GameRedDot.star) != -1
  72. this.starRedNode.active = starActive;
  73. },
  74. handleTabbarClick(index) {
  75. switch (index) {
  76. case 0:
  77. this.handleSkillAction();
  78. break;
  79. case 1:
  80. this.handleCatAction();
  81. break;
  82. case 2:
  83. this.handleStarAction();
  84. break;
  85. default:
  86. break;
  87. }
  88. },
  89. //显示招财猫
  90. handleCatAction() {
  91. if (this.catMng.isHided) {
  92. this.isShowOffice = false;
  93. this.isShowStar = false;
  94. this.officeCommonNode.active = true;
  95. this.officeSelectedNode.active = false;
  96. this.starCommonNode.active = true;
  97. this.starSelectedNode.active = false;
  98. GameEvent.fire("skillAlert_done");
  99. GameEvent.fire("starAlert_done");
  100. this.showCat();
  101. }
  102. },
  103. //显示技能界面
  104. handleSkillAction() {
  105. if (!GameModule.homeGuide.getComponent('HomeGuide').isPassGuideState('state7')) {
  106. return;
  107. }
  108. if (this.isShowOffice) {
  109. this.officeCommonNode.active = true;
  110. this.officeSelectedNode.active = false;
  111. this.showCat();
  112. GameEvent.fire("skillAlert_done");
  113. } else {
  114. //如果已点开明星界面则需要关闭
  115. if (this.isShowStar) {
  116. this.starCommonNode.active = true;
  117. this.starSelectedNode.active = false;
  118. GameEvent.fire("starAlert_done");
  119. this.isShowStar = false;
  120. }
  121. AlertManager.showSkillAlert();
  122. this.officeCommonNode.active = false;
  123. this.officeSelectedNode.active = true;
  124. if (!this.catMng.isHided) {
  125. this.hideCat();
  126. } else {
  127. this.resetCatPosition();
  128. }
  129. }
  130. this.isShowOffice = !this.isShowOffice;
  131. },
  132. //显示明星界面
  133. handleStarAction() {
  134. if (!GameModule.homeGuide.getComponent('HomeGuide').isPassGuideState('state27')) {
  135. return;
  136. }
  137. if (this.isShowStar) {
  138. this.starCommonNode.active = true;
  139. this.starSelectedNode.active = false;
  140. this.showCat();
  141. GameEvent.fire("starAlert_done");
  142. } else {
  143. //如果已点开技能界面则需要关闭
  144. if (this.isShowOffice) {
  145. this.officeCommonNode.active = true;
  146. this.officeSelectedNode.active = false;
  147. GameEvent.fire("skillAlert_done");
  148. this.isShowOffice = false;
  149. }
  150. GameEvent.fire("skillAlert_done");
  151. AlertManager.showStarAlert();
  152. this.starCommonNode.active = false;
  153. this.starSelectedNode.active = true;
  154. if (!this.catMng.isHided) {
  155. this.hideCat();
  156. } else {
  157. this.resetCatPosition();
  158. }
  159. }
  160. this.isShowStar = !this.isShowStar;
  161. },
  162. showCat() {
  163. GameModule.audioMng.playClickButton();
  164. this.catNode.stopAllActions();
  165. let showAction = cc.moveTo(0.2,0,-11);
  166. this.catNode.runAction(showAction);
  167. this.catMng.isHided = false;
  168. GameModule.homeGuide.getComponent('HomeGuide').tabbarShowCat();
  169. },
  170. hideCat() {
  171. this.catNode.stopAllActions();
  172. let hideAction = cc.moveTo(0.2,0,-161);
  173. this.catNode.runAction(hideAction);
  174. this.catMng.isHided = true;
  175. GameModule.homeGuide.getComponent('HomeGuide').tabbarHideCat();
  176. },
  177. resetCatPosition() {
  178. this.catNode.y = -161;
  179. }
  180. // update (dt) {},
  181. });