123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- cc.Class({
- extends: cc.Component,
- properties: {
- headDefaultSpriteFrame: cc.SpriteFrame,
- headSprite: cc.Sprite,
- background: cc.Sprite,
- rankSprite: cc.Sprite,
- // rankRichText: cc.RichText,
- rankLabel: cc.Label,
- nameLabel: cc.Label,
- // lvRichText: cc.RichText,
- lvLabel: cc.Label,
- rankSpriteFrame: [cc.SpriteFrame],
- backgroundSpriteFrame: [cc.SpriteFrame],
- isMe: {
- get: function() {
- if (!this._isMe) {
- this._isMe = false;
- }
- return this._isMe;
- },
- set: function(value) {
- this._isMe = value;
- if (this._isMe) {
- this.background.spriteFrame = this.backgroundSpriteFrame[1];
- } else {
- this.background.spriteFrame = this.backgroundSpriteFrame[0];
- }
- }
- },
- },
- // LIFE-CYCLE CALLBACKS:
- // onLoad () {},
- init (model, isMe = false) {
- this.configData(model);
- this.isMe = isMe;
- },
- start () {
- },
- configData(model) {
- this.headSprite.spriteFrame = this.headDefaultSpriteFrame;
- if (model.avatarUrl) {
- this.createImageFromUrl(model.avatarUrl, (spriteFrame) => {
- this.headSprite.spriteFrame = spriteFrame;
- });
- }
- this.nameLabel.string = model.nickname == undefined ? model.nickName : model.nickname;
-
- if (model.rank < 4) {
- this.rankSprite.node.active = true;
- this.rankLabel.node.active = false;
- this.rankSprite.spriteFrame = this.rankSpriteFrame[(model.rank - 1)];
- } else {
- this.rankSprite.node.active = false;
- this.rankLabel.node.active = true;
- let rank = (model.rank > 100) ? "100+" : model.rank;
- this.rankLabel.string = `${rank}`;
- }
- if (model.score != undefined) {
- this.lvLabel.string = `LV.${model.score}`;
- } else {
- if (model.KVDataList && model.KVDataList.length > 0) {
- let value = JSON.parse(model.KVDataList[0].value);
- this.lvLabel.string = `LV.${value.wxgame.score}`;
- }
- }
- },
- createImageFromUrl(avatarUrl, success, fail) {
- if (avatarUrl) {
- var index = avatarUrl.indexOf('https:');
- var httpIndex = avatarUrl.indexOf('http:');
- if (index === 0 || httpIndex === 0) {
- //以'https:'开头
- } else {
- avatarUrl = 'https:' + avatarUrl;
- }
- if (window.wx != undefined) {
- try {
- let image = wx.createImage();
- image.onload = () => {
- try {
- let texture = new cc.Texture2D();
- texture.initWithElement(image);
- texture.handleLoadedTexture();
- success(new cc.SpriteFrame(texture))
- } catch (e) {
- cc.log(e);
- cc.loader.loadRes('./common/default_avatar', cc.SpriteFrame, (err, spriteFrame) => {
- success(spriteFrame);
- })
- }
- };
- image.src = avatarUrl;
- } catch (e) {
- cc.log(e);
- cc.loader.loadRes('./common/default_avatar', cc.SpriteFrame, (err, spriteFrame) => {
- success(spriteFrame);
- })
- }
- } else {
- cc.loader.load({
- url: avatarUrl, type: 'jpg'
- }, (err, texture) => {
- if (err === undefined || err === null) {
- success(new cc.SpriteFrame(texture));
- } else {
- cc.loader.loadRes('./common/default_avatar', cc.SpriteFrame, (err, spriteFrame) => {
- success(spriteFrame);
- })
- }
- });
- }
- } else {
- cc.loader.loadRes('./common/default_avatar', cc.SpriteFrame, (err, spriteFrame) => {
- success(spriteFrame);
- })
- }
- }
- // update (dt) {},
- });
|