FriendSystem.js 5.2 KB

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