81 lines
2.0 KiB
JavaScript
81 lines
2.0 KiB
JavaScript
let fileUtil = require('fileutils');
|
|
cc.Class({
|
|
extends: cc.Component,
|
|
|
|
properties: {
|
|
lb_name: {
|
|
default: null,
|
|
type: cc.Label
|
|
},
|
|
lb_rank: {
|
|
default: null,
|
|
type: cc.Label
|
|
},
|
|
lb_score: {
|
|
default: null,
|
|
type: cc.Label
|
|
},
|
|
sp_head: {
|
|
default: null,
|
|
type: cc.Sprite
|
|
},
|
|
sp_more: cc.Node,
|
|
sp_rank: {
|
|
default: null,
|
|
type: cc.Sprite
|
|
},
|
|
sf_rank: {
|
|
default: [],
|
|
type: cc.SpriteFrame
|
|
},
|
|
nd_bg: {
|
|
default: null,
|
|
type: cc.Node
|
|
},
|
|
tipTag: false,
|
|
default_avatar: 'texture/comppreload/default_avatar.png',
|
|
},
|
|
|
|
// LIFE-CYCLE CALLBACKS:
|
|
|
|
// onLoad () {},
|
|
|
|
start() {
|
|
|
|
},
|
|
setData(data) {
|
|
var self = this;
|
|
let nickname = data.nick || data.nickname || '';
|
|
nickname = nickname.length > 6 ? nickname.substring(0, 6) + '...' : nickname;
|
|
this.lb_name.string = nickname;
|
|
this.lb_rank.string = data.rank > 0 ? (data.rank > 999 ? '999+' : data.rank) : '-';
|
|
this.lb_score.string = this.tipTap ? '历史最高分 ' + data.score : data.score;
|
|
if (data.rank <= 3 && data.rank > 0) {
|
|
this.sp_rank.spriteFrame = this.sf_rank[data.rank - 1];
|
|
this.lb_rank.node.active = false;
|
|
this.sp_rank.node.active = true;
|
|
this.sp_more.active = false;
|
|
(this.sp_more) && (this.sp_more.active = false);
|
|
} else {
|
|
this.sp_rank.node.active = false;
|
|
(this.sp_more) && (this.sp_more.active = true);
|
|
this.lb_rank.node.active = true;
|
|
}
|
|
let avatar = data.url || data.avatar || self.default_avatar;
|
|
console.log('show avatar: ', avatar);
|
|
if ((cc.jc.channelID === cc.jc.channel.TT || cc.jc.channelID === cc.jc.channel.TEST
|
|
|| cc.jc.channelID === cc.jc.channel.QQ_MINI
|
|
|| cc.jc.channelID === cc.jc.channel.ANDROID
|
|
|| cc.jc.channelID === cc.jc.channel.WECHAT) && (data.url || data.avatar)) {
|
|
try {
|
|
fileUtil.loadImage(avatar, self.sp_head);
|
|
} catch (e) {
|
|
console.log(e);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
// update (dt) {},
|
|
});
|