FriendSystem.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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._wechatFriendNode.active = false;
  84. },
  85. showTalent() {
  86. cc.loader.loadRes('/prefabs/talent_mission', cc.Prefab, (error, prefab) => {
  87. if (error === null) {
  88. let mission = cc.instantiate(prefab);
  89. mission = mission.getComponent('TalentMission');
  90. mission.init();
  91. } else {
  92. console.log(JSON.stringify(error));
  93. }
  94. });
  95. },
  96. inviteFriend: function () {
  97. wechat.inviteFriendPromise().then(() => {
  98. FriendSystemApi.shareSuccessNotice();
  99. });
  100. // cc.loader.loadRes('/prefabs/share_dialog', cc.Prefab, (error, prefab) => {
  101. // if (error === null) {
  102. // let shareDialog = cc.instantiate(prefab);
  103. // this.node.addChild(shareDialog);
  104. // shareDialog.getComponent('ShareDialog').showInviteFriend();
  105. // } else {
  106. // console.log(JSON.stringify(error));
  107. // }
  108. // });
  109. },
  110. changeToWechatFriendTab() {
  111. this.setTabState(2);
  112. },
  113. changeToRecommendTab() {
  114. this.setTabState(1);
  115. },
  116. changeToFriendTab() {
  117. this.setTabState(0);
  118. },
  119. setTabSelected(selected, button, tabBgs, listViewNode) {
  120. if (selected && button.node.zIndex === 0 || !selected && button.node.zIndex === 1) {
  121. button.getComponent(cc.Sprite).spriteFrame = selected ? tabBgs[1] : tabBgs[0];
  122. listViewNode.active = selected;
  123. button.node.zIndex = selected ? 1 : 0;
  124. button.node.y = selected ? this._selectedY : this._defaultY;
  125. // let finish = cc.callFunc(() => {
  126. // button.node.zIndex = selected ? 1 : 0;
  127. // })
  128. // var animation = cc.sequence(cc.moveTo(0.2, button.node.x, moveY), finish);
  129. // button.node.runAction(animation);
  130. }
  131. },
  132. // update (dt) {},
  133. });