const {QuestMainMissionType, GameNotificationKey} = require("../utils/GameEnum"); const DWTool = require('../utils/DWTool'); const InviteApi = require('../net/InviteApi'); const GameModule = require("../utils/GameModule"); const TapTapTool = require("../utils/TapTapTool"); const GameRedDot = require('../utils/GameEnum').GameRedDot; cc.Class({ extends: cc.Component, properties: { friendCountRichText: cc.RichText, timeRichText: cc.RichText, noButton: cc.Button, gainButton: cc.Button, finishButton: cc.Button, }, // LIFE-CYCLE CALLBACKS: // onLoad () {}, start () { }, configData(model) { this.model = model; this.hideAllButton(); switch (model.status) { case QuestMainMissionType.NoFinished: this.noButton.node.active = true; break; case QuestMainMissionType.AlreadyGet: this.finishButton.node.active = true; break; case QuestMainMissionType.CanGain: this.gainButton.node.active = true; break; } this.friendCountRichText.string = `${model.count}位好友已成功点击`; var timeString = model.time / 60; if (DWTool.isDot(timeString)) { timeString = timeString.toFixed(2); } this.timeRichText.string = `${timeString}分钟`; }, hideAllButton() { this.noButton.node.active = false; this.gainButton.node.active = false; this.finishButton.node.active = false; }, gainAward() { InviteApi.postFriendGainAward(this.model.rewardId, (responseData) => { if (responseData.isCancel) { TapTapTool.removeRedDot(GameRedDot.friendAward); } this.refreshButtonState(); let isNew = true; for (let i = 0; i < Global._timeInformations.length; ++ i) { let information = Global._timeInformations[i]; if (information.type == 3) { /// 如果是已经使用过的直接刷新时间就可以啦 information.cdTime = Global.friendRewardCdTime; isNew = false; break; } } if (isNew) { let messageItem = {'cdTime': Global.friendRewardCdTime, 'type': 3}; Global._timeInformations.push(messageItem); GameEvent.fire(GameNotificationKey.GameUpdateMessageList, 1, true); } }, (error) => { Global.commonAlert.showCommonErrorAlert("领取失败"); }); }, refreshButtonState() { GameModule.audioMng.playGetAward(); this.model.status = QuestMainMissionType.AlreadyGet; this.hideAllButton(); this.finishButton.node.active = true; Global.friendRewardCdTime += this.model.time * 1000; GameEvent.fire(GameNotificationKey.GainFriendHelpClick); } // update (dt) {}, });