GameRank.js 5.2 KB

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