Spring774
2025-10-27 a621979f62588ed1a899d17c937dc3aee8670ec1
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
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() {
 
    }
}