格式化代码

This commit is contained in:
2025-05-28 18:47:51 +08:00
parent 6d44fc21b4
commit a7df8ec739
38 changed files with 2768 additions and 2840 deletions

View File

@@ -1,205 +1,200 @@
import { G_ShowScoreTips } from "../views/common/GUITips";
import { DOBlock } from "../models/DOBlock";
import { config } from "../constants/config";
import type { DOBlock } from "../models/DOBlock"
import { config } from "../constants/config"
import { G_ShowScoreTips } from "../views/common/GUITips"
const { regClass, property } = Laya;
const { regClass, property } = Laya
@regClass()
export class Block extends Laya.Script {
declare owner : Laya.Sprite;
declare owner: Laya.Sprite
@property(Number)
public XIndex: number = 0;
@property(Number)
public YIndex: number = 0;
@property(Number)
public XGroup: number = 0;
@property(Number)
public YGroup: number = 0;
@property(Number)
public XIndex: number = 0
private tips_bgs: Array<Laya.Sprite> = new Array();
private label_show: Laya.Label;
private tips_labels: Array<Laya.Label> = new Array();
private selected: boolean = false
@property(Number)
public YIndex: number = 0
private data: DOBlock
@property(Number)
public XGroup: number = 0
@property(Number)
public YGroup: number = 0
public onInit(XIndex: number, YIndex: number, XGroup: number, YGroup: number, label_obj: Laya.Box, handler: any, func: any): void {
this.XIndex = XIndex;
this.YIndex = YIndex;
this.XGroup = XGroup;
this.YGroup = YGroup;
private tips_bgs: Array<Laya.Sprite> = []
private label_show: Laya.Label
private tips_labels: Array<Laya.Label> = []
var VBox = this.owner.getChildByName("VBox")
for (var i=0; i<VBox.numChildren; i++) {
var hbox = VBox.getChildAt(i)
for (var j=0; j<hbox.numChildren; j++) {
var sp = hbox.getChildAt(j) as Laya.Sprite
this.tips_bgs.push(sp)
}
}
this.label_show = label_obj.getChildByName("label_show") as Laya.Label
// this.label_show.text = XGroup + "" + YGroup
VBox = label_obj.getChildByName("VBox")
for (var i=0; i<VBox.numChildren; i++) {
var hbox = VBox.getChildAt(i);
for (var j=0; j<hbox.numChildren; j++) {
var Label = hbox.getChildAt(j) as Laya.Label
Label.text = ""
this.tips_labels.push(Label)
}
}
this.owner.on(Laya.Event.CLICK, handler, func);
private selected: boolean = false
private data: DOBlock
public onInit(XIndex: number, YIndex: number, XGroup: number, YGroup: number, label_obj: Laya.Box, handler: any, func: any): void {
this.XIndex = XIndex
this.YIndex = YIndex
this.XGroup = XGroup
this.YGroup = YGroup
let VBox = this.owner.getChildByName("VBox")
for (var i = 0; i < VBox.numChildren; i++) {
var hbox = VBox.getChildAt(i)
for (var j = 0; j < hbox.numChildren; j++) {
const sp = hbox.getChildAt(j) as Laya.Sprite
this.tips_bgs.push(sp)
}
}
public setSelected(selected: boolean): void {
this.selected = selected
this.updateBlock()
this.label_show = label_obj.getChildByName("label_show") as Laya.Label
// this.label_show.text = XGroup + "" + YGroup
VBox = label_obj.getChildByName("VBox")
for (var i = 0; i < VBox.numChildren; i++) {
var hbox = VBox.getChildAt(i)
for (var j = 0; j < hbox.numChildren; j++) {
const Label = hbox.getChildAt(j) as Laya.Label
Label.text = ""
this.tips_labels.push(Label)
}
}
this.owner.on(Laya.Event.CLICK, handler, func)
}
public setBlockColor(color: string, alpha: number=1, animated: boolean=false, completedColor: string = "", completedAlpha: number=1): void {
var blockSize = 116
if (config.H_SCREEN)
blockSize = 96
public setSelected(selected: boolean): void {
this.selected = selected
this.updateBlock()
}
public setBlockColor(color: string, alpha: number = 1, animated: boolean = false, completedColor: string = "", completedAlpha: number = 1): void {
let blockSize = 116
if (config.H_SCREEN)
blockSize = 96
this.owner.graphics.clear()
this.owner.graphics.drawRect(0, 0, blockSize, blockSize, color)
if (animated) {
this.owner.alpha = 0
Laya.Tween.to(this.owner, { alpha }, 100, Laya.Ease.linearIn)
Laya.Tween.to(this.owner, { alpha: 0 }, 150, Laya.Ease.linearIn, null, 100)
Laya.Tween.to(this.owner, { alpha }, 100, Laya.Ease.linearIn, Laya.Handler.create(this, () => {
this.owner.graphics.clear()
this.owner.graphics.drawRect(0, 0, blockSize, blockSize, color)
if (animated) {
this.owner.alpha = 0
Laya.Tween.to(this.owner, {alpha:alpha}, 100, Laya.Ease.linearIn)
Laya.Tween.to(this.owner, {alpha:0}, 150, Laya.Ease.linearIn, null, 100)
Laya.Tween.to(this.owner, {alpha:alpha}, 100, Laya.Ease.linearIn, Laya.Handler.create(this, () => {
this.owner.graphics.clear()
this.owner.graphics.drawRect(0, 0, blockSize, blockSize, completedColor)
this.owner.alpha = completedAlpha
}), 250)
}
else {
this.owner.alpha = alpha
}
this.owner.graphics.drawRect(0, 0, blockSize, blockSize, completedColor)
this.owner.alpha = completedAlpha
}), 250)
} else {
this.owner.alpha = alpha
}
}
public setFadeAnimation(): void {
Laya.timer.once(200, this, ()=>{
this.label_show.color = "#ff0000"
Laya.timer.once(100, this, ()=>{
this.label_show.color = "#2d3138"
Laya.timer.once(200, this, ()=>{
this.label_show.color = "#ff0000"
Laya.timer.once(100, this, ()=>{
this.updateBlock()
})
})
})
public setFadeAnimation(): void {
Laya.timer.once(200, this, () => {
this.label_show.color = "#ff0000"
Laya.timer.once(100, this, () => {
this.label_show.color = "#2d3138"
Laya.timer.once(200, this, () => {
this.label_show.color = "#ff0000"
Laya.timer.once(100, this, () => {
this.updateBlock()
})
})
})
})
}
public setTipsBgColor(visible: boolean, noteNumber: number = 0, color: string = "", alpha: number = 1): void {
let blockSize = 38
if (config.H_SCREEN)
blockSize = 30
if (visible) {
var obj = this.tips_bgs[noteNumber - 1]
obj.visible = true
obj.graphics.clear()
obj.graphics.drawRect(0, 0, blockSize, blockSize, color)
obj.alpha = alpha
} else {
for (let i = 0; i < this.tips_bgs.length; i++) {
var obj = this.tips_bgs[i]
obj.visible = false
}
}
}
public setBlock(data: DOBlock): void {
this.data = data
this.updateBlock()
}
public getData(): DOBlock {
return this.data
}
public setShowNumber(showNumber: number, score: number): boolean {
this.data.set_show(showNumber)
if (this.data.get_checked()) {
this.data.set_score(score)
if (score > 0)
G_ShowScoreTips(score.toString(), this.label_show.parent)
} else {
if (this.data.get_score() != 0)
this.data.set_score(0)
}
this.data.clean_notes()
this.updateBlock()
return this.data.get_checked()
}
public addNoteNumber(noteNumber: number): void {
this.data.set_show(0)
const note_numbers = this.data.get_notes()
const find = note_numbers.indexOf(noteNumber)
if (find >= 0) {
this.data.remove_note(noteNumber)
} else {
this.data.add_note(noteNumber)
}
this.updateBlock()
}
public setNotes(notes: Array<number>): void {
this.data.set_show(0)
this.data.clean_notes()
for (let i = 0; i < notes.length; i++) {
this.data.add_note(notes[i])
}
this.updateBlock()
}
updateBlock(): void {
// 设置文字颜色
if (this.selected) {
this.label_show.color = "#ffffff"
for (var i = 0; i < this.tips_labels.length; i++) {
this.tips_labels[i].color = "#ffffff"
}
} else {
if (this.data.get_show() == this.data.get_correct()) {
if (this.data.get_preset()) {
this.label_show.color = "#2d3138"
} else {
this.label_show.color = "#2559c0"
}
} else {
this.label_show.color = "#cb3256"
}
for (var i = 0; i < this.tips_labels.length; i++) {
this.tips_labels[i].color = "#2d3138"
}
}
public setTipsBgColor(visible: boolean, noteNumber: number=0, color: string="", alpha: number=1): void {
var blockSize = 38
if (config.H_SCREEN)
blockSize = 30
if (visible) {
var obj = this.tips_bgs[noteNumber-1]
obj.visible = true
obj.graphics.clear()
obj.graphics.drawRect(0, 0, blockSize, blockSize, color)
obj.alpha = alpha
}
else {
for (var i=0; i<this.tips_bgs.length; i++) {
var obj = this.tips_bgs[i]
obj.visible = false
}
}
for (var i = 0; i < this.tips_labels.length; i++) {
this.tips_labels[i].text = ""
}
public setBlock(data: DOBlock): void {
this.data = data;
this.updateBlock();
if (this.data.get_show() > 0) {
this.label_show.text = this.data.get_show().toString()
} else {
this.label_show.text = ""
const note_numbers = this.data.get_notes()
for (var i = 0; i < note_numbers.length; i++) {
const value = note_numbers[i]
const label = this.tips_labels[value - 1]
label.text = value.toString()
}
}
public getData(): DOBlock {
return this.data
}
public setShowNumber(showNumber: number, score: number): boolean {
this.data.set_show(showNumber)
if (this.data.get_checked()) {
this.data.set_score(score)
if (score > 0)
G_ShowScoreTips(score.toString(), this.label_show.parent)
}
else {
if (this.data.get_score() != 0)
this.data.set_score(0)
}
this.data.clean_notes()
this.updateBlock()
return this.data.get_checked()
}
public addNoteNumber(noteNumber: number): void {
this.data.set_show(0)
var note_numbers = this.data.get_notes()
var find = note_numbers.indexOf(noteNumber)
if (find >= 0) {
this.data.remove_note(noteNumber)
}
else {
this.data.add_note(noteNumber)
}
this.updateBlock()
}
public setNotes(notes: Array<number>): void {
this.data.set_show(0)
this.data.clean_notes()
for (var i=0; i<notes.length; i++) {
this.data.add_note(notes[i])
}
this.updateBlock()
}
updateBlock(): void {
//设置文字颜色
if (this.selected) {
this.label_show.color = "#ffffff"
for (var i=0; i<this.tips_labels.length; i++) {
this.tips_labels[i].color = "#ffffff"
}
}
else {
if (this.data.get_show() == this.data.get_correct()) {
if (this.data.get_preset()) {
this.label_show.color = "#2d3138"
}
else {
this.label_show.color = "#2559c0"
}
}
else {
this.label_show.color = "#cb3256"
}
for (var i=0; i<this.tips_labels.length; i++) {
this.tips_labels[i].color = "#2d3138"
}
}
for (var i=0; i<this.tips_labels.length; i++) {
this.tips_labels[i].text = ""
}
if (this.data.get_show() > 0) {
this.label_show.text = this.data.get_show().toString()
}
else {
this.label_show.text = "";
var note_numbers = this.data.get_notes()
for (var i=0; i<note_numbers.length; i++) {
var value = note_numbers[i]
var label = this.tips_labels[value-1]
label.text = value.toString()
}
}
}
}
}
}

View File

@@ -1,62 +1,57 @@
const { regClass, property } = Laya;
const { regClass, property } = Laya
@regClass()
export class Candy extends Laya.Script {
declare owner : Laya.Box;
declare owner: Laya.Box
private show_sprite: Laya.Sprite
private label_show: Laya.Label;
private label_left: Laya.Label;
private show_sprite: Laya.Sprite
private label_show: Laya.Label
private label_left: Laya.Label
private show: number
private left: number
private show: number
private left: number
public onInit(label_obj: Laya.Box, handler: any, func: any): void {
this.owner.on(Laya.Event.CLICK, handler, func)
this.show_sprite = this.owner.getChildByName("Sprite") as Laya.Sprite
this.label_show = label_obj.getChildByName("label") as Laya.Label
this.label_left = label_obj.getChildByName("label_left") as Laya.Label
public onInit(label_obj: Laya.Box, handler: any, func: any): void {
this.owner.on(Laya.Event.CLICK, handler, func)
this.show_sprite = this.owner.getChildByName("Sprite") as Laya.Sprite
this.label_show = label_obj.getChildByName("label") as Laya.Label
this.label_left = label_obj.getChildByName("label_left") as Laya.Label
}
public setNoteStatus(note_open: boolean) {
if (note_open) {
this.show_sprite.visible = false
this.label_show.color = "#7b818c"
} else {
this.show_sprite.visible = true
this.label_show.color = "#2559c0"
}
}
public setCandy(show: number, left: number): void {
this.show = show
this.left = left
this.updateCandy()
}
public get_show(): number {
return this.show
}
updateCandy(): void {
if (this.show > 0) {
this.label_show.text = this.show.toString()
} else {
this.label_show.text = ""
}
public setNoteStatus(note_open: boolean) {
if (note_open) {
this.show_sprite.visible = false
this.label_show.color = "#7b818c"
}
else {
this.show_sprite.visible = true
this.label_show.color = "#2559c0"
}
if (this.left > 0) {
this.label_left.text = this.left.toString()
this.owner.visible = true
} else {
this.label_left.text = ""
this.owner.visible = false
this.label_show.text = ""
}
public setCandy(show: number, left: number): void {
this.show = show
this.left = left
this.updateCandy()
}
public get_show(): number {
return this.show
}
updateCandy(): void {
if (this.show > 0) {
this.label_show.text = this.show.toString()
}
else {
this.label_show.text = ""
}
if (this.left > 0) {
this.label_left.text = this.left.toString();
this.owner.visible = true
}
else {
this.label_left.text = ""
this.owner.visible = false
this.label_show.text = ""
}
}
}
}
}

View File

@@ -1,59 +1,61 @@
import { respath } from "../constants/respath";
import { UIManager } from "../models/UIManager";
const { regClass, property } = Laya;
import { respath } from "../constants/respath"
import { UIManager } from "../models/UIManager"
const { regClass, property } = Laya
export function G_ShowCommonTips(title: string, content: string, showToggle: boolean, func: any): void {
Laya.loader.load(respath.common_tips_ui_res).then((go)=>{
var prefab = go.create()
var obj = UIManager.getInstance().getUIRoot().addChild(prefab).getComponent(CommonTips)
obj.showCommonTips(title, content, showToggle, func)
})
Laya.loader.load(respath.common_tips_ui_res).then((go) => {
const prefab = go.create()
const obj = UIManager.getInstance().getUIRoot().addChild(prefab).getComponent(CommonTips)
obj.showCommonTips(title, content, showToggle, func)
})
}
@regClass()
export class CommonTips extends Laya.Script {
declare owner : Laya.Box;
declare owner: Laya.Box
@property(Laya.Label)
public label_title: Laya.Label
@property(Laya.Label)
public label_content: Laya.Label
@property(Laya.Label)
public label_title: Laya.Label
@property(Laya.Box)
public btn_ok: Laya.Box
@property(Laya.Box)
public btn_cancel: Laya.Box
@property(Laya.Label)
public label_content: Laya.Label
@property(Laya.Box)
public toggle: Laya.Box
@property(Laya.Image)
public check: Laya.Image
private isChecked = false
@property(Laya.Box)
public btn_ok: Laya.Box
public showCommonTips(title: string, content: string, showToggle: boolean, func: any): void {
this.label_title.text = title
this.label_content.text = content
this.toggle.visible = showToggle
this.check.visible = false
this.toggle.on(Laya.Event.CLICK, this, ()=>{
this.isChecked = !this.isChecked
this.check.visible = this.isChecked
})
@property(Laya.Box)
public btn_cancel: Laya.Box
this.btn_ok.on(Laya.Event.CLICK, this, ()=>{
if (func) {
func(true, this.isChecked)
}
this.owner.destroy()
})
this.btn_cancel.on(Laya.Event.CLICK, this, ()=>{
if (func) {
func(false, this.isChecked)
}
this.owner.destroy()
})
@property(Laya.Box)
public toggle: Laya.Box
}
}
@property(Laya.Image)
public check: Laya.Image
private isChecked = false
public showCommonTips(title: string, content: string, showToggle: boolean, func: any): void {
this.label_title.text = title
this.label_content.text = content
this.toggle.visible = showToggle
this.check.visible = false
this.toggle.on(Laya.Event.CLICK, this, () => {
this.isChecked = !this.isChecked
this.check.visible = this.isChecked
})
this.btn_ok.on(Laya.Event.CLICK, this, () => {
if (func) {
func(true, this.isChecked)
}
this.owner.destroy()
})
this.btn_cancel.on(Laya.Event.CLICK, this, () => {
if (func) {
func(false, this.isChecked)
}
this.owner.destroy()
})
}
}

View File

@@ -1,48 +1,46 @@
import { config } from "../constants/config";
import { CommonData } from "./common/CommonData";
import { config } from "../constants/config"
import { CommonData } from "./common/CommonData"
const { regClass, property } = Laya;
const { regClass, property } = Laya
@regClass()
export class Difficulty extends Laya.Script {
declare owner : Laya.Box;
declare owner: Laya.Box
@property(Laya.Box)
public obj_items: Laya.Box
@property(Laya.Box)
public obj_items: Laya.Box;
// 组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
onAwake(): void {
const offset = this.owner.getChildByName("offset") as Laya.Box
const bg = offset.getChildByName("bg") as Laya.Sprite
bg.graphics.clear()
bg.graphics.drawRoundRect(0, 0, offset.width, offset.height, 20, 20, 0, 0, "#f5f7fb")
Laya.Tween.to(offset, { y: 705 }, 500)
//组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
onAwake(): void {
var offset = this.owner.getChildByName("offset") as Laya.Box
var bg = offset.getChildByName("bg") as Laya.Sprite
bg.graphics.clear()
bg.graphics.drawRoundRect(0, 0, offset.width, offset.height, 20, 20, 0, 0, "#f5f7fb")
const mask = this.owner.getChildByName("mask")
mask.on(Laya.Event.CLICK, this, () => {
Laya.Tween.to(offset, { y: 2400 }, 500, null, Laya.Handler.create(this, () => {
this.owner.destroy()
}))
})
}
Laya.Tween.to(offset, {y: 705}, 500)
var mask = this.owner.getChildByName("mask")
mask.on(Laya.Event.CLICK, this, ()=>{
Laya.Tween.to(offset, {y: 2400}, 500, null, Laya.Handler.create(this, () => {
this.owner.destroy()
}))
})
}
public onInit(callback: any): void {
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 = config.DIFFICULTY_LIST[i]
var data = obj.getComponent(CommonData)
data.strValue = config.DIFFICULTY_LIST[i]
obj.on(Laya.Event.CLICK, this, (evt: Laya.Event)=>{
var data = evt.target.getComponent(CommonData)
if (callback) {
callback(data.strValue)
}
this.owner.destroy()
})
public onInit(callback: any): void {
for (let i = 0; i < config.DIFFICULTY_LIST.length; i++) {
const obj = this.obj_items.getChildAt(i)
const Label = obj.getChildByName("Label") as Laya.Label
Label.text = config.DIFFICULTY_LIST[i]
const data = obj.getComponent(CommonData)
data.strValue = config.DIFFICULTY_LIST[i]
obj.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
const data = evt.target.getComponent(CommonData)
if (callback) {
callback(data.strValue)
}
this.owner.destroy()
})
}
}
}
}

View File

@@ -1,88 +1,87 @@
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 { config } from "../constants/config";
import { DOStage } from "../models/DOStage";
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"
const { regClass, property } = Laya;
const { regClass, property } = Laya
@regClass()
export class GameDone extends Laya.Script {
declare owner : Laya.Box;
declare owner: Laya.Box
@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.Label)
public label_diffucuty: 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
@property(Laya.Label)
public label_time: Laya.Label
@property(Laya.Label)
public label_score: Laya.Label
onStart(): void {
@property(Laya.Box)
public btn_new: Laya.Box
}
@property(Laya.Box)
public btn_home: Laya.Box
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()
@property(Laya.Box)
public btn_continue: Laya.Box
this.btn_new.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
if (config.H_SCREEN) {
var 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);
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()
this.btn_new.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
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)
this.owner.destroy()
}
else {
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().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, value, value)
UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID);
this.owner.destroy()
})
})
}
})
})
}
})
this.btn_continue.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {//这个按钮只有从DC来的会显示
UIManager.getInstance().loadDCUI()
UIManager.getInstance().closeStageUI();
this.owner.destroy()
})
this.btn_continue.on(Laya.Event.CLICK, this, (evt: Laya.Event) => { // 这个按钮只有从DC来的会显示
UIManager.getInstance().loadDCUI()
UIManager.getInstance().closeStageUI()
this.owner.destroy()
})
this.btn_home.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
if (config.H_SCREEN) {
UIManager.getInstance().closeDCUI()
if (doStage.get_stageType() == config.STAGE_TYPE.MAIN) {
var 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);
}
else if (doStage.get_stageType() == config.STAGE_TYPE.DC) {
UIManager.getInstance().setTopbarTo(true)
}
this.btn_home.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
if (config.H_SCREEN) {
UIManager.getInstance().closeDCUI()
if (doStage.get_stageType() == config.STAGE_TYPE.MAIN) {
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)
} else if (doStage.get_stageType() == config.STAGE_TYPE.DC) {
UIManager.getInstance().setTopbarTo(true)
}
else {
UIManager.getInstance().loadHomeUI()
UIManager.getInstance().closeStageUI();
}
this.owner.destroy()
})
}
}
} else {
UIManager.getInstance().loadHomeUI()
UIManager.getInstance().closeStageUI()
}
this.owner.destroy()
})
}
}

View File

@@ -1,81 +1,76 @@
import { respath } from "../constants/respath";
import { config } from "../constants/config";
import { UIManager } from "../models/UIManager";
import { StorageManager } from "../models/StorageManager";
import { EventManager, EVENT_TYPES } from "../models/EventManager";
import { Difficulty } from "./Difficulty";
import { DOStage } from "../models/DOStage";
import type { DOStage } from "../models/DOStage"
import { config } from "../constants/config"
import { respath } from "../constants/respath"
import { EVENT_TYPES, EventManager } from "../models/EventManager"
import { StorageManager } from "../models/StorageManager"
import { UIManager } from "../models/UIManager"
import { Difficulty } from "./Difficulty"
const { regClass, property } = Laya;
const { regClass, property } = Laya
@regClass()
export class GameOver extends Laya.Script {
declare owner : Laya.Box;
declare owner: Laya.Box
@property(Laya.Sprite)
public btn_second: Laya.Sprite
@property(Laya.Sprite)
public btn_second: Laya.Sprite
@property(Laya.Sprite)
public btn_restart: Laya.Sprite
@property(Laya.Sprite)
public btn_restart: Laya.Sprite
@property(Laya.Sprite)
public btn_newOrClose: Laya.Sprite
@property(Laya.Sprite)
public btn_newOrClose: Laya.Sprite
@property(Laya.Label)
public label_newOrClose: Laya.Label
@property(Laya.Label)
public label_newOrClose: Laya.Label
public onSetStageInfo(doStage: DOStage): void {
public onSetStageInfo(doStage: DOStage): void {
this.btn_second.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
doStage.set_mistake(doStage.get_mistake() - 1)
EventManager.getInstance().DispatchEvent(EVENT_TYPES.NOT_UPDATE_MISTAKE)
this.owner.destroy()
})
this.btn_second.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
doStage.set_mistake(doStage.get_mistake()-1)
EventManager.getInstance().DispatchEvent(EVENT_TYPES.NOT_UPDATE_MISTAKE)
this.owner.destroy()
this.btn_restart.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
const stageID = doStage.get_stageID()
const type = doStage.get_stageType()
const difficulty = doStage.get_difficulty()
StorageManager.getInstance().newStage(stageID, type, difficulty, difficulty)
UIManager.getInstance().loadStageUI(stageID)
this.owner.destroy()
})
const 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) => {
if (config.H_SCREEN) {
const user = StorageManager.getInstance().getUser()
user.update_progress(doStage.get_difficulty(), doStage.get_stageIndex() + 1)// 主线关卡更新难度进度
const difficulty = doStage.get_difficulty()
StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, difficulty, 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)
this.owner.destroy()
})
})
}
})
this.btn_restart.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
var stageID = doStage.get_stageID()
var type = doStage.get_stageType()
var difficulty = doStage.get_difficulty()
StorageManager.getInstance().newStage(stageID, type, difficulty, difficulty)
UIManager.getInstance().loadStageUI(stageID);
} 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()
})
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) => {
if (config.H_SCREEN) {
var user = StorageManager.getInstance().getUser()
user.update_progress(doStage.get_difficulty(), doStage.get_stageIndex()+1)//主线关卡更新难度进度
var difficulty = doStage.get_difficulty()
StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, difficulty, difficulty)
UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID);
this.owner.destroy()
}
else {
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().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, value, 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()
})
}
}
}
}
}

View File

@@ -1,54 +1,49 @@
import type { DOStage } from "../models/DOStage"
import { EVENT_TYPES, EventManager } from "../models/EventManager"
import { StorageManager } from "../models/StorageManager"
import { UIManager } from "../models/UIManager"
import { Utility_ConvertSecondToString } from "../utils/utility"
import { UIManager } from "../models/UIManager";
import { StorageManager } from "../models/StorageManager";
import { Utility_ConvertSecondToString } from "../utils/utility";
import { EVENT_TYPES, EventManager } from "../models/EventManager";
import { DOStage } from "../models/DOStage";
const { regClass, property } = Laya;
const { regClass, property } = Laya
@regClass()
export class GamePause extends Laya.Script {
declare owner : Laya.Box;
declare owner: Laya.Box
@property(Laya.Label)
public label_time: Laya.Label
@property(Laya.Label)
public label_diffucuty: Laya.Label
@property(Laya.Label)
public label_time: Laya.Label
@property(Laya.Sprite)
public btn_continue: Laya.Sprite
@property(Laya.Sprite)
public btn_restart: Laya.Sprite
@property(Laya.Label)
public label_diffucuty: Laya.Label
@property(Laya.Sprite)
public btn_continue: Laya.Sprite
//组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
onAwake(): void {
}
@property(Laya.Sprite)
public btn_restart: Laya.Sprite
public onSetStageInfo(doStage: DOStage): void {
// 组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
onAwake(): void {
this.label_time.text = Utility_ConvertSecondToString(doStage.get_duration())
this.label_diffucuty.text = doStage.get_difficulty()
}
EventManager.getInstance().DispatchEvent(EVENT_TYPES.NOT_UPDATE_PAUSE, true)
this.btn_continue.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
EventManager.getInstance().DispatchEvent(EVENT_TYPES.NOT_UPDATE_PAUSE, false)
this.owner.destroy()
})
public onSetStageInfo(doStage: DOStage): void {
this.label_time.text = Utility_ConvertSecondToString(doStage.get_duration())
this.label_diffucuty.text = doStage.get_difficulty()
this.btn_restart.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
var stageID = doStage.get_stageID()
var type = doStage.get_stageType()
var difficulty = doStage.get_difficulty()
StorageManager.getInstance().newStage(stageID, type, difficulty, difficulty)
UIManager.getInstance().loadStageUI(stageID);
this.owner.destroy()
})
}
}
EventManager.getInstance().DispatchEvent(EVENT_TYPES.NOT_UPDATE_PAUSE, true)
this.btn_continue.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
EventManager.getInstance().DispatchEvent(EVENT_TYPES.NOT_UPDATE_PAUSE, false)
this.owner.destroy()
})
this.btn_restart.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
const stageID = doStage.get_stageID()
const type = doStage.get_stageType()
const difficulty = doStage.get_difficulty()
StorageManager.getInstance().newStage(stageID, type, difficulty, difficulty)
UIManager.getInstance().loadStageUI(stageID)
this.owner.destroy()
})
}
}

View File

@@ -1,168 +1,164 @@
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";
import { G_getMonthInfo } from "../models/DCManager";
import { config } from "../constants/config"
import { respath } from "../constants/respath"
import { G_getMonthInfo } from "../models/DCManager"
import { StorageManager } from "../models/StorageManager"
import { UIManager } from "../models/UIManager"
import { Utility_ConvertSecondToString } from "../utils/utility"
import { Difficulty } from "./Difficulty"
const { regClass, property } = Laya
@regClass()
export class Home extends Laya.Script {
declare owner : Laya.Box;
declare owner: Laya.Box
@property(Laya.Image)
public bg_dc: Laya.Image;
@property(Laya.Image)
public icon_dc: Laya.Image;
@property(Laya.Label)
public label_dc_title: Laya.Label;
@property(Laya.Label)
public label_dc_date: 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.Image)
public bg_dc: Laya.Image
@property(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;
@property(Laya.Image)
public icon_dc: Laya.Image
@property(Laya.Box)
public btn_clean: Laya.Box;
@property(Laya.Label)
public label_dc_title: Laya.Label
//组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
onAwake(): void {
var user = StorageManager.getInstance().getUser()
var now = new Date()
var nowYear = now.getFullYear()
var nowMonth = now.getMonth() + 1
var nowDay = now.getDate()
var find = G_getMonthInfo(nowYear, nowMonth)
if (find) {
this.icon_dc.skin = find.icon_res
if (user.get_doneCountByDate(nowYear, nowMonth) >= find.dayCount) {
this.bg_dc.skin = respath.home_top_dc_bg_finish
this.label_dc_title.color = "#ffffff"
this.label_dc_date.color = "#ffffff"
}
else {
this.bg_dc.skin = respath.home_top_dc_bg_normal
this.label_dc_title.color = "#2d3138"
this.label_dc_date.color = "#2d3138"
}
}
else {
@property(Laya.Label)
public label_dc_date: 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_new_blue: Laya.Box
@property(Laya.Box)
public btn_go: Laya.Box
@property(Laya.Box)
public btn_new_white: Laya.Box
@property(Laya.Box)
public btn_clean: Laya.Box
// 组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
onAwake(): void {
var user = StorageManager.getInstance().getUser()
const now = new Date()
const nowYear = now.getFullYear()
const nowMonth = now.getMonth() + 1
const nowDay = now.getDate()
const find = G_getMonthInfo(nowYear, nowMonth)
if (find) {
this.icon_dc.skin = find.icon_res
if (user.get_doneCountByDate(nowYear, nowMonth) >= find.dayCount) {
this.bg_dc.skin = respath.home_top_dc_bg_finish
this.label_dc_title.color = "#ffffff"
this.label_dc_date.color = "#ffffff"
} else {
this.bg_dc.skin = respath.home_top_dc_bg_normal
this.label_dc_title.color = "#2d3138"
this.label_dc_date.color = "#2d3138"
}
var stageID = `${nowYear}-${nowMonth}-${nowDay}`
this.label_dc_date.text = `${config.MONTH_ABBRS[nowMonth-1]} ${nowDay}`
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 stageName = `${config.MONTH_ABBRS[nowMonth-1]} ${nowDay}`
StorageManager.getInstance().newStage(stageID, config.STAGE_TYPE.DC, stageName)
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()
})
}
} else {
this.bg_dc.skin = respath.home_top_dc_bg_normal
this.label_dc_title.color = "#2d3138"
this.label_dc_date.color = "#2d3138"
}
const stageID = `${nowYear}-${nowMonth}-${nowDay}`
this.label_dc_date.text = `${config.MONTH_ABBRS[nowMonth - 1]} ${nowDay}`
this.btn_new_blue.on(Laya.Event.CLICK, this, this.onClickNew)
this.btn_new_white.on(Laya.Event.CLICK, this, this.onClickNew)
this.btn_go.on(Laya.Event.CLICK, this, (evt: Laya.Event)=>{
UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID);
const 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
const stageName = `${config.MONTH_ABBRS[nowMonth - 1]} ${nowDay}`
StorageManager.getInstance().newStage(stageID, config.STAGE_TYPE.DC, stageName)
UIManager.getInstance().loadStageUI(stageID)
this.owner.destroy()
})
var user = StorageManager.getInstance().getUser()
if (user.get_done(config.DEFAULT_STAGE_ID) >= 1) {
console.log("当前主线关卡完成")
} 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_go.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID)
this.owner.destroy()
})
var user = StorageManager.getInstance().getUser()
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 {
const doStage = StorageManager.getInstance().getStage(config.DEFAULT_STAGE_ID)
if (doStage) {
console.log("当前主线关卡进行中 mistake=", doStage.get_mistake())
if (doStage.get_mistake() >= config.MISTAKE_MAX) {
this.btn_new_blue.visible = true
this.btn_new_white.visible = false
this.btn_go.visible = false
} else {
this.btn_new_blue.visible = false
this.btn_new_white.visible = true
this.btn_go.visible = true
const label_time = this.btn_go.getChildByName("time").getChildByName("label_time") as Laya.Label
const duration = doStage.get_duration()
const 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
}
else {
var doStage = StorageManager.getInstance().getStage(config.DEFAULT_STAGE_ID)
if (doStage) {
console.log("当前主线关卡进行中 mistake=", doStage.get_mistake())
if (doStage.get_mistake() >= config.MISTAKE_MAX) {
this.btn_new_blue.visible = true
this.btn_new_white.visible = false
this.btn_go.visible = false
}
else {
this.btn_new_blue.visible = false
this.btn_new_white.visible = true
this.btn_go.visible = true
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()
})
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)
StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, value, value)
UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID);
this.owner.destroy()
})
// 测试逻辑
this.btn_clean.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
console.log("btn_clean=", evt)
StorageManager.getInstance().cleanAll()
})
this.btn_clean.visible = config.DEBUG
// ======
}
public onClickNew(evt: Laya.Event): void {
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)
this.owner.destroy()
})
}
})
}
}

View File

@@ -1,44 +1,39 @@
import { config } from "../constants/config";
import { AutoDestroy } from "./common/AutoDestroy";
import { AutoDestroy } from "./common/AutoDestroy"
const { regClass, property } = Laya;
const { regClass, property } = Laya
@regClass()
export class ScoreAdd extends Laya.Script {
declare owner : Laya.Box;
declare owner: Laya.Box
@property(Laya.Label)
public label: Laya.Label
@property(Laya.Label)
public label: Laya.Label
onAwake(): void {
this.label.scaleX = 0
this.label.skewY = 0
var d = this.owner.getComponent(AutoDestroy)
d.lifeTime = 2
}
onAwake(): void {
this.label.scaleX = 0
this.label.skewY = 0
onStart(): void {
const d = this.owner.getComponent(AutoDestroy)
d.lifeTime = 2
}
var wait = 0
onStart(): void {
let wait = 0
var duration = 300
Laya.Tween.to(this.label, {scaleX: 1, scaleY: 1}, duration, Laya.Ease.strongIn, null, wait)
wait += duration
let duration = 300
Laya.Tween.to(this.label, { scaleX: 1, scaleY: 1 }, duration, Laya.Ease.strongIn, null, wait)
wait += duration
duration = 300
Laya.Tween.to(this.label, {y:-102}, duration, Laya.Ease.strongIn, null, wait)
wait += duration
duration = 300
Laya.Tween.to(this.label, { y: -102 }, duration, Laya.Ease.strongIn, null, wait)
wait += duration
duration = 300
Laya.Tween.to(this.label, {alpha:0}, duration, Laya.Ease.strongIn, null, wait)
wait += duration
duration = 300
Laya.Tween.to(this.label, { alpha: 0 }, duration, Laya.Ease.strongIn, null, wait)
wait += duration
}
}
public onSetText(text: string): void {
this.label.text = text
}
}
public onSetText(text: string): void {
this.label.text = text
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,150 +1,149 @@
import { config } from "../constants/config";
import { StorageManager } from "../models/StorageManager";
import { UIManager } from "../models/UIManager";
import { CommonData } from "./common/CommonData";
import { G_ShowCommonTips } from "./CommonTips";
import { config } from "../constants/config"
import { StorageManager } from "../models/StorageManager"
import { UIManager } from "../models/UIManager"
import { CommonData } from "./common/CommonData"
import { G_ShowCommonTips } from "./CommonTips"
const { regClass, property } = Laya;
const { regClass, property } = Laya
@regClass()
export class TopBar extends Laya.Script {
declare owner : Laya.Box;
declare owner: Laya.Box
@property(Laya.Box)
public btn_classic: Laya.Box
@property(Laya.Sprite)
public sprite_classic: Laya.Sprite
@property(Laya.Label)
public label_classic: Laya.Label
@property(Laya.Box)
public btn_classic: Laya.Box
@property(Laya.Box)
public btn_dc: Laya.Box
@property(Laya.Sprite)
public sprite_dc: Laya.Sprite
@property(Laya.Label)
public label_dc: Laya.Label
@property(Laya.Sprite)
public sprite_classic: Laya.Sprite
private isClassic: boolean = true
@property(Laya.Label)
public label_classic: Laya.Label
@property(Laya.Label)
public obj_label: Laya.Label
@property(Laya.Box)
public obj_items: Laya.Box
private items: Map<string, Laya.Label> = new Map()
@property(Laya.Box)
public btn_dc: Laya.Box
onStart(): void {
@property(Laya.Sprite)
public sprite_dc: Laya.Sprite
//如果是第一次以横屏启动游戏需要创建经典关卡
var difficulty = Laya.LocalStorage.getItem("difficulty")//读取用户上次选择的难度
if (!difficulty || difficulty.length<=0) {
difficulty = config.DIFFICULTY_TYPE.Easy
Laya.LocalStorage.setItem("difficulty", difficulty)
}
var doStage = StorageManager.getInstance().getStage(config.DEFAULT_STAGE_ID)
if (!doStage) {
StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, difficulty, difficulty)
}
else {
var user = StorageManager.getInstance().getUser()
if (user.get_done(config.DEFAULT_STAGE_ID) >= 1) {
console.log("当前主线关卡完成")
user.update_progress(doStage.get_difficulty(), doStage.get_stageIndex()+1)//主线关卡更新难度进度
StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, difficulty, difficulty)
}
else if (doStage.get_mistake() >= config.MISTAKE_MAX) {//上次失败了则重新开始
StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, difficulty, difficulty)
}
}
@property(Laya.Label)
public label_dc: Laya.Label
this.btn_classic.on(Laya.Event.CLICK, this, ()=>{
if (this.isClassic == false) {
this.onClickTab(true)
}
})
this.btn_dc.on(Laya.Event.CLICK, this, ()=>{
if (this.isClassic) {
this.onClickTab(false)
}
})
this.onClickTab(this.isClassic)
private isClassic: boolean = true
var showToggle = Laya.LocalStorage.getItem("showToggle")
if (!showToggle || showToggle.length <= 0) {
Laya.LocalStorage.setItem("showToggle", "true")
}
@property(Laya.Label)
public obj_label: Laya.Label
for (var i=0; i<this.obj_items.numChildren; i++) {
var obj = this.obj_items.getChildAt(i)
var value = config.DIFFICULTY_LIST[i]
var label = obj.getChildByName("Label") as Laya.Label
label.text = value
this.items.set(value, label)
var common = obj.getComponent(CommonData)
common.strValue = value
obj.on(Laya.Event.CLICK, this, (evt: Laya.Event)=>{
var common = evt.target.getComponent(CommonData)
var difficulty = Laya.LocalStorage.getItem("difficulty")
if (common.strValue != difficulty) {
if (Laya.LocalStorage.getItem("showToggle")=="true") {
var title = "Start New Game"
var content = "Current game progress will be lost"
G_ShowCommonTips(title, content, true, (ok: boolean, toggleValue: boolean)=>{
if (ok) {
if (toggleValue) {
Laya.LocalStorage.setItem("showToggle", "false")
}
this.onClickDifficulty(common.strValue)
}
})
}
else {
this.onClickDifficulty(common.strValue)
}
}
})
}
this.updateDifficulty(difficulty)
@property(Laya.Box)
public obj_items: Laya.Box
private items: Map<string, Laya.Label> = new Map()
onStart(): void {
// 如果是第一次以横屏启动游戏需要创建经典关卡
let difficulty = Laya.LocalStorage.getItem("difficulty")// 读取用户上次选择的难度
if (!difficulty || difficulty.length <= 0) {
difficulty = config.DIFFICULTY_TYPE.Easy
Laya.LocalStorage.setItem("difficulty", difficulty)
}
onClickTab(isClassic: boolean): void {
this.isClassic = isClassic
if (isClassic) {
UIManager.getInstance().closeTrophyUI()
UIManager.getInstance().closeDCUI()
UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID)
}
else {
UIManager.getInstance().closeStageUI()
UIManager.getInstance().loadDCUI()
}
this.updateLeftTab()
}
updateLeftTab(): void {
this.sprite_classic.alpha = this.isClassic ? 1 : 0.1
this.label_classic.color = this.isClassic ? "#ffffff" : "#0e2a53"
this.sprite_dc.alpha = this.isClassic ? 0.1 : 1
this.label_dc.color = this.isClassic ? "#0e2a53" : "#ffffff"
this.obj_label.visible = this.isClassic
this.obj_items.visible = this.isClassic
}
onClickDifficulty(difficulty: string): void {
Laya.LocalStorage.setItem("difficulty", difficulty)//记录横屏模式用户选择的难度
const doStage = StorageManager.getInstance().getStage(config.DEFAULT_STAGE_ID)
if (!doStage) {
StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, difficulty, difficulty)
} else {
const user = StorageManager.getInstance().getUser()
if (user.get_done(config.DEFAULT_STAGE_ID) >= 1) {
console.log("当前主线关卡完成")
user.update_progress(doStage.get_difficulty(), doStage.get_stageIndex() + 1)// 主线关卡更新难度进度
StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, difficulty, difficulty)
UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID)
this.updateDifficulty(difficulty)
} else if (doStage.get_mistake() >= config.MISTAKE_MAX) { // 上次失败了则重新开始
StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, difficulty, difficulty)
}
}
updateDifficulty(difficulty: string): void {
this.items.forEach((label: Laya.Label, key: string)=>{
label.color = "#0e2a53"
})
var label = this.items.get(difficulty)
label.color = "#1d5cdc"
this.btn_classic.on(Laya.Event.CLICK, this, () => {
if (this.isClassic == false) {
this.onClickTab(true)
}
})
this.btn_dc.on(Laya.Event.CLICK, this, () => {
if (this.isClassic) {
this.onClickTab(false)
}
})
this.onClickTab(this.isClassic)
const showToggle = Laya.LocalStorage.getItem("showToggle")
if (!showToggle || showToggle.length <= 0) {
Laya.LocalStorage.setItem("showToggle", "true")
}
}
for (let i = 0; i < this.obj_items.numChildren; i++) {
const obj = this.obj_items.getChildAt(i)
const value = config.DIFFICULTY_LIST[i]
const label = obj.getChildByName("Label") as Laya.Label
label.text = value
this.items.set(value, label)
const common = obj.getComponent(CommonData)
common.strValue = value
obj.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
const common = evt.target.getComponent(CommonData)
const difficulty = Laya.LocalStorage.getItem("difficulty")
if (common.strValue != difficulty) {
if (Laya.LocalStorage.getItem("showToggle") == "true") {
const title = "Start New Game"
const content = "Current game progress will be lost"
G_ShowCommonTips(title, content, true, (ok: boolean, toggleValue: boolean) => {
if (ok) {
if (toggleValue) {
Laya.LocalStorage.setItem("showToggle", "false")
}
this.onClickDifficulty(common.strValue)
}
})
} else {
this.onClickDifficulty(common.strValue)
}
}
})
}
this.updateDifficulty(difficulty)
}
onClickTab(isClassic: boolean): void {
this.isClassic = isClassic
if (isClassic) {
UIManager.getInstance().closeTrophyUI()
UIManager.getInstance().closeDCUI()
UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID)
} else {
UIManager.getInstance().closeStageUI()
UIManager.getInstance().loadDCUI()
}
this.updateLeftTab()
}
updateLeftTab(): void {
this.sprite_classic.alpha = this.isClassic ? 1 : 0.1
this.label_classic.color = this.isClassic ? "#ffffff" : "#0e2a53"
this.sprite_dc.alpha = this.isClassic ? 0.1 : 1
this.label_dc.color = this.isClassic ? "#0e2a53" : "#ffffff"
this.obj_label.visible = this.isClassic
this.obj_items.visible = this.isClassic
}
onClickDifficulty(difficulty: string): void {
Laya.LocalStorage.setItem("difficulty", difficulty)// 记录横屏模式用户选择的难度
StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, difficulty, difficulty)
UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID)
this.updateDifficulty(difficulty)
}
updateDifficulty(difficulty: string): void {
this.items.forEach((label: Laya.Label, key: string) => {
label.color = "#0e2a53"
})
const label = this.items.get(difficulty)
label.color = "#1d5cdc"
}
}

View File

@@ -1,19 +1,19 @@
const { regClass, property } = Laya;
const { regClass, property } = Laya
@regClass()
export class AutoDestroy extends Laya.Script {
declare owner : Laya.Box;
declare owner: Laya.Box
@property(Number)
public lifeTime: number = 1;
@property(Number)
public lifeTime: number = 1
//组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
onStart(): void {
if (this.lifeTime < 1) {
this.lifeTime = 1
}
Laya.timer.once(this.lifeTime*1000, this, ()=>{
this.owner.destroy()
})
// 组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
onStart(): void {
if (this.lifeTime < 1) {
this.lifeTime = 1
}
}
Laya.timer.once(this.lifeTime * 1000, this, () => {
this.owner.destroy()
})
}
}

View File

@@ -1,13 +1,12 @@
const { regClass, property } = Laya;
const { regClass, property } = Laya
@regClass()
export class CommonData extends Laya.Script {
declare owner : Laya.Box;
declare owner: Laya.Box
@property(Number)
public intValue: number = 0;
@property(Number)
public intValue: number = 0
@property(String)
public strValue: string = "";
}
@property(String)
public strValue: string = ""
}

View File

@@ -2,9 +2,9 @@ import { respath } from "../../constants/respath"
import { ScoreAdd } from "../ScoreAdd"
export function G_ShowScoreTips(text: string, parent: any): void {
Laya.loader.load(respath.score_add_ui_res()).then((go)=>{
var prefab = go.create()
var score = parent.addChild(prefab).getComponent(ScoreAdd)
score.onSetText(text)
})
Laya.loader.load(respath.score_add_ui_res()).then((go) => {
const prefab = go.create()
const score = parent.addChild(prefab).getComponent(ScoreAdd)
score.onSetText(text)
})
}

View File

@@ -1,131 +1,131 @@
import { config } from "../../constants/config";
import { config } from "../../constants/config"
const { regClass, property } = Laya;
const { regClass, property } = Laya
@regClass()
export class CalendarUnit extends Laya.Script {
declare owner : Laya.Box;
declare owner: Laya.Box
@property(Number)
public year: number = 0;
@property(Number)
public month: number = 0;
@property(Number)
public day: number = 0;
@property(Boolean)
public open: boolean = false;
@property(Number)
public progress: number = 0;
@property(Number)
public year: number = 0
private selected: boolean = false
@property(Number)
public month: number = 0
@property(Laya.Sprite)
public obj_selected: Laya.Sprite;
@property(Number)
public day: number = 0
@property(Laya.Box)
public obj_pie: Laya.Box;
@property(Laya.Sprite)
public sprite_pie: Laya.Sprite;
@property(Boolean)
public open: boolean = false
@property(Laya.Sprite)
public obj_mask: Laya.Sprite;
@property(Laya.Sprite)
public sprite_mask: Laya.Sprite;
@property(Number)
public progress: number = 0
@property(Laya.Image)
public obj_star: Laya.Image;
private selected: boolean = false
@property(Laya.Label)
public label_show: Laya.Label;
@property(Laya.Sprite)
public obj_selected: Laya.Sprite
@property(Laya.Box)
public obj_pie: Laya.Box
//组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
onAwake(): void {
@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(label_obj: Laya.Label): void {
this.label_show = label_obj
}
public setCalendarUnit(year: number, month: number, day: number, open: boolean, progress: number, handler: any, func: any): void {
this.selected = false
this.year = year
this.month = month
this.day = day
this.open = open
this.progress = progress
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
}
public onInit(label_obj: Laya.Label): void {
this.label_show = label_obj
this.obj_star.visible = this.progress >= 1
let blockSize = 48
if (config.H_SCREEN)
blockSize = 33
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(blockSize, blockSize, blockSize, 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(blockSize, blockSize, blockSize, 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
}
}
public setCalendarUnit(year: number, month: number, day: number, open: boolean, progress: number, handler: any, func: any): void {
this.selected = false
this.year = year
this.month = month
this.day = day
this.open = open
this.progress = progress
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
var blockSize = 48
if (config.H_SCREEN)
blockSize = 33
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(blockSize, blockSize, blockSize, 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(blockSize, blockSize, blockSize, 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
}
}
}
}
}
}

View File

@@ -1,282 +1,293 @@
import { config } from "../../constants/config";
import { Utility_ConvertSecondToString } from "../../utils/utility";
import { StorageManager } from "../../models/StorageManager";
import { CalendarUnit } from "./CalendarUnit";
import { UIManager } from "../../models/UIManager";
import { respath } from "../../constants/respath";
import { MONTH_LIST } from "../../models/DCManager";
import { EVENT_TYPES, EventManager } from "../../models/EventManager";
import { config } from "../../constants/config"
import { respath } from "../../constants/respath"
import { MONTH_LIST } from "../../models/DCManager"
import { EVENT_TYPES, EventManager } from "../../models/EventManager"
import { StorageManager } from "../../models/StorageManager"
import { UIManager } from "../../models/UIManager"
import { Utility_ConvertSecondToString } from "../../utils/utility"
import { CalendarUnit } from "./CalendarUnit"
const { regClass, property } = Laya;
const { regClass, property } = Laya
@regClass()
export class DailyChallenge extends Laya.Script {
declare owner : Laya.Box;
declare owner: Laya.Box
@property(Laya.Button)
public btn_back: Laya.Button
@property(Laya.Image)
public btn_trophy: Laya.Image
@property(Laya.Sprite)
public btn_trophy_red: Laya.Sprite
@property(Laya.Image)
public trophy_light: Laya.Image
@property(Laya.Image)
public trophy_icon: Laya.Image
@property(Laya.Box)
public btn_left: Laya.Box
@property(Laya.Box)
public btn_right: Laya.Box
@property(Laya.Button)
public btn_back: Laya.Button
@property(Laya.Image)
public bg_dc: Laya.Image;
@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.Image)
public btn_trophy: Laya.Image
@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.Sprite)
public btn_trophy_red: Laya.Sprite
@property(Laya.Box)
public obj_items: Laya.Box;
@property(Laya.Box)
public obj_labels: Laya.Box;
private units: Array<CalendarUnit> = new Array();
@property(Laya.Image)
public trophy_light: Laya.Image
private selectedUnit: CalendarUnit;
private currentIndex: number
private indexMax: number
@property(Laya.Image)
public trophy_icon: Laya.Image
private static _instance: DailyChallenge
onAwake(): void {
DailyChallenge._instance = this
@property(Laya.Box)
public btn_left: Laya.Box
if (this.btn_back) {
this.btn_back.on(Laya.Event.CLICK, this, ()=>{
UIManager.getInstance().loadHomeUI()
UIManager.getInstance().closeDCUI()
})
}
@property(Laya.Box)
public btn_right: Laya.Box
var user = StorageManager.getInstance().getUser()
this.btn_trophy_red.visible = user.get_trophyHasUnread()
this.btn_trophy.on(Laya.Event.CLICK, this, ()=>{
user.set_trophyAllread()
this.btn_trophy_red.visible = false
UIManager.getInstance().loadTrophyUI()
})
@property(Laya.Image)
public bg_dc: Laya.Image
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().getStage(stageID)
console.log("play >>>>>>>>>>>>>>>>>>>>>>>", stageID, doStage)
if (!doStage || doStage.get_mistake() >= config.MISTAKE_MAX) {
var stageName = `${config.MONTH_ABBRS[month-1]} ${dayNow}`
StorageManager.getInstance().newStage(stageID, config.STAGE_TYPE.DC, stageName)
}
UIManager.getInstance().loadStageUI(stageID);
this.owner.destroy()
})
@property(Laya.Label)
public label_year: Laya.Label
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 unit = hbox.getChildAt(j).getComponent(CalendarUnit)
var l_obj = l_hbox.getChildAt(j) as Laya.Label
this.units.push(unit)
unit.onInit(l_obj)
}
}
@property(Laya.Label)
public label_month: Laya.Label
this.indexMax = MONTH_LIST.length - 1
var now = new Date()
var nowYear = now.getFullYear()
var nowMonth = now.getMonth() + 1
for (var i=0; i<MONTH_LIST.length; i++) {
var obj = MONTH_LIST[i]
if (nowYear == obj.year && nowMonth == obj.month) {
this.indexMax = i;
break
}
}
this.btn_left.on(Laya.Event.CLICK, this, ()=>{
if (this.currentIndex > 0) {
this.currentIndex --
this.loadWithIndex(this.currentIndex)
}
})
this.btn_right.on(Laya.Event.CLICK, this, ()=>{
if (this.currentIndex < this.indexMax) {
this.currentIndex ++
this.loadWithIndex(this.currentIndex)
}
})
@property(Laya.Label)
public label_star: Laya.Label
EventManager.getInstance().RegisterEvent(EVENT_TYPES.NOT_SET_TROPHY_BUTTON, DailyChallenge.EventUpdateTrophyButton)
@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> = []
private selectedUnit: CalendarUnit
private currentIndex: number
private indexMax: number
private static _instance: DailyChallenge
onAwake(): void {
DailyChallenge._instance = this
if (this.btn_back) {
this.btn_back.on(Laya.Event.CLICK, this, () => {
UIManager.getInstance().loadHomeUI()
UIManager.getInstance().closeDCUI()
})
}
onDestroy(): void {
EventManager.getInstance().UnregisterEvent(EVENT_TYPES.NOT_SET_TROPHY_BUTTON, DailyChallenge.EventUpdateTrophyButton)
}
public static EventUpdateTrophyButton(arg: any): void {
if (DailyChallenge._instance) {
DailyChallenge._instance.btn_trophy.visible = arg
}
const user = StorageManager.getInstance().getUser()
this.btn_trophy_red.visible = user.get_trophyHasUnread()
this.btn_trophy.on(Laya.Event.CLICK, this, () => {
user.set_trophyAllread()
this.btn_trophy_red.visible = false
UIManager.getInstance().loadTrophyUI()
})
this.btn_play.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
// console.log(">>>>>>>>>>>>>>>>>>>>>>>", this.selectedUnit.day)
const now = new Date()
const year = now.getFullYear()
const month = now.getMonth() + 1
const dayNow = this.selectedUnit.day
const stageID = `${year}-${month}-${dayNow}`
const doStage = StorageManager.getInstance().getStage(stageID)
console.log("play >>>>>>>>>>>>>>>>>>>>>>>", stageID, doStage)
if (!doStage || doStage.get_mistake() >= config.MISTAKE_MAX) {
const stageName = `${config.MONTH_ABBRS[month - 1]} ${dayNow}`
StorageManager.getInstance().newStage(stageID, config.STAGE_TYPE.DC, stageName)
}
UIManager.getInstance().loadStageUI(stageID)
this.owner.destroy()
})
for (var i = 0; i < this.obj_items.numChildren; i++) {
const hbox = this.obj_items.getChildAt(i)
const l_hbox = this.obj_labels.getChildAt(i)
for (let j = 0; j < hbox.numChildren; j++) {
const unit = hbox.getChildAt(j).getComponent(CalendarUnit)
const l_obj = l_hbox.getChildAt(j) as Laya.Label
this.units.push(unit)
unit.onInit(l_obj)
}
}
loadWithMonth(): void {
var now = new Date()
var nowYear = now.getFullYear()
var nowMonth = now.getMonth() + 1
this.currentIndex = 0
for (var i=0; i<MONTH_LIST.length; i++) {
var obj = MONTH_LIST[i]
if (nowYear == obj.year && nowMonth == obj.month) {
this.currentIndex = i;
break
}
}
console.log("DailyChallenge loadWithMonth >>>>>>>>>>>>>>>", nowYear, nowMonth, this.currentIndex)
this.indexMax = MONTH_LIST.length - 1
const now = new Date()
const nowYear = now.getFullYear()
const nowMonth = now.getMonth() + 1
for (var i = 0; i < MONTH_LIST.length; i++) {
const obj = MONTH_LIST[i]
if (nowYear == obj.year && nowMonth == obj.month) {
this.indexMax = i
break
}
}
this.btn_left.on(Laya.Event.CLICK, this, () => {
if (this.currentIndex > 0) {
this.currentIndex--
this.loadWithIndex(this.currentIndex)
}
})
this.btn_right.on(Laya.Event.CLICK, this, () => {
if (this.currentIndex < this.indexMax) {
this.currentIndex++
this.loadWithIndex(this.currentIndex)
}
})
EventManager.getInstance().RegisterEvent(EVENT_TYPES.NOT_SET_TROPHY_BUTTON, DailyChallenge.EventUpdateTrophyButton)
}
onDestroy(): void {
EventManager.getInstance().UnregisterEvent(EVENT_TYPES.NOT_SET_TROPHY_BUTTON, DailyChallenge.EventUpdateTrophyButton)
}
public static EventUpdateTrophyButton(arg: any): void {
if (DailyChallenge._instance) {
DailyChallenge._instance.btn_trophy.visible = arg
}
}
public loadWithIndex(index: number): void {
this.btn_left.visible = this.currentIndex > 0
this.btn_right.visible = this.currentIndex < this.indexMax
var info = MONTH_LIST[index]
var user = StorageManager.getInstance().getUser()
var now = new Date()
var nowYear = now.getFullYear()
var nowMonth = now.getMonth() + 1
var nowDay = new Date().getDate()
this.trophy_icon.skin = info.icon_res
//设置背景
var starCount = user.get_doneCountByDate(info.year, info.month)
if (starCount >= info.dayCount) {
this.bg_dc.skin = respath.dc_top_bg_month_finish
this.trophy_light.visible = true
}
else {
this.bg_dc.skin = respath.dc_top_bg_normal
this.trophy_light.visible = false
}
this.label_year.text = info.year.toString()
this.label_month.text = config.MONTH_FULLNAMES[info.month-1]
this.label_star.text = `${starCount}/${info.dayCount}`
loadWithMonth(): void {
const now = new Date()
const nowYear = now.getFullYear()
const nowMonth = now.getMonth() + 1
this.currentIndex = 0
for (let i = 0; i < MONTH_LIST.length; i++) {
const obj = MONTH_LIST[i]
if (nowYear == obj.year && nowMonth == obj.month) {
this.currentIndex = i
break
}
}
console.log("DailyChallenge loadWithMonth >>>>>>>>>>>>>>>", nowYear, nowMonth, this.currentIndex)
this.loadWithIndex(this.currentIndex)
}
this.selectedUnit = null
var day = 1
for (var i=0; i<this.units.length; i++) {
var unit = this.units[i]
if (i >= info.begin && i < info.begin+info.dayCount) {
unit.owner.visible = true
unit.label_show.visible = true
var open = true
if (info.year > nowYear) {
open = false
}
else if (info.year == nowYear) {
if (info.month > nowMonth) {
open = false
}
else if (info.month == nowMonth) {
if (day > nowDay) {
open = false
}
}
}
var stageID = `${info.year}-${info.month}-${day}`
var progress = user.get_done(stageID)
if (open && progress < 1) {//检查失败的关卡,如果失败了就重置
var doStage = StorageManager.getInstance().getStage(stageID)
if (doStage) {//有关卡数据
if (doStage.get_mistake() >= config.MISTAKE_MAX) {
progress = 0
user.update_stage_done(stageID, 0)
StorageManager.getInstance().cleanStage(stageID)
}
}
}
unit.setCalendarUnit(info.year, info.month, day, open, progress, this, this.onClickUnit)
if (info.year == nowYear && info.month == nowMonth && day == nowDay) {
this.selectedUnit = unit
}
day ++
public loadWithIndex(index: number): void {
this.btn_left.visible = this.currentIndex > 0
this.btn_right.visible = this.currentIndex < this.indexMax
const info = MONTH_LIST[index]
const user = StorageManager.getInstance().getUser()
const now = new Date()
const nowYear = now.getFullYear()
const nowMonth = now.getMonth() + 1
const nowDay = new Date().getDate()
this.trophy_icon.skin = info.icon_res
// 设置背景
const starCount = user.get_doneCountByDate(info.year, info.month)
if (starCount >= info.dayCount) {
this.bg_dc.skin = respath.dc_top_bg_month_finish
this.trophy_light.visible = true
} else {
this.bg_dc.skin = respath.dc_top_bg_normal
this.trophy_light.visible = false
}
this.label_year.text = info.year.toString()
this.label_month.text = config.MONTH_FULLNAMES[info.month - 1]
this.label_star.text = `${starCount}/${info.dayCount}`
this.selectedUnit = null
let day = 1
for (let i = 0; i < this.units.length; i++) {
const unit = this.units[i]
if (i >= info.begin && i < info.begin + info.dayCount) {
unit.owner.visible = true
unit.label_show.visible = true
let open = true
if (info.year > nowYear) {
open = false
} else if (info.year == nowYear) {
if (info.month > nowMonth) {
open = false
} else if (info.month == nowMonth) {
if (day > nowDay) {
open = false
}
else {
unit.owner.visible = false
unit.label_show.visible = false
}
}
const stageID = `${info.year}-${info.month}-${day}`
let progress = user.get_done(stageID)
if (open && progress < 1) { // 检查失败的关卡,如果失败了就重置
const doStage = StorageManager.getInstance().getStage(stageID)
if (doStage) { // 有关卡数据
if (doStage.get_mistake() >= config.MISTAKE_MAX) {
progress = 0
user.update_stage_done(stageID, 0)
StorageManager.getInstance().cleanStage(stageID)
}
}
}
if (!this.selectedUnit)
this.selectedUnit = this.units[info.begin+info.dayCount-1]
this.onApplyUnit(this.selectedUnit)
unit.setCalendarUnit(info.year, info.month, day, open, progress, this, this.onClickUnit)
if (info.year == nowYear && info.month == nowMonth && day == nowDay) {
this.selectedUnit = unit
}
day++
} else {
unit.owner.visible = false
unit.label_show.visible = false
}
}
if (!this.selectedUnit)
this.selectedUnit = this.units[info.begin + info.dayCount - 1]
this.onApplyUnit(this.selectedUnit)
}
public onApplyUnit(unit: CalendarUnit): void {
this.selectedUnit.setSelected(false)
this.selectedUnit = unit
this.selectedUnit.setSelected(true)
public onApplyUnit(unit: CalendarUnit): void {
this.selectedUnit.setSelected(false)
this.selectedUnit = unit
this.selectedUnit.setSelected(true)
var stageID = `${unit.year}-${unit.month}-${unit.day}`
this.label_date.text = `${config.MONTH_ABBRS[unit.month-1]} ${unit.day},${unit.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().getStage(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().getStage(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)
const stageID = `${unit.year}-${unit.month}-${unit.day}`
this.label_date.text = `${config.MONTH_ABBRS[unit.month - 1]} ${unit.day},${unit.year}`
const user = StorageManager.getInstance().getUser()
const 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().getStage(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().getStage(stageID)
if (doStage) {
this.label_play.text = "Continue"
} else {
this.label_play.text = "Play"
}
}
}
onStart(): void {
var user = StorageManager.getInstance().getUser()
var find = user.get_trophyHasNew()
if (find) {
UIManager.getInstance().loadTrophyClaimUI(find)
user.set_trophyNew(find, false)
}
public onClickUnit(evt: Laya.Event): void {
const unit = evt.target.getComponent(CalendarUnit)
this.onApplyUnit(unit)
}
onStart(): void {
const user = StorageManager.getInstance().getUser()
const find = user.get_trophyHasNew()
if (find) {
UIManager.getInstance().loadTrophyClaimUI(find)
user.set_trophyNew(find, false)
}
}
}
}

View File

@@ -1,36 +1,35 @@
import { config } from "../../constants/config";
import { MONTH_LIST } from "../../models/DCManager";
import { TrophyRecord } from "../../types/global";
import type { TrophyRecord } from "../../types/global"
import { config } from "../../constants/config"
import { MONTH_LIST } from "../../models/DCManager"
const { regClass, property } = Laya;
const { regClass, property } = Laya
@regClass()
export class TrophyClaim extends Laya.Script {
declare owner : Laya.Box;
declare owner: Laya.Box
@property(Laya.Image)
public icon: Laya.Image
@property(Laya.Image)
public icon: Laya.Image
@property(Laya.Label)
public label_date: Laya.Label
@property(Laya.Label)
public label_date: Laya.Label
@property(Laya.Box)
public btn_close: Laya.Box
@property(Laya.Box)
public btn_close: Laya.Box
public onSetShow(record: TrophyRecord): void {
for (var i=0; i<MONTH_LIST.length; i++) {
var obj = MONTH_LIST[i]
if (obj.year == record.year && obj.month == record.month) {
this.icon.skin = obj.icon_res
break
}
}
this.label_date.text = `${config.MONTH_ABBRS[record.month-1]} ${record.day},${record.year}`
this.btn_close.on(Laya.Event.CLICK, this, ()=>{
this.owner.destroy()
})
public onSetShow(record: TrophyRecord): void {
for (let i = 0; i < MONTH_LIST.length; i++) {
const obj = MONTH_LIST[i]
if (obj.year == record.year && obj.month == record.month) {
this.icon.skin = obj.icon_res
break
}
}
}
this.label_date.text = `${config.MONTH_ABBRS[record.month - 1]} ${record.day},${record.year}`
this.btn_close.on(Laya.Event.CLICK, this, () => {
this.owner.destroy()
})
}
}

View File

@@ -1,116 +1,109 @@
import { config } from "../../constants/config"
import { respath } from "../../constants/respath"
import { MONTH_LIST } from "../../models/DCManager"
import { EVENT_TYPES, EventManager } from "../../models/EventManager"
import { UIManager } from "../../models/UIManager"
import { TrophyUnit } from "./TrophyUnit"
import { config } from "../../constants/config";
import { respath } from "../../constants/respath";
import { MONTH_LIST } from "../../models/DCManager";
import { EVENT_TYPES, EventManager } from "../../models/EventManager";
import { UIManager } from "../../models/UIManager";
import { TrophyUnit } from "./TrophyUnit";
const { regClass, property } = Laya;
const { regClass, property } = Laya
@regClass()
export class TrophyRoom extends Laya.Script {
declare owner : Laya.Box;
declare owner: Laya.Box
@property(Laya.Box)
public btn_back: Laya.Box;
@property(Laya.Box)
public btn_back: Laya.Box
@property(Laya.Box)
public obj_items: Laya.Box;
@property(Laya.Box)
public obj_items: Laya.Box
//第一次执行update之前执行只会执行一次
onStart(): void {
// 第一次执行update之前执行只会执行一次
onStart(): void {
let trophyCountOfCell = 3
if (config.H_SCREEN)
trophyCountOfCell = 5
var trophyCountOfCell = 3
if (config.H_SCREEN)
trophyCountOfCell = 5
this.btn_back.on(Laya.Event.CLICK, this, () => {
UIManager.getInstance().closeTrophyUI()
})
this.btn_back.on(Laya.Event.CLICK, this, ()=>{
UIManager.getInstance().closeTrophyUI()
})
var infos: Array<any> = new Array()
var now = new Date()
var nowYear = now.getFullYear()
var nowMonth = now.getMonth() + 1
for (var i=0; i<MONTH_LIST.length; i++) {
var obj = MONTH_LIST[i]
infos.push(obj)
if (obj.year == nowYear && obj.month == nowMonth) {
break
}
}
infos.reverse()
var years: Array<number> = new Array()
var monthMap: Map<number, Array<any>> = new Map()
for (var i=0; i<infos.length; i++) {
obj = infos[i]
if (years.indexOf(obj.year) < 0) {
years.push(obj.year)
}
if (monthMap.has(obj.year)== false) {
monthMap.set(obj.year, new Array())
}
var list = monthMap.get(obj.year)
list.push(obj)
}
console.log(">>>>>>>>>>>>years=", years)
Laya.loader.load(respath.trophy_year_ui_res()).then((go)=>{
for (var i=1; i<years.length; i++) {
var obj_year = this.obj_items.getChildAt(i)
if (!obj_year) {
var prefab = go.create()
this.obj_items.addChild(prefab)
}
}
Laya.loader.load(respath.trophy_cell_ui_res()).then((go)=>{
var itemsHeight = 0
for (var i=0; i<years.length; i++) {
var list = monthMap.get(years[i])
var cellCount = Math.ceil(list.length/trophyCountOfCell)
var yearHeight = 120 + cellCount * 444
itemsHeight += yearHeight
var obj_year = this.obj_items.getChildAt(i) as Laya.Box
obj_year.height = yearHeight
var label = obj_year.getChildByName("year").getChildByName("Label") as Laya.Label
label.text = years[i].toString()
var index = -1
for (var j=1; j<cellCount+1; j++) {
var obj_cell = obj_year.getChildAt(j)
if (!obj_cell) {
var prefab = go.create()
obj_cell = obj_year.addChild(prefab)
}
var hbox = obj_cell.getChildByName("HBox")
for (var k=0; k<hbox.numChildren; k++) {
var unit = hbox.getChildAt(k).getComponent(TrophyUnit)
index ++
if (index < list.length) {
unit.owner.visible = true
unit.onInit(list[index])
}
else {
unit.owner.visible = false
}
}
}
}
this.obj_items.height = itemsHeight
})
})
EventManager.getInstance().DispatchEvent(EVENT_TYPES.NOT_SET_TROPHY_BUTTON, false)
const infos: Array<any> = []
const now = new Date()
const nowYear = now.getFullYear()
const nowMonth = now.getMonth() + 1
for (var i = 0; i < MONTH_LIST.length; i++) {
var obj = MONTH_LIST[i]
infos.push(obj)
if (obj.year == nowYear && obj.month == nowMonth) {
break
}
}
infos.reverse()
onDestroy(): void {
EventManager.getInstance().DispatchEvent(EVENT_TYPES.NOT_SET_TROPHY_BUTTON, true)
const years: Array<number> = []
const monthMap: Map<number, Array<any>> = new Map()
for (var i = 0; i < infos.length; i++) {
obj = infos[i]
if (!years.includes(obj.year)) {
years.push(obj.year)
}
if (monthMap.has(obj.year) == false) {
monthMap.set(obj.year, [])
}
const list = monthMap.get(obj.year)
list.push(obj)
}
}
console.log(">>>>>>>>>>>>years=", years)
Laya.loader.load(respath.trophy_year_ui_res()).then((go) => {
for (let i = 1; i < years.length; i++) {
const obj_year = this.obj_items.getChildAt(i)
if (!obj_year) {
const prefab = go.create()
this.obj_items.addChild(prefab)
}
}
Laya.loader.load(respath.trophy_cell_ui_res()).then((go) => {
let itemsHeight = 0
for (let i = 0; i < years.length; i++) {
const list = monthMap.get(years[i])
const cellCount = Math.ceil(list.length / trophyCountOfCell)
const yearHeight = 120 + cellCount * 444
itemsHeight += yearHeight
const obj_year = this.obj_items.getChildAt(i) as Laya.Box
obj_year.height = yearHeight
const label = obj_year.getChildByName("year").getChildByName("Label") as Laya.Label
label.text = years[i].toString()
let index = -1
for (let j = 1; j < cellCount + 1; j++) {
let obj_cell = obj_year.getChildAt(j)
if (!obj_cell) {
const prefab = go.create()
obj_cell = obj_year.addChild(prefab)
}
const hbox = obj_cell.getChildByName("HBox")
for (let k = 0; k < hbox.numChildren; k++) {
const unit = hbox.getChildAt(k).getComponent(TrophyUnit)
index++
if (index < list.length) {
unit.owner.visible = true
unit.onInit(list[index])
} else {
unit.owner.visible = false
}
}
}
}
this.obj_items.height = itemsHeight
})
})
EventManager.getInstance().DispatchEvent(EVENT_TYPES.NOT_SET_TROPHY_BUTTON, false)
}
onDestroy(): void {
EventManager.getInstance().DispatchEvent(EVENT_TYPES.NOT_SET_TROPHY_BUTTON, true)
}
}

View File

@@ -1,37 +1,35 @@
import type { TrophyRecord } from "../../types/global"
import { config } from "../../constants/config"
import { MONTH_LIST } from "../../models/DCManager"
import { config } from "../../constants/config";
import { MONTH_LIST } from "../../models/DCManager";
import { TrophyRecord } from "../../types/global";
const { regClass, property } = Laya;
const { regClass, property } = Laya
@regClass()
export class TrophyShow extends Laya.Script {
declare owner : Laya.Box;
declare owner: Laya.Box
@property(Laya.Image)
public icon: Laya.Image
@property(Laya.Image)
public icon: Laya.Image
@property(Laya.Label)
public label_date: Laya.Label
@property(Laya.Label)
public label_date: Laya.Label
@property(Laya.Box)
public btn_close: Laya.Box
@property(Laya.Box)
public btn_close: Laya.Box
public onSetShow(record: TrophyRecord): void {
for (var i=0; i<MONTH_LIST.length; i++) {
var obj = MONTH_LIST[i]
if (obj.year == record.year && obj.month == record.month) {
this.icon.skin = obj.icon_res
break
}
}
this.label_date.text = `${config.MONTH_ABBRS[record.month-1]} ${record.day},${record.year}`
this.btn_close.on(Laya.Event.CLICK, this, ()=>{
this.owner.destroy()
})
public onSetShow(record: TrophyRecord): void {
for (let i = 0; i < MONTH_LIST.length; i++) {
const obj = MONTH_LIST[i]
if (obj.year == record.year && obj.month == record.month) {
this.icon.skin = obj.icon_res
break
}
}
}
this.label_date.text = `${config.MONTH_ABBRS[record.month - 1]} ${record.day},${record.year}`
this.btn_close.on(Laya.Event.CLICK, this, () => {
this.owner.destroy()
})
}
}

View File

@@ -1,45 +1,47 @@
import { config } from "../../constants/config";
import { respath } from "../../constants/respath";
import { StorageManager } from "../../models/StorageManager";
import { UIManager } from "../../models/UIManager";
import { config } from "../../constants/config"
import { respath } from "../../constants/respath"
import { StorageManager } from "../../models/StorageManager"
import { UIManager } from "../../models/UIManager"
const { regClass, property } = Laya;
const { regClass, property } = Laya
@regClass()
export class TrophyUnit extends Laya.Script {
declare owner : Laya.Box;
declare owner: Laya.Box
@property(Laya.Image)
public bg_light: Laya.Image;
@property(Laya.Image)
public icon: Laya.Image;
@property(Laya.Label)
public label_count: Laya.Label;
@property(Laya.Label)
public label_month: Laya.Label;
@property(Laya.Image)
public bg_light: Laya.Image
public onInit(info: any): void {
var user = StorageManager.getInstance().getUser()
var starCount = user.get_doneCountByDate(info.year, info.month)
this.icon.skin = info.icon_res
this.label_count.text = `${starCount}/${info.dayCount}`
this.label_month.text = config.MONTH_ABBRS[info.month-1]
if (starCount >= info.dayCount) {
this.bg_light.skin = respath.trophy_bg_light_gold
this.icon.gray = false
this.label_month.color = "#2d3138"
}
else {
this.bg_light.skin = respath.trophy_bg_light_grey
this.icon.gray = true
this.label_month.color = "#a7abb3"
}
@property(Laya.Image)
public icon: Laya.Image
this.icon.on(Laya.Event.CLICK, this, ()=>{
var find = user.get_trophyRecord(info.year, info.month)
if (find) {
UIManager.getInstance().loadTrophyShowUI(find)
}
})
@property(Laya.Label)
public label_count: Laya.Label
@property(Laya.Label)
public label_month: Laya.Label
public onInit(info: any): void {
const user = StorageManager.getInstance().getUser()
const starCount = user.get_doneCountByDate(info.year, info.month)
this.icon.skin = info.icon_res
this.label_count.text = `${starCount}/${info.dayCount}`
this.label_month.text = config.MONTH_ABBRS[info.month - 1]
if (starCount >= info.dayCount) {
this.bg_light.skin = respath.trophy_bg_light_gold
this.icon.gray = false
this.label_month.color = "#2d3138"
} else {
this.bg_light.skin = respath.trophy_bg_light_grey
this.icon.gray = true
this.label_month.color = "#a7abb3"
}
}
this.icon.on(Laya.Event.CLICK, this, () => {
const find = user.get_trophyRecord(info.year, info.month)
if (find) {
UIManager.getInstance().loadTrophyShowUI(find)
}
})
}
}