Spring774
2025-10-30 a972605e1cf8122330de5b6ff53857be130972be
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
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();
    }
}