HomeSideCtrl.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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.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. GameModule.audioMng.playClickButton();
  101. if (this.moreWelfareNode.active) {
  102. this.moreWelfareNode.active = false;
  103. this.arrowNode.scaleX = 1;
  104. this.arrowNode.getComponent(cc.Widget).right = 75;
  105. } else {
  106. this.moreWelfareNode.active = true;
  107. this.arrowNode.scaleX = -1;
  108. this.arrowNode.getComponent(cc.Widget).right = this.moreContentWidth + 50 + 65;
  109. }
  110. },
  111. hideMore() {
  112. if (this.moreWelfareNode.active) {
  113. this.moreWelfareNode.active = false;
  114. this.arrowNode.scaleX = 1;
  115. this.arrowNode.getComponent(cc.Widget).right = 74;
  116. }
  117. },
  118. start () {
  119. let finish = cc.callFunc(() => {
  120. this.arrowNode2.opacity = 255;
  121. this.arrowNode2.x = 14;
  122. }, this);
  123. let fadeAction = cc.fadeOut(1.0);
  124. let moveAction = cc.moveBy(1.0, -28, 0);
  125. let spaw = cc.spawn(fadeAction,moveAction);
  126. let sequence = cc.sequence(spaw,finish);
  127. let foreverAction = cc.repeatForever(sequence);
  128. this.arrowNode2.runAction(foreverAction);
  129. },
  130. handelShowRedDot() {
  131. if (GameGlobal._redTypes == null || GameGlobal._redTypes == undefined || GameGlobal._redTypes.length == 0) {
  132. this.taskRedNode.active = false;
  133. this.drawRedNode.active = false;
  134. this.storeRedNode.active = false;
  135. this.inviteFriendRedNode.active = false;
  136. this.signRedNode.active = false;
  137. this.giftRedNode.active = false;
  138. this.awardRedNode.active = false;
  139. return;
  140. }
  141. let redTypes = GameGlobal._redTypes;
  142. this.taskRedNode.active = (redTypes.indexOf(GameRedDot.mainTask) != -1 || redTypes.indexOf(GameRedDot.dayTask) != -1);
  143. this.drawRedNode.active = redTypes.indexOf(GameRedDot.draw) != -1;
  144. this.inviteFriendRedNode.active = redTypes.indexOf(GameRedDot.inviteFriend) != -1;
  145. this.signRedNode.active = redTypes.indexOf(GameRedDot.sign) != -1;
  146. this.awardRedNode.active = redTypes.indexOf(GameRedDot.award) != -1;
  147. this.helpRedNode.active = redTypes.indexOf(GameRedDot.friendAward) != -1;
  148. /// 只要这里一个有红点就都有红点
  149. this.giftRedNode.active = this.awardRedNode.active || this.inviteFriendRedNode.active || this.signRedNode.active;
  150. if (GameGlobal.isShowBar && window.tt == undefined) {
  151. let isStoreRed = (redTypes.indexOf(GameRedDot.storeDiamond) != -1 || redTypes.indexOf(GameRedDot.storeCoin) != -1);
  152. this.storeRedNode.active = isStoreRed;
  153. if (isStoreRed) {
  154. if (this._isTimer === false) {
  155. this._isTimer = true;
  156. this._storeTimeCount = 0;
  157. this.storeRedNode.runAction(cc.repeatForever(cc.sequence(cc.moveBy(0.2, 3, 0), cc.moveBy(0.2, -3, 0))));
  158. this.schedule(this.storeTimeAction, 6);
  159. }
  160. } else {
  161. if (this._isTimer == true) {
  162. this.unschedule(this.storeTimeAction, this);
  163. this._isTimer = false;
  164. }
  165. }
  166. } else {
  167. if (this._isTimer === true) {
  168. this.unschedule(this.storeTimeAction, this);
  169. this._isTimer = false;
  170. }
  171. this.storeRedNode.active = false;
  172. }
  173. },
  174. /// 商城未读消息的显示
  175. storeTimeAction() {
  176. this._storeTimeCount += 1;
  177. /// 第一个6秒的时候
  178. if (this._storeTimeCount === 1) {
  179. this.storeRedNode.active = false;
  180. } else if (this._storeTimeCount === 6) {
  181. this.storeRedNode.active = true;
  182. this._storeTimeCount = 0;
  183. // this.storeRedNode.runAction(cc.repeatForever(cc.sequence(cc.moveBy(0.2, 3, 0), cc.moveBy(0.2, -3, 0))));
  184. }
  185. },
  186. _hideLoginReward() {
  187. this.loginRewardNode.active = false;
  188. this.moreContentWidth = 225;
  189. },
  190. // update (dt) {},
  191. //任务中心
  192. handleQuestPopup: _.debounce((event) => {
  193. AlertManager.showQuestPopup();
  194. GameEvent.fire("hide_welfare_more");
  195. }, 1000, true),
  196. //显示抽奖界面
  197. handleShowDraw: _.debounce((event) => {
  198. AlertManager.showDrawAlert();
  199. GameEvent.fire("hide_welfare_more");
  200. }, 1000, true),
  201. //显示商城界面
  202. handleShowStore: _.debounce((event) => {
  203. AlertManager.showStoreAlert();
  204. }, 1000, true),
  205. //显示排行榜界面
  206. handleShowRank: _.debounce((event) => {
  207. AlertManager.showRankAlert();
  208. GameEvent.fire("hide_welfare_more");
  209. }, 1000, true),
  210. //显示邀请好友任务
  211. handleShowInvite: _.debounce((event) => {
  212. AlertManager.showInviteAlert();
  213. GameEvent.fire("hide_welfare_more");
  214. }, 1000, true),
  215. //显示7天登录
  216. handleShowLoginReward: _.debounce((event) => {
  217. AlertManager.showLoginRewardAlert();
  218. GameEvent.fire("hide_welfare_more");
  219. }, 1000, true),
  220. //显示好友助力
  221. handleShowFriendHelp: _.debounce((event) => {
  222. AlertManager.showFriendHelpAlert();
  223. GameEvent.fire("hide_welfare_more");
  224. }, 1000, true),
  225. //显示在线奖励
  226. handleShowOnlineReward: _.debounce((event) => {
  227. AlertManager.showGetAward();
  228. GameEvent.fire("hide_welfare_more");
  229. }, 1000, true),
  230. showMoreWelfare() {
  231. this.handleShowMore();
  232. },
  233. recordTimeAction() {
  234. this._recordTime += 1;
  235. if (this._recordTime === 4) {
  236. this.recordButton.interactable = true;
  237. }
  238. this.recordTimeRichText.string = `<b><color=#fdfdef >${DWTool.calculateTime(this._recordTime)}</c></b>`;
  239. },
  240. //处理头条录制视频然后分享的功能
  241. handleTTRecordVideo() {
  242. this.recordButton.interactable = false;
  243. let recorder = tt.getGameRecorderManager();
  244. /// 如果是开始录制了
  245. if (this._starRecord) {
  246. recorder.stop();
  247. } else {
  248. recorder.start({
  249. duration: 120,
  250. microphoneEnabled: true,
  251. });
  252. }
  253. recorder.onStart(res =>{
  254. // 录屏开始
  255. console.log('录屏开始');
  256. GameGlobal.commonAlert.showCommonErrorAlert('录屏开始');
  257. this._starRecord = true;
  258. this.startRecordNode.active = false;
  259. this.recordingNode.active = true;
  260. this.schedule(this.recordTimeAction, 1);
  261. })
  262. recorder.onStop(res =>{
  263. // 录屏结束;
  264. GameGlobal.commonAlert.showCommonErrorAlert('录屏结束');
  265. this._starRecord = false;
  266. this.startRecordNode.active = true;
  267. this.recordingNode.active = false;
  268. this.recordTimeRichText.string = '<b><color=#fdfdef >00:00</c></b>';
  269. this._recordTime = 0;
  270. this.unschedule(this.recordTimeAction, this);
  271. setTimeout(() => {
  272. this.recordButton.interactable = true;
  273. }, 1000);
  274. tt.shareVideo({
  275. videoPath: `${res.videoPath}`,
  276. success () {
  277. console.log(`分享成功!`);
  278. },
  279. fail (e) {
  280. console.log(`分享失败!`);
  281. }
  282. });
  283. })
  284. recorder.onPause(() =>{
  285. // 录屏已暂停;
  286. })
  287. recorder.onResume(() =>{
  288. // 录屏已恢复;
  289. })
  290. },
  291. });