GameRank.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. if (window.tt != undefined) {
  76. this.tabIndex = 1;
  77. }
  78. this._initTab();
  79. },
  80. hideGameRank() {
  81. this.node.destroy();
  82. },
  83. onDestroy() {
  84. if (CC_WECHATGAME && window.tt == undefined) {
  85. window.wx.postMessage({
  86. messageType: 4
  87. });
  88. }
  89. GameGlobal.shareTicket = '';
  90. GameEvent.off(GameNotificationKey.GameShowGroupRank, this);
  91. },
  92. start () {
  93. },
  94. /**
  95. * 初始化Tab
  96. */
  97. _initTab () {
  98. for(let i = 0; i < this.rankTab.length; i++) {
  99. this.rankTab[i] = this.rankTab[i].getComponent('GameTab');
  100. this.rankTab[i].init();
  101. if (window.tt != undefined) {
  102. if (i == 0 || i == 2) {
  103. this.rankTab[i].node.active = false;
  104. }
  105. }
  106. }
  107. this.handleTab(null, this.tabIndex);
  108. },
  109. closeNode() {
  110. GameModule.audioMng.playClickButton();
  111. this.node.destroy();
  112. },
  113. /**
  114. * Tab切换
  115. * @param {number} tabIndex [0: 好友排行, 1: 全国排行,2:群排行]
  116. */
  117. handleTab(event, tabIndex) {
  118. this.rankTab.forEach((item, index) => {
  119. if(tabIndex == index) {
  120. this.showPageButton();
  121. item.show();
  122. this.tabList[index].wrap.active = true;
  123. this.tabList[index].init.apply(this);
  124. if (this.isFirst) {
  125. this.isFirst = false
  126. } else {
  127. GameModule.audioMng.playClickButton();
  128. }
  129. } else {
  130. item.hide();
  131. this.tabList[index].wrap.active = false;
  132. }
  133. this.tabIndex = tabIndex;
  134. })
  135. },
  136. /**
  137. * 初始化好友排行
  138. */
  139. _initFriend () {
  140. if(!this.initFriendDone) {
  141. this.initFriendDone = true;
  142. this.friendNode = this.friendNode.getComponent('GameFriendRank');
  143. this.friendNode.init();
  144. }
  145. },
  146. /**
  147. * 初始化全国排行
  148. */
  149. _initCountry () {
  150. if(!this.initCountryDone) {
  151. this.initCountryDone = true;
  152. this.countryNode = this.countryNode.getComponent('GameCountryRank');
  153. this.countryNode.init();
  154. }
  155. },
  156. /**
  157. * 初始化群排行
  158. */
  159. _initCrowd () {
  160. if(!this.initCowdDone) {
  161. this.initCowdDone = true;
  162. this.crowdNode = this.crowdNode.getComponent('GameCrowdRank');
  163. this.crowdNode.init(this);
  164. }
  165. },
  166. //上一页、下一页翻页
  167. _pageFlipOver (isNext = false) {
  168. GameModule.audioMng.playClickButton();
  169. if (isNext) {
  170. if (this.tabIndex == 0) {
  171. this.friendNode.nextPage();
  172. } else if (this.tabIndex == 1) {
  173. this.countryNode.nextPage();
  174. } else {
  175. this.crowdNode.nextPage();
  176. }
  177. } else {
  178. if (this.tabIndex == 0) {
  179. this.friendNode.previousPage();
  180. } else if (this.tabIndex == 1) {
  181. this.countryNode.previousPage();
  182. } else {
  183. this.crowdNode.previousPage();
  184. }
  185. }
  186. },
  187. hidePageButton() {
  188. this.previousButton.active = false;
  189. this.nextButton.active = false;
  190. },
  191. showPageButton() {
  192. this.previousButton.active = true;
  193. this.nextButton.active = true;
  194. }
  195. // update (dt) {},
  196. });