123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
- const GameModule = require('../utils/GameModule');
- cc.Class({
- extends: cc.Component,
- properties: {
- 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;
- 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) {},
- });
|