
const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {
    @property(cc.Label)
    count: cc.Label = null;
    @property(cc.Label)
    time: cc.Label = null;
    @property(cc.Node)
    selfNode: cc.Node = null;
    @property(cc.Node)
    one: cc.Node = null;
    @property(cc.Node)
    two: cc.Node = null;
    @property(cc.Node)
    three: cc.Node = null;
    @property(cc.Node)
    four: cc.Node = null;
    @property(cc.Node)
    five: cc.Node = null;
    listData: any;
    selfData: any;
    efficiency: number;
    level: number;
    // onLoad () {}
    start () {
        this.init();
    }


    //初始化数据
    init(){
        this.listData = [];
        this.selfData = null;
        // this.getRank();
    }
    //打开排行榜
    openRank(){
        // alert("跳转");
        cc.director.loadScene("LoadScene");
    }
    //重新开始玩
    again(){
        // let levelTemp = cc.fx.GameConfig.GM_INFO.level;
        cc.fx.GameConfig.GM_INFO_init();
        // if(cc.fx.GameConfig.GM_INFO.isCustom){
        //     cc.fx.GameConfig.GM_INFO.level = levelTemp;
        // }
        cc.director.loadScene("GameScene");

    }
    //获取排行榜
    getRank(){
        //获取排行榜数据  所需数据量
        let dataFile = {
            length:5
        }
         cc.fx.GameTool.getRank(dataFile,data =>this.getRankData(data));
    }
    //设置排行信息
    getRankData(data){
        if(data){
             cc.fx.GameTool.getRankData(data,this,4);
             cc.fx.GameTool.setPic(this.selfNode.getChildByName("pic").getChildByName("icon"),this.selfData.pic);
            for(let i=0;i<=4;i++){
                this.setRank(i,this.listData[i]);
            }
        }
    }
    //根据内容填充排行榜
    setRank(num,data){
        var hitNode = null;
        if(num == 0){
            hitNode = this.one;
        }
        else if(num == 1){
            hitNode = this.two;
        }
        else if(num == 2){
            hitNode = this.three;
        }
        else if(num == 3){
            hitNode = this.four;
        }
        else if(num == 4){
            hitNode = this.five;
        }
        if(hitNode){
            hitNode.active = true;
             cc.fx.GameTool.subName(data.nickName,4);
            hitNode.getChildByName("name").getComponent(cc.Label).string = data.nickName;
            hitNode.getChildByName("total").getComponent(cc.Label).string = data.totalSunCount;
             cc.fx.GameTool.setPic(hitNode.getChildByName("pic").getChildByName("icon"),data.pic);
        }
    }   


}
