const DWTool = require('./utils/DWTool'); const Style = require('./utils/GameEnum').LevelHomeFriendItemStyle; const HomeApi = require('./net/HomeApi'); const GameModule = require("./utils/GameModule"); const Notikey = require('./utils/GameEnum').GameNotificationKey; cc.Class({ extends: cc.Component, properties: { bgNode: cc.Node, friendSpriteFrames: [cc.SpriteFrame], artistSpriteFrames: [cc.SpriteFrame], friendBtn: cc.Button, artistBtn: cc.Button, friendItem: cc.Prefab, friendScrollView: cc.ScrollView, artistScrollView: cc.ScrollView, noArtistTipNode: cc.Node, _currentTab: 0 , allFriendNode: cc.Node }, // LIFE-CYCLE CALLBACKS: onLoad () { GameModule.tab = this.node; this.friends = []; this.artists = []; this.setBtnSpriteFrames(); this.bgNode.zIndex = 1; this.friendScrollView.node.zIndex = 1; // this.artistScrollView.node.zIndex = 1; if (this._currentTab === 0) { // this.friendBtn.node.setScale(1.0, 1.0); // this.artistBtn.node.setScale(0.9, 0.9); // this.friendBtn.node.zIndex = 2; // this.artistBtn.node.zIndex = 0; this.friendScrollView.node.active = true; // this.artistScrollView.node.active = false; // this.artistScrollView.node.position = cc.v2(0, -250); } else { // this.friendBtn.node.setScale(0.9, 0.9); // this.artistBtn.node.setScale(1.0, 1.0); // this.friendBtn.node.zIndex = 0; // this.artistBtn.node.zIndex = 2; // this.friendScrollView.node.active = false; // this.artistScrollView.node.active = true; // this.friendScrollView.node.position = cc.v2(0, -250); } this.allFriendNode.on(cc.Node.EventType.TOUCH_END, _.debounce(() => { GameEvent.fire(Notikey.ShowFriendSystem); GameModule.audioMng.playButton(); }, 1000, true), this); // 刷新好友列表 GameEvent.on(Notikey.RefreshFriendList, this, () => { this.loadFriendData().then((data) => { Global.friendList = this.friends = data.users || []; this.friendLayout(); }).catch((err) => { console.log(err); }); }); // 刷新艺人列表 GameEvent.on(Notikey.RefreshArtistManagerList, this, () => { this.loadArtists() .then((result) => { if (result != undefined) { this.artists = result; this.noArtistTipNode.active = false; } else { this.artists = []; this.noArtistTipNode.active = true; } this.artistLayout(); }).catch((err) => { console.log(err); }); }); this.changeTabEvent = _.debounce((eventData) => { this._currentTab = eventData; this.setBtnSpriteFrames(); let showBtn = (eventData == 0) ? this.friendBtn : this.artistBtn; let hideBtn = (eventData == 0) ? this.artistBtn : this.friendBtn; let showScrollView = (eventData == 0) ? this.friendScrollView : this.artistScrollView; let hideScrollView = (eventData == 0) ? this.artistScrollView : this.friendScrollView; this.showAnimation(showBtn, hideScrollView); this.hideAnimation(hideBtn, showScrollView); }, 500, true); }, init(game) { this.game = game this.loadFriendData().then((data) => { // 好友数据回调 Global.friendList = this.friends = data.users || []; this.noArtistTipNode.active = false; this.friendLayout(); }).catch((err) => { // 捕获到报错 console.log(err); }); }, setBtnSpriteFrames() { this.friendBtn.getComponent(cc.Sprite).spriteFrame = this.friendSpriteFrames[this._currentTab]; this.artistBtn.getComponent(cc.Sprite).spriteFrame = this.artistSpriteFrames[this._currentTab]; }, showAnimation(btn, scrollView) { let tempBtn = btn; let tempScrollView = scrollView; tempBtn.node.zIndex = 2; let scrollMoveAction = cc.moveTo(0.3, cc.p(0, -250)); let scrollCallback = cc.callFunc(() => { tempScrollView.node.active = false; }); tempScrollView.node.runAction(cc.sequence(scrollMoveAction, scrollCallback)); }, hideAnimation(btn, scrollView) { let tempBtn = btn; let tempScrollView = scrollView; tempBtn.node.zIndex = 0; tempScrollView.node.active = true; let scrollMoveAction = cc.moveTo(0.3, cc.p(0, -10)); tempScrollView.node.runAction(scrollMoveAction); }, changeTab(target, eventData) { if (this._currentTab == eventData) { return; } this.changeTabEvent(eventData); }, loadFriendData() { return new Promise((resolve, reject) => { HomeApi.getFriends((responseData) => { resolve(responseData); }, (error) => { reject(error); }); }); }, loadArtists() { return new Promise((resolve, reject) => { HomeApi.getFriendManageList((responseData) => { resolve(responseData); }, (error) => { reject(error); }) }); }, layout() { this.friendLayout(); // this.artistLayout(); }, friendLayout() { for (let child of this.friendScrollView.content.children) { child.destroy(); } for (let i = 0; i < this.friends.length; i++) { let item = cc.instantiate(this.friendItem); let scriptComponent = item.getComponent('LevelHomeFriendItem'); scriptComponent.style = Style.Friend; scriptComponent.setFriendInfo(this.friends[i]); this.friendScrollView.content.addChild(item); } }, artistLayout() { for (let child of this.artistScrollView.content.children) { child.destroy(); } let artistCount = 1; artistCount += this.artists.length; for (let i = 0; i < artistCount; i++) { let item = cc.instantiate(this.friendItem); let scriptComponent = item.getComponent('LevelHomeFriendItem'); if (i === 0) { scriptComponent.style = Style.Talent; } else { scriptComponent.style = Style.Artist; scriptComponent.setFriendInfo(this.artists[i-1]); } this.artistScrollView.content.addChild(item); } }, });