LevelHomeFriendItem.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. const Style = require('../utils/GameEnum').LevelHomeFriendItemStyle;
  2. const Api = require('../net/Api');
  3. const NotiKey = require('../utils/GameEnum').GameNotificationKey;
  4. var WeChat = require("../net/WeChat");
  5. const DWTool = require('../utils/DWTool');
  6. const AlertManager = require('../utils/AlertManager');
  7. cc.Class({
  8. extends: cc.Component,
  9. properties: {
  10. itemBg: cc.Node,
  11. allFriendNode: cc.Node,
  12. friendInfoNode: cc.Node,
  13. talentNode: cc.Node,
  14. identityNode: cc.Node,
  15. identitySpriteFrames: [cc.SpriteFrame],
  16. headSprite: cc.Sprite,
  17. nickLabel: cc.Label,
  18. starsLabel: cc.Label,
  19. noticeNode: cc.Node,
  20. style: {
  21. get: function () {
  22. if (!this._style) {
  23. this._style = Style.Friend;
  24. }
  25. return this._style;
  26. },
  27. set: function (value) {
  28. this._style = value;
  29. this.setEvent();
  30. this.layout();
  31. }
  32. },
  33. },
  34. // LIFE-CYCLE CALLBACKS:
  35. onLoad() {
  36. },
  37. setEvent() {
  38. switch (this.style) {
  39. case Style.AllFriend:
  40. this.allFriendNode.on(cc.Node.EventType.TOUCH_END, _.debounce(() => {
  41. GameEvent.fire(NotiKey.ShowFriendSystem);
  42. }, 1000, true), this);
  43. break;
  44. case Style.Friend:
  45. this.friendInfoNode.on(cc.Node.EventType.TOUCH_END, _.debounce(() => {
  46. GameEvent.fire(NotiKey.VisitFriendHome, this.info.uid);
  47. }, 1000, true), this);
  48. break;
  49. case Style.Artist:
  50. this.friendInfoNode.on(cc.Node.EventType.TOUCH_END, _.debounce(() => {
  51. GameEvent.fire(NotiKey.ShowUserInfomation, this.info.uid);
  52. }, 1000, true), this);
  53. break;
  54. case Style.Talent:
  55. this.talentNode.on(cc.Node.EventType.TOUCH_END, function () {
  56. cc.loader.loadRes('/prefabs/talent_mission', cc.Prefab, (error, prefab) => {
  57. if (error === null) {
  58. let mission = cc.instantiate(prefab);
  59. mission = mission.getComponent('TalentMission');
  60. mission.init();
  61. } else {
  62. console.log(JSON.stringify(error));
  63. }
  64. });
  65. }, this);
  66. break;
  67. }
  68. },
  69. setFriendInfo(info) {
  70. this.info = info;
  71. this.starsLabel.string = info.stars;
  72. this.nickLabel.string = info.nick;
  73. Api.createImageFromUrl(info.head, (spriteFrame) => {
  74. this.headSprite.spriteFrame = spriteFrame;
  75. }, null);
  76. if (info.role === 1) { // 我的老板
  77. this.identityNode.getComponent(cc.Sprite).spriteFrame = this.identitySpriteFrames[0];
  78. } else { // 我的艺人
  79. this.identityNode.getComponent(cc.Sprite).spriteFrame = this.identitySpriteFrames[1];
  80. }
  81. // 显示消息提示节点
  82. if (this.style === Style.Friend && info.isStationed) {
  83. this.noticeNode.active = true
  84. } else {
  85. this.noticeNode.active = false
  86. }
  87. },
  88. layout() {
  89. switch (this.style) {
  90. case Style.AllFriend:
  91. this.allFriendNode.active = true;
  92. this.friendInfoNode.active = false;
  93. this.talentNode.active = false;
  94. this.itemBg.active = false;
  95. this.noticeNode.active = false
  96. break;
  97. case Style.Friend:
  98. this.friendInfoNode.active = true;
  99. this.allFriendNode.active = false;
  100. this.talentNode.active = false;
  101. this.identityNode.active = false;
  102. this.itemBg.active = true;
  103. break;
  104. case Style.Invite:
  105. this.friendInfoNode.active = false;
  106. this.allFriendNode.active = false;
  107. this.talentNode.active = false;
  108. this.itemBg.active = true;
  109. this.noticeNode.active = false
  110. break;
  111. case Style.Talent:
  112. this.friendInfoNode.active = false;
  113. this.allFriendNode.active = false;
  114. this.talentNode.active = true;
  115. this.itemBg.active = false;
  116. this.noticeNode.active = false
  117. break;
  118. case Style.Artist:
  119. this.friendInfoNode.active = true;
  120. this.allFriendNode.active = false;
  121. this.talentNode.active = false;
  122. this.identityNode.active = true;
  123. this.itemBg.active = true;
  124. this.noticeNode.active = false
  125. break;
  126. default:
  127. break;
  128. }
  129. },
  130. // update (dt) {},
  131. });