GameRank.js 5.3 KB

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