FriendListItem.js 7.5 KB

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