import { respath } from "../constants/respath" import { StorageManager } from "./StorageManager" import { Stage } from "../views/Stage" import { DailyChallenge } from "../views/dc/DailyChallenge" import { TrophyRecord } from "../types/global" import { TrophyClaim } from "../views/dc/TrophyClaim" import { TrophyShow } from "../views/dc/TrophyShow" import { config } from "../constants/config" 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 { if (config.H_SCREEN) { this.loadTopBarUI() } else { 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 loadTopBarUI(): void { Laya.loader.load(respath.topbar_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 loadTrophyClaimUI(record: TrophyRecord): void { Laya.loader.load(respath.trophy_claim_ui_res).then((go)=>{ var prefab = go.create() var obj = this.getUIRoot().addChild(prefab).getComponent(TrophyClaim) obj.onSetShow(record) }) } public loadTrophyUI(): void { Laya.loader.load(respath.trophy_ui_res).then((go)=>{ var prefab = go.create() this.getUIRoot().addChild(prefab) }) } public loadTrophyShowUI(record: TrophyRecord): void { Laya.loader.load(respath.trophy_show_ui_res).then((go)=>{ var prefab = go.create() var obj = this.getUIRoot().addChild(prefab).getComponent(TrophyShow) obj.onSetShow(record) }) } 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 loadGamePauseUI(): void { Laya.loader.load(respath.gamepause_ui_res).then((go)=>{ var prefab = go.create() this.getUIRoot().addChild(prefab) }) } 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) }) } }