const InviteApi = require('../net/InviteApi'); const WeChat = require('../net/WeChat'); const inviteReward = require('../data/inviteReward'); const { GameNotificationKey, WechatShareType } = require('../utils/GameEnum'); const GameModule = require("../utils/GameModule"); const InvitedItem = require("InvitedItem"); const AlertManager = require('../utils/AlertManager'); cc.Class({ extends: cc.Component, properties: { contentNode: cc.Node, invitedPrefab: cc.Prefab, invitedScrollViewNode: cc.ScrollView, listScrollViewNode: cc.ScrollView, missionPrefab: cc.Prefab, invitedItemArray: [InvitedItem], shareButtonNode: cc.Node, shareTipsLabel: cc.Label }, // LIFE-CYCLE CALLBACKS: onLoad() { if (GameGlobal.winSize.height <= 1000) { this.contentNode.height = 820; } this.giftMap = ['diamond']; for (var i = 0; i < 10; i++) { let item = cc.instantiate(this.invitedPrefab); item = item.getComponent('InvitedItem'); item.node.parent = this.invitedScrollViewNode.content; this.invitedItemArray.push(item); } GameEvent.on(GameNotificationKey.InviteGainAward, this, (model) => { this.gainActGift(model); }); if (window.tt != undefined) { this.shareTipsLabel.string = "发送链接给你的好友,邀请TA来一起玩游戏吧~"; } else if (CC_QQPLAY) { this.shareTipsLabel.string = "发送链接给你的QQ好友,邀请TA来一起玩游戏吧~"; } }, start() { this.getNetworkData(); let scaleAction1 = cc.scaleTo(0.6, 1.2, 1.2); let scaleAction2 = cc.scaleTo(0.6, 0.8, 0.8); let seq = cc.repeatForever(cc.sequence(scaleAction1, scaleAction2)); this.shareButtonNode.runAction(seq); }, onDestroy() { GameEvent.off(GameNotificationKey.InviteGainAward, this); }, closeNode() { GameModule.audioMng.playClickButton(); this.node.destroy(); }, getNetworkData() { InviteApi.getInviteMissionList((responseData) => { // console.log("responseData: " + JSON.stringify(responseData)); this.loadData(responseData); }, (error) => { console.log('mission error' + error); }); }, loadData(responseData) { this.userHeadInfoList = responseData.userHeadInfoList; this.inviteRewardRecordVoList = responseData.inviteRewardRecordVoList; this.invitedCount = responseData.invited; this.layoutInvitedUser(); this.layoutMission(); }, layoutInvitedUser() { for (var i = 0; i < this.userHeadInfoList.length; i++) { let item = this.invitedItemArray[i]; let itemModel = this.userHeadInfoList[i]; item.configData(itemModel); } }, layoutMission() { for (var i = 0; i < this.inviteRewardRecordVoList.length; i++) { let itemModel = this.inviteRewardRecordVoList[i]; for (let mission of inviteReward) { if (mission.id == itemModel.rid) { let item = cc.instantiate(this.missionPrefab); item = item.getComponent('InviteMissionItem'); item.node.parent = this.listScrollViewNode.content; item.node.width = this.listScrollViewNode.node._contentSize.width; mission.state = itemModel.state; item.configData(mission, this.invitedCount); break; } } } }, gainActGift(model) { let diamond = model.diamond; let gainModel = { 'type': 'diamond', 'text': `钻石 x ${diamond}` }; AlertManager.showActGiftAlert(gainModel.type, gainModel.text); GameModule.userInfo.updateUserRes({ diamond: parseInt(diamond) }); }, inviteFriend() { GameModule.audioMng.playClickButton(); WeChat.shareAction(WechatShareType.InviteFriend, () => { }, () => { console.log('分享失败或取消'); }); GameGlobal.isIgnoreShareStatus = true; }, });