const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey; const GameModule = require('../utils/GameModule'); cc.Class({ extends: cc.Component, properties: { content: cc.Node, friendNode: { tooltip: '好友排行容器', default: null, type: cc.Node }, countryNode: { tooltip: '全国排行容器', default: null, type: cc.Node }, crowdNode: { tooltip: '群排行容器', default: null, type: cc.Node }, rankTab: [cc.Node], previousButton: cc.Node, nextButton: cc.Node, zIndex: { default: 0, notify(oldValue) { //减少无效赋值 if (oldValue === this.zIndex) { return; } this.node.zIndex = this.zIndex; } } }, // LIFE-CYCLE CALLBACKS: onLoad () { this.isFirst = true; this.node.zIndex = this.zIndex; if (Global.winSize.height <= 1000) { this.content.height = 800; } this.tabList = [{ wrap: this.friendNode, init: () => { this._initFriend(); }, }, { wrap: this.countryNode, init: () => { this._initCountry(); } }, { wrap: this.crowdNode, init: () => { this._initCrowd(); } }]; let self = this; this.handlePageFlipOver = _.throttle((event, index) => { if (index == 0) { self._pageFlipOver(); } else { self._pageFlipOver(true); } }, 500, true); GameEvent.on(GameNotificationKey.GameShowGroupRank, this, this.hideGameRank); }, init(index = 0) { this.tabIndex = index; this._initTab(); }, hideGameRank() { this.node.destroy(); }, onDestroy() { if (window.wx != undefined) { window.wx.postMessage({ messageType: 4 }); } Global.shareTicket = ''; GameEvent.off(GameNotificationKey.GameShowGroupRank, this); }, start () { }, /** * 初始化Tab */ _initTab () { for(let i = 0; i < this.rankTab.length; i++) { this.rankTab[i] = this.rankTab[i].getComponent('GameTab'); this.rankTab[i].init(); } this.handleTab(null, this.tabIndex); }, closeNode() { GameModule.audioMng.playClickButton(); this.node.destroy(); }, /** * Tab切换 * @param {number} tabIndex [0: 好友排行, 1: 全国排行,2:群排行] */ handleTab(event, tabIndex) { this.rankTab.forEach((item, index) => { if(tabIndex == index) { this.showPageButton(); item.show(); this.tabList[index].wrap.active = true; this.tabList[index].init.apply(this); if (this.isFirst) { this.isFirst = false } else { GameModule.audioMng.playClickButton(); } } else { item.hide(); this.tabList[index].wrap.active = false; } this.tabIndex = tabIndex; }) }, /** * 初始化好友排行 */ _initFriend () { if(!this.initFriendDone) { this.initFriendDone = true; this.friendNode = this.friendNode.getComponent('GameFriendRank'); this.friendNode.init(); } }, /** * 初始化全国排行 */ _initCountry () { if(!this.initCountryDone) { this.initCountryDone = true; this.countryNode = this.countryNode.getComponent('GameCountryRank'); this.countryNode.init(); } }, /** * 初始化群排行 */ _initCrowd () { if(!this.initCowdDone) { this.initCowdDone = true; this.crowdNode = this.crowdNode.getComponent('GameCrowdRank'); this.crowdNode.init(this); } }, //上一页、下一页翻页 _pageFlipOver (isNext = false) { GameModule.audioMng.playClickButton(); if (isNext) { if (this.tabIndex == 0) { this.friendNode.nextPage(); } else if (this.tabIndex == 1) { this.countryNode.nextPage(); } else { this.crowdNode.nextPage(); } } else { if (this.tabIndex == 0) { this.friendNode.previousPage(); } else if (this.tabIndex == 1) { this.countryNode.previousPage(); } else { this.crowdNode.previousPage(); } } }, hidePageButton() { this.previousButton.active = false; this.nextButton.active = false; }, showPageButton() { this.previousButton.active = true; this.nextButton.active = true; } // update (dt) {}, });