

import { UIManager } from "../models/UIManager";
import { StorageManager } from "../models/StorageManager";
import { Utility_ConvertSecondToString } from "../utils/utility";
import { EVENT_TYPES, EventManager } from "../models/EventManager";
import { DOStage } from "../models/DOStage";



const { regClass, property } = Laya;

@regClass()
export class GamePause extends Laya.Script {
    declare owner : Laya.Box;

    @property(Laya.Label)
    public label_time: Laya.Label
    @property(Laya.Label)
    public label_diffucuty: Laya.Label

    @property(Laya.Sprite)
    public btn_continue: Laya.Sprite
    @property(Laya.Sprite)
    public btn_restart: Laya.Sprite


    //组件被激活后执行，此时所有节点和组件均已创建完毕，此方法只执行一次
    onAwake(): void {
    
    }

    public onSetStageInfo(doStage: DOStage): void {

      this.label_time.text = Utility_ConvertSecondToString(doStage.get_duration())
      this.label_diffucuty.text = doStage.get_difficulty()

      EventManager.getInstance().DispatchEvent(EVENT_TYPES.NOT_UPDATE_PAUSE, true)
      this.btn_continue.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
        EventManager.getInstance().DispatchEvent(EVENT_TYPES.NOT_UPDATE_PAUSE, false)
        this.owner.destroy()
      })

      this.btn_restart.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
        var stageID = doStage.get_stageID()
        var type = doStage.get_stageType()
        var difficulty = doStage.get_difficulty()
        StorageManager.getInstance().newStage(stageID, type, difficulty, difficulty)
        UIManager.getInstance().loadStageUI(stageID);
        this.owner.destroy()
      })
      
    }
}