123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- 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) => { // 好友数据回调
- let _friendList = data.users || [];
- // 过滤好友申请项
- _friendList = _friendList.filter(n => {
- return n.isApplied != 1
- });
- 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() {
- 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);
- }
- },
- });
|