const AlertManager = require('../utils/AlertManager'); const GameRedDot = require('../utils/GameEnum').GameRedDot; const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey; const DWTool = require('../utils/DWTool'); 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, }, // LIFE-CYCLE CALLBACKS: onLoad () { let self = this; this.handleShowMore = _.throttle(() => { self.hideOrShowMore(); }, 500, true); //判断正在审核中的版本隐藏商城、抽奖按钮 if (Global.isCheck) { this.storeNode.active = false; this.drawNode.active = false; } //判断正在审核中的版本隐藏7天登录按钮或已完成7天登录任务 if (Global.isCheck || (Global.userLoginReward.isLoginReward && Global.userLoginReward.rewardCount == 7)) { this.loginRewardNode.active = false; this.moreContentWidth = 225; } else { this.moreContentWidth = 346; } /// 加载商城打折图片 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); }, onDestroy() { GameEvent.off('hide_welfare_more',this); GameEvent.off(GameNotificationKey.LoginRewardGainFinish, this); }, _loadStoreDiscountSprite() { if (Global._shopZk > 0) { 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`; 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 (Global._redTypes == null || Global._redTypes == undefined || Global._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 = Global._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 (this.isShowBar) { 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(); } });