Files
sudoku/src/models/UIManager.ts

168 lines
4.7 KiB
TypeScript
Raw Normal View History

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-23 20:47:03 +08:00
import { DailyChallenge } from "../views/dc/DailyChallenge"
2025-05-22 14:54:48 +08:00
import { TrophyRecord } from "../types/global"
2025-05-23 20:47:03 +08:00
import { TrophyClaim } from "../views/dc/TrophyClaim"
import { TrophyShow } from "../views/dc/TrophyShow"
import { config } from "../constants/config"
2025-05-26 19:57:17 +08:00
import { TrophyRoom } from "../views/dc/TrophyRoom"
import { DOStage } from "./DOStage"
import { GamePause } from "../views/GamePause"
import { GameOver } from "../views/GameOver"
import { GameDone } from "../views/GameDone"
2025-05-26 21:17:05 +08:00
import { TopBar } from "../views/TopBar"
2025-05-09 19:10:40 +08:00
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
2025-05-26 20:56:15 +08:00
public static getInstance(): UIManager {
return UIManager._instance
}
2025-05-09 19:10:40 +08:00
onAwake(): void {
UIManager._instance = this
2025-05-19 19:51:17 +08:00
}
2025-05-13 20:31:44 +08:00
2025-05-26 20:56:15 +08:00
private UIRoot: Laya.Panel
public getUIRoot(): Laya.Node {
if (this.UIRoot == null) {
this.UIRoot = this.owner.getChildByName("UIRoot") as Laya.Panel
if (config.H_SCREEN) {
this.UIRoot.width = config.DESIGN_HEIGHT
this.UIRoot.height = config.DESIGN_WIDTH
}
else {
this.UIRoot.width = config.DESIGN_WIDTH
this.UIRoot.height = config.DESIGN_HEIGHT
}
2025-05-23 20:47:03 +08:00
}
2025-05-26 20:56:15 +08:00
return this.UIRoot
2025-05-09 19:10:40 +08:00
}
2025-05-26 21:17:05 +08:00
private topbar : TopBar
2025-05-14 12:17:47 +08:00
private stage: Stage
2025-05-26 19:57:17 +08:00
private dc_ui: DailyChallenge
private trophyRoom: TrophyRoom
2025-05-14 12:17:47 +08:00
2025-05-19 19:51:17 +08:00
2025-05-26 20:56:15 +08:00
onStart(): void {
if (config.H_SCREEN) {
this.loadTopBarUI()
}
else {
this.loadHomeUI()
}
2025-05-19 19:51:17 +08:00
}
2025-05-26 20:56:15 +08:00
2025-05-19 19:51:17 +08:00
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-23 20:47:03 +08:00
})
}
public loadTopBarUI(): void {
Laya.loader.load(respath.topbar_ui_res).then((go)=>{
var prefab = go.create()
2025-05-26 21:17:05 +08:00
this.topbar = this.getUIRoot().addChild(prefab).getComponent(TopBar)
2025-05-12 22:06:04 +08:00
})
}
2025-05-26 21:17:05 +08:00
public setTopbarTo(isClassic: boolean): void {
if (this.topbar) {
this.topbar.onClickTab(isClassic)
}
}
2025-05-12 22:06:04 +08:00
2025-05-20 17:41:43 +08:00
public loadDCUI(): void {
2025-05-26 19:57:17 +08:00
Laya.loader.load(respath.dc_ui_res()).then((go)=>{
2025-05-20 17:41:43 +08:00
var prefab = go.create()
2025-05-26 19:57:17 +08:00
this.dc_ui = this.getUIRoot().addChild(prefab).getComponent(DailyChallenge)
this.dc_ui.loadWithMonth()
2025-05-20 17:41:43 +08:00
})
}
2025-05-26 19:57:17 +08:00
public closeDCUI(): void {
if (this.dc_ui) {
this.dc_ui.owner.destroy()
this.dc_ui = null
}
}
2025-05-20 17:41:43 +08:00
2025-05-22 14:54:48 +08:00
public loadTrophyClaimUI(record: TrophyRecord): void {
2025-05-26 19:57:17 +08:00
Laya.loader.load(respath.trophy_claim_ui_res()).then((go)=>{
2025-05-22 14:54:48 +08:00
var prefab = go.create()
var obj = this.getUIRoot().addChild(prefab).getComponent(TrophyClaim)
obj.onSetShow(record)
})
}
2025-05-20 21:05:30 +08:00
public loadTrophyUI(): void {
2025-05-26 19:57:17 +08:00
Laya.loader.load(respath.trophy_ui_res()).then((go)=>{
2025-05-20 21:05:30 +08:00
var prefab = go.create()
2025-05-26 19:57:17 +08:00
this.trophyRoom = this.getUIRoot().addChild(prefab).getComponent(TrophyRoom)
2025-05-20 21:05:30 +08:00
})
}
2025-05-26 19:57:17 +08:00
public closeTrophyUI(): void {
if (this.trophyRoom) {
this.trophyRoom.owner.destroy()
this.trophyRoom = null
}
}
2025-05-20 21:05:30 +08:00
2025-05-22 14:54:48 +08:00
public loadTrophyShowUI(record: TrophyRecord): void {
2025-05-26 19:57:17 +08:00
Laya.loader.load(respath.trophy_show_ui_res()).then((go)=>{
2025-05-22 14:54:48 +08:00
var prefab = go.create()
var obj = this.getUIRoot().addChild(prefab).getComponent(TrophyShow)
obj.onSetShow(record)
})
}
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 {
2025-05-22 17:17:47 +08:00
Laya.loader.load(respath.stage_ui_res()).then((go)=>{
2025-05-14 12:17:47 +08:00
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-26 19:57:17 +08:00
public loadGamePauseUI(doStage: DOStage): void {
Laya.loader.load(respath.gamepause_ui_res()).then((go)=>{
2025-05-22 19:12:00 +08:00
var prefab = go.create()
2025-05-26 19:57:17 +08:00
var ui = this.getUIRoot().addChild(prefab).getComponent(GamePause)
ui.onSetStageInfo(doStage)
2025-05-22 19:12:00 +08:00
})
}
2025-05-26 19:57:17 +08:00
public loadGameOverUI(doStage: DOStage): void {
Laya.loader.load(respath.gameover_ui_res()).then((go)=>{
2025-05-12 22:06:04 +08:00
var prefab = go.create()
2025-05-26 19:57:17 +08:00
var ui = this.getUIRoot().addChild(prefab).getComponent(GameOver)
ui.onSetStageInfo(doStage)
2025-05-14 12:17:47 +08:00
})
}
2025-05-26 19:57:17 +08:00
public loadGameDoneUI(isClassic: boolean, doStage: DOStage): void {
Laya.loader.load(respath.gamedone_ui_res(isClassic)).then((go)=>{
2025-05-14 12:17:47 +08:00
var prefab = go.create()
2025-05-26 19:57:17 +08:00
var ui = this.getUIRoot().addChild(prefab).getComponent(GameDone)
ui.onSetStageInfo(doStage)
2025-05-12 22:06:04 +08:00
})
2025-05-09 19:10:40 +08:00
}
}