import { Sdk } from "./Sdk/Sdk";
|
import Userdata from "./Userdata";
|
|
const { ccclass, property } = cc._decorator;
|
var rankCallback;
|
|
@ccclass
|
export class RankItem extends cc.Component {
|
|
@property(cc.Label)
|
rankLabel: cc.Label = null;
|
|
@property(cc.Sprite)
|
icon: cc.Sprite = null;
|
|
@property(cc.Sprite)
|
skin: cc.Sprite = null;
|
|
@property(cc.Label)
|
nicknameLabel: cc.Label = null;
|
|
@property(cc.Label)
|
scoreLabel: cc.Label = null;
|
|
@property(cc.Label)
|
btnLabel: cc.Label = null;
|
|
playerid: string = null;
|
|
init(rankNum, rankdata, scoreName, playerid: string, callback?: Function) {
|
this.rankLabel.string = rankNum;
|
this.nicknameLabel.string = rankdata.nick;
|
this.scoreLabel.string = rankdata[scoreName];
|
|
this.playerid = playerid;
|
rankCallback = callback;
|
|
let self = this;
|
cc.loader.load({
|
url: rankdata.url, type: 'png'
|
}, (err, texture) => {
|
if (self && cc.isValid(self.icon))
|
self.icon.spriteFrame = new cc.SpriteFrame(texture);
|
});
|
|
if (rankdata.selfFlag) {
|
this.rankLabel.node.color = new cc.Color(0, 255, 0);
|
this.nicknameLabel.node.color = new cc.Color(0, 255, 0);
|
this.scoreLabel.node.color = new cc.Color(0, 255, 0);
|
} else {
|
if (rankNum == 1) {
|
this.rankLabel.node.color = new cc.Color(255, 22, 241);
|
this.nicknameLabel.node.color = new cc.Color(255, 22, 241);
|
this.scoreLabel.node.color = new cc.Color(255, 22, 241);
|
} else if (rankNum == 2) {
|
this.rankLabel.node.color = new cc.Color(255, 99, 22);
|
this.nicknameLabel.node.color = new cc.Color(255, 99, 22);
|
this.scoreLabel.node.color = new cc.Color(255, 99, 22);
|
} else if (rankNum == 3) {
|
this.rankLabel.node.color = new cc.Color(22, 192, 255);
|
this.nicknameLabel.node.color = new cc.Color(22, 192, 255);
|
this.scoreLabel.node.color = new cc.Color(22, 192, 255);
|
}
|
}
|
|
if (this.skin && rankdata.extra != null && rankdata.extra != undefined) {
|
let skinImg = 'skins/skin_' + rankdata.extra;
|
cc.loader.loadRes(skinImg, cc.SpriteFrame, (err, spriteFrame) => {
|
if (self && cc.isValid(self.skin))
|
self.skin.spriteFrame = spriteFrame;
|
});
|
}
|
|
if (Sdk.isFB) {
|
if (this.playerid && Sdk.ins.getPlayerId() == this.playerid) {//curr player
|
if (this.btnLabel) {
|
this.btnLabel.string = "Share";
|
}
|
}
|
}
|
}
|
|
initWithOvertake(rankdata, scoreName) {
|
this.nicknameLabel.string = rankdata.nick;
|
this.scoreLabel.string = rankdata[scoreName];
|
|
let self = this;
|
cc.loader.load({
|
url: rankdata.url, type: 'png'
|
}, (err, texture) => {
|
self.icon.spriteFrame = new cc.SpriteFrame(texture);
|
});
|
}
|
|
onClickPlay() {
|
|
}
|
}
|