GameRank.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
  2. const GameModule = require('../utils/GameModule');
  3. cc.Class({
  4. extends: cc.Component,
  5. properties: {
  6. friendNode: {
  7. tooltip: '好友排行容器',
  8. default: null,
  9. type: cc.Node
  10. },
  11. countryNode: {
  12. tooltip: '全国排行容器',
  13. default: null,
  14. type: cc.Node
  15. },
  16. crowdNode: {
  17. tooltip: '群排行容器',
  18. default: null,
  19. type: cc.Node
  20. },
  21. rankTab: [cc.Node],
  22. previousButton: cc.Node,
  23. nextButton: cc.Node,
  24. zIndex: {
  25. default: 0,
  26. notify(oldValue) {
  27. //减少无效赋值
  28. if (oldValue === this.zIndex) {
  29. return;
  30. }
  31. this.node.zIndex = this.zIndex;
  32. }
  33. }
  34. },
  35. // LIFE-CYCLE CALLBACKS:
  36. onLoad () {
  37. this.isFirst = true;
  38. this.node.zIndex = this.zIndex;
  39. this.tabList = [{
  40. wrap: this.friendNode,
  41. init: () => {
  42. this._initFriend();
  43. },
  44. }, {
  45. wrap: this.countryNode,
  46. init: () => {
  47. this._initCountry();
  48. }
  49. }, {
  50. wrap: this.crowdNode,
  51. init: () => {
  52. this._initCrowd();
  53. }
  54. }];
  55. let self = this;
  56. this.handlePageFlipOver = _.throttle((event, index) => {
  57. if (index == 0) {
  58. self._pageFlipOver();
  59. } else {
  60. self._pageFlipOver(true);
  61. }
  62. }, 500, true);
  63. GameEvent.on(GameNotificationKey.GameShowGroupRank, this, this.hideGameRank);
  64. },
  65. init(index = 0) {
  66. this.tabIndex = index;
  67. this._initTab();
  68. },
  69. hideGameRank() {
  70. this.node.destroy();
  71. },
  72. onDestroy() {
  73. if (window.wx != undefined) {
  74. window.wx.postMessage({
  75. messageType: 4
  76. });
  77. }
  78. Global.shareTicket = '';
  79. GameEvent.off(GameNotificationKey.GameShowGroupRank, this);
  80. },
  81. start () {
  82. },
  83. /**
  84. * 初始化Tab
  85. */
  86. _initTab () {
  87. for(let i = 0; i < this.rankTab.length; i++) {
  88. this.rankTab[i] = this.rankTab[i].getComponent('GameTab');
  89. this.rankTab[i].init();
  90. }
  91. this.handleTab(null, this.tabIndex);
  92. },
  93. closeNode() {
  94. GameModule.audioMng.playClickButton();
  95. this.node.destroy();
  96. },
  97. /**
  98. * Tab切换
  99. * @param {number} tabIndex [0: 好友排行, 1: 全国排行,2:群排行]
  100. */
  101. handleTab(event, tabIndex) {
  102. this.rankTab.forEach((item, index) => {
  103. if(tabIndex == index) {
  104. this.showPageButton();
  105. item.show();
  106. this.tabList[index].wrap.active = true;
  107. this.tabList[index].init.apply(this);
  108. if (this.isFirst) {
  109. this.isFirst = false
  110. } else {
  111. GameModule.audioMng.playClickButton();
  112. }
  113. } else {
  114. item.hide();
  115. this.tabList[index].wrap.active = false;
  116. }
  117. this.tabIndex = tabIndex;
  118. })
  119. },
  120. /**
  121. * 初始化好友排行
  122. */
  123. _initFriend () {
  124. if(!this.initFriendDone) {
  125. this.initFriendDone = true;
  126. this.friendNode = this.friendNode.getComponent('GameFriendRank');
  127. this.friendNode.init();
  128. }
  129. },
  130. /**
  131. * 初始化全国排行
  132. */
  133. _initCountry () {
  134. if(!this.initCountryDone) {
  135. this.initCountryDone = true;
  136. this.countryNode = this.countryNode.getComponent('GameCountryRank');
  137. this.countryNode.init();
  138. }
  139. },
  140. /**
  141. * 初始化群排行
  142. */
  143. _initCrowd () {
  144. if(!this.initCowdDone) {
  145. this.initCowdDone = true;
  146. this.crowdNode = this.crowdNode.getComponent('GameCrowdRank');
  147. this.crowdNode.init(this);
  148. }
  149. },
  150. //上一页、下一页翻页
  151. _pageFlipOver (isNext = false) {
  152. GameModule.audioMng.playClickButton();
  153. if (isNext) {
  154. if (this.tabIndex == 0) {
  155. this.friendNode.nextPage();
  156. } else if (this.tabIndex == 1) {
  157. this.countryNode.nextPage();
  158. } else {
  159. this.crowdNode.nextPage();
  160. }
  161. } else {
  162. if (this.tabIndex == 0) {
  163. this.friendNode.previousPage();
  164. } else if (this.tabIndex == 1) {
  165. this.countryNode.previousPage();
  166. } else {
  167. this.crowdNode.previousPage();
  168. }
  169. }
  170. },
  171. hidePageButton() {
  172. this.previousButton.active = false;
  173. this.nextButton.active = false;
  174. },
  175. showPageButton() {
  176. this.previousButton.active = true;
  177. this.nextButton.active = true;
  178. }
  179. // update (dt) {},
  180. });