GameTabbar.js 5.1 KB

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