HomeSideCtrl.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. const AlertManager = require('../utils/AlertManager');
  2. const GameRedDot = require('../utils/GameEnum').GameRedDot;
  3. const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
  4. const DWTool = require('../utils/DWTool');
  5. cc.Class({
  6. extends: cc.Component,
  7. properties: {
  8. moreWelfareNode: cc.Node,
  9. arrowNode: cc.Node,
  10. arrowNode1: cc.Node,
  11. arrowNode2: cc.Node,
  12. taskRedNode: cc.Node,
  13. storeRedNode: cc.Node,
  14. drawRedNode: cc.Node,
  15. inviteFriendRedNode: cc.Node,
  16. signRedNode: cc.Node,
  17. giftRedNode: cc.Node,
  18. ///每天时间段奖励的红点
  19. awardRedNode: cc.Node,
  20. /// 好友助力点击红点
  21. helpRedNode: cc.Node,
  22. //7天登录按钮节点
  23. loginRewardNode: cc.Node,
  24. storeNode: cc.Node,
  25. drawNode: cc.Node,
  26. },
  27. // LIFE-CYCLE CALLBACKS:
  28. onLoad () {
  29. let self = this;
  30. this.handleShowMore = _.throttle(() => {
  31. self.hideOrShowMore();
  32. }, 500, true);
  33. //判断正在审核中的版本隐藏商城、抽奖按钮
  34. if (Global.isCheck) {
  35. this.storeNode.active = false;
  36. this.drawNode.active = false;
  37. }
  38. //判断正在审核中的版本隐藏7天登录按钮或已完成7天登录任务
  39. if (Global.isCheck || (Global.userLoginReward.isLoginReward && Global.userLoginReward.rewardCount == 7)) {
  40. this.loginRewardNode.active = false;
  41. this.moreContentWidth = 225;
  42. } else {
  43. this.moreContentWidth = 346;
  44. }
  45. /// 加载商城打折图片
  46. this._loadStoreDiscountSprite();
  47. GameEvent.on('hide_welfare_more', this, () => {
  48. this.hideMore();
  49. });
  50. GameEvent.on(GameNotificationKey.GameRedDotUpdate, this, this.handelShowRedDot);
  51. //7天登录奖励完成隐藏按钮
  52. GameEvent.on(GameNotificationKey.LoginRewardGainFinish, this, this._hideLoginReward);
  53. },
  54. onDestroy() {
  55. GameEvent.off('hide_welfare_more',this);
  56. GameEvent.off(GameNotificationKey.LoginRewardGainFinish, this);
  57. },
  58. _loadStoreDiscountSprite() {
  59. if (Global._shopZk > 0) {
  60. let url = Global.debug ? `https://pub.dwstatic.com/wxgame/taptapstar_test/assets/shop_${Global._shopZk}.png` : `https://pub.dwstatic.com/wxgame/taptapstar/assets/shop_${Global._shopZk}.png`;
  61. DWTool.loadSpriteFrame(url).then( (spriteFrame) => {
  62. this.storeNode.getComponent(cc.Sprite).spriteFrame = spriteFrame;
  63. }).catch((err) => {
  64. console.log(err);
  65. })
  66. }
  67. },
  68. hideOrShowMore() {
  69. if (this.moreWelfareNode.active) {
  70. this.moreWelfareNode.active = false;
  71. this.arrowNode.scaleX = 1;
  72. this.arrowNode.getComponent(cc.Widget).right = 75;
  73. } else {
  74. this.moreWelfareNode.active = true;
  75. this.arrowNode.scaleX = -1;
  76. this.arrowNode.getComponent(cc.Widget).right = this.moreContentWidth + 50 + 65;
  77. }
  78. },
  79. hideMore() {
  80. if (this.moreWelfareNode.active) {
  81. this.moreWelfareNode.active = false;
  82. this.arrowNode.scaleX = 1;
  83. this.arrowNode.getComponent(cc.Widget).right = 74;
  84. }
  85. },
  86. start () {
  87. let finish = cc.callFunc(() => {
  88. this.arrowNode2.opacity = 255;
  89. this.arrowNode2.x = 14;
  90. }, this);
  91. let fadeAction = cc.fadeOut(1.0);
  92. let moveAction = cc.moveBy(1.0, -28, 0);
  93. let spaw = cc.spawn(fadeAction,moveAction);
  94. let sequence = cc.sequence(spaw,finish);
  95. let foreverAction = cc.repeatForever(sequence);
  96. this.arrowNode2.runAction(foreverAction);
  97. },
  98. handelShowRedDot() {
  99. if (Global._redTypes == null || Global._redTypes == undefined || Global._redTypes.length == 0) {
  100. this.taskRedNode.active = false;
  101. this.drawRedNode.active = false;
  102. this.storeRedNode.active = false;
  103. this.inviteFriendRedNode.active = false;
  104. this.signRedNode.active = false;
  105. this.giftRedNode.active = false;
  106. this.awardRedNode.active = false;
  107. return;
  108. }
  109. let redTypes = Global._redTypes;
  110. this.taskRedNode.active = (redTypes.indexOf(GameRedDot.mainTask) != -1 || redTypes.indexOf(GameRedDot.dayTask) != -1);
  111. this.drawRedNode.active = redTypes.indexOf(GameRedDot.draw) != -1;
  112. this.inviteFriendRedNode.active = redTypes.indexOf(GameRedDot.inviteFriend) != -1;
  113. this.signRedNode.active = redTypes.indexOf(GameRedDot.sign) != -1;
  114. this.awardRedNode.active = redTypes.indexOf(GameRedDot.award) != -1;
  115. this.helpRedNode.active = redTypes.indexOf(GameRedDot.friendAward) != -1;
  116. /// 只要这里一个有红点就都有红点
  117. this.giftRedNode.active = this.awardRedNode.active || this.inviteFriendRedNode.active || this.signRedNode.active;
  118. if (this.isShowBar) {
  119. let isStoreRed = (redTypes.indexOf(GameRedDot.storeDiamond) != -1 || redTypes.indexOf(GameRedDot.storeCoin) != -1);
  120. this.storeRedNode.active = isStoreRed;
  121. if (isStoreRed) {
  122. if (this._isTimer === false) {
  123. this._isTimer = true;
  124. this._storeTimeCount = 0;
  125. this.storeRedNode.runAction(cc.repeatForever(cc.sequence(cc.moveBy(0.2, 3, 0), cc.moveBy(0.2, -3, 0))));
  126. this.schedule(this.storeTimeAction, 6);
  127. }
  128. } else {
  129. if (this._isTimer == true) {
  130. this.unschedule(this.storeTimeAction, this);
  131. this._isTimer = false;
  132. }
  133. }
  134. } else {
  135. if (this._isTimer === true) {
  136. this.unschedule(this.storeTimeAction, this);
  137. this._isTimer = false;
  138. }
  139. this.storeRedNode.active = false;
  140. }
  141. },
  142. /// 商城未读消息的显示
  143. storeTimeAction() {
  144. this._storeTimeCount += 1;
  145. /// 第一个6秒的时候
  146. if (this._storeTimeCount === 1) {
  147. this.storeRedNode.active = false;
  148. } else if (this._storeTimeCount === 6) {
  149. this.storeRedNode.active = true;
  150. this._storeTimeCount = 0;
  151. // this.storeRedNode.runAction(cc.repeatForever(cc.sequence(cc.moveBy(0.2, 3, 0), cc.moveBy(0.2, -3, 0))));
  152. }
  153. },
  154. _hideLoginReward() {
  155. this.loginRewardNode.active = false;
  156. this.moreContentWidth = 225;
  157. },
  158. // update (dt) {},
  159. //任务中心
  160. handleQuestPopup: _.debounce((event) => {
  161. AlertManager.showQuestPopup();
  162. GameEvent.fire("hide_welfare_more");
  163. }, 1000, true),
  164. //显示抽奖界面
  165. handleShowDraw: _.debounce((event) => {
  166. AlertManager.showDrawAlert();
  167. GameEvent.fire("hide_welfare_more");
  168. }, 1000, true),
  169. //显示商城界面
  170. handleShowStore: _.debounce((event) => {
  171. AlertManager.showStoreAlert();
  172. }, 1000, true),
  173. //显示排行榜界面
  174. handleShowRank: _.debounce((event) => {
  175. AlertManager.showRankAlert();
  176. GameEvent.fire("hide_welfare_more");
  177. }, 1000, true),
  178. //显示邀请好友任务
  179. handleShowInvite: _.debounce((event) => {
  180. AlertManager.showInviteAlert();
  181. GameEvent.fire("hide_welfare_more");
  182. }, 1000, true),
  183. //显示7天登录
  184. handleShowLoginReward: _.debounce((event) => {
  185. AlertManager.showLoginRewardAlert();
  186. GameEvent.fire("hide_welfare_more");
  187. }, 1000, true),
  188. //显示好友助力
  189. handleShowFriendHelp: _.debounce((event) => {
  190. AlertManager.showFriendHelpAlert();
  191. GameEvent.fire("hide_welfare_more");
  192. }, 1000, true),
  193. //显示在线奖励
  194. handleShowOnlineReward: _.debounce((event) => {
  195. AlertManager.showGetAward();
  196. GameEvent.fire("hide_welfare_more");
  197. }, 1000, true),
  198. showMoreWelfare() {
  199. this.handleShowMore();
  200. }
  201. });