2025-05-12 22:06:04 +08:00
|
|
|
import { respath } from "../constants/respath"
|
2025-05-13 20:31:44 +08:00
|
|
|
import { StorageManager } from "./StorageManager"
|
2025-05-09 19:10:40 +08:00
|
|
|
import { Stage } from "../views/Stage"
|
|
|
|
|
|
2025-05-13 20:31:44 +08:00
|
|
|
|
2025-05-09 19:10:40 +08:00
|
|
|
const { regClass, property } = Laya
|
|
|
|
|
|
|
|
|
|
@regClass()
|
|
|
|
|
export class UIManager extends Laya.Script {
|
2025-05-12 22:06:04 +08:00
|
|
|
declare owner: Laya.Scene
|
2025-05-09 19:10:40 +08:00
|
|
|
|
|
|
|
|
private static _instance: UIManager
|
|
|
|
|
onAwake(): void {
|
|
|
|
|
UIManager._instance = this
|
2025-05-19 19:51:17 +08:00
|
|
|
}
|
2025-05-13 20:31:44 +08:00
|
|
|
|
2025-05-19 19:51:17 +08:00
|
|
|
onStart(): void {
|
|
|
|
|
this.loadHomeUI()
|
2025-05-09 19:10:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static getInstance(): UIManager {
|
|
|
|
|
return UIManager._instance
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-14 12:17:47 +08:00
|
|
|
private stage: Stage
|
|
|
|
|
|
2025-05-19 19:51:17 +08:00
|
|
|
|
|
|
|
|
public getUIRoot(): Laya.Node {
|
|
|
|
|
return this.owner
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public loadHomeUI(): void {
|
2025-05-12 22:06:04 +08:00
|
|
|
Laya.loader.load(respath.home_ui_res).then((go)=>{
|
|
|
|
|
var prefab = go.create()
|
2025-05-19 19:51:17 +08:00
|
|
|
this.getUIRoot().addChild(prefab)
|
2025-05-12 22:06:04 +08:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-19 19:51:17 +08:00
|
|
|
public loadStageUI(stageID: string): void {
|
2025-05-14 12:17:47 +08:00
|
|
|
if (this.stage) {
|
|
|
|
|
this.stage.onLoadStage(StorageManager.getInstance().loadStage(stageID))
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
Laya.loader.load(respath.stage_ui_res).then((go)=>{
|
|
|
|
|
var prefab = go.create()
|
2025-05-19 19:51:17 +08:00
|
|
|
this.stage = this.getUIRoot().addChild(prefab).getComponent(Stage)
|
2025-05-14 12:17:47 +08:00
|
|
|
this.stage.onLoadStage(StorageManager.getInstance().loadStage(stageID))
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-19 19:51:17 +08:00
|
|
|
public closeStageUI(): void {
|
2025-05-14 12:17:47 +08:00
|
|
|
if (this.stage) {
|
|
|
|
|
this.stage.owner.destroy()
|
|
|
|
|
this.stage = null
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-19 19:51:17 +08:00
|
|
|
public loadGameOverUI(): void {
|
2025-05-14 12:17:47 +08:00
|
|
|
Laya.loader.load(respath.gameover_ui_res).then((go)=>{
|
2025-05-12 22:06:04 +08:00
|
|
|
var prefab = go.create()
|
2025-05-19 19:51:17 +08:00
|
|
|
this.getUIRoot().addChild(prefab)
|
2025-05-14 12:17:47 +08:00
|
|
|
})
|
|
|
|
|
}
|
2025-05-19 19:51:17 +08:00
|
|
|
public loadGameDoneUI(): void {
|
2025-05-14 12:17:47 +08:00
|
|
|
Laya.loader.load(respath.gamedone_ui_res).then((go)=>{
|
|
|
|
|
var prefab = go.create()
|
2025-05-19 19:51:17 +08:00
|
|
|
this.getUIRoot().addChild(prefab)
|
2025-05-12 22:06:04 +08:00
|
|
|
})
|
2025-05-09 19:10:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|