完善关卡逻辑
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
|
||||
import { UIManager } from "../models/UIManager";
|
||||
import { StorageManager } from "../models/StorageManager";
|
||||
import { respath } from "../constants/respath";
|
||||
import { Difficulty } from "./Difficulty";
|
||||
import { LevelManager } from "../models/LevelManager";
|
||||
import { config } from "../constants/config";
|
||||
import { Utility_ConvertSecondToString } from "../utils/utility";
|
||||
|
||||
const { regClass, property } = Laya
|
||||
|
||||
@@ -9,23 +14,71 @@ export class Home extends Laya.Script {
|
||||
declare owner : Laya.Box;
|
||||
|
||||
@property(Laya.Box)
|
||||
public btn_start: Laya.Box;
|
||||
public btn_new_blue: Laya.Box;
|
||||
|
||||
@property(Laya.Box)
|
||||
public btn_continue: Laya.Box;
|
||||
@property(Laya.Box)
|
||||
public btn_new_white: Laya.Box;
|
||||
|
||||
@property(Laya.Box)
|
||||
public btn_clean: Laya.Box;
|
||||
|
||||
//组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
|
||||
onAwake(): void {
|
||||
this.btn_start.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
|
||||
console.log("btn_start=", evt);
|
||||
UIManager.getInstance().loadStage("first");
|
||||
this.btn_new_blue.on(Laya.Event.CLICK, this, this.onClickNew)
|
||||
this.btn_new_white.on(Laya.Event.CLICK, this, this.onClickNew)
|
||||
this.btn_continue.on(Laya.Event.CLICK, this, (evt: Laya.Event)=>{
|
||||
UIManager.getInstance().closeStageUI()
|
||||
UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID);
|
||||
this.owner.destroy()
|
||||
})
|
||||
var user = StorageManager.getInstance().getUser()
|
||||
this.btn_new_blue.visible = user.get_isCompletedMain()
|
||||
this.btn_new_white.visible = user.get_isCompletedMain() == false
|
||||
this.btn_continue.visible = user.get_isCompletedMain() == false
|
||||
if (user.get_isCompletedMain() == false) {
|
||||
var label_time = this.btn_continue.getChildByName("time").getChildByName("label_time") as Laya.Label
|
||||
var doStage = StorageManager.getInstance().loadStage(config.DEFAULT_STAGE_ID)
|
||||
var duration = doStage.get_duration()
|
||||
var timeStr = Utility_ConvertSecondToString(duration)
|
||||
label_time.text = `${timeStr} - ${doStage.get_difficulty()}`
|
||||
}
|
||||
|
||||
|
||||
//测试逻辑
|
||||
this.btn_clean.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
|
||||
console.log("btn_clean=", evt);
|
||||
StorageManager.getInstance().cleanStage()
|
||||
Laya.LocalStorage.clear()
|
||||
StorageManager.getInstance().cleanAll()
|
||||
user = StorageManager.getInstance().getUser()
|
||||
this.btn_new_blue.visible = user.get_isCompletedMain()
|
||||
this.btn_new_white.visible = user.get_isCompletedMain() == false
|
||||
this.btn_continue.visible = user.get_isCompletedMain() == false
|
||||
})
|
||||
this.btn_clean.visible = config.DEBUG
|
||||
//======
|
||||
}
|
||||
|
||||
public onClickNew(evt: Laya.Event): void {
|
||||
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)
|
||||
UIManager.getInstance().closeStageUI()
|
||||
|
||||
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()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user