补充UI细节 添加每日挑战
This commit is contained in:
@@ -13,11 +13,19 @@ const { regClass, property } = Laya
|
||||
export class Home extends Laya.Script {
|
||||
declare owner : Laya.Box;
|
||||
|
||||
@property(Laya.Box)
|
||||
public btn_new_blue: Laya.Box;
|
||||
@property(Laya.Label)
|
||||
public label_dc_title: Laya.Label;
|
||||
@property(Laya.Sprite)
|
||||
public btn_play: Laya.Sprite;
|
||||
@property(Laya.Sprite)
|
||||
public btn_continue: Laya.Sprite;
|
||||
@property(Laya.Sprite)
|
||||
public btn_more: Laya.Sprite;
|
||||
|
||||
@property(Laya.Box)
|
||||
public btn_continue: Laya.Box;
|
||||
public btn_new_blue: Laya.Box;
|
||||
@property(Laya.Box)
|
||||
public btn_go: Laya.Box;
|
||||
@property(Laya.Box)
|
||||
public btn_new_white: Laya.Box;
|
||||
|
||||
@@ -26,34 +34,87 @@ export class Home extends Laya.Script {
|
||||
|
||||
//组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
|
||||
onAwake(): void {
|
||||
|
||||
var user = StorageManager.getInstance().getUser()
|
||||
|
||||
var now = new Date()
|
||||
var year = now.getFullYear()
|
||||
var month = now.getMonth() + 1
|
||||
var dayNow = new Date().getDate()
|
||||
this.label_dc_title.text = `${config.MONTH_ABBRS[month-1]} ${dayNow}`
|
||||
var stageID = `${year}-${month}-${dayNow}`
|
||||
var progress = user.get_done(stageID)
|
||||
if (progress <= 0) {
|
||||
this.btn_play.visible = true
|
||||
this.btn_continue.visible = false
|
||||
this.btn_more.visible = false
|
||||
this.btn_play.on(Laya.Event.CLICK, this, ()=>{//Play
|
||||
var random = Math.random()
|
||||
var value = config.DIFFICULTY_LIST[Math.floor(random*config.DIFFICULTY_LIST.length)]
|
||||
var list = LevelManager.getInstance().getLevelList(value)
|
||||
random = Math.random()
|
||||
var index = Math.floor(random*list.length)
|
||||
var stageName = `${config.MONTH_ABBRS[month-1]} ${dayNow}`
|
||||
console.log("随机一个关卡", value, index)
|
||||
StorageManager.getInstance().newStage(stageID, config.STAGE_TYPE.DC, stageName, value, index)
|
||||
UIManager.getInstance().loadStageUI(stageID);
|
||||
this.owner.destroy()
|
||||
})
|
||||
}
|
||||
else if (progress >= 1) {
|
||||
this.btn_play.visible = false
|
||||
this.btn_continue.visible = false
|
||||
this.btn_more.visible = true
|
||||
this.btn_more.on(Laya.Event.CLICK, this, ()=>{//更多
|
||||
UIManager.getInstance().loadDCUI();
|
||||
this.owner.destroy()
|
||||
})
|
||||
}
|
||||
else {
|
||||
this.btn_play.visible = false
|
||||
this.btn_continue.visible = true
|
||||
this.btn_more.visible = false
|
||||
this.btn_continue.on(Laya.Event.CLICK, this, ()=>{//继续
|
||||
UIManager.getInstance().loadStageUI(stageID);
|
||||
this.owner.destroy()
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
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()
|
||||
this.btn_go.on(Laya.Event.CLICK, this, (evt: Laya.Event)=>{
|
||||
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()}`
|
||||
if (user.get_done(config.DEFAULT_STAGE_ID) >= 1) {
|
||||
console.log("当前主线关卡完成")
|
||||
this.btn_new_blue.visible = true
|
||||
this.btn_new_white.visible = false
|
||||
this.btn_go.visible = false
|
||||
}
|
||||
else {
|
||||
var doStage = StorageManager.getInstance().loadStage(config.DEFAULT_STAGE_ID)
|
||||
if (doStage) {
|
||||
console.log("当前主线关卡进行中")
|
||||
var label_time = this.btn_go.getChildByName("time").getChildByName("label_time") as Laya.Label
|
||||
var duration = doStage.get_duration()
|
||||
var timeStr = Utility_ConvertSecondToString(duration)
|
||||
label_time.text = `${timeStr} - ${doStage.get_difficulty()}`
|
||||
}
|
||||
else {
|
||||
console.log("当前主线关卡未开始")
|
||||
this.btn_new_blue.visible = true
|
||||
this.btn_new_white.visible = false
|
||||
this.btn_go.visible = false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//测试逻辑
|
||||
this.btn_clean.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
|
||||
console.log("btn_clean=", evt);
|
||||
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
|
||||
//======
|
||||
@@ -65,11 +126,8 @@ export class Home extends Laya.Script {
|
||||
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)
|
||||
StorageManager.getInstance().cleanMainStage()
|
||||
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) {//说明当前难度已经打通了,所以给他从头开始
|
||||
|
||||
Reference in New Issue
Block a user