GameFriendCtrl.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. const GameModule = require('../utils/GameModule');
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. friendNode: {
  6. tooltip: '我的好友容器',
  7. default: null,
  8. type: cc.Node
  9. },
  10. recommendNode: {
  11. tooltip: '推荐好友容器',
  12. default: null,
  13. type: cc.Node
  14. },
  15. searchNode: {
  16. tooltip: '找朋友容器',
  17. default: null,
  18. type: cc.Node
  19. },
  20. friendTab: [cc.Node],
  21. bottomNode: cc.Node,
  22. goldCountRichText: cc.RichText,
  23. friendCountRichText: cc.RichText
  24. },
  25. // LIFE-CYCLE CALLBACKS:
  26. onLoad () {
  27. this.isFirst = true;
  28. if (GameGlobal.winSize.height <= 1000) {
  29. this.content.height = 800;
  30. }
  31. this.tabList = [{
  32. wrap: this.friendNode,
  33. init: () => {
  34. this._initFriend();
  35. },
  36. }, {
  37. wrap: this.recommendNode,
  38. init: () => {
  39. this._initRecommend();
  40. }
  41. }, {
  42. wrap: this.searchNode,
  43. init: () => {
  44. this._initSearch();
  45. }
  46. }];
  47. },
  48. init(index = 0) {
  49. this.tabIndex = index;
  50. this._initTab();
  51. },
  52. start () {
  53. },
  54. onDestroy() {
  55. },
  56. _initTab () {
  57. for(let i = 0; i < this.friendTab.length; i++) {
  58. this.friendTab[i] = this.friendTab[i].getComponent('GameFriendTab');
  59. this.friendTab[i].init();
  60. }
  61. this.handleTab(null, this.tabIndex);
  62. },
  63. /**
  64. * Tab切换
  65. * @param {number} tabIndex [0: 我的好友, 1: 推荐好友,2:找朋友]
  66. */
  67. handleTab(event, tabIndex) {
  68. this.friendTab.forEach((item, index) => {
  69. if(tabIndex == index) {
  70. item.show();
  71. this.tabList[index].wrap.active = true;
  72. this.tabList[index].init.apply(this);
  73. if (this.isFirst) {
  74. this.isFirst = false
  75. } else {
  76. GameModule.audioMng.playClickButton();
  77. }
  78. } else {
  79. item.hide();
  80. this.tabList[index].wrap.active = false;
  81. }
  82. this.tabIndex = tabIndex;
  83. })
  84. },
  85. /**
  86. * 我的好友
  87. */
  88. _initFriend () {
  89. if(!this.initFriendDone) {
  90. this.initFriendDone = true;
  91. this.friendNode = this.friendNode.getComponent('GameMyFriend');
  92. this.friendNode.init();
  93. }
  94. },
  95. /**
  96. * 推荐
  97. */
  98. _initRecommend() {
  99. if(!this.RecommendDone) {
  100. this.RecommendDone = true;
  101. // this.countryNode = this.countryNode.getComponent('GameCountryRank');
  102. // this.countryNode.init();
  103. }
  104. },
  105. /**
  106. * 找朋友
  107. */
  108. _initSearch() {
  109. if(!this.initSearchDone) {
  110. this.initSearchDone = true;
  111. this.searchNode = this.searchNode.getComponent('GameFriendSearch');
  112. this.searchNode.init(this);
  113. }
  114. },
  115. closeNode() {
  116. GameModule.audioMng.playClickButton();
  117. this.node.destroy();
  118. },
  119. gainGold() {
  120. }
  121. // update (dt) {},
  122. });