OtherArtistItem.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. headSprite: cc.Sprite,
  9. nickLabel: cc.Label,
  10. starCountLabel: cc.Label,
  11. genderIcon: cc.Sprite,
  12. roleSprite: cc.Sprite,
  13. _itemId: 0,
  14. jobLevelNameLabel: cc.Label,
  15. jobLevelText: cc.RichText,
  16. },
  17. onLoad() {
  18. this.node.on(cc.Node.EventType.TOUCH_END, () => {
  19. if (this.user.isFriend) {
  20. this.cb();
  21. GameEvent.fire(GameNotificationKey.VisitFriendHome, this.user.uid);
  22. }
  23. }, this);
  24. },
  25. /**
  26. * gender [int]
  27. * head [string]
  28. * nick [string]
  29. * stars [int]
  30. * uid [int]
  31. * */
  32. updateItem(userInfo, itemId, cb) {
  33. this._itemId = itemId;
  34. this.user = userInfo;
  35. this.cb = cb || function () { };
  36. if (userInfo.isFriend) {
  37. this.roleSprite.node.active = true;
  38. } else {
  39. this.roleSprite.node.active = false;
  40. }
  41. DWTool.setGenderIcon(userInfo.gender).then((spriteFrame) => {
  42. this.genderIcon.node.active = true;
  43. this.genderIcon.spriteFrame = spriteFrame;
  44. }, (error) => {
  45. this.genderIcon.node.active = false;
  46. });
  47. this.nickLabel.string = userInfo.nick;
  48. this.starCountLabel.string = userInfo.stars;
  49. Api.createImageFromUrl(userInfo.head, (spriteFrame) => {
  50. this.headSprite.spriteFrame = spriteFrame;
  51. }, null);
  52. if (userInfo.jobLevelName) {
  53. this.jobLevelNameLabel.string = userInfo.jobLevelName;
  54. } else {
  55. this.jobLevelNameLabel.string = "";
  56. }
  57. if (userInfo.jobLevel) {
  58. this.jobLevelText.string = `<outline color=#524340 width=2>${userInfo.jobLevel}</outline >`;
  59. } else {
  60. this.jobLevelText.string = '0';
  61. }
  62. },
  63. });