Files
sudoku/src/views/GameDone.ts

88 lines
3.2 KiB
TypeScript
Raw Normal View History

2025-05-28 18:47:51 +08:00
import type { DOStage } from "../models/DOStage"
import { config } from "../constants/config"
import { respath } from "../constants/respath"
import { StorageManager } from "../models/StorageManager"
import { UIManager } from "../models/UIManager"
import { Utility_ConvertSecondToString } from "../utils/utility"
import { Difficulty } from "./Difficulty"
2025-05-14 12:17:47 +08:00
2025-05-28 18:47:51 +08:00
const { regClass, property } = Laya
2025-05-14 12:17:47 +08:00
@regClass()
export class GameDone extends Laya.Script {
2025-05-28 18:47:51 +08:00
declare owner: Laya.Box
2025-05-14 12:17:47 +08:00
2025-05-28 18:47:51 +08:00
@property(Laya.Label)
public label_diffucuty: Laya.Label
2025-05-20 17:41:43 +08:00
2025-05-28 18:47:51 +08:00
@property(Laya.Label)
public label_time: Laya.Label
2025-05-20 17:41:43 +08:00
2025-05-28 18:47:51 +08:00
@property(Laya.Label)
public label_score: Laya.Label
2025-05-20 17:41:43 +08:00
2025-05-28 18:47:51 +08:00
@property(Laya.Box)
public btn_new: Laya.Box
2025-05-26 19:57:17 +08:00
2025-05-28 18:47:51 +08:00
@property(Laya.Box)
public btn_home: Laya.Box
2025-05-26 19:57:17 +08:00
2025-05-28 18:47:51 +08:00
@property(Laya.Box)
public btn_continue: Laya.Box
2025-05-14 12:17:47 +08:00
2025-05-28 18:47:51 +08:00
onStart(): void {
}
public onSetStageInfo(doStage: DOStage): void {
this.label_diffucuty.text = doStage.get_difficulty()
this.label_time.text = Utility_ConvertSecondToString(doStage.get_duration())
this.label_score.text = doStage.get_score().toString()
2025-05-28 20:29:24 +08:00
this.btn_new.on(Laya.Event.CLICK, this, () => {
2025-05-28 18:47:51 +08:00
if (config.H_SCREEN) {
const user = StorageManager.getInstance().getUser()
user.update_progress(doStage.get_difficulty(), doStage.get_stageIndex() + 1)// 主线关卡更新难度进度
StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, doStage.get_difficulty(), doStage.get_difficulty())
UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID)
this.owner.destroy()
} else {
Laya.loader.load(respath.difficulty_ui_res).then((go) => {
const prefab = go.create()
const d = UIManager.getInstance().getUIRoot().addChild(prefab).getComponent(Difficulty)
d.onInit((value: string) => {
console.log("选择难度", value)
StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, value, value)
UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID)
2025-05-20 17:41:43 +08:00
this.owner.destroy()
})
2025-05-28 18:47:51 +08:00
})
}
})
2025-05-20 17:41:43 +08:00
2025-05-28 20:29:24 +08:00
this.btn_continue.on(Laya.Event.CLICK, this, () => { // 这个按钮只有从DC来的会显示
2025-05-28 18:47:51 +08:00
UIManager.getInstance().loadDCUI()
UIManager.getInstance().closeStageUI()
this.owner.destroy()
})
2025-05-20 17:41:43 +08:00
2025-05-28 20:29:24 +08:00
this.btn_home.on(Laya.Event.CLICK, this, () => {
2025-05-28 18:47:51 +08:00
if (config.H_SCREEN) {
UIManager.getInstance().closeDCUI()
2025-05-28 19:15:32 +08:00
if (doStage.get_stageType() === config.STAGE_TYPE.MAIN) {
2025-05-28 18:47:51 +08:00
const user = StorageManager.getInstance().getUser()
user.update_progress(doStage.get_difficulty(), doStage.get_stageIndex() + 1)// 主线关卡更新难度进度
StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, doStage.get_difficulty(), doStage.get_difficulty())
UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID)
2025-05-28 19:15:32 +08:00
} else if (doStage.get_stageType() === config.STAGE_TYPE.DC) {
2025-05-28 18:47:51 +08:00
UIManager.getInstance().setTopbarTo(true)
2025-05-26 19:57:17 +08:00
}
2025-05-28 18:47:51 +08:00
} else {
UIManager.getInstance().loadHomeUI()
UIManager.getInstance().closeStageUI()
}
this.owner.destroy()
})
}
}