FriendSystem.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. var wechat = require("../net/WeChat");
  2. const DWTool = require('../utils/DWTool');
  3. var shareDialog = require('./ShareDialog')
  4. const ShareAction = require('../utils/ShareAction');
  5. const FriendSystemApi = require('../net/FriendSystemApi')
  6. cc.Class({
  7. extends: cc.Component,
  8. properties: {
  9. content: cc.Node,
  10. friendNode: cc.Node,
  11. recommendNode: cc.Node,
  12. _wechatFriendNode: cc.Node,
  13. friendButton: cc.Button,
  14. recommendButton: cc.Button,
  15. wechatFriendButton: cc.Button,
  16. friendTabSprites: [cc.SpriteFrame],
  17. recommendTabSprites: [cc.SpriteFrame],
  18. wechatFriendTabSprites: [cc.SpriteFrame],
  19. },
  20. onLoad() {
  21. this.node.height = cc.view.getVisibleSize().height;
  22. this.contentY = this.content.y = (this.content.height - this.node.height) / 2;
  23. this._defaultY = 496;
  24. this._selectedY = 480;
  25. },
  26. onEnable() {
  27. },
  28. onDisable() {
  29. },
  30. show(wechatFriendNode) {
  31. this.setWechatFriendNode(wechatFriendNode);
  32. this.node.parent = cc.find('Canvas');
  33. this.node.active = true;
  34. this.content.y = -cc.view.getVisibleSize().height;
  35. let s = cc.sequence(cc.moveTo(0.2, 0, this.contentY + 20).easing(cc.easeCubicActionOut()), cc.moveBy(0.05, 0, -20));
  36. this.content.runAction(s);
  37. this.scheduleOnce(() => {
  38. this.setTabState(0);
  39. }, 0.2);
  40. },
  41. close() {
  42. if (this.node && this.node.parent) {
  43. this._wechatFriendNode.active = false;
  44. let finish = cc.callFunc(() => {
  45. this.closeFriendSystem();
  46. }, this)
  47. this.content.runAction(cc.sequence(cc.moveTo(0.2, 0, -cc.view.getVisibleSize().height).easing(cc.easeCubicActionIn()), finish));
  48. }
  49. },
  50. setTabState(currentIndex) {
  51. if (this.currentIndex === currentIndex) {
  52. return;
  53. }
  54. console.log('currentIndex:' + currentIndex);
  55. this.currentIndex = currentIndex;
  56. switch (currentIndex) {
  57. case 0:
  58. this.setTabSelected(true, this.friendButton, this.friendTabSprites, this.friendNode);
  59. this.setTabSelected(false, this.recommendButton, this.recommendTabSprites, this.recommendNode);
  60. this.setTabSelected(false, this.wechatFriendButton, this.wechatFriendTabSprites, this._wechatFriendNode);
  61. break;
  62. case 1:
  63. this.setTabSelected(false, this.friendButton, this.friendTabSprites, this.friendNode);
  64. this.setTabSelected(true, this.recommendButton, this.recommendTabSprites, this.recommendNode);
  65. this.setTabSelected(false, this.wechatFriendButton, this.wechatFriendTabSprites, this._wechatFriendNode);
  66. break;
  67. case 2:
  68. this._wechatFriendNode.zIndex = 2;
  69. this.setTabSelected(false, this.friendButton, this.friendTabSprites, this.friendNode);
  70. this.setTabSelected(false, this.recommendButton, this.recommendTabSprites, this.recommendNode);
  71. this.setTabSelected(true, this.wechatFriendButton, this.wechatFriendTabSprites, this._wechatFriendNode);
  72. break;
  73. }
  74. },
  75. setWechatFriendNode(wechatFriendNode) {
  76. this._wechatFriendNode = wechatFriendNode;
  77. this._wechatFriendNode.height = cc.view.getVisibleSize().height;
  78. },
  79. closeFriendSystem: function () {
  80. this.friendNode.getComponent('FriendList').friendLastRequestTime = -1;
  81. this.currentIndex = -1;
  82. // this.node.active = false;
  83. this.node.destroy();
  84. this._wechatFriendNode.active = false;
  85. },
  86. showTalent() {
  87. cc.loader.loadRes('/prefabs/talent_mission', cc.Prefab, (error, prefab) => {
  88. if (error === null) {
  89. let mission = cc.instantiate(prefab);
  90. mission = mission.getComponent('TalentMission');
  91. mission.init();
  92. } else {
  93. console.log(JSON.stringify(error));
  94. }
  95. });
  96. },
  97. inviteFriend: function () {
  98. wechat.inviteFriendPromise().then(() => {
  99. FriendSystemApi.shareSuccessNotice();
  100. });
  101. // cc.loader.loadRes('/prefabs/share_dialog', cc.Prefab, (error, prefab) => {
  102. // if (error === null) {
  103. // let shareDialog = cc.instantiate(prefab);
  104. // this.node.addChild(shareDialog);
  105. // shareDialog.getComponent('ShareDialog').showInviteFriend();
  106. // } else {
  107. // console.log(JSON.stringify(error));
  108. // }
  109. // });
  110. },
  111. changeToWechatFriendTab() {
  112. this.setTabState(2);
  113. },
  114. changeToRecommendTab() {
  115. this.setTabState(1);
  116. },
  117. changeToFriendTab() {
  118. this.setTabState(0);
  119. },
  120. setTabSelected(selected, button, tabBgs, listViewNode) {
  121. if (selected && button.node.zIndex === 0 || !selected && button.node.zIndex === 1) {
  122. button.getComponent(cc.Sprite).spriteFrame = selected ? tabBgs[1] : tabBgs[0];
  123. listViewNode.active = selected;
  124. button.node.zIndex = selected ? 1 : 0;
  125. button.node.y = selected ? this._selectedY : this._defaultY;
  126. // let finish = cc.callFunc(() => {
  127. // button.node.zIndex = selected ? 1 : 0;
  128. // })
  129. // var animation = cc.sequence(cc.moveTo(0.2, button.node.x, moveY), finish);
  130. // button.node.runAction(animation);
  131. }
  132. },
  133. // update (dt) {},
  134. });