1
0

FriendListItem.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. const Api = require('../net/Api');
  2. const FriendApi = require('../net/FriendSystemApi');
  3. const UserInformationType = require('../utils/GameEnum').UserInformationType;
  4. var ShaderUtil = require('../utils/ShaderUtil');
  5. const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
  6. var DWTool = require('../utils/DWTool');
  7. cc.Class({
  8. extends: cc.Component,
  9. properties: {
  10. bgSprite: cc.Sprite,
  11. content: cc.Node,
  12. headSprite: cc.Sprite,
  13. nickLabel: cc.Label,
  14. starCountLabel: cc.Label,
  15. jobLevelNode: cc.Node,
  16. jobLevelText: cc.RichText,
  17. genderIcon: cc.Sprite,
  18. homeNode: cc.Node,
  19. acceptButton: cc.Node,
  20. rejectButton: cc.Node,
  21. apply: cc.Node,
  22. topBarSprite: cc.Sprite,
  23. roleText: cc.RichText,
  24. stateSprite: cc.Sprite,
  25. _friendList: null,
  26. _itemId: 0,
  27. _listViewAdapter: null,
  28. clickable: true,
  29. titleLabel: cc.Label,
  30. },
  31. // LIFE-CYCLE CALLBACKS:
  32. onLoad() {
  33. this.bgSprite.node.on(cc.Node.EventType.TOUCH_END, () => {
  34. if (this.user.isApplied) {
  35. return;
  36. }
  37. GameEvent.fire(GameNotificationKey.ShowUserInfomation, this.user.uid);
  38. }, this)
  39. this.homeNode.on(cc.Node.EventType.TOUCH_END, _.debounce(() => {
  40. GameEvent.fire(GameNotificationKey.VisitFriendHome, this.user.uid);
  41. }, 1000, true), this);
  42. // this.headSprite.node.width = this.headSprite.node.width / 4;
  43. // this.headSprite.node.height = this.headSprite.node.height / 4;
  44. },
  45. setFriendList(friendList) {
  46. this._friendList = friendList;
  47. },
  48. setListViewAdapter(listViewAdapter) {
  49. this._listViewAdapter = listViewAdapter;
  50. },
  51. /**
  52. * gender [int]
  53. * head [string]
  54. * nick [string]
  55. * stars [int]
  56. * uid [int]
  57. * */
  58. updateItem(userInfo, itemId) {
  59. this._itemId = itemId;
  60. this.user = userInfo;
  61. if (userInfo.isApplied) {
  62. this.apply.active = true;
  63. this.homeNode.active = false;
  64. this.stateSprite.node.active = false;
  65. this.topBarSprite.node.active = false;
  66. this.roleText.node.active = false;
  67. this.titleLabel.node.active = false;
  68. this.content.y = 20;
  69. } else {
  70. this.apply.active = false;
  71. this.homeNode.active = true;
  72. this.topBarSprite.node.active = true;
  73. this.roleText.node.active = true;
  74. this.titleLabel.node.active = true;
  75. this.content.y = 0;
  76. let typeImage = '';
  77. let typeText = '';
  78. switch (userInfo.role) {
  79. case UserInformationType.Boss:
  80. this.stateSprite.node.active = false;
  81. typeImage = './friendList/my_boss_bar'
  82. typeText = '我的老板';
  83. break;
  84. case UserInformationType.MyArtist:
  85. this.stateSprite.node.active = false;
  86. typeImage = './friendList/my_actor_bar'
  87. typeText = '我的艺人';
  88. break;
  89. case UserInformationType.ArtistFree:
  90. this.stateSprite.node.active = true;
  91. DWTool.loadResSpriteFrame('./friendList/state_free').then(spriteFrame => {
  92. this.stateSprite.spriteFrame = spriteFrame;
  93. });
  94. typeImage = './friendList/free_bar'
  95. typeText = '自由身';
  96. break;
  97. case UserInformationType.OtherArtist:
  98. this.stateSprite.node.active = true;
  99. DWTool.loadResSpriteFrame('./friendList/state_other_actor').then(spriteFrame => {
  100. this.stateSprite.spriteFrame = spriteFrame;
  101. });
  102. typeImage = './friendList/other_actor_bar'
  103. typeText = '他人艺人';
  104. break;
  105. default:
  106. this.stateSprite.node.active = true;
  107. DWTool.loadResSpriteFrame('./friendList/state_free').then(spriteFrame => {
  108. this.stateSprite.spriteFrame = spriteFrame;
  109. });
  110. typeImage = './friendList/free_bar'
  111. typeText = '自由身';
  112. break;
  113. }
  114. DWTool.loadResSpriteFrame(typeImage).then(spriteFrame => {
  115. this.topBarSprite.spriteFrame = spriteFrame;
  116. });
  117. this.roleText.string = '<b>' + typeText + '</b>'
  118. if (userInfo.jobName) {
  119. this.jobLevelNode.active = true;
  120. this.titleLabel.string = userInfo.jobName;
  121. } else {
  122. this.jobLevelNode.active = false;
  123. }
  124. if (userInfo.jobLevel) {
  125. this.jobLevelText.string = `<outline color=#524340 width=2>${userInfo.jobLevel}</outline >`
  126. } else {
  127. this.jobLevelText.string = '';
  128. }
  129. }
  130. DWTool.setGenderIcon(userInfo.gender).then((spriteFrame) => {
  131. this.genderIcon.node.active = true;
  132. this.genderIcon.spriteFrame = spriteFrame;
  133. }, (error) => {
  134. this.genderIcon.node.active = true;
  135. });
  136. this.nickLabel.string = userInfo.nick;
  137. this.starCountLabel.string = userInfo.stars;
  138. Api.createImageFromUrl(userInfo.head, (spriteFrame) => {
  139. this.headSprite.spriteFrame = spriteFrame;
  140. // this.headSprite.node.scaleX = 4;
  141. // this.headSprite.node.scaleY = 4;
  142. }, () => {
  143. });
  144. // if (userInfo.isApplied && userInfo.commons != undefined && userInfo.commons != null && userInfo.commons.length > 0) {
  145. // this.commonFriendLabel.string = userInfo.commons.length;
  146. // this.sameFriend1.node.active = true;
  147. // Api.createImageFromUrl(userInfo.commons[0].head, (spriteFrame) => {
  148. // this.sameFriend1.spriteFrame = spriteFrame;
  149. // });
  150. // if (userInfo.commons.length > 1) {
  151. // this.sameFriend2.node.active = true;
  152. // Api.createImageFromUrl(userInfo.commons[1].head, (spriteFrame) => {
  153. // this.sameFriend2.spriteFrame = spriteFrame;
  154. // })
  155. // } else {
  156. // this.sameFriend2.node.active = false;
  157. // this.sameFriend3.node.active = false;
  158. // }
  159. // if (userInfo.commons.length > 2) {
  160. // this.sameFriend3.node.active = true;
  161. // Api.createImageFromUrl(userInfo.commons[2].head, (spriteFrame) => {
  162. // this.sameFriend3.spriteFrame = spriteFrame;
  163. // })
  164. // } else {
  165. // this.sameFriend3.node.active = false;
  166. // }
  167. // } else {
  168. // this.commonFriendTip.active = false;
  169. // this.commonFriendLabel.node.active = false;
  170. // }
  171. },
  172. start() {
  173. },
  174. deleteItem() {
  175. FriendApi.processApply(this.user.uid, -1);
  176. this._listViewAdapter.removeItem(this);
  177. },
  178. acceptApply() {
  179. FriendApi.processApply(this.user.uid, 1);
  180. this.user.isApplied = false;
  181. this.updateItem(this.user, this._itemId);
  182. // 通过好友申请,操作类型:9
  183. let opt = 9;
  184. GameEvent.fire(GameNotificationKey.NoticeRoleOpt, this.user.uid, opt)
  185. },
  186. // update (dt) {},
  187. });