补充UI细节 添加每日挑战
This commit is contained in:
115
src/views/CalendarUnit.ts
Normal file
115
src/views/CalendarUnit.ts
Normal file
@@ -0,0 +1,115 @@
|
||||
const { regClass, property } = Laya;
|
||||
|
||||
@regClass()
|
||||
export class CalendarUnit extends Laya.Script {
|
||||
declare owner : Laya.Box;
|
||||
|
||||
@property(Number)
|
||||
public day: number = 0;
|
||||
@property(Boolean)
|
||||
public open: boolean = false;
|
||||
@property(Number)
|
||||
public progress: number = 0;
|
||||
|
||||
private selected: boolean = false
|
||||
|
||||
@property(Laya.Sprite)
|
||||
public obj_selected: Laya.Sprite;
|
||||
|
||||
@property(Laya.Box)
|
||||
public obj_pie: Laya.Box;
|
||||
@property(Laya.Sprite)
|
||||
public sprite_pie: Laya.Sprite;
|
||||
|
||||
@property(Laya.Sprite)
|
||||
public obj_mask: Laya.Sprite;
|
||||
@property(Laya.Sprite)
|
||||
public sprite_mask: Laya.Sprite;
|
||||
|
||||
@property(Laya.Image)
|
||||
public obj_star: Laya.Image;
|
||||
|
||||
@property(Laya.Label)
|
||||
public label_show: Laya.Label;
|
||||
|
||||
|
||||
//组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
|
||||
onAwake(): void {
|
||||
|
||||
}
|
||||
|
||||
public onInit(day: number, open: boolean, progress: number, label_obj: Laya.Label, handler: any, func: any): void {
|
||||
this.day = day;
|
||||
this.open = open
|
||||
this.progress = progress
|
||||
this.label_show = label_obj
|
||||
if (open) {
|
||||
if (progress >= 1) {
|
||||
this.label_show.text = ""
|
||||
}
|
||||
else {
|
||||
this.label_show.text = this.day.toString()
|
||||
}
|
||||
this.label_show.color = "#2d3138"
|
||||
this.owner.on(Laya.Event.CLICK, handler, func)
|
||||
this.updateUnit()
|
||||
}
|
||||
else {
|
||||
this.label_show.text = this.day.toString()
|
||||
this.label_show.color = "#d3d5db"
|
||||
this.owner.on(Laya.Event.CLICK, this, (evt: Laya.Event)=>{
|
||||
|
||||
})
|
||||
this.obj_selected.visible = false
|
||||
this.obj_pie.visible = false
|
||||
this.obj_mask.visible = false
|
||||
this.obj_star.visible = false
|
||||
}
|
||||
}
|
||||
|
||||
public setSelected(selected: boolean): void {
|
||||
this.selected = selected
|
||||
this.updateUnit()
|
||||
}
|
||||
|
||||
updateUnit(): void {
|
||||
if (this.open == false) {
|
||||
return
|
||||
}
|
||||
|
||||
this.obj_star.visible = this.progress >= 1
|
||||
|
||||
if (this.selected) {
|
||||
this.label_show.color = "#ffffff"
|
||||
this.obj_selected.visible = true
|
||||
if (this.progress > 0) {
|
||||
this.obj_pie.visible = true
|
||||
this.obj_mask.visible = true
|
||||
this.sprite_pie.graphics.clear()
|
||||
this.sprite_pie.graphics.drawPie(48, 48, 48, 0, 360*this.progress, "#ffffff")
|
||||
this.sprite_mask.graphics.clear()
|
||||
this.sprite_mask.graphics.drawCircle(0.5, 0.5, 0.5, "#1d5cdc")
|
||||
}
|
||||
else {
|
||||
this.obj_pie.visible = false
|
||||
this.obj_mask.visible = false
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.label_show.color = "#2d3138"
|
||||
this.obj_selected.visible = false
|
||||
if (this.progress > 0 && this.progress < 1) {
|
||||
this.obj_pie.visible = true
|
||||
this.obj_mask.visible = true
|
||||
this.sprite_pie.graphics.clear()
|
||||
this.sprite_pie.graphics.drawPie(48, 48, 48, 0, 360*this.progress, "#2d3138")
|
||||
this.sprite_mask.graphics.clear()
|
||||
this.sprite_mask.graphics.drawCircle(0.5, 0.5, 0.5, "#ffffff")
|
||||
}
|
||||
else {
|
||||
this.obj_pie.visible = false
|
||||
this.obj_mask.visible = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
3
src/views/CalendarUnit.ts.meta
Normal file
3
src/views/CalendarUnit.ts.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"uuid": "04c54914-715e-4e07-8a45-770f2a2c05a6"
|
||||
}
|
||||
161
src/views/DailyChallenge.ts
Normal file
161
src/views/DailyChallenge.ts
Normal file
@@ -0,0 +1,161 @@
|
||||
import { config } from "../constants/config";
|
||||
import { Utility_ConvertSecondToString } from "../utils/utility";
|
||||
import { StorageManager } from "../models/StorageManager";
|
||||
import { CalendarUnit } from "./CalendarUnit";
|
||||
import { LevelManager } from "../models/LevelManager";
|
||||
import { UIManager } from "../models/UIManager";
|
||||
|
||||
const { regClass, property } = Laya;
|
||||
|
||||
@regClass()
|
||||
export class DailyChallenge extends Laya.Script {
|
||||
declare owner : Laya.Box;
|
||||
|
||||
@property(Laya.Button)
|
||||
public btn_back: Laya.Button
|
||||
|
||||
@property(Laya.Label)
|
||||
public label_year: Laya.Label;
|
||||
@property(Laya.Label)
|
||||
public label_month: Laya.Label;
|
||||
@property(Laya.Label)
|
||||
public label_star: Laya.Label;
|
||||
|
||||
@property(Laya.Box)
|
||||
public btn_play: Laya.Box
|
||||
@property(Laya.Label)
|
||||
public label_play: Laya.Label
|
||||
@property(Laya.Box)
|
||||
public obj_summary: Laya.Box
|
||||
@property(Laya.Label)
|
||||
public label_date: Laya.Label;
|
||||
@property(Laya.Label)
|
||||
public label_diffucuty: Laya.Label
|
||||
@property(Laya.Label)
|
||||
public label_score: Laya.Label
|
||||
@property(Laya.Label)
|
||||
public label_time: Laya.Label
|
||||
|
||||
@property(Laya.Box)
|
||||
public obj_items: Laya.Box;
|
||||
@property(Laya.Box)
|
||||
public obj_labels: Laya.Box;
|
||||
private units: Array<CalendarUnit> = new Array();
|
||||
private selectedUnit: CalendarUnit;
|
||||
|
||||
//组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
|
||||
onAwake(): void {
|
||||
this.btn_back.on(Laya.Event.CLICK, this, ()=>{
|
||||
UIManager.getInstance().loadHomeUI()
|
||||
this.owner.destroy()
|
||||
})
|
||||
|
||||
var now = new Date()
|
||||
var year = now.getFullYear()
|
||||
var month = now.getMonth() + 1
|
||||
var dayNow = new Date().getDate()
|
||||
var stageID = `${year}-${month}-${day}`
|
||||
|
||||
this.label_year.text = year.toString()
|
||||
this.label_month.text = config.MONTH_ABBRS[month-1]
|
||||
var starCount = 0
|
||||
var day = 1
|
||||
var dayCount = 31
|
||||
var begin = 4
|
||||
var index = -1
|
||||
for (var i=0; i<this.obj_items.numChildren; i++) {
|
||||
var hbox = this.obj_items.getChildAt(i)
|
||||
var l_hbox = this.obj_labels.getChildAt(i)
|
||||
for (var j=0; j<hbox.numChildren; j++) {
|
||||
var obj = hbox.getChildAt(j) as Laya.Box
|
||||
var l_obj = l_hbox.getChildAt(j) as Laya.Label
|
||||
index ++
|
||||
if (index >= begin && index < begin+dayCount) {
|
||||
obj.visible = true
|
||||
l_obj.visible = true
|
||||
var unit = obj.getComponent(CalendarUnit)
|
||||
this.units.push(unit)
|
||||
var stageID = `${year}-${month}-${day}`
|
||||
var progress = StorageManager.getInstance().getUser().get_done(stageID)
|
||||
unit.onInit(day, day<=dayNow, progress, l_obj, this, this.onClickUnit)
|
||||
if (day == dayNow) {
|
||||
this.selectedUnit = unit
|
||||
}
|
||||
if (progress >= 1) {
|
||||
starCount ++
|
||||
}
|
||||
day ++
|
||||
}
|
||||
else {
|
||||
obj.visible = false
|
||||
l_obj.visible = false
|
||||
}
|
||||
}
|
||||
}
|
||||
this.label_star.text = `${starCount}/${dayCount}`
|
||||
|
||||
this.onApplyUnit(this.selectedUnit)
|
||||
|
||||
this.btn_play.on(Laya.Event.CLICK, this, (evt: Laya.Event)=>{
|
||||
// console.log(">>>>>>>>>>>>>>>>>>>>>>>", this.selectedUnit.day)
|
||||
var now = new Date()
|
||||
var year = now.getFullYear()
|
||||
var month = now.getMonth() + 1
|
||||
var dayNow = this.selectedUnit.day
|
||||
var stageID = `${year}-${month}-${dayNow}`
|
||||
var doStage = StorageManager.getInstance().loadStage(stageID)
|
||||
console.log("play >>>>>>>>>>>>>>>>>>>>>>>", stageID, doStage)
|
||||
if (!doStage) {
|
||||
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()
|
||||
})
|
||||
}
|
||||
|
||||
public onApplyUnit(unit: CalendarUnit): void {
|
||||
this.selectedUnit.setSelected(false)
|
||||
this.selectedUnit = unit
|
||||
this.selectedUnit.setSelected(true)
|
||||
|
||||
var now = new Date()
|
||||
var year = now.getFullYear()
|
||||
var month = now.getMonth() + 1
|
||||
var dayNow = unit.day
|
||||
var stageID = `${year}-${month}-${dayNow}`
|
||||
this.label_date.text = `${config.MONTH_ABBRS[month-1]} ${dayNow},${year}`
|
||||
var user = StorageManager.getInstance().getUser()
|
||||
var progress = user.get_done(stageID)
|
||||
// console.log("onApplyUnit >>>>>", stageID, progress)
|
||||
if (progress >= 1) {
|
||||
this.btn_play.visible = false
|
||||
this.obj_summary.visible = true
|
||||
var doStage = StorageManager.getInstance().loadStage(stageID)
|
||||
this.label_diffucuty.text = doStage.get_difficulty()
|
||||
this.label_score.text = doStage.get_score().toString()
|
||||
this.label_time.text = Utility_ConvertSecondToString(doStage.get_duration())
|
||||
}
|
||||
else {
|
||||
this.btn_play.visible = true
|
||||
this.obj_summary.visible = false
|
||||
var doStage = StorageManager.getInstance().loadStage(stageID)
|
||||
if (doStage) {
|
||||
this.label_play.text = "Continue"
|
||||
}
|
||||
else {
|
||||
this.label_play.text = "Play"
|
||||
}
|
||||
}
|
||||
}
|
||||
public onClickUnit(evt: Laya.Event): void {
|
||||
var unit = evt.target.getComponent(CalendarUnit)
|
||||
this.onApplyUnit(unit)
|
||||
}
|
||||
}
|
||||
3
src/views/DailyChallenge.ts.meta
Normal file
3
src/views/DailyChallenge.ts.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"uuid": "3f68d98d-3867-41a7-b277-a24d279a22fa"
|
||||
}
|
||||
@@ -30,18 +30,12 @@ export class Difficulty extends Laya.Script {
|
||||
}
|
||||
|
||||
public onInit(callback: any): void {
|
||||
var list: Array<string> = new Array()
|
||||
list.push(config.DIFFICULTY_TYPE.Easy)
|
||||
list.push(config.DIFFICULTY_TYPE.Medium)
|
||||
list.push(config.DIFFICULTY_TYPE.Hard)
|
||||
list.push(config.DIFFICULTY_TYPE.Expert)
|
||||
list.push(config.DIFFICULTY_TYPE.Extreme)
|
||||
for (var i=0; i<list.length; i++) {
|
||||
for (var i=0; i<config.DIFFICULTY_LIST.length; i++) {
|
||||
var obj = this.obj_items.getChildAt(i)
|
||||
var Label = obj.getChildByName("Label") as Laya.Label
|
||||
Label.text = list[i]
|
||||
Label.text = config.DIFFICULTY_LIST[i]
|
||||
var data = obj.getComponent(CommonData)
|
||||
data.strValue = list[i]
|
||||
data.strValue = config.DIFFICULTY_LIST[i]
|
||||
obj.on(Laya.Event.CLICK, this, (evt: Laya.Event)=>{
|
||||
var data = evt.target.getComponent(CommonData)
|
||||
if (callback) {
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
import { UIManager } from "../models/UIManager";
|
||||
import { StorageManager } from "../models/StorageManager";
|
||||
import { Utility_ConvertSecondToString } from "../utils/utility";
|
||||
import { respath } from "../constants/respath";
|
||||
import { Difficulty } from "./Difficulty";
|
||||
import { LevelManager } from "../models/LevelManager";
|
||||
import { config } from "../constants/config";
|
||||
|
||||
const { regClass, property } = Laya;
|
||||
|
||||
@@ -7,15 +12,80 @@ const { regClass, property } = Laya;
|
||||
export class GameDone extends Laya.Script {
|
||||
declare owner : Laya.Box;
|
||||
|
||||
@property(Laya.Button)
|
||||
public btn_new: Laya.Button
|
||||
@property(Laya.Box)
|
||||
public obj_top: Laya.Box
|
||||
@property(Laya.Box)
|
||||
public obj_stars: Laya.Box
|
||||
@property(Laya.Image)
|
||||
public obj_star: Laya.Image
|
||||
|
||||
@property(Laya.Label)
|
||||
public label_diffucuty: Laya.Label
|
||||
@property(Laya.Label)
|
||||
public label_time: Laya.Label
|
||||
@property(Laya.Label)
|
||||
public label_score: Laya.Label
|
||||
|
||||
@property(Laya.Box)
|
||||
public btn_new: Laya.Box
|
||||
@property(Laya.Box)
|
||||
public btn_home: Laya.Box
|
||||
@property(Laya.Box)
|
||||
public btn_continue: Laya.Box
|
||||
|
||||
|
||||
onStart(): void {
|
||||
var doStage = StorageManager.getInstance().getStage()
|
||||
var type = doStage.get_stageType()
|
||||
if (type == config.STAGE_TYPE.MAIN) {
|
||||
this.obj_top.y = 356
|
||||
this.obj_stars.visible = true
|
||||
this.obj_star.visible = false
|
||||
this.btn_new.visible = true
|
||||
this.btn_home.visible = true
|
||||
this.btn_continue.visible = false
|
||||
}
|
||||
else {
|
||||
this.obj_top.y = 456
|
||||
this.obj_stars.visible = false
|
||||
this.obj_star.visible = true
|
||||
this.btn_new.visible = false
|
||||
this.btn_home.visible = false
|
||||
this.btn_continue.visible = true
|
||||
}
|
||||
this.label_diffucuty.text = doStage.get_difficulty()
|
||||
this.label_time.text = Utility_ConvertSecondToString(doStage.get_duration())
|
||||
this.label_score.text = doStage.get_score().toString()
|
||||
|
||||
//组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
|
||||
onAwake(): void {
|
||||
this.btn_new.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
|
||||
UIManager.getInstance().closeStage();
|
||||
UIManager.getInstance().loadHome();
|
||||
StorageManager.getInstance().cleanStage()
|
||||
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()
|
||||
var user = StorageManager.getInstance().getUser()
|
||||
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()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
this.btn_home.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
|
||||
UIManager.getInstance().loadHomeUI()
|
||||
UIManager.getInstance().closeStageUI();
|
||||
this.owner.destroy()
|
||||
})
|
||||
|
||||
this.btn_continue.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
|
||||
UIManager.getInstance().loadDCUI()
|
||||
UIManager.getInstance().closeStageUI();
|
||||
this.owner.destroy()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -20,49 +20,65 @@ export class GameOver extends Laya.Script {
|
||||
public btn_restart: Laya.Sprite
|
||||
|
||||
@property(Laya.Sprite)
|
||||
public btn_new: Laya.Sprite
|
||||
public btn_newOrClose: Laya.Sprite
|
||||
@property(Laya.Label)
|
||||
public label_newOrClose: Laya.Label
|
||||
|
||||
//组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
|
||||
onAwake(): void {
|
||||
|
||||
this.btn_second.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
|
||||
var doStage = StorageManager.getInstance().loadStage(config.DEFAULT_STAGE_ID)
|
||||
var doStage = StorageManager.getInstance().getStage()
|
||||
doStage.set_mistake(doStage.get_mistake()-1)
|
||||
EventManager.getInstance().DispatchEvent(EVENT_TYPES.NOT_UPDATE_MISTAKE, "adsf")
|
||||
EventManager.getInstance().DispatchEvent(EVENT_TYPES.NOT_UPDATE_MISTAKE)
|
||||
this.owner.destroy()
|
||||
})
|
||||
|
||||
this.btn_restart.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
|
||||
var doStage = StorageManager.getInstance().loadStage(config.DEFAULT_STAGE_ID)
|
||||
var doStage = StorageManager.getInstance().getStage()
|
||||
var stageID = doStage.get_stageID()
|
||||
var type = doStage.get_stageType()
|
||||
var difficulty = doStage.get_difficulty()
|
||||
StorageManager.getInstance().cleanStage(config.DEFAULT_STAGE_ID)
|
||||
StorageManager.getInstance().cleanStage()
|
||||
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);
|
||||
StorageManager.getInstance().newStage(stageID, type, difficulty, difficulty, user.get_progress(difficulty))
|
||||
UIManager.getInstance().loadStageUI(stageID);
|
||||
this.owner.destroy()
|
||||
})
|
||||
|
||||
this.btn_new.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
|
||||
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()
|
||||
var doStage = StorageManager.getInstance().getStage()
|
||||
var type = doStage.get_stageType()
|
||||
|
||||
if (type == config.STAGE_TYPE.MAIN) {
|
||||
this.label_newOrClose.text = "New Game"
|
||||
this.btn_newOrClose.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
|
||||
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()
|
||||
var user = StorageManager.getInstance().getUser()
|
||||
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()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
else {
|
||||
this.label_newOrClose.text = "Close"
|
||||
this.btn_newOrClose.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
|
||||
UIManager.getInstance().loadDCUI()
|
||||
UIManager.getInstance().closeStageUI();
|
||||
this.owner.destroy()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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) {//说明当前难度已经打通了,所以给他从头开始
|
||||
|
||||
@@ -22,7 +22,7 @@ export class Stage extends Laya.Script {
|
||||
@property(Laya.Label)
|
||||
public label_mistake: Laya.Label;
|
||||
@property(Laya.Label)
|
||||
public label_diff: Laya.Label;
|
||||
public label_name: Laya.Label;
|
||||
@property(Laya.Label)
|
||||
public label_time: Laya.Label;
|
||||
|
||||
@@ -59,8 +59,14 @@ export class Stage extends Laya.Script {
|
||||
onAwake(): void {
|
||||
Stage._instance = this
|
||||
this.btn_back.on(Laya.Event.CLICK, this, ()=>{
|
||||
UIManager.getInstance().loadHomeUI();
|
||||
UIManager.getInstance().closeStageUI();
|
||||
if (this.data.get_stageType() == config.STAGE_TYPE.MAIN) {
|
||||
UIManager.getInstance().loadHomeUI();
|
||||
UIManager.getInstance().closeStageUI();
|
||||
}
|
||||
else {
|
||||
UIManager.getInstance().loadDCUI();
|
||||
UIManager.getInstance().closeStageUI();
|
||||
}
|
||||
})
|
||||
for (var i=0; i<this.obj_blocks.numChildren; i++) {
|
||||
var hbox = this.obj_blocks.getChildAt(i);
|
||||
@@ -116,7 +122,7 @@ export class Stage extends Laya.Script {
|
||||
this.data = doStage
|
||||
|
||||
this.onUpdateScore()
|
||||
this.label_diff.text = this.data.get_difficulty()
|
||||
this.label_name.text = this.data.get_stageName()
|
||||
this.onUpdateMistake()
|
||||
var begin = Date.now()
|
||||
Laya.timer.loop(1000, this, ()=>{
|
||||
@@ -143,13 +149,14 @@ export class Stage extends Laya.Script {
|
||||
this.onApplyBlock(this.selectedBlock)
|
||||
}
|
||||
|
||||
onUpdateScore(): void {
|
||||
onUpdateScore(): number {
|
||||
var score = 0
|
||||
var blocks = this.data.get_blocks()
|
||||
for (var i=0; i<blocks.length; i++) {
|
||||
score += blocks[i].get_score()
|
||||
}
|
||||
this.label_score.text = `Score: ${score}`
|
||||
return score
|
||||
}
|
||||
|
||||
onUpdateMistake(): void {
|
||||
@@ -341,20 +348,28 @@ export class Stage extends Laya.Script {
|
||||
}
|
||||
else {
|
||||
var b = this.selectedBlock.setShowNumber(showNumber)
|
||||
this.onUpdateScore()
|
||||
var score = this.onUpdateScore()
|
||||
this.onSetBlock(this.selectedBlock, true)
|
||||
if (b) {
|
||||
var user = StorageManager.getInstance().getUser()
|
||||
var all = 0
|
||||
var finished = 0
|
||||
var blocks = this.data.get_blocks()
|
||||
for (var i=0; i<blocks.length; i++) {
|
||||
if (blocks[i].get_preset() == false) {
|
||||
all ++
|
||||
if (blocks[i].get_checked()) {
|
||||
finished ++
|
||||
}
|
||||
}
|
||||
}
|
||||
user.update_stage_done(this.data.get_stageID(), finished/all)//更新关卡完成进度
|
||||
if (this.getIsComplete()) {
|
||||
console.log("完成关卡")
|
||||
StorageManager.getInstance().cleanStage(this.data.get_stageID())//完成关卡清除关卡数据
|
||||
var user = StorageManager.getInstance().getUser()
|
||||
if (this.data.get_stageType() == config.STAGE_TYPE.MAIN) {
|
||||
user.set_isCompletedMain(true)
|
||||
this.data.set_score(score)
|
||||
if (this.data.get_stageType() == config.STAGE_TYPE.MAIN) {//主线关卡更新难度进度
|
||||
user.update_progress(this.data.get_difficulty(), this.data.get_stageIndex()+1)
|
||||
}
|
||||
else if (this.data.get_stageType() == config.STAGE_TYPE.DC) {
|
||||
user.add_done(this.data.get_stageID())
|
||||
}
|
||||
UIManager.getInstance().loadGameDoneUI()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user