Game.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. const HomeApi = require("../net/HomeApi");
  2. const AlertManager = require('../utils/AlertManager');
  3. const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
  4. const ShareAction = require('../utils/ShareAction');
  5. const GameModule = require("../utils/GameModule");
  6. cc.Class({
  7. extends: cc.Component,
  8. properties: {
  9. levelHomePrefab: cc.Prefab,
  10. myInfoTop: cc.Node,
  11. sidebar: cc.Node,
  12. clickAddMoney: cc.Prefab,
  13. additionTipsNode: cc.Node,
  14. homeGuide: cc.Node
  15. },
  16. // LIFE-CYCLE CALLBACKS:
  17. onLoad () {
  18. this.isShowBar = false;
  19. // 引导界面
  20. this.homeGuide.zIndex = 200;
  21. GameModule.homeGuide = this.homeGuide;
  22. this.homeGuide = this.homeGuide.getComponent('HomeGuide');
  23. this.homeGuide.init();
  24. // 创建一个事件监听实例, 用来实现跨节点监听事件
  25. GameEvent.init();
  26. cc.debug.setDisplayStats(false);
  27. //建筑展示
  28. let levelHome = cc.instantiate(this.levelHomePrefab);
  29. levelHome = levelHome.getComponent('LevelHome');
  30. levelHome.init(Global.user.uid);
  31. this.levelHome = levelHome;
  32. this.levelHome.node.active = true;
  33. let XHeight = 1624;
  34. this.winSize = cc.view.getVisibleSize();
  35. console.log('game ======================= ' + this.winSize);
  36. if (this.winSize.height >= XHeight) {
  37. this.myInfoTop.height = 200;
  38. this.sidebar.getComponent(cc.Widget).top = 180;
  39. }
  40. this.additionTipsNode = this.additionTipsNode.getComponent('AdditionTips');
  41. this._setEventListener();
  42. if (Global.shareType == ShareAction.SHOW_GROUP_RANK && Global.shareTicket.length > 0) {
  43. if (this.homeGuide.guideState.state1.pass) {
  44. GameEvent.fire(GameNotificationKey.GameShowGroupRank);
  45. }
  46. }
  47. },
  48. start () {
  49. if (!this.homeGuide.guideState.state1.pass) {
  50. // 触发引导系统state1状态
  51. GameModule.homeGuide.getComponent('HomeGuide').handleState('state1');
  52. }
  53. GameModule.homeGuide.getComponent('HomeGuide').handleGuideStateNext('state4', 'state5');
  54. GameModule.homeGuide.getComponent('HomeGuide').handleGuideStateNext('state6', 'state7');
  55. // GameModule.homeGuide.getComponent('HomeGuide').handleState('state31');
  56. GameModule.homeGuide.getComponent('HomeGuide').handleGuideStateNext('state29', 'state31');
  57. GameModule.homeGuide.on('Fire_state29', this.finishState29, this);
  58. GameModule.homeGuide.on('Fire_state31', this.handleQuestPopup, this);
  59. if (this.homeGuide.guideState.state7.pass || this.homeGuide.guideState.state11.pass) {
  60. GameModule.homeGuide.getComponent('HomeGuide').handleState('state13');
  61. GameModule.homeGuide.getComponent('HomeGuide').changeGuideTask1315(false);
  62. if (this.homeGuide.guideState.state13.pass) {
  63. GameModule.homeGuide.getComponent('HomeGuide').handleState('state15');
  64. GameModule.homeGuide.getComponent('HomeGuide').changeGuideTask1315(false);
  65. }
  66. }
  67. this._showSidebarUI();
  68. },
  69. update (dt) {
  70. if (GameModule.skill.isUsingSkill3) {
  71. GameEvent.fire(GameNotificationKey.PlaySuccessAnimation);
  72. }
  73. },
  74. _setEventListener() {
  75. GameEvent.on(GameNotificationKey.GameShowAdditionTips, this, this.showAdditionTips);
  76. GameEvent.on(GameNotificationKey.GameShowGroupRank, this, this.showGroupRank);
  77. },
  78. onDestroy() {
  79. GameEvent.off(GameNotificationKey.GameShowAdditionTips, this);
  80. GameEvent.off(GameNotificationKey.GameShowGroupRank, this);
  81. },
  82. _showSidebarUI() {
  83. let isOk = false;
  84. //教程31还没有完成不显示
  85. if (!this.homeGuide.guideState.state31.pass) {
  86. // 1. 总部大楼大于25级
  87. // 2. 已拥有1个明星
  88. let unLockStatus1 = GameModule.userInfo.buildingLevel >= 25;
  89. let unLockStatus2 = GameModule.userInfo.buyStarCount > 0;
  90. if (unLockStatus1 && unLockStatus2) {
  91. isOk = true
  92. }
  93. } else {
  94. isOk = true
  95. }
  96. if (!isOk) {
  97. return;
  98. }
  99. this.isShowBar = true;
  100. let action = cc.moveBy(0.3, cc.v2(-this.sidebar.width, 0));
  101. this.sidebar.runAction(action);
  102. },
  103. finishState29() {
  104. if (this.isShowBar) {
  105. return;
  106. }
  107. this.isShowBar = true;
  108. let action = cc.moveBy(0.3, cc.v2(-this.sidebar.width, 0));
  109. this.sidebar.runAction(action);
  110. },
  111. //
  112. handleQuestPopup: _.debounce((event) => {
  113. AlertManager.showQuestPopup();
  114. if (event) {
  115. event.target.getChildByName("notice_point").active = false;
  116. }
  117. }, 1000, true),
  118. //显示抽奖界面
  119. handleShowDraw: _.debounce((event) => {
  120. AlertManager.showDrawAlert();
  121. }, 1000, true),
  122. //显示商城界面
  123. handleShowStore: _.debounce((event) => {
  124. AlertManager.showStoreAlert();
  125. }, 1000, true),
  126. //显示排行榜界面
  127. handleShowRank: _.debounce((event) => {
  128. AlertManager.showRankAlert();
  129. }, 1000, true),
  130. showGroupRank() {
  131. AlertManager.showRankAlert(2);
  132. },
  133. showAdditionTips(text, type) {
  134. if (this.node.active) {
  135. this.additionTipsNode.show(text, type);
  136. }
  137. },
  138. // update (dt) {},
  139. });