2025-05-19 19:51:17 +08:00
|
|
|
import { respath } from "../constants/respath";
|
|
|
|
|
import { config } from "../constants/config";
|
2025-05-14 12:17:47 +08:00
|
|
|
import { UIManager } from "../models/UIManager";
|
2025-05-19 19:51:17 +08:00
|
|
|
import { StorageManager } from "../models/StorageManager";
|
|
|
|
|
import { LevelManager } from "../models/LevelManager";
|
|
|
|
|
import { Difficulty } from "./Difficulty";
|
2025-05-14 12:17:47 +08:00
|
|
|
|
|
|
|
|
const { regClass, property } = Laya;
|
|
|
|
|
|
|
|
|
|
@regClass()
|
|
|
|
|
export class GameOver extends Laya.Script {
|
|
|
|
|
declare owner : Laya.Box;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@property(Laya.Button)
|
|
|
|
|
public btn_restart: Laya.Button
|
|
|
|
|
|
|
|
|
|
@property(Laya.Button)
|
|
|
|
|
public btn_new: Laya.Button
|
|
|
|
|
|
|
|
|
|
//组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
|
|
|
|
|
onAwake(): void {
|
|
|
|
|
this.btn_restart.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
|
2025-05-19 19:51:17 +08:00
|
|
|
var doStage = StorageManager.getInstance().loadStage(config.DEFAULT_STAGE_ID)
|
|
|
|
|
var difficulty = doStage.get_difficulty()
|
|
|
|
|
StorageManager.getInstance().cleanStage(config.DEFAULT_STAGE_ID)
|
|
|
|
|
var user = StorageManager.getInstance().getUser()
|
|
|
|
|
user.set_isCompletedMain(false)
|
|
|
|
|
StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, difficulty, difficulty, user.get_progress(difficulty))
|
|
|
|
|
UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID);
|
|
|
|
|
this.owner.destroy()
|
2025-05-14 12:17:47 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
this.btn_new.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
|
2025-05-19 19:51:17 +08:00
|
|
|
Laya.loader.load(respath.difficulty_ui_res).then((go)=>{
|
|
|
|
|
var prefab = go.create()
|
|
|
|
|
var d = UIManager.getInstance().getUIRoot().addChild(prefab).getComponent(Difficulty)
|
|
|
|
|
d.onInit((value: string)=> {
|
|
|
|
|
console.log("选择难度", value)
|
|
|
|
|
StorageManager.getInstance().cleanStage(config.DEFAULT_STAGE_ID)
|
|
|
|
|
var user = StorageManager.getInstance().getUser()
|
|
|
|
|
user.set_isCompletedMain(false)
|
|
|
|
|
var index = user.get_progress(value)
|
|
|
|
|
var levelStr = LevelManager.getInstance().getLevelStr(value, index)
|
|
|
|
|
if (!levelStr || levelStr.length <= 0) {//说明当前难度已经打通了,所以给他从头开始
|
|
|
|
|
user.update_progress(value, 0)
|
|
|
|
|
}
|
|
|
|
|
StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, value, value, user.get_progress(value))
|
|
|
|
|
UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID);
|
|
|
|
|
this.owner.destroy()
|
|
|
|
|
})
|
|
|
|
|
})
|
2025-05-14 12:17:47 +08:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|