import Userdata from "./Userdata";
|
import SoundManager from "./SoundManager";
|
import { Sdk } from "./Sdk/Sdk";
|
import RankTool from "./Sdk/RankTool";
|
|
|
const { ccclass, property } = cc._decorator;
|
|
@ccclass
|
export class Leaderboard extends cc.Component {
|
|
// LIFE-CYCLE CALLBACKS:
|
|
@property(cc.Sprite)
|
rankingScrollView: cc.Sprite = null;//显示排行榜
|
|
//好友排行列表
|
@property(cc.ScrollView)
|
friendScrollview: cc.ScrollView = null;
|
@property(cc.Label)
|
friendNoDataLabel: cc.Label = null;
|
//全球排行列表
|
@property(cc.ScrollView)
|
globalScrollview: cc.ScrollView = null;
|
@property(cc.Label)
|
globalNoDataLabel: cc.Label = null;
|
|
@property(cc.Prefab)
|
rankitemPrefab: cc.Prefab = null;
|
|
@property(cc.Node)
|
myRankitemNode: cc.Node = null;
|
|
@property(cc.Button)
|
friendButton: cc.Button = null;
|
@property(cc.Label)
|
friendLabel: cc.Label = null;
|
@property(cc.Button)
|
globalButton: cc.Button = null;
|
@property(cc.Label)
|
globalLabel: cc.Label = null;
|
|
fbOffset: number = 0;
|
fbSize: number = 50;
|
|
onClickBack() {
|
SoundManager.playButton();
|
|
this.friendScrollview.content.removeAllChildren();
|
this.globalScrollview.content.removeAllChildren();
|
this.node.removeFromParent();
|
this.node.destroy();
|
}
|
|
onEnable() {
|
if (Sdk.isFB) {
|
this.showFriendRank();
|
}
|
}
|
|
showFriendRank() {
|
this.friendButton.node.color = cc.Color.WHITE;
|
this.friendLabel.node.color = cc.Color.WHITE;
|
this.globalButton.node.color = cc.Color.GRAY;
|
this.globalLabel.node.color = cc.Color.GRAY;
|
this.friendScrollview.node.active = true;
|
this.globalScrollview.node.active = false;
|
this.friendNoDataLabel.node.active = true;
|
this.friendNoDataLabel.string = 'LOADING...';
|
|
if (Sdk.isFB) {
|
if (this.friendScrollview.content.childrenCount > 0) {
|
this.friendNoDataLabel.node.active = false;
|
return;
|
}
|
RankTool.friendsAsync(Userdata.Stars, (result) => {
|
if (result) {
|
if (result.data) {
|
if (result.data.length > 0) {
|
this.friendScrollview.content.removeAllChildren();
|
this.drawRankItemsFB(result.data, this.friendScrollview.content);
|
}
|
}
|
if (result.my) {
|
let rd = { extra: result.my.extra, nick: result.my.name, score: result.my.score, selfFlag: true, url: result.my.icon };
|
this.myRankitemNode.getComponent('RankItem').init(result.my.rank, rd, 'score', '');
|
}
|
}
|
});
|
}
|
}
|
|
showGlobalRank() {
|
this.friendButton.node.color = cc.Color.GRAY;
|
this.friendLabel.node.color = cc.Color.GRAY;
|
this.globalButton.node.color = cc.Color.WHITE;
|
this.globalLabel.node.color = cc.Color.WHITE;
|
this.friendScrollview.node.active = false;
|
this.globalScrollview.node.active = true;
|
this.globalNoDataLabel.node.active = true;
|
this.globalNoDataLabel.string = 'LOADING...';
|
|
if (Sdk.isFB) {
|
if (this.globalScrollview.content.childrenCount > 0) {
|
this.globalNoDataLabel.node.active = false;
|
return;
|
}
|
RankTool.weeklyAsync((result) => {
|
if (result) {
|
if (result.data) {
|
if (result.data.length > 0) {
|
this.globalScrollview.content.removeAllChildren();
|
this.drawRankItemsFB(result.data, this.globalScrollview.content);
|
}
|
}
|
if (result.my) {
|
let rd = { extra: result.my.extra, nick: result.my.name, score: result.my.score, selfFlag: true, url: result.my.icon };
|
this.myRankitemNode.getComponent('RankItem').init(result.my.rank, rd, 'score', '');
|
}
|
}
|
});
|
}
|
}
|
|
drawRankItemsFB(entries, parent) {
|
if (entries.length > 0) {
|
if (parent == this.friendScrollview.content) {
|
this.friendNoDataLabel.node.active = false;
|
} else {
|
this.globalNoDataLabel.node.active = false;
|
}
|
} else {
|
if (parent == this.friendScrollview.content) {
|
this.friendNoDataLabel.node.active = true;
|
this.friendNoDataLabel.string = 'NO DATA';
|
} else {
|
this.globalNoDataLabel.node.active = true;
|
this.globalNoDataLabel.string = 'NO DATA';
|
}
|
}
|
for (let i = 0; i < entries.length; i++) {
|
{
|
let rankitemNode = cc.instantiate(this.rankitemPrefab);
|
rankitemNode.parent = parent;
|
rankitemNode.active = true;
|
|
let rd = { extra: entries[i].extra, nick: entries[i].name, score: entries[i].score, selfFlag: false, url: entries[i].icon };
|
rankitemNode.getComponent('RankItem').init(entries[i].rank, rd, 'score', '');
|
}
|
}
|
}
|
|
onClickInvite() {
|
SoundManager.playButton();
|
let screenShot = cc.find('ScreenShot');
|
if (screenShot) {
|
let ss1: any = screenShot.getComponent('ScreenShot');
|
ss1.updateInfo(Userdata.Stars, false, (baseImg64) => {
|
Sdk.ins.share(baseImg64, 'Come and play this interesting game.');
|
});
|
}
|
}
|
|
onClickFriend() {
|
SoundManager.playButton();
|
this.showFriendRank();
|
}
|
|
onClickGlobal() {
|
SoundManager.playButton();
|
this.showGlobalRank();
|
}
|
}
|