const Api = require('../net/Api'); const DWTool = require('../utils/DWTool'); const { GameNotificationKey } = require('../utils/GameEnum') cc.Class({ extends: cc.Component, properties: { bgSprite: cc.Sprite, artistLevelSprite: cc.Sprite, headSprite: cc.Sprite, nickLabel: cc.Label, starCountLabel: cc.Label, genderIcon: cc.Sprite, roleSprite: cc.Sprite, _itemId: 0, jobLevelNameLabel: cc.Label, artistLevelBgs: [cc.SpriteFrame], femaleFrame: cc.SpriteFrame, maleFrame: cc.SpriteFrame, }, onLoad() { this.node.on(cc.Node.EventType.TOUCH_END, () => { if (this.user.isFriend) { this.cb(); GameEvent.fire(GameNotificationKey.VisitFriendHome, this.user.uid); } }, this); }, /** * gender [int] * head [string] * nick [string] * stars [int] * uid [int] * */ updateItem(userInfo, itemId, cb) { this._itemId = itemId; this.user = userInfo; this.cb = cb || function () { }; if (userInfo.isFriend) { this.roleSprite.node.active = true; } else { this.roleSprite.node.active = false; } this.genderIcon.spriteFrame = userInfo.gender == 1 ? this.maleFrame : this.femaleFrame; this.nickLabel.string = userInfo.nick; this.starCountLabel.string = userInfo.stars; Api.createImageFromUrl(userInfo.head, (spriteFrame) => { this.headSprite.spriteFrame = spriteFrame; }, null); if (userInfo.jobLevelName) { this.jobLevelNameLabel.node.active = true; this.jobLevelNameLabel.string = userInfo.jobLevelName; } else { this.jobLevelNameLabel.node.active = false; } if (userInfo.jobLevel) { this.artistLevelSprite.node.active = true; this.artistLevelSprite.spriteFrame = this.artistLevelBgs[userInfo.jobLevel - 1]; } else { this.artistLevelSprite.node.active = false; } }, });