FriendSystem.js 5.5 KB

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