UIPause.ts 2.15 KB
// 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 { WindowName } from "../../Global";
import { BattleManager } from "../../kernel/battle/BattleManager";
import { UIBase } from "../UIBase";
import { UIManager } from "../UIManager";
import { UICommonNoticeEnableParam } from "./UICommonNoticeEnableParam";

const { ccclass, property } = cc._decorator;

@ccclass
export default class UIPause extends UIBase {

    private _noticeParam: UICommonNoticeEnableParam;

    //#region  LIFE-CYCLE CALLBACKS:

    onLoad() {
        this._noticeParam = new UICommonNoticeEnableParam();
        this._noticeParam.desc = '您想重新开始游戏吗?';
        this._noticeParam.callBackThisObj = this;
        this._noticeParam.doneCallBack = this.onNoticeDoneClick;

        // this._useCloseEffect = false;
    }

    protected onEnable(): void {

        if (!this.closing) {
            this.node.getChildByName('back').getChildByName('level').getChildByName('txtLevel').getComponent(cc.Label).string = BattleManager.ins.curBattle.levelId.toString();
            BattleManager.ins.paused = true;
        }

    }

    protected onDisable(): void {
        BattleManager.ins.paused = false;
    }

    // update (dt) {}

    //#endregion

    //#region public method


    //#endregion

    //#region event

    onRestartClick() {

        UIManager.ins.openWindow(WindowName.COMMON_NOTICE, this._noticeParam);
    }

    onContinueClick() {
        this.leave();
    }

    private onNoticeDoneClick() {
        this.leave();
        BattleManager.ins.leaveBattle();
        UIManager.ins.openScene('Battle');

        // UIManager.ins.closeWindow(WindowName.PAUSE, () => {
        //     BattleManager.ins.leaveBattle();
        //     UIManager.ins.openScene('Main');
        // });


    }

    //#endregion

    //#region private method

    private leave() {
        UIManager.ins.closeWindow(WindowName.PAUSE);
    }

    //#endregion
}