Files
sudoku/src/models/UIManager.ts

204 lines
5.8 KiB
TypeScript
Raw Normal View History

2025-05-28 18:47:51 +08:00
import type { TrophyRecord } from "../types/global"
import type { DOStage } from "./DOStage"
import { config } from "../constants/config"
2025-05-12 22:06:04 +08:00
import { respath } from "../constants/respath"
2025-05-23 20:47:03 +08:00
import { DailyChallenge } from "../views/dc/DailyChallenge"
import { TrophyClaim } from "../views/dc/TrophyClaim"
2025-05-26 19:57:17 +08:00
import { TrophyRoom } from "../views/dc/TrophyRoom"
2025-05-28 18:47:51 +08:00
import { TrophyShow } from "../views/dc/TrophyShow"
2025-05-26 19:57:17 +08:00
import { GameDone } from "../views/GameDone"
2025-05-28 18:47:51 +08:00
import { GameOver } from "../views/GameOver"
import { GamePause } from "../views/GamePause"
import { Stage } from "../views/Stage"
2025-05-26 21:17:05 +08:00
import { TopBar } from "../views/TopBar"
2025-05-28 18:47:51 +08:00
import { StorageManager } from "./StorageManager"
2025-05-13 20:31:44 +08:00
2025-05-29 17:28:40 +08:00
const { regClass, property } = Laya
2025-05-09 19:10:40 +08:00
@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-30 11:52:25 +08:00
@property(Boolean)
public debug: boolean = false
2025-05-29 17:28:40 +08:00
@property(Laya.Image)
public mask: Laya.Image
2025-05-30 11:52:25 +08:00
@property(Laya.Box)
public btn_clean: Laya.Box
2025-05-09 19:10:40 +08:00
onAwake(): void {
UIManager._instance = this
2025-05-30 11:52:25 +08:00
config.DEBUG = this.debug
2025-05-29 19:15:32 +08:00
this.mask.on(Laya.Event.CLICK, this, () => {
2025-05-29 17:28:40 +08:00
console.log("on click mask >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
})
this.mask.visible = false
2025-05-30 11:52:25 +08:00
this.btn_clean.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
console.log("btn_clean=", evt)
StorageManager.getInstance().cleanAll()
})
this.btn_clean.visible = this.debug
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 {
2025-05-28 17:00:47 +08:00
if (!this.UIRoot) {
2025-05-26 20:56:15 +08:00
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
2025-05-28 18:47:51 +08:00
} else {
2025-05-26 20:56:15 +08:00
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-28 18:47:51 +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
2025-05-30 17:25:15 +08:00
private dc_year: number = -1
private dc_month: number = -1
2025-05-26 19:57:17 +08:00
private trophyRoom: TrophyRoom
2025-05-14 12:17:47 +08:00
2025-05-26 20:56:15 +08:00
onStart(): void {
if (config.H_SCREEN) {
this.loadTopBarUI()
2025-05-28 18:47:51 +08:00
} else {
2025-05-26 20:56:15 +08:00
this.loadHomeUI()
}
2025-05-19 19:51:17 +08:00
}
public loadHomeUI(): void {
2025-05-28 18:47:51 +08:00
Laya.loader.load(respath.home_ui_res).then((go) => {
const 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 {
2025-05-28 18:47:51 +08:00
Laya.loader.load(respath.topbar_ui_res).then((go) => {
const 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-28 18:47:51 +08:00
2025-05-26 21:17:05 +08:00
public setTopbarTo(isClassic: boolean): void {
if (this.topbar) {
this.topbar.onClickTab(isClassic)
}
}
2025-05-28 18:47:51 +08:00
2025-05-30 17:25:15 +08:00
public setCurrentDCMonth(year: number, month: number): void {
this.dc_year = year
this.dc_month = month
console.log("setCurrentDCMonth >>>>>>>>>>>>>>>>>>>>", year, month)
}
2025-05-20 17:41:43 +08:00
public loadDCUI(): void {
2025-05-29 17:28:40 +08:00
this.mask.visible = true
2025-05-28 18:47:51 +08:00
Laya.loader.load(respath.dc_ui_res()).then((go) => {
const prefab = go.create()
2025-05-26 19:57:17 +08:00
this.dc_ui = this.getUIRoot().addChild(prefab).getComponent(DailyChallenge)
2025-05-30 17:25:15 +08:00
if (this.dc_year <= 0 || this.dc_month <= 0) {
const now = new Date()
this.dc_year = now.getFullYear()
this.dc_month = now.getMonth() + 1
}
this.dc_ui.loadWithMonth(this.dc_year, this.dc_month)
2025-05-29 17:28:40 +08:00
this.mask.visible = false
2025-05-20 17:41:43 +08:00
})
}
2025-05-28 18:47:51 +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-28 18:47:51 +08:00
Laya.loader.load(respath.trophy_claim_ui_res()).then((go) => {
const prefab = go.create()
const obj = this.getUIRoot().addChild(prefab).getComponent(TrophyClaim)
2025-05-22 14:54:48 +08:00
obj.onSetShow(record)
})
}
2025-05-20 21:05:30 +08:00
public loadTrophyUI(): void {
2025-05-29 17:28:40 +08:00
this.mask.visible = true
2025-05-28 18:47:51 +08:00
Laya.loader.load(respath.trophy_ui_res()).then((go) => {
const prefab = go.create()
2025-05-26 19:57:17 +08:00
this.trophyRoom = this.getUIRoot().addChild(prefab).getComponent(TrophyRoom)
2025-05-29 17:28:40 +08:00
this.mask.visible = false
2025-05-20 21:05:30 +08:00
})
}
2025-05-28 18:47:51 +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-28 18:47:51 +08:00
}
2025-05-26 19:57:17 +08:00
}
2025-05-20 21:05:30 +08:00
2025-05-22 14:54:48 +08:00
public loadTrophyShowUI(record: TrophyRecord): void {
2025-05-28 18:47:51 +08:00
Laya.loader.load(respath.trophy_show_ui_res()).then((go) => {
const prefab = go.create()
const obj = this.getUIRoot().addChild(prefab).getComponent(TrophyShow)
2025-05-22 14:54:48 +08:00
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) {
2025-05-28 18:47:51 +08:00
this.stage.onLoadStage(StorageManager.getInstance().loadStage(stageID))
} else {
Laya.loader.load(respath.stage_ui_res()).then((go) => {
const 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-28 18:47:51 +08:00
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 {
2025-05-28 18:47:51 +08:00
Laya.loader.load(respath.gamepause_ui_res()).then((go) => {
const prefab = go.create()
const ui = this.getUIRoot().addChild(prefab).getComponent(GamePause)
2025-05-26 19:57:17 +08:00
ui.onSetStageInfo(doStage)
2025-05-22 19:12:00 +08:00
})
}
2025-05-28 18:47:51 +08:00
2025-05-26 19:57:17 +08:00
public loadGameOverUI(doStage: DOStage): void {
2025-05-28 18:47:51 +08:00
Laya.loader.load(respath.gameover_ui_res()).then((go) => {
const prefab = go.create()
const ui = this.getUIRoot().addChild(prefab).getComponent(GameOver)
2025-05-26 19:57:17 +08:00
ui.onSetStageInfo(doStage)
2025-05-14 12:17:47 +08:00
})
}
2025-05-28 18:47:51 +08:00
2025-05-26 19:57:17 +08:00
public loadGameDoneUI(isClassic: boolean, doStage: DOStage): void {
2025-05-28 18:47:51 +08:00
Laya.loader.load(respath.gamedone_ui_res(isClassic)).then((go) => {
const prefab = go.create()
const ui = this.getUIRoot().addChild(prefab).getComponent(GameDone)
2025-05-26 19:57:17 +08:00
ui.onSetStageInfo(doStage)
2025-05-12 22:06:04 +08:00
})
2025-05-09 19:10:40 +08:00
}
}