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); this.updateFriendList(); GameModule.audioMng.playButton(); }, 1000, true), this); // 刷新好友列表 GameEvent.on(Notikey.RefreshFriendList, this, () => { this.updateFriendList(); }); // 刷新艺人列表 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.initFriendList = false; this.updateFriendList(); }, updateFriendList () { this.loadFriendData().then((data) => { // 好友数据回调 let _friendList = data.users || []; // 过滤好友申请项 _friendList = _friendList.filter(n => { return n.isApplied != 1 }); Global.friendList = _friendList; this.friends = _friendList.slice(0, 20); this.noArtistTipNode.active = false; this.friendLayout(); // 暂时注释,国庆回来可能要用到 // if(!this.initFriendList) { // Global.friendList = this.friends = _friendList; // if(_friendList.length > 0) { // this.initFriendList = true; // } // this.noArtistTipNode.active = false; // this.friendLayout(); // } else { // // 判断列表是否有更改,如果没有更改则不重新渲染 // let fChange = _friendList[0].uid != this.friends[0].uid; // let lChange = _friendList[_friendList.length - 1].uid != this.friends[this.friends.length - 1].uid; // if(fChange || lChange) { // Global.friendList = this.friends = _friendList; // 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() { console.log('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); } }, });