123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343 |
- 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.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() {
- GameModule.audioMng.playClickButton();
- 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 = `<b><color=#fdfdef >${DWTool.calculateTime(this._recordTime)}</c></b>`;
- },
- //处理头条录制视频然后分享的功能
- 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 = '<b><color=#fdfdef >00:00</c></b>';
- 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(() =>{
- // 录屏已恢复;
- })
- },
- });
|