var wechat = require("../net/WeChat"); const DWTool = require('../utils/DWTool'); var shareDialog = require('./ShareDialog') const ShareAction = require('../utils/ShareAction'); const FriendSystemApi = require('../net/FriendSystemApi') cc.Class({ extends: cc.Component, properties: { content: cc.Node, friendNode: cc.Node, recommendNode: cc.Node, _wechatFriendNode: cc.Node, friendButton: cc.Button, recommendButton: cc.Button, wechatFriendButton: cc.Button, friendTabSprites: [cc.SpriteFrame], recommendTabSprites: [cc.SpriteFrame], wechatFriendTabSprites: [cc.SpriteFrame], }, onLoad() { this.node.height = cc.view.getVisibleSize().height; this.contentY = this.content.y = (this.content.height - this.node.height) / 2; this._defaultY = 496; this._selectedY = 480; }, onEnable() { }, onDisable() { }, show(wechatFriendNode) { this.setWechatFriendNode(wechatFriendNode); this.node.parent = cc.find('Canvas'); this.node.active = true; this.content.y = -cc.view.getVisibleSize().height; let s = cc.sequence(cc.moveTo(0.2, 0, this.contentY + 20).easing(cc.easeCubicActionOut()), cc.moveBy(0.05, 0, -20)); this.content.runAction(s); this.scheduleOnce(() => { this.setTabState(0); }, 0.2); }, close() { if (this.node && this.node.parent) { this._wechatFriendNode.active = false; let finish = cc.callFunc(() => { this.closeFriendSystem(); }, this) this.content.runAction(cc.sequence(cc.moveTo(0.2, 0, -cc.view.getVisibleSize().height).easing(cc.easeCubicActionIn()), finish)); } }, setTabState(currentIndex) { if (this.currentIndex === currentIndex) { return; } console.log('currentIndex:' + currentIndex); this.currentIndex = currentIndex; switch (currentIndex) { case 0: this.setTabSelected(true, this.friendButton, this.friendTabSprites, this.friendNode); this.setTabSelected(false, this.recommendButton, this.recommendTabSprites, this.recommendNode); this.setTabSelected(false, this.wechatFriendButton, this.wechatFriendTabSprites, this._wechatFriendNode); break; case 1: this.setTabSelected(false, this.friendButton, this.friendTabSprites, this.friendNode); this.setTabSelected(true, this.recommendButton, this.recommendTabSprites, this.recommendNode); this.setTabSelected(false, this.wechatFriendButton, this.wechatFriendTabSprites, this._wechatFriendNode); break; case 2: this._wechatFriendNode.zIndex = 2; this.setTabSelected(false, this.friendButton, this.friendTabSprites, this.friendNode); this.setTabSelected(false, this.recommendButton, this.recommendTabSprites, this.recommendNode); this.setTabSelected(true, this.wechatFriendButton, this.wechatFriendTabSprites, this._wechatFriendNode); break; } }, setWechatFriendNode(wechatFriendNode) { this._wechatFriendNode = wechatFriendNode; this._wechatFriendNode.height = cc.view.getVisibleSize().height; }, closeFriendSystem: function () { this.friendNode.getComponent('FriendList').friendLastRequestTime = -1; this.currentIndex = -1; // this.node.active = false; this.node.destroy(); this._wechatFriendNode.active = false; }, showTalent() { cc.loader.loadRes('/prefabs/talent_mission', cc.Prefab, (error, prefab) => { if (error === null) { let mission = cc.instantiate(prefab); mission = mission.getComponent('TalentMission'); mission.init(); } else { console.log(JSON.stringify(error)); } }); }, inviteFriend: function () { wechat.inviteFriendPromise().then(() => { FriendSystemApi.shareSuccessNotice(); }); // cc.loader.loadRes('/prefabs/share_dialog', cc.Prefab, (error, prefab) => { // if (error === null) { // let shareDialog = cc.instantiate(prefab); // this.node.addChild(shareDialog); // shareDialog.getComponent('ShareDialog').showInviteFriend(); // } else { // console.log(JSON.stringify(error)); // } // }); }, changeToWechatFriendTab() { this.setTabState(2); }, changeToRecommendTab() { this.setTabState(1); }, changeToFriendTab() { this.setTabState(0); }, setTabSelected(selected, button, tabBgs, listViewNode) { if (selected && button.node.zIndex === 0 || !selected && button.node.zIndex === 1) { button.getComponent(cc.Sprite).spriteFrame = selected ? tabBgs[1] : tabBgs[0]; listViewNode.active = selected; button.node.zIndex = selected ? 1 : 0; button.node.y = selected ? this._selectedY : this._defaultY; // let finish = cc.callFunc(() => { // button.node.zIndex = selected ? 1 : 0; // }) // var animation = cc.sequence(cc.moveTo(0.2, button.node.x, moveY), finish); // button.node.runAction(animation); } }, // update (dt) {}, });