import { respath } from "../constants/respath" import { StorageManager } from "./StorageManager" import { Stage } from "../views/Stage" import { DailyChallenge } from "../views/DailyChallenge" const { regClass, property } = Laya @regClass() export class UIManager extends Laya.Script { declare owner: Laya.Scene private static _instance: UIManager onAwake(): void { UIManager._instance = this } onStart(): void { this.loadHomeUI() } public static getInstance(): UIManager { return UIManager._instance } private stage: Stage public getUIRoot(): Laya.Node { return this.owner } public loadHomeUI(): void { Laya.loader.load(respath.home_ui_res).then((go)=>{ var prefab = go.create() this.getUIRoot().addChild(prefab) }) } public loadDCUI(): void { Laya.loader.load(respath.dc_ui_res).then((go)=>{ var prefab = go.create() var dc = this.getUIRoot().addChild(prefab).getComponent(DailyChallenge) dc.loadWithMonth() }) } public loadTrophyUI(): void { Laya.loader.load(respath.trophy_ui_res).then((go)=>{ var prefab = go.create() this.getUIRoot().addChild(prefab) }) } public loadStageUI(stageID: string): void { if (this.stage) { this.stage.onLoadStage(StorageManager.getInstance().loadStage(stageID)) } else { Laya.loader.load(respath.stage_ui_res).then((go)=>{ var prefab = go.create() this.stage = this.getUIRoot().addChild(prefab).getComponent(Stage) this.stage.onLoadStage(StorageManager.getInstance().loadStage(stageID)) }) } } public closeStageUI(): void { if (this.stage) { this.stage.owner.destroy() this.stage = null } } public loadGameOverUI(): void { Laya.loader.load(respath.gameover_ui_res).then((go)=>{ var prefab = go.create() this.getUIRoot().addChild(prefab) }) } public loadGameDoneUI(): void { Laya.loader.load(respath.gamedone_ui_res).then((go)=>{ var prefab = go.create() this.getUIRoot().addChild(prefab) }) } }