OtherArtistItem.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. const Api = require('../net/Api');
  2. const DWTool = require('../utils/DWTool');
  3. const { GameNotificationKey } = require('../utils/GameEnum')
  4. cc.Class({
  5. extends: cc.Component,
  6. properties: {
  7. bgSprite: cc.Sprite,
  8. artistLevelSprite: cc.Sprite,
  9. headSprite: cc.Sprite,
  10. nickLabel: cc.Label,
  11. starCountLabel: cc.Label,
  12. genderIcon: cc.Sprite,
  13. roleSprite: cc.Sprite,
  14. _itemId: 0,
  15. jobLevelNameLabel: cc.Label,
  16. artistLevelBgs: [cc.SpriteFrame],
  17. femaleFrame: cc.SpriteFrame,
  18. maleFrame: cc.SpriteFrame,
  19. },
  20. onLoad() {
  21. this.node.on(cc.Node.EventType.TOUCH_END, () => {
  22. if (this.user.isFriend) {
  23. this.cb();
  24. GameEvent.fire(GameNotificationKey.VisitFriendHome, this.user.uid);
  25. }
  26. }, this);
  27. },
  28. /**
  29. * gender [int]
  30. * head [string]
  31. * nick [string]
  32. * stars [int]
  33. * uid [int]
  34. * */
  35. updateItem(userInfo, itemId, cb) {
  36. this._itemId = itemId;
  37. this.user = userInfo;
  38. this.cb = cb || function () { };
  39. if (userInfo.isFriend) {
  40. this.roleSprite.node.active = true;
  41. } else {
  42. this.roleSprite.node.active = false;
  43. }
  44. this.genderIcon.spriteFrame = userInfo.gender == 1 ? this.maleFrame : this.femaleFrame;
  45. this.nickLabel.string = userInfo.nick;
  46. this.starCountLabel.string = userInfo.stars;
  47. Api.createImageFromUrl(userInfo.head, (spriteFrame) => {
  48. this.headSprite.spriteFrame = spriteFrame;
  49. }, null);
  50. if (userInfo.jobLevelName) {
  51. this.jobLevelNameLabel.node.active = true;
  52. this.jobLevelNameLabel.string = userInfo.jobLevelName;
  53. } else {
  54. this.jobLevelNameLabel.node.active = false;
  55. }
  56. if (userInfo.jobLevel) {
  57. this.artistLevelSprite.node.active = true;
  58. this.artistLevelSprite.spriteFrame = this.artistLevelBgs[userInfo.jobLevel - 1];
  59. } else {
  60. this.artistLevelSprite.node.active = false;
  61. }
  62. },
  63. });