const AlertManager = require('../utils/AlertManager'); const GameRedDot = require('../utils/GameEnum').GameRedDot; const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey; const DWTool = require('../utils/DWTool'); const GameModule = require("../utils/GameModule"); cc.Class({ extends: cc.Component, properties: { moreWelfareNode: cc.Node, arrowNode: cc.Node, arrowNode1: cc.Node, arrowNode2: cc.Node, taskRedNode: cc.Node, storeRedNode: cc.Node, drawRedNode: cc.Node, inviteFriendRedNode: cc.Node, signRedNode: cc.Node, giftRedNode: cc.Node, ///每天时间段奖励的红点 awardRedNode: cc.Node, /// 好友助力点击红点 helpRedNode: cc.Node, //7天登录按钮节点 loginRewardNode: cc.Node, //对应按钮 //商城 storeNode: cc.Node, //抽奖 drawNode: cc.Node, //自动点击 friendRewardNode: cc.Node, //邀请 inviteNode: cc.Node, //// 以下都是头条录屏功能需要的节点 recordButton: cc.Button, startRecordNode: cc.Node, /// 正在录屏 recordingNode: cc.Node, recordTimeRichText: cc.RichText, }, // LIFE-CYCLE CALLBACKS: onLoad () { let self = this; this.handleShowMore = _.throttle(() => { self.hideOrShowMore(); }, 500, true); //判断正在审核中的版本隐藏商城、抽奖按钮 if (GameGlobal.isCheck) { this.storeNode.active = false; this.drawNode.active = false; } /// 如果是头条那么隐藏商城 if (window.tt !== undefined) { this.storeNode.active = false; this.friendRewardNode.active = false; this.inviteNode.active = false; this._starRecord = false; this._recordTime = 0; } else { this.recordButton.node.active = false; } //判断正在审核中的版本隐藏7天登录按钮或已完成7天登录任务 if (GameGlobal.isCheck || (GameGlobal.userLoginReward.isLoginReward && GameGlobal.userLoginReward.rewardCount == 7)) { this.loginRewardNode.active = false; this.moreContentWidth = 225; if (window.tt != undefined) { this.moreContentWidth = 104; } } else { this.moreContentWidth = 346; if (window.tt != undefined) { this.moreContentWidth = 225; } } /// 加载商城打折图片 this._loadStoreDiscountSprite(); GameEvent.on('hide_welfare_more', this, () => { this.hideMore(); }); GameEvent.on(GameNotificationKey.GameRedDotUpdate, this, this.handelShowRedDot); //7天登录奖励完成隐藏按钮 GameEvent.on(GameNotificationKey.LoginRewardGainFinish, this, this._hideLoginReward); GameModule.homeGuide.on('Fire_state31', this.handleQuestPopup, this); }, onDestroy() { GameEvent.off('hide_welfare_more',this); GameEvent.off(GameNotificationKey.LoginRewardGainFinish, this); }, _loadStoreDiscountSprite() { if (GameGlobal._shopZk > 0) { 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`; DWTool.loadSpriteFrame(url).then( (spriteFrame) => { this.storeNode.getComponent(cc.Sprite).spriteFrame = spriteFrame; }).catch((err) => { console.log(err); }) } }, hideOrShowMore() { if (this.moreWelfareNode.active) { this.moreWelfareNode.active = false; this.arrowNode.scaleX = 1; this.arrowNode.getComponent(cc.Widget).right = 75; } else { this.moreWelfareNode.active = true; this.arrowNode.scaleX = -1; this.arrowNode.getComponent(cc.Widget).right = this.moreContentWidth + 50 + 65; } }, hideMore() { if (this.moreWelfareNode.active) { this.moreWelfareNode.active = false; this.arrowNode.scaleX = 1; this.arrowNode.getComponent(cc.Widget).right = 74; } }, start () { let finish = cc.callFunc(() => { this.arrowNode2.opacity = 255; this.arrowNode2.x = 14; }, this); let fadeAction = cc.fadeOut(1.0); let moveAction = cc.moveBy(1.0, -28, 0); let spaw = cc.spawn(fadeAction,moveAction); let sequence = cc.sequence(spaw,finish); let foreverAction = cc.repeatForever(sequence); this.arrowNode2.runAction(foreverAction); }, handelShowRedDot() { if (GameGlobal._redTypes == null || GameGlobal._redTypes == undefined || GameGlobal._redTypes.length == 0) { this.taskRedNode.active = false; this.drawRedNode.active = false; this.storeRedNode.active = false; this.inviteFriendRedNode.active = false; this.signRedNode.active = false; this.giftRedNode.active = false; this.awardRedNode.active = false; return; } let redTypes = GameGlobal._redTypes; this.taskRedNode.active = (redTypes.indexOf(GameRedDot.mainTask) != -1 || redTypes.indexOf(GameRedDot.dayTask) != -1); this.drawRedNode.active = redTypes.indexOf(GameRedDot.draw) != -1; this.inviteFriendRedNode.active = redTypes.indexOf(GameRedDot.inviteFriend) != -1; this.signRedNode.active = redTypes.indexOf(GameRedDot.sign) != -1; this.awardRedNode.active = redTypes.indexOf(GameRedDot.award) != -1; this.helpRedNode.active = redTypes.indexOf(GameRedDot.friendAward) != -1; /// 只要这里一个有红点就都有红点 this.giftRedNode.active = this.awardRedNode.active || this.inviteFriendRedNode.active || this.signRedNode.active; if (GameGlobal.isShowBar && window.tt == undefined) { let isStoreRed = (redTypes.indexOf(GameRedDot.storeDiamond) != -1 || redTypes.indexOf(GameRedDot.storeCoin) != -1); this.storeRedNode.active = isStoreRed; if (isStoreRed) { if (this._isTimer === false) { this._isTimer = true; this._storeTimeCount = 0; this.storeRedNode.runAction(cc.repeatForever(cc.sequence(cc.moveBy(0.2, 3, 0), cc.moveBy(0.2, -3, 0)))); this.schedule(this.storeTimeAction, 6); } } else { if (this._isTimer == true) { this.unschedule(this.storeTimeAction, this); this._isTimer = false; } } } else { if (this._isTimer === true) { this.unschedule(this.storeTimeAction, this); this._isTimer = false; } this.storeRedNode.active = false; } }, /// 商城未读消息的显示 storeTimeAction() { this._storeTimeCount += 1; /// 第一个6秒的时候 if (this._storeTimeCount === 1) { this.storeRedNode.active = false; } else if (this._storeTimeCount === 6) { this.storeRedNode.active = true; this._storeTimeCount = 0; // this.storeRedNode.runAction(cc.repeatForever(cc.sequence(cc.moveBy(0.2, 3, 0), cc.moveBy(0.2, -3, 0)))); } }, _hideLoginReward() { this.loginRewardNode.active = false; this.moreContentWidth = 225; }, // update (dt) {}, //任务中心 handleQuestPopup: _.debounce((event) => { AlertManager.showQuestPopup(); GameEvent.fire("hide_welfare_more"); }, 1000, true), //显示抽奖界面 handleShowDraw: _.debounce((event) => { AlertManager.showDrawAlert(); GameEvent.fire("hide_welfare_more"); }, 1000, true), //显示商城界面 handleShowStore: _.debounce((event) => { AlertManager.showStoreAlert(); }, 1000, true), //显示排行榜界面 handleShowRank: _.debounce((event) => { AlertManager.showRankAlert(); GameEvent.fire("hide_welfare_more"); }, 1000, true), //显示邀请好友任务 handleShowInvite: _.debounce((event) => { AlertManager.showInviteAlert(); GameEvent.fire("hide_welfare_more"); }, 1000, true), //显示7天登录 handleShowLoginReward: _.debounce((event) => { AlertManager.showLoginRewardAlert(); GameEvent.fire("hide_welfare_more"); }, 1000, true), //显示好友助力 handleShowFriendHelp: _.debounce((event) => { AlertManager.showFriendHelpAlert(); GameEvent.fire("hide_welfare_more"); }, 1000, true), //显示在线奖励 handleShowOnlineReward: _.debounce((event) => { AlertManager.showGetAward(); GameEvent.fire("hide_welfare_more"); }, 1000, true), showMoreWelfare() { this.handleShowMore(); }, recordTimeAction() { this._recordTime += 1; if (this._recordTime === 4) { this.recordButton.interactable = true; } this.recordTimeRichText.string = `${DWTool.calculateTime(this._recordTime)}`; }, //处理头条录制视频然后分享的功能 handleTTRecordVideo() { this.recordButton.interactable = false; let recorder = tt.getGameRecorderManager(); /// 如果是开始录制了 if (this._starRecord) { recorder.stop(); } else { recorder.start({ duration: 120, microphoneEnabled: true, }); } recorder.onStart(res =>{ // 录屏开始 console.log('录屏开始'); GameGlobal.commonAlert.showCommonErrorAlert('录屏开始'); this._starRecord = true; this.startRecordNode.active = false; this.recordingNode.active = true; this.schedule(this.recordTimeAction, 1); }) recorder.onStop(res =>{ // 录屏结束; GameGlobal.commonAlert.showCommonErrorAlert('录屏结束'); this._starRecord = false; this.startRecordNode.active = true; this.recordingNode.active = false; this.recordTimeRichText.string = '00:00'; this._recordTime = 0; this.unschedule(this.recordTimeAction, this); setTimeout(() => { this.recordButton.interactable = true; }, 1000); tt.shareVideo({ videoPath: `${res.videoPath}`, success () { console.log(`分享成功!`); }, fail (e) { console.log(`分享失败!`); } }); }) recorder.onPause(() =>{ // 录屏已暂停; }) recorder.onResume(() =>{ // 录屏已恢复; }) }, });