|
@@ -34,18 +34,20 @@ export default class UIRank extends cc.Component {
|
|
|
const content: cc.Node = CCUtils.findChild(this.node , 'tcBg/scrollView/view/content');
|
|
|
content.removeAllChildren();
|
|
|
// 获取数组中最大的值
|
|
|
- const maxNum: number = gameModel.historyScores.reduce((a, b) => Math.max(a, b));
|
|
|
- console.log('maxNum', maxNum);
|
|
|
- CCUtils.findChild(this.node , 'tcBg/scrollView/view/content').height = gameModel.historyScores.length * 100 + 100;
|
|
|
- for (let i: number = gameModel.historyScores.length; i > 0; i--) {
|
|
|
- const node: cc.Node = cc.instantiate(CCUtils.findChild(this.node, 'tcBg/scoreItem'));
|
|
|
- node.parent = content;
|
|
|
- node.setPosition(0, -i * 100);
|
|
|
- CCUtils.getLabel(node, 'score').string = gameModel.historyScores[i - 1].toString();
|
|
|
- CCUtils.getLabel(node, 'name').string = Utiles.random(1, 20).toString();
|
|
|
+ if (gameModel?.historyScores.length > 0) {
|
|
|
+ const maxNum: number = gameModel.historyScores.reduce((a, b) => Math.max(a, b));
|
|
|
+ console.log('maxNum', maxNum);
|
|
|
+ CCUtils.findChild(this.node , 'tcBg/scrollView/view/content').height = gameModel.historyScores.length * 100 + 100;
|
|
|
+ for (let i: number = gameModel.historyScores.length; i > 0; i--) {
|
|
|
+ const node: cc.Node = cc.instantiate(CCUtils.findChild(this.node, 'tcBg/scoreItem'));
|
|
|
+ node.parent = content;
|
|
|
+ node.setPosition(0, -i * 100);
|
|
|
+ CCUtils.getLabel(node, 'score').string = gameModel.historyScores[i - 1].toString();
|
|
|
+ CCUtils.getLabel(node, 'name').string = Utiles.random(1, 20).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ CCUtils.getLabel(this.node, 'tcBg/goatLabel').string = 'Highest score: ' + maxNum.toString();
|
|
|
}
|
|
|
-
|
|
|
- CCUtils.getLabel(this.node, 'tcBg/goatLabel').string = 'Highest score: ' + maxNum.toString();
|
|
|
}
|
|
|
|
|
|
protected onDisable(): void {
|