12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- // Learn TypeScript:
- // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
- // Learn Attribute:
- // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
- // Learn life-cycle callbacks:
- // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
- import PrefabManager from "../Manager/core/PrefabManager";
- import {UIID} from "../Manager/core/UIID";
- import { gameModel } from "../Module/Module";
- import CCUtils from "../Utiles/CCUtils";
- import Utiles from "../Utiles/Utiles";
- const {ccclass, property} = cc._decorator;
- @ccclass
- export default class UIRank extends cc.Component {
- @property(cc.Sprite)
- closeBtn: cc.Sprite = null;
-
-
- // LIFE-CYCLE CALLBACKS:
- // onLoad () {}
- start () {
- }
- protected onEnable(): void {
- this.closeBtn.node.on('click',this.closeEvent,this)
- const content: cc.Node = CCUtils.findChild(this.node , 'tcBg/scrollView/view/content');
- content.removeAllChildren();
- // 获取数组中最大的值
- 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();
- }
- }
- protected onDisable(): void {
- this.closeBtn.node.off('click',this.closeEvent,this)
- }
- private closeEvent():void{
- console.log("=====closeEvent====")
- // this.node.destroy()
- PrefabManager.close(UIID.UIRankPrefab);
- }
- // update (dt) {}
- }
|