HomeSideCtrl.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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. const GameModule = require("../utils/GameModule");
  6. cc.Class({
  7. extends: cc.Component,
  8. properties: {
  9. moreWelfareNode: cc.Node,
  10. arrowNode: cc.Node,
  11. arrowNode1: cc.Node,
  12. arrowNode2: cc.Node,
  13. taskRedNode: cc.Node,
  14. storeRedNode: cc.Node,
  15. drawRedNode: cc.Node,
  16. inviteFriendRedNode: cc.Node,
  17. signRedNode: cc.Node,
  18. giftRedNode: cc.Node,
  19. ///每天时间段奖励的红点
  20. awardRedNode: cc.Node,
  21. /// 好友助力点击红点
  22. helpRedNode: cc.Node,
  23. //7天登录按钮节点
  24. loginRewardNode: cc.Node,
  25. //对应按钮
  26. //商城
  27. storeNode: cc.Node,
  28. //抽奖
  29. drawNode: cc.Node,
  30. //自动点击
  31. friendRewardNode: cc.Node,
  32. //邀请
  33. inviteNode: cc.Node,
  34. //// 以下都是头条录屏功能需要的节点
  35. recordButton: cc.Button,
  36. startRecordNode: cc.Node,
  37. /// 正在录屏
  38. recordingNode: cc.Node,
  39. recordTimeRichText: cc.RichText,
  40. },
  41. // LIFE-CYCLE CALLBACKS:
  42. onLoad () {
  43. let self = this;
  44. this.handleShowMore = _.throttle(() => {
  45. self.hideOrShowMore();
  46. }, 500, true);
  47. //判断正在审核中的版本隐藏商城、抽奖按钮
  48. if (GameGlobal.isCheck) {
  49. this.storeNode.active = false;
  50. this.drawNode.active = false;
  51. }
  52. /// 如果是头条那么隐藏商城
  53. if (window.tt !== undefined) {
  54. this.storeNode.active = false;
  55. this.friendRewardNode.active = false;
  56. this.inviteNode.active = false;
  57. this._starRecord = false;
  58. this._recordTime = 0;
  59. } else {
  60. this.recordButton.node.active = false;
  61. }
  62. //判断正在审核中的版本隐藏7天登录按钮或已完成7天登录任务
  63. if (GameGlobal.isCheck || (GameGlobal.userLoginReward.isLoginReward && GameGlobal.userLoginReward.rewardCount == 7)) {
  64. this.loginRewardNode.active = false;
  65. this.moreContentWidth = 225;
  66. if (window.tt != undefined) {
  67. this.moreContentWidth = 104;
  68. }
  69. } else {
  70. this.moreContentWidth = 346;
  71. if (window.tt != undefined) {
  72. this.moreContentWidth = 225;
  73. }
  74. }
  75. /// 加载商城打折图片
  76. this._loadStoreDiscountSprite();
  77. GameEvent.on('hide_welfare_more', this, () => {
  78. this.hideMore();
  79. });
  80. GameEvent.on(GameNotificationKey.GameRedDotUpdate, this, this.handelShowRedDot);
  81. //7天登录奖励完成隐藏按钮
  82. GameEvent.on(GameNotificationKey.LoginRewardGainFinish, this, this._hideLoginReward);
  83. GameModule.homeGuide.on('Fire_state31', this.handleQuestPopup, this);
  84. },
  85. onDestroy() {
  86. GameEvent.off('hide_welfare_more',this);
  87. GameEvent.off(GameNotificationKey.LoginRewardGainFinish, this);
  88. },
  89. _loadStoreDiscountSprite() {
  90. if (GameGlobal._shopZk > 0) {
  91. let url = GameGlobal.debug ? `https://pub.dwstatic.com/wxgame/taptapstar_test/assets/shop_${GameGlobal._shopZk}.png` : `https://pub.dwstatic.com/wxgame/taptapstar/assets/shop_${GameGlobal._shopZk}.png`;
  92. DWTool.loadSpriteFrame(url).then( (spriteFrame) => {
  93. this.storeNode.getComponent(cc.Sprite).spriteFrame = spriteFrame;
  94. }).catch((err) => {
  95. console.log(err);
  96. })
  97. }
  98. },
  99. hideOrShowMore() {
  100. if (this.moreWelfareNode.active) {
  101. this.moreWelfareNode.active = false;
  102. this.arrowNode.scaleX = 1;
  103. this.arrowNode.getComponent(cc.Widget).right = 75;
  104. } else {
  105. this.moreWelfareNode.active = true;
  106. this.arrowNode.scaleX = -1;
  107. this.arrowNode.getComponent(cc.Widget).right = this.moreContentWidth + 50 + 65;
  108. }
  109. },
  110. hideMore() {
  111. if (this.moreWelfareNode.active) {
  112. this.moreWelfareNode.active = false;
  113. this.arrowNode.scaleX = 1;
  114. this.arrowNode.getComponent(cc.Widget).right = 74;
  115. }
  116. },
  117. start () {
  118. let finish = cc.callFunc(() => {
  119. this.arrowNode2.opacity = 255;
  120. this.arrowNode2.x = 14;
  121. }, this);
  122. let fadeAction = cc.fadeOut(1.0);
  123. let moveAction = cc.moveBy(1.0, -28, 0);
  124. let spaw = cc.spawn(fadeAction,moveAction);
  125. let sequence = cc.sequence(spaw,finish);
  126. let foreverAction = cc.repeatForever(sequence);
  127. this.arrowNode2.runAction(foreverAction);
  128. },
  129. handelShowRedDot() {
  130. if (GameGlobal._redTypes == null || GameGlobal._redTypes == undefined || GameGlobal._redTypes.length == 0) {
  131. this.taskRedNode.active = false;
  132. this.drawRedNode.active = false;
  133. this.storeRedNode.active = false;
  134. this.inviteFriendRedNode.active = false;
  135. this.signRedNode.active = false;
  136. this.giftRedNode.active = false;
  137. this.awardRedNode.active = false;
  138. return;
  139. }
  140. let redTypes = GameGlobal._redTypes;
  141. this.taskRedNode.active = (redTypes.indexOf(GameRedDot.mainTask) != -1 || redTypes.indexOf(GameRedDot.dayTask) != -1);
  142. this.drawRedNode.active = redTypes.indexOf(GameRedDot.draw) != -1;
  143. this.inviteFriendRedNode.active = redTypes.indexOf(GameRedDot.inviteFriend) != -1;
  144. this.signRedNode.active = redTypes.indexOf(GameRedDot.sign) != -1;
  145. this.awardRedNode.active = redTypes.indexOf(GameRedDot.award) != -1;
  146. this.helpRedNode.active = redTypes.indexOf(GameRedDot.friendAward) != -1;
  147. /// 只要这里一个有红点就都有红点
  148. this.giftRedNode.active = this.awardRedNode.active || this.inviteFriendRedNode.active || this.signRedNode.active;
  149. if (GameGlobal.isShowBar && window.tt == undefined) {
  150. let isStoreRed = (redTypes.indexOf(GameRedDot.storeDiamond) != -1 || redTypes.indexOf(GameRedDot.storeCoin) != -1);
  151. this.storeRedNode.active = isStoreRed;
  152. if (isStoreRed) {
  153. if (this._isTimer === false) {
  154. this._isTimer = true;
  155. this._storeTimeCount = 0;
  156. this.storeRedNode.runAction(cc.repeatForever(cc.sequence(cc.moveBy(0.2, 3, 0), cc.moveBy(0.2, -3, 0))));
  157. this.schedule(this.storeTimeAction, 6);
  158. }
  159. } else {
  160. if (this._isTimer == true) {
  161. this.unschedule(this.storeTimeAction, this);
  162. this._isTimer = false;
  163. }
  164. }
  165. } else {
  166. if (this._isTimer === true) {
  167. this.unschedule(this.storeTimeAction, this);
  168. this._isTimer = false;
  169. }
  170. this.storeRedNode.active = false;
  171. }
  172. },
  173. /// 商城未读消息的显示
  174. storeTimeAction() {
  175. this._storeTimeCount += 1;
  176. /// 第一个6秒的时候
  177. if (this._storeTimeCount === 1) {
  178. this.storeRedNode.active = false;
  179. } else if (this._storeTimeCount === 6) {
  180. this.storeRedNode.active = true;
  181. this._storeTimeCount = 0;
  182. // this.storeRedNode.runAction(cc.repeatForever(cc.sequence(cc.moveBy(0.2, 3, 0), cc.moveBy(0.2, -3, 0))));
  183. }
  184. },
  185. _hideLoginReward() {
  186. this.loginRewardNode.active = false;
  187. this.moreContentWidth = 225;
  188. },
  189. // update (dt) {},
  190. //任务中心
  191. handleQuestPopup: _.debounce((event) => {
  192. AlertManager.showQuestPopup();
  193. GameEvent.fire("hide_welfare_more");
  194. }, 1000, true),
  195. //显示抽奖界面
  196. handleShowDraw: _.debounce((event) => {
  197. AlertManager.showDrawAlert();
  198. GameEvent.fire("hide_welfare_more");
  199. }, 1000, true),
  200. //显示商城界面
  201. handleShowStore: _.debounce((event) => {
  202. AlertManager.showStoreAlert();
  203. }, 1000, true),
  204. //显示排行榜界面
  205. handleShowRank: _.debounce((event) => {
  206. AlertManager.showRankAlert();
  207. GameEvent.fire("hide_welfare_more");
  208. }, 1000, true),
  209. //显示邀请好友任务
  210. handleShowInvite: _.debounce((event) => {
  211. AlertManager.showInviteAlert();
  212. GameEvent.fire("hide_welfare_more");
  213. }, 1000, true),
  214. //显示7天登录
  215. handleShowLoginReward: _.debounce((event) => {
  216. AlertManager.showLoginRewardAlert();
  217. GameEvent.fire("hide_welfare_more");
  218. }, 1000, true),
  219. //显示好友助力
  220. handleShowFriendHelp: _.debounce((event) => {
  221. AlertManager.showFriendHelpAlert();
  222. GameEvent.fire("hide_welfare_more");
  223. }, 1000, true),
  224. //显示在线奖励
  225. handleShowOnlineReward: _.debounce((event) => {
  226. AlertManager.showGetAward();
  227. GameEvent.fire("hide_welfare_more");
  228. }, 1000, true),
  229. showMoreWelfare() {
  230. this.handleShowMore();
  231. },
  232. recordTimeAction() {
  233. this._recordTime += 1;
  234. if (this._recordTime === 4) {
  235. this.recordButton.interactable = true;
  236. }
  237. this.recordTimeRichText.string = `<b><color=#fdfdef >${DWTool.calculateTime(this._recordTime)}</c></b>`;
  238. },
  239. //处理头条录制视频然后分享的功能
  240. handleTTRecordVideo() {
  241. this.recordButton.interactable = false;
  242. let recorder = tt.getGameRecorderManager();
  243. /// 如果是开始录制了
  244. if (this._starRecord) {
  245. recorder.stop();
  246. } else {
  247. recorder.start({
  248. duration: 120,
  249. microphoneEnabled: true,
  250. });
  251. }
  252. recorder.onStart(res =>{
  253. // 录屏开始
  254. console.log('录屏开始');
  255. GameGlobal.commonAlert.showCommonErrorAlert('录屏开始');
  256. this._starRecord = true;
  257. this.startRecordNode.active = false;
  258. this.recordingNode.active = true;
  259. this.schedule(this.recordTimeAction, 1);
  260. })
  261. recorder.onStop(res =>{
  262. // 录屏结束;
  263. GameGlobal.commonAlert.showCommonErrorAlert('录屏结束');
  264. this._starRecord = false;
  265. this.startRecordNode.active = true;
  266. this.recordingNode.active = false;
  267. this.recordTimeRichText.string = '<b><color=#fdfdef >00:00</c></b>';
  268. this._recordTime = 0;
  269. this.unschedule(this.recordTimeAction, this);
  270. setTimeout(() => {
  271. this.recordButton.interactable = true;
  272. }, 1000);
  273. tt.shareVideo({
  274. videoPath: `${res.videoPath}`,
  275. success () {
  276. console.log(`分享成功!`);
  277. },
  278. fail (e) {
  279. console.log(`分享失败!`);
  280. }
  281. });
  282. })
  283. recorder.onPause(() =>{
  284. // 录屏已暂停;
  285. })
  286. recorder.onResume(() =>{
  287. // 录屏已恢复;
  288. })
  289. },
  290. });