import GameData from "./module/Config/GameData"; import { GameTool } from "./module/Tool/GameTool"; 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; // onLoad () {} start () { this.count.string = GameData._instance.GM_INFO.total; if(GameData._instance.GM_INFO.mean_Time > 10){ GameData._instance.GM_INFO.mean_Time = (parseInt(Math.random()*10+"")+5)/10 } this.time.string = GameData._instance.GM_INFO.mean_Time + "s"; this.init(); } //初始化数据 init(){ this.listData = []; this.selfData = null; this.one.active = false; this.two.active = false; this.three.active = false; this.four.active = false; this.five.active = false; this.getRank(); } //打开排行榜 openRank(){ cc.director.loadScene("RankScene"); } //重新开始玩 again(){ cc.director.loadScene("GameScene"); } //获取排行榜 getRank(){ GameTool.getRank(5,data =>this.getRankData(data)); } //设置排行信息 getRankData(data){ if(data){ GameTool.getRankData(data,this,4); 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; GameTool.subName(data.nickName,4); hitNode.getChildByName("name").getComponent(cc.Label).string = data.nickName; hitNode.getChildByName("total").getComponent(cc.Label).string = data.totalSunCount; GameTool.setPic(hitNode.getChildByName("pic").getChildByName("icon"),data.pic); } } }