From a7df8ec73981593c9dc25e8ac7dec22ef2d04bbd Mon Sep 17 00:00:00 2001 From: yangwen Date: Wed, 28 May 2025 18:47:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/launch.json | 28 +- README.md | 8 +- src/Entry.ts | 4 +- src/Main.ts | 36 +- src/constants/config.ts | 27 +- src/constants/respath.ts | 18 +- src/models/DCManager.ts | 76 +-- src/models/DOBlock.ts | 124 ++-- src/models/DOCandy.ts | 39 +- src/models/DOStage.ts | 337 +++++----- src/models/DOUser.ts | 328 +++++----- src/models/EventManager.ts | 77 +-- src/models/LevelManager.ts | 270 ++++---- src/models/StorageManager.ts | 103 ++- src/models/UIManager.ts | 111 ++-- src/types/global.ts | 101 ++- src/utils/utility.ts | 60 +- src/views/Block.ts | 363 +++++------ src/views/Candy.ts | 101 ++- src/views/CommonTips.ts | 94 +-- src/views/Difficulty.ts | 72 +- src/views/GameDone.ts | 143 ++-- src/views/GameOver.ts | 129 ++-- src/views/GamePause.ts | 79 ++- src/views/Home.ts | 282 ++++---- src/views/ScoreAdd.ts | 59 +- src/views/Stage.ts | 1086 +++++++++++++++---------------- src/views/TopBar.ts | 263 ++++---- src/views/common/AutoDestroy.ts | 26 +- src/views/common/CommonData.ts | 15 +- src/views/common/GUITips.ts | 10 +- src/views/dc/CalendarUnit.ts | 228 +++---- src/views/dc/DailyChallenge.ts | 511 ++++++++------- src/views/dc/TrophyClaim.ts | 51 +- src/views/dc/TrophyRoom.ts | 201 +++--- src/views/dc/TrophyShow.ts | 54 +- src/views/dc/TrophyUnit.ts | 76 +-- tsconfig.json | 18 +- 38 files changed, 2768 insertions(+), 2840 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 074843b..86b4b33 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,15 +1,15 @@ { - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "type": "chrome", - "request": "launch", - "name": "LayaAir Debug", - "url": "http://localhost:18090", - "webRoot": "${workspaceFolder}/bin" - } - ] -} \ No newline at end of file + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "chrome", + "request": "launch", + "name": "LayaAir Debug", + "url": "http://localhost:18090", + "webRoot": "${workspaceFolder}/bin" + } + ] +} diff --git a/README.md b/README.md index cdb4911..dcef09c 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,28 @@ # **项目名称** + > 数独 ## **环境推荐** + - Node.js (>= 22.x) - npm (>= 11.x) - LayaAir (> 3.2.x) ## **打包构建** + (如有特殊配置或脚本,需备注) ## **IDE插件** + (如有,需提供IDE插件列表) ## **环境变量(宏)** + (如有,需提供宏列表) ## **其他** + - (接口文档)[link] - (需求文档)[link] - (技术设计文档)[link] -- (相关资料)[link] \ No newline at end of file +- (相关资料)[link] diff --git a/src/Entry.ts b/src/Entry.ts index a9b41bf..59ec4a0 100644 --- a/src/Entry.ts +++ b/src/Entry.ts @@ -1,4 +1,3 @@ - import { config } from "./constants/config" Laya.addBeforeInitCallback((stageConfig) => { @@ -8,8 +7,7 @@ Laya.addBeforeInitCallback((stageConfig) => { stageConfig.designWidth = config.DESIGN_HEIGHT stageConfig.designHeight = config.DESIGN_WIDTH config.H_SCREEN = true - } - else { + } else { stageConfig.designWidth = config.DESIGN_WIDTH stageConfig.designHeight = config.DESIGN_HEIGHT config.H_SCREEN = false diff --git a/src/Main.ts b/src/Main.ts index 8d151cb..07cb87f 100644 --- a/src/Main.ts +++ b/src/Main.ts @@ -1,25 +1,23 @@ +import { config } from "./constants/config" +import { LevelManager } from "./models/LevelManager" +import { StorageManager } from "./models/StorageManager" - -import { StorageManager } from "./models/StorageManager"; -import { LevelManager } from "./models/LevelManager"; -import { config } from "./constants/config"; -const { regClass, property } = Laya; +const { regClass, property } = Laya @regClass() export class Main extends Laya.Script { + @property(Boolean) + public debug: boolean = false - @property(Boolean) - public debug: boolean = false + onAwake() { + console.log("Game onAwake") + config.DEBUG = this.debug + LevelManager.getInstance().init() + StorageManager.getInstance().init() + } - onAwake() { - console.log("Game onAwake") - config.DEBUG = this.debug - LevelManager.getInstance().init() - StorageManager.getInstance().init() - } - - onLateUpdate(): void { - StorageManager.getInstance().saveUser() - StorageManager.getInstance().saveStage() - } -} \ No newline at end of file + onLateUpdate(): void { + StorageManager.getInstance().saveUser() + StorageManager.getInstance().saveStage() + } +} diff --git a/src/constants/config.ts b/src/constants/config.ts index 806b53a..d590448 100644 --- a/src/constants/config.ts +++ b/src/constants/config.ts @@ -1,8 +1,5 @@ - - - export const config = { - + DESIGN_WIDTH: 1080, DESIGN_HEIGHT: 1920, H_SCREEN: false, // 是否横屏 @@ -10,22 +7,21 @@ export const config = { DEBUG: false, OPEN_GUIDE: true, - MISTAKE_MAX: 3,//最大错误数 + MISTAKE_MAX: 3, // 最大错误数 - STAGE_TYPE: {//关卡类型 - MAIN: 1,//主线 - DC: 2,//每日挑战 + STAGE_TYPE: { // 关卡类型 + MAIN: 1, // 主线 + DC: 2// 每日挑战 }, - - DEFAULT_STAGE_ID: "main",//主线关卡标识 + DEFAULT_STAGE_ID: "main", // 主线关卡标识 - DIFFICULTY_TYPE: {//难度 + DIFFICULTY_TYPE: { // 难度 Easy: "Easy", Medium: "Medium", Hard: "Hard", Expert: "Expert", - Extreme: "Extreme", + Extreme: "Extreme" }, DIFFICULTY_LIST: ["Easy", "Medium", "Hard", "Expert", "Extreme"], @@ -33,13 +29,10 @@ export const config = { WHITE: "#ffffff", GREY: "#f0f2f7", RED: "#ef3e67", - BLUE: "#2559c0", + BLUE: "#2559c0" }, MONTH_ABBRS: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], - MONTH_FULLNAMES: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], - + MONTH_FULLNAMES: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"] } - - diff --git a/src/constants/respath.ts b/src/constants/respath.ts index 3d6d25d..b4452ae 100644 --- a/src/constants/respath.ts +++ b/src/constants/respath.ts @@ -1,5 +1,4 @@ -import { config } from "./config"; - +import { config } from "./config" export const respath = { home_ui_res: "resources/Home.lh", @@ -7,7 +6,7 @@ export const respath = { stage_ui_res: function func(): string { return config.H_SCREEN ? "resources/Stage_H.lh" : "resources/Stage.lh" - }, + }, gamepause_ui_res: function func(): string { return config.H_SCREEN ? "resources/GamePause_H.lh" : "resources/GamePause.lh" @@ -18,8 +17,7 @@ export const respath = { gamedone_ui_res: function func(isClassic: boolean): string { if (isClassic) { return config.H_SCREEN ? "resources/GameDone_Normal_H.lh" : "resources/GameDone_Normal.lh" - } - else { + } else { return config.H_SCREEN ? "resources/GameDone_DC_H.lh" : "resources/GameDone_DC.lh" } }, @@ -27,7 +25,7 @@ export const respath = { score_add_ui_res: function func(): string { return config.H_SCREEN ? "resources/ScoreAdd_H.lh" : "resources/ScoreAdd.lh" }, - + common_tips_ui_res: "resources/CommonTips.lh", difficulty_ui_res: "resources/Difficulty.lh", @@ -50,16 +48,15 @@ export const respath = { return config.H_SCREEN ? "resources/dc/TrophyRoomCell_H.lh" : "resources/dc/TrophyRoomCell.lh" }, - //=============================== + // =============================== home_top_dc_bg_normal: "atlas/images/bg_dc_top1.png", home_top_dc_bg_finish: "atlas/images/bg_dc_top2.png", dc_top_bg_normal: "atlas/images/img_dc_bg2.png", dc_top_bg_month_finish: "atlas/images/img_dc_finished.png", - trophy_bg_light_gold: "atlas/trophys/img_trophy_bg_light_gold.png", trophy_bg_light_grey: "atlas/trophys/img_trophy_bg_light_gray.png", - + trophy_01: "atlas/trophys/trophy_01.png", trophy_02: "atlas/trophys/trophy_02.png", trophy_03: "atlas/trophys/trophy_03.png", @@ -71,6 +68,5 @@ export const respath = { trophy_09: "atlas/trophys/trophy_09.png", trophy_10: "atlas/trophys/trophy_10.png", trophy_11: "atlas/trophys/trophy_11.png", - trophy_12: "atlas/trophys/trophy_12.png", + trophy_12: "atlas/trophys/trophy_12.png" } - diff --git a/src/models/DCManager.ts b/src/models/DCManager.ts index 34b17ef..f5f2959 100644 --- a/src/models/DCManager.ts +++ b/src/models/DCManager.ts @@ -1,43 +1,38 @@ - - - import { respath } from "../constants/respath" - export const MONTH_LIST = [ - {year: 2024, month: 12, begin: 0, dayCount: 31, icon_res: respath.trophy_12}, + { year: 2024, month: 12, begin: 0, dayCount: 31, icon_res: respath.trophy_12 }, - {year: 2025, month: 1, begin: 3, dayCount: 31, icon_res: respath.trophy_01}, - {year: 2025, month: 2, begin: 6, dayCount: 30, icon_res: respath.trophy_02}, - {year: 2025, month: 3, begin: 6, dayCount: 31, icon_res: respath.trophy_03}, - {year: 2025, month: 4, begin: 2, dayCount: 30, icon_res: respath.trophy_04}, - {year: 2025, month: 5, begin: 4, dayCount: 31, icon_res: respath.trophy_05}, - {year: 2025, month: 6, begin: 0, dayCount: 30, icon_res: respath.trophy_06}, - {year: 2025, month: 7, begin: 2, dayCount: 31, icon_res: respath.trophy_07}, - {year: 2025, month: 8, begin: 5, dayCount: 31, icon_res: respath.trophy_08}, - {year: 2025, month: 9, begin: 1, dayCount: 30, icon_res: respath.trophy_09}, - {year: 2025, month: 10, begin: 3, dayCount: 31, icon_res: respath.trophy_10}, - {year: 2025, month: 11, begin: 6, dayCount: 30, icon_res: respath.trophy_11}, - {year: 2025, month: 12, begin: 1, dayCount: 31, icon_res: respath.trophy_12}, + { year: 2025, month: 1, begin: 3, dayCount: 31, icon_res: respath.trophy_01 }, + { year: 2025, month: 2, begin: 6, dayCount: 30, icon_res: respath.trophy_02 }, + { year: 2025, month: 3, begin: 6, dayCount: 31, icon_res: respath.trophy_03 }, + { year: 2025, month: 4, begin: 2, dayCount: 30, icon_res: respath.trophy_04 }, + { year: 2025, month: 5, begin: 4, dayCount: 31, icon_res: respath.trophy_05 }, + { year: 2025, month: 6, begin: 0, dayCount: 30, icon_res: respath.trophy_06 }, + { year: 2025, month: 7, begin: 2, dayCount: 31, icon_res: respath.trophy_07 }, + { year: 2025, month: 8, begin: 5, dayCount: 31, icon_res: respath.trophy_08 }, + { year: 2025, month: 9, begin: 1, dayCount: 30, icon_res: respath.trophy_09 }, + { year: 2025, month: 10, begin: 3, dayCount: 31, icon_res: respath.trophy_10 }, + { year: 2025, month: 11, begin: 6, dayCount: 30, icon_res: respath.trophy_11 }, + { year: 2025, month: 12, begin: 1, dayCount: 31, icon_res: respath.trophy_12 }, - {year: 2026, month: 1, begin: 4, dayCount: 31, icon_res: respath.trophy_01}, - {year: 2026, month: 2, begin: 0, dayCount: 30, icon_res: respath.trophy_02}, - {year: 2026, month: 3, begin: 0, dayCount: 31, icon_res: respath.trophy_03}, - {year: 2026, month: 4, begin: 3, dayCount: 30, icon_res: respath.trophy_04}, - {year: 2026, month: 5, begin: 5, dayCount: 31, icon_res: respath.trophy_05}, - {year: 2026, month: 6, begin: 1, dayCount: 30, icon_res: respath.trophy_06}, - {year: 2026, month: 7, begin: 3, dayCount: 31, icon_res: respath.trophy_07}, - {year: 2026, month: 8, begin: 6, dayCount: 31, icon_res: respath.trophy_08}, - {year: 2026, month: 9, begin: 2, dayCount: 30, icon_res: respath.trophy_09}, - {year: 2026, month: 10, begin: 4, dayCount: 31, icon_res: respath.trophy_10}, - {year: 2026, month: 11, begin: 0, dayCount: 30, icon_res: respath.trophy_11}, - {year: 2026, month: 12, begin: 2, dayCount: 31, icon_res: respath.trophy_12}, + { year: 2026, month: 1, begin: 4, dayCount: 31, icon_res: respath.trophy_01 }, + { year: 2026, month: 2, begin: 0, dayCount: 30, icon_res: respath.trophy_02 }, + { year: 2026, month: 3, begin: 0, dayCount: 31, icon_res: respath.trophy_03 }, + { year: 2026, month: 4, begin: 3, dayCount: 30, icon_res: respath.trophy_04 }, + { year: 2026, month: 5, begin: 5, dayCount: 31, icon_res: respath.trophy_05 }, + { year: 2026, month: 6, begin: 1, dayCount: 30, icon_res: respath.trophy_06 }, + { year: 2026, month: 7, begin: 3, dayCount: 31, icon_res: respath.trophy_07 }, + { year: 2026, month: 8, begin: 6, dayCount: 31, icon_res: respath.trophy_08 }, + { year: 2026, month: 9, begin: 2, dayCount: 30, icon_res: respath.trophy_09 }, + { year: 2026, month: 10, begin: 4, dayCount: 31, icon_res: respath.trophy_10 }, + { year: 2026, month: 11, begin: 0, dayCount: 30, icon_res: respath.trophy_11 }, + { year: 2026, month: 12, begin: 2, dayCount: 31, icon_res: respath.trophy_12 } ] - export function G_getMonthInfo(year: number, month: number): any { - for (var i=0; i { - return this.data.notes - } - public add_note(noteNumber: number): void { - if (this.data.notes.indexOf(noteNumber) < 0) { - this.data.notes.push(noteNumber) - StorageManager.getInstance().onStageChanged() - } - } - public remove_note(noteNumber: number): void { - var find = this.data.notes.indexOf(noteNumber) - if (find >= 0) { - this.data.notes.splice(find, 1) - StorageManager.getInstance().onStageChanged() - } - } - public clean_notes(): void { - if (this.data.notes.length > 0) { - this.data.notes = new Array() - StorageManager.getInstance().onStageChanged() - } - } - //====================================持久化数据 + public set_score(score: number): void { + this.data.score = score + StorageManager.getInstance().onStageChanged() + } - public get_preset(): boolean { - return this.preset + public get_notes(): Array { + return this.data.notes + } + + public add_note(noteNumber: number): void { + if (!this.data.notes.includes(noteNumber)) { + this.data.notes.push(noteNumber) + StorageManager.getInstance().onStageChanged() } + } - public get_correct(): number { - return this.correct + public remove_note(noteNumber: number): void { + const find = this.data.notes.indexOf(noteNumber) + if (find >= 0) { + this.data.notes.splice(find, 1) + StorageManager.getInstance().onStageChanged() } + } - public get_checked(): boolean { - return this.checked + public clean_notes(): void { + if (this.data.notes.length > 0) { + this.data.notes = [] + StorageManager.getInstance().onStageChanged() } + } + // ====================================持久化数据 + public get_preset(): boolean { + return this.preset + } + public get_correct(): number { + return this.correct + } -} \ No newline at end of file + public get_checked(): boolean { + return this.checked + } +} diff --git a/src/models/DOCandy.ts b/src/models/DOCandy.ts index 50efeea..7f14d4b 100644 --- a/src/models/DOCandy.ts +++ b/src/models/DOCandy.ts @@ -1,28 +1,21 @@ - - - - export class DOCandy { + private show: number + private left: number - private show: number - private left: number + constructor(show: number, left: number) { + this.show = show + this.left = left + } - constructor(show: number, left: number) { - this.show = show - this.left = left - } + public get_show(): number { + return this.show + } - public get_show(): number { - return this.show - } + public get_left(): number { + return this.left + } - public get_left(): number { - return this.left - } - public set_left(left: number): void { - this.left = left - } - - - -} \ No newline at end of file + public set_left(left: number): void { + this.left = left + } +} diff --git a/src/models/DOStage.ts b/src/models/DOStage.ts index 1ceb245..e141fd2 100644 --- a/src/models/DOStage.ts +++ b/src/models/DOStage.ts @@ -1,190 +1,197 @@ - - -import { StorageManager } from "./StorageManager" +import type { DataBlock, DataStage, DataUndo } from "../types/global" import { DOBlock } from "./DOBlock" -import { DataBlock, DataUndo, DataStage } from "../types/global" import { LevelManager } from "./LevelManager" - +import { StorageManager } from "./StorageManager" export class DOStage { + private data: DataStage + private blocks: Array = [] - private data: DataStage - private blocks: Array = new Array() + private letterToNumber: Map + private numberToLetter: Map - private letterToNumber: Map; - private numberToLetter: Map; + constructor(dataStage: DataStage) { + this.data = dataStage - constructor(dataStage: DataStage) { - this.data = dataStage + this.letterToNumber = new Map() + this.letterToNumber.set("A", 1) + this.letterToNumber.set("B", 2) + this.letterToNumber.set("C", 3) + this.letterToNumber.set("D", 4) + this.letterToNumber.set("E", 5) + this.letterToNumber.set("F", 6) + this.letterToNumber.set("G", 7) + this.letterToNumber.set("H", 8) + this.letterToNumber.set("I", 9) - this.letterToNumber = new Map(); - this.letterToNumber.set("A", 1); - this.letterToNumber.set("B", 2); - this.letterToNumber.set("C", 3); - this.letterToNumber.set("D", 4); - this.letterToNumber.set("E", 5); - this.letterToNumber.set("F", 6); - this.letterToNumber.set("G", 7); - this.letterToNumber.set("H", 8); - this.letterToNumber.set("I", 9); + this.numberToLetter = new Map() + this.numberToLetter.set(1, "a") + this.numberToLetter.set(2, "b") + this.numberToLetter.set(3, "c") + this.numberToLetter.set(4, "d") + this.numberToLetter.set(5, "e") + this.numberToLetter.set(6, "f") + this.numberToLetter.set(7, "g") + this.numberToLetter.set(8, "h") + this.numberToLetter.set(9, "i") - this.numberToLetter = new Map(); - this.numberToLetter.set(1, "a"); - this.numberToLetter.set(2, "b"); - this.numberToLetter.set(3, "c"); - this.numberToLetter.set(4, "d"); - this.numberToLetter.set(5, "e"); - this.numberToLetter.set(6, "f"); - this.numberToLetter.set(7, "g"); - this.numberToLetter.set(8, "h"); - this.numberToLetter.set(9, "i"); + const blockMap: Map = new Map() + for (var i = 0; i < this.data.blocks.length; i++) { + var dataBlock = this.data.blocks[i] + blockMap.set(dataBlock.index, dataBlock) + } - var blockMap: Map = new Map() - for (var i=0; i { - return this.data.undos - } - public add_undo(index: number, show: number=0, notes: Array=new Array()): void { - var _notes: Array - if (notes) { - _notes = new Array() - for (var i=0; i>>>>>>>>>>>>>>>>>>>>>>>>>>>", JSON.stringify(dataUndo)) - this.data.undos.push(dataUndo) - StorageManager.getInstance().onStageChanged() - } - public pop_undo(): DataUndo { - var dataUndo: DataUndo - if (this.data.undos.length > 0) { - dataUndo = this.data.undos[this.data.undos.length-1] - this.data.undos.splice(this.data.undos.length-1, 1) - StorageManager.getInstance().onStageChanged() - } - return dataUndo - } - //====================================持久化数据 + public set_score(score: number): void { + this.data.score = score + StorageManager.getInstance().onStageChanged() + } - public get_blocks(): Array { - return this.blocks + public get_duration(): number { + return this.data.duration + } + + public set_duration(duration: number): void { // 关卡计时 + this.data.duration = duration + StorageManager.getInstance().onStageChanged() + } + + public get_last_hit_time(): number { + return this.data.last_hit_time + } + + public set_last_hit_time(last_hit_time: number): void { + this.data.last_hit_time = last_hit_time + StorageManager.getInstance().onStageChanged() + } + + public get_note_open(): boolean { + return this.data.note_open + } + + public set_note_open(note_open: boolean): void { + this.data.note_open = note_open + StorageManager.getInstance().onStageChanged() + } + + public get_select_index(): number { + return this.data.select_index + } + + public set_select_index(select_index: number): void { // 当前选中 + this.data.select_index = select_index + StorageManager.getInstance().onStageChanged() + } + + public get_hint(): number { + return this.data.hint + } + + public set_hint(hint: number): void { // 提示 + this.data.hint = hint + StorageManager.getInstance().onStageChanged() + } + + public get_undos(): Array { + return this.data.undos + } + + public add_undo(index: number, show: number = 0, notes: Array = []): void { + let _notes: Array + if (notes) { + _notes = [] + for (let i = 0; i < notes.length; i++) + _notes.push(notes[i]) } -} \ No newline at end of file + const dataUndo: DataUndo = { index, show, notes: _notes } + console.log("add_undo >>>>>>>>>>>>>>>>>>>>>>>>>>>>", JSON.stringify(dataUndo)) + this.data.undos.push(dataUndo) + StorageManager.getInstance().onStageChanged() + } + + public pop_undo(): DataUndo { + let dataUndo: DataUndo + if (this.data.undos.length > 0) { + dataUndo = this.data.undos[this.data.undos.length - 1] + this.data.undos.splice(this.data.undos.length - 1, 1) + StorageManager.getInstance().onStageChanged() + } + return dataUndo + } + // ====================================持久化数据 + + public get_blocks(): Array { + return this.blocks + } +} diff --git a/src/models/DOUser.ts b/src/models/DOUser.ts index cdee901..5349723 100644 --- a/src/models/DOUser.ts +++ b/src/models/DOUser.ts @@ -1,171 +1,177 @@ -import { DataProgress, DataUser, StageProgress, TrophyRecord } from "../types/global"; +import type { DataProgress, DataUser, StageProgress, TrophyRecord } from "../types/global" import { StorageManager } from "./StorageManager" - export class DOUser { + private data: DataUser + private mapDones: Map = new Map() - private data: DataUser - private mapDones: Map = new Map() + constructor(dataUser: DataUser) { + this.data = dataUser + for (let i = 0; i < this.data.dones.length; i++) { + const obj = this.data.dones[i] + this.mapDones.set(obj.stageID, obj.progress) + } + } - constructor(dataUser: DataUser) { - this.data = dataUser - for (var i=0; i{ - if (stageID.startsWith(key) && progres >= 1) { - count ++ - } - }) - return count - } - public get_isAllDoneByDate(year: number, month: number): boolean { - var boolean = true - var key = `${year}-${month}` - this.mapDones.forEach((progres: number, stageID: string)=>{ - if (stageID.startsWith(key) && progres < 1) { - boolean = false - } - }) - return boolean - } - public update_stage_done(stageID: string, progress: number): void { - var find: StageProgress - for (var i=0; i { + if (stageID.startsWith(key) && progres >= 1) { + count++ + } + }) + return count + } - //=======关卡难度进度 - public get_progress(difficulty: string): number { - var find: DataProgress - for (var i=0; i { + if (stageID.startsWith(key) && progres < 1) { + boolean = false + } + }) + return boolean + } - //====================================持久化数据 -} \ No newline at end of file + public update_stage_done(stageID: string, progress: number): void { + let find: StageProgress + for (let i = 0; i < this.data.dones.length; i++) { + const obj = this.data.dones[i] + if (obj.stageID == stageID) { + find = obj + break + } + } + if (find) { + find.progress = progress + } else { + find = { stageID, progress } + this.data.dones.push(find) + } + this.mapDones.set(find.stageID, find.progress) + StorageManager.getInstance().onUserChanged() + } + + // ================奖杯获得记录 + public get_trophyRecord(year: number, month: number): TrophyRecord { + let find: TrophyRecord + for (let i = 0; i < this.data.trophy_records.length; i++) { + const obj = this.data.trophy_records[i] + if (obj.year == year && obj.month == month) { + find = obj + break + } + } + return find + } + + public get_trophyHasNew(): TrophyRecord { + let find: TrophyRecord + for (let i = 0; i < this.data.trophy_records.length; i++) { + const obj = this.data.trophy_records[i] + if (obj.isNew) { + find = obj + break + } + } + return find + } + + public set_trophyNew(record: TrophyRecord, isNew: boolean): void { + if (record.isNew != isNew) { + record.isNew = isNew + StorageManager.getInstance().onUserChanged() + } + } + + public get_trophyHasUnread(): boolean { + let unread = false + for (let i = 0; i < this.data.trophy_records.length; i++) { + const obj = this.data.trophy_records[i] + if (obj.read == false) { + unread = true + break + } + } + return unread + } + + public set_trophyAllread(): void { + let changed = false + for (let i = 0; i < this.data.trophy_records.length; i++) { + const obj = this.data.trophy_records[i] + if (obj.read == false) { + obj.read = true + changed = true + } + } + if (changed) { + StorageManager.getInstance().onUserChanged() + } + } + + public add_trophy_record(year: number, month: number, day: number): void { + let find + for (let i = 0; i < this.data.trophy_records.length; i++) { + const obj = this.data.trophy_records[i] + if (obj.year == year && obj.month == month) { + find = obj + break + } + } + if (!find) { + this.data.trophy_records.push({ year, month, day, isNew: true, read: false }) + StorageManager.getInstance().onUserChanged() + } + } + + // =======关卡难度进度 + public get_progress(difficulty: string): number { + let find: DataProgress + for (let i = 0; i < this.data.progresses.length; i++) { + const obj = this.data.progresses[i] + if (obj.difficulty == difficulty) { + find = obj + break + } + } + if (find) { + return find.index + } + return 0 + } + + public update_progress(difficulty: string, index: number): void { + let find: DataProgress + for (let i = 0; i < this.data.progresses.length; i++) { + const obj = this.data.progresses[i] + if (obj.difficulty == difficulty) { + find = obj + break + } + } + if (find) { + find.index = index + } else { + find = { difficulty, index } + this.data.progresses.push(find) + } + StorageManager.getInstance().onUserChanged() + } + + // ====================================持久化数据 +} diff --git a/src/models/EventManager.ts b/src/models/EventManager.ts index d103360..49d2fe4 100644 --- a/src/models/EventManager.ts +++ b/src/models/EventManager.ts @@ -1,53 +1,48 @@ - - - export const EVENT_TYPES = { - NOT_UPDATE_MISTAKE: "NOT_UPDATE_MISTAKE",//更新分数 - NOT_UPDATE_PAUSE: "NOT_UPDATE_PAUSE",//更新暂停状态 + NOT_UPDATE_MISTAKE: "NOT_UPDATE_MISTAKE", // 更新分数 + NOT_UPDATE_PAUSE: "NOT_UPDATE_PAUSE", // 更新暂停状态 - NOT_SET_TROPHY_BUTTON: "NOT_SET_TROPHY_BUTTON", + NOT_SET_TROPHY_BUTTON: "NOT_SET_TROPHY_BUTTON" } - export class EventManager { - - private static instance: EventManager - public static getInstance(): EventManager { - if (!EventManager.instance) { - EventManager.instance = new EventManager() - } - return EventManager.instance + private static instance: EventManager + public static getInstance(): EventManager { + if (!EventManager.instance) { + EventManager.instance = new EventManager() } + return EventManager.instance + } - private listeners: Map> = new Map() + private listeners: Map> = new Map() - public RegisterEvent(eventID: string, func: any): void { - if (this.listeners.has(eventID) == false) { - this.listeners.set(eventID, new Array()) - } - var list: Array = this.listeners.get(eventID) - var find = list.indexOf(func) - if (find < 0) { - list.push(func) - } + public RegisterEvent(eventID: string, func: any): void { + if (this.listeners.has(eventID) == false) { + this.listeners.set(eventID, []) } - - public UnregisterEvent(eventID: string, func: any): void { - if (this.listeners.has(eventID)) { - var list: Array = this.listeners.get(eventID) - var find = list.indexOf(func) - if (find >= 0) { - list.splice(find, 1) - } - } + const list: Array = this.listeners.get(eventID) + const find = list.indexOf(func) + if (find < 0) { + list.push(func) } + } - public DispatchEvent(eventID: string, arg: any=null): void { - if (this.listeners.has(eventID)) { - var list: Array = this.listeners.get(eventID) - for (var i=0; i = this.listeners.get(eventID) + const find = list.indexOf(func) + if (find >= 0) { + list.splice(find, 1) + } } -} \ No newline at end of file + } + + public DispatchEvent(eventID: string, arg: any = null): void { + if (this.listeners.has(eventID)) { + const list: Array = this.listeners.get(eventID) + for (let i = 0; i < list.length; i++) { + list[i](arg) + } + } + } +} diff --git a/src/models/LevelManager.ts b/src/models/LevelManager.ts index d0bc73f..5e7a291 100644 --- a/src/models/LevelManager.ts +++ b/src/models/LevelManager.ts @@ -1,157 +1,153 @@ import { config } from "../constants/config" - - const Easy = [ - "aBCeIGFhdEDFcAHBGIhigBdfecAgHDiFBCaeBEAGHCIdffcIdEAHbgcABfGEdiHIFHaCDGEBDGEHbiaFC", - "abecfIgdhdICGhbAFEHGfeAdIcBCFAbigEHDGDhFeABICIEbHdCFGAFaGDBHcEIbCDIGehAFeHIaCFdbG", - "AbIGdeHFCHFDbCieaGgEcfaHbDIEiAdBFGcHFHGcEAIBddCBHIGFEaCdfiGBAHEbgeAHCDIfIaHefdCgB", - "ACEdBIGHFBHGFacDEIdiFheGAbCcEiBdFHaGhfBGIAecDGadcHeIfBIgCaFHbDEFdAegbcIHEBHICDfGa", - "acEIhbgFDFIDAgEBHCBGHfCdeaIDEaBFgicHcFGHAidebIHbDecaGFeBFCIAHdGGDCebHfIAHAiGdfCBE", - "aCfDbGHIEGHBIcEFdaedIAFhbCGDFahGiebCHbecaDIGFiGCbEFdAHBEHGIcAfDFiGedACHBCAdFHBgei", - "ACGBfIHDeHEBCdgFAIfdIHaegcBDgEAHCIBFIbhFEdaGCcAFGIbDEHgIDebHcfabHADcFEiGEfcigABHd", - "AcGFdihBEdHEbGCAifBFIEhaGDCEgADIBfcHhibGcfDEaFDChaEigbGBHCFdEAIIEdabHCFGcAfIEGbHD", - "ACGIFbEhdbFEDGhaCIIHDCAEBGFFAIHBDceggdbecfIahHEcAIGdFBeIHFDAGBcdGFbeCHIacbAgHifdE", + "aBCeIGFhdEDFcAHBGIhigBdfecAgHDiFBCaeBEAGHCIdffcIdEAHbgcABfGEdiHIFHaCDGEBDGEHbiaFC", + "abecfIgdhdICGhbAFEHGfeAdIcBCFAbigEHDGDhFeABICIEbHdCFGAFaGDBHcEIbCDIGehAFeHIaCFdbG", + "AbIGdeHFCHFDbCieaGgEcfaHbDIEiAdBFGcHFHGcEAIBddCBHIGFEaCdfiGBAHEbgeAHCDIfIaHefdCgB", + "ACEdBIGHFBHGFacDEIdiFheGAbCcEiBdFHaGhfBGIAecDGadcHeIfBIgCaFHbDEFdAegbcIHEBHICDfGa", + "acEIhbgFDFIDAgEBHCBGHfCdeaIDEaBFgicHcFGHAidebIHbDecaGFeBFCIAHdGGDCebHfIAHAiGdfCBE", + "aCfDbGHIEGHBIcEFdaedIAFhbCGDFahGiebCHbecaDIGFiGCbEFdAHBEHGIcAfDFiGedACHBCAdFHBgei", + "ACGBfIHDeHEBCdgFAIfdIHaegcBDgEAHCIBFIbhFEdaGCcAFGIbDEHgIDebHcfabHADcFEiGEfcigABHd", + "AcGFdihBEdHEbGCAifBFIEhaGDCEgADIBfcHhibGcfDEaFDChaEigbGBHCFdEAIIEdabHCFGcAfIEGbHD", + "ACGIFbEhdbFEDGhaCIIHDCAEBGFFAIHBDceggdbecfIahHEcAIGdFBeIHFDAGBcdGFbeCHIacbAgHifdE" ] const Medium = [ - "achEDIBFGgeIHbFaDCFDBaCGHeIbHaceDGiFCIFGHBeadeGDIFAChbDAGbIeFCHhfEdGCIbaiBcFAhdGE", - "ADBeIGhFCGhCDFabiefiECHBgDACGDbaFieHEBIHGCFADhFAIedCbGdAFGbheCIbEhaciDGFIcGFDeaHb", - "aDBIEcHFGEGHbDFcaiIFCAGHeDbgHdEIafBCCIaHFbdGeBefGcdIHADCGFbeAIHhbedAIGcFFaIcHgBEd", - "AdEGCHfibHGbefIacdCIFABdehgICgHDAbFefahbecDgIEBDIGFCAHbeICAGHDFGFCDheIbADHAFIBGec", - "ADeIBFgHCIHFcgabdebGCeDhaIfHfaDeIcGbgIBFacHEdECdBHGFaiFBHAIEDcGDeGHcBiFaCAIgFDEBH", - "aDFIEHbcGciHaGbFDEeGBcdFHIAbeadhCgfIGHIfBEcAdFCdGAIeHBDAeHcgibFHFGbIDaECIBcEFADGh", - "aDgEICFBHHCFdGBAeIIEBFHacdgcAEgBIdhFDGhCFEiabBFIADHEGCGbciaDHfEEHdbcFgiAFiAHeGbcd", - "adHEbCIfGegBfHIDAcIcfgDaHEBDFABIGcHEHIcdfegbaBEGcAHFdIFAdIgBeCHCbihEFAGdghEACDBIF", - "aecDbHIGFDGHCFIBEAfiBEGaHCdgAFBIedHcHCEaDFGBIbDIghCFAeibahcdeFGcHdfeGAIBefGIAbCDH", + "achEDIBFGgeIHbFaDCFDBaCGHeIbHaceDGiFCIFGHBeadeGDIFAChbDAGbIeFCHhfEdGCIbaiBcFAhdGE", + "ADBeIGhFCGhCDFabiefiECHBgDACGDbaFieHEBIHGCFADhFAIedCbGdAFGbheCIbEhaciDGFIcGFDeaHb", + "aDBIEcHFGEGHbDFcaiIFCAGHeDbgHdEIafBCCIaHFbdGeBefGcdIHADCGFbeAIHhbedAIGcFFaIcHgBEd", + "AdEGCHfibHGbefIacdCIFABdehgICgHDAbFefahbecDgIEBDIGFCAHbeICAGHDFGFCDheIbADHAFIBGec", + "ADeIBFgHCIHFcgabdebGCeDhaIfHfaDeIcGbgIBFacHEdECdBHGFaiFBHAIEDcGDeGHcBiFaCAIgFDEBH", + "aDFIEHbcGciHaGbFDEeGBcdFHIAbeadhCgfIGHIfBEcAdFCdGAIeHBDAeHcgibFHFGbIDaECIBcEFADGh", + "aDgEICFBHHCFdGBAeIIEBFHacdgcAEgBIdhFDGhCFEiabBFIADHEGCGbciaDHfEEHdbcFgiAFiAHeGbcd", + "adHEbCIfGegBfHIDAcIcfgDaHEBDFABIGcHEHIcdfegbaBEGcAHFdIFAdIgBeCHCbihEFAGdghEACDBIF", + "aecDbHIGFDGHCFIBEAfiBEGaHCdgAFBIedHcHCEaDFGBIbDIghCFAeibahcdeFGcHdfeGAIBefGIAbCDH" ] const Hard = [ - "AEdfiHgCBIFGECbahdcbHGADeIFGIFCDaBeHHDCbGEIFAeabhfICdgbCIAHFDGeFGadEcHBiDHeIBgFac", - "aEFGBihCdHcIefdGBAGdbcahIfeIBAFDcegHDHEAGBCiFFgcHIEadBeFHDCGBaicidBHAFEGbAGIeFDHC", - "AEGIdchFBFICbehgAdbHDFAGeIchdEgBaFCiGbfchIadeCAIefdbGHdfBaIeChGEGHdCFibAIcaHGbDEf", - "afbCGDehiIGhEaFCdBECDIbHAFGhEGADbfICdbifechGAFACHIGbeDgDFBHAIcEcIaDFeGBHBHegCIdaF", - "AFhIgCdEBcEGDBHAFIiDbfaeGCHhGIEcfbdafcdBIAHGEBaeHdGCIfEBACFdIHggHcAeiFbDdiFGHBEAC", - "agcfdHbEIHBDEIGCaFFiecBAhGDBEghcFIdaDHiAGbEfCCAFiEdGBHGCabfIdHeIDHgAEFCbEFBdHcAIg", - "agibdeFchcHDGIfeBAEFbHAcDIgiDCAEBGHFHBeDFGCaIFAGICHBdEgEaCBihfdbIfeHDAGCdCHFGaIeb", - "AHbIEDcGFCifgHBAdeGEDAfcIHBBdGHCEFaiIFcbdaHeGHaeFIGBCDeBAcGFdIhFGHDaieBcDcIebhGFA", - "AHEbCIGfdiBGDEFHCAdfcHGaBIEBGICfdaeHhCFEAbIdGEAdihgFbcFIAgDECHbcdBAIHegfGEHFbcdAI", - "AHECBgFdIBIGDAfhCECfDHIEagbIGHEDcBFAEBFAGichddCaBFHeigFEIgHadbChDcIeBGaFGabFcdiEH", + "AEdfiHgCBIFGECbahdcbHGADeIFGIFCDaBeHHDCbGEIFAeabhfICdgbCIAHFDGeFGadEcHBiDHeIBgFac", + "aEFGBihCdHcIefdGBAGdbcahIfeIBAFDcegHDHEAGBCiFFgcHIEadBeFHDCGBaicidBHAFEGbAGIeFDHC", + "AEGIdchFBFICbehgAdbHDFAGeIchdEgBaFCiGbfchIadeCAIefdbGHdfBaIeChGEGHdCFibAIcaHGbDEf", + "afbCGDehiIGhEaFCdBECDIbHAFGhEGADbfICdbifechGAFACHIGbeDgDFBHAIcEcIaDFeGBHBHegCIdaF", + "AFhIgCdEBcEGDBHAFIiDbfaeGCHhGIEcfbdafcdBIAHGEBaeHdGCIfEBACFdIHggHcAeiFbDdiFGHBEAC", + "agcfdHbEIHBDEIGCaFFiecBAhGDBEghcFIdaDHiAGbEfCCAFiEdGBHGCabfIdHeIDHgAEFCbEFBdHcAIg", + "agibdeFchcHDGIfeBAEFbHAcDIgiDCAEBGHFHBeDFGCaIFAGICHBdEgEaCBihfdbIfeHDAGCdCHFGaIeb", + "AHbIEDcGFCifgHBAdeGEDAfcIHBBdGHCEFaiIFcbdaHeGHaeFIGBCDeBAcGFdIhFGHDaieBcDcIebhGFA", + "AHEbCIGfdiBGDEFHCAdfcHGaBIEBGICfdaeHhCFEAbIdGEAdihgFbcFIAgDECHbcdBAIHegfGEHFbcdAI", + "AHECBgFdIBIGDAfhCECfDHIEagbIGHEDcBFAEBFAGichddCaBFHeigFEIgHadbChDcIeBGaFGabFcdiEH" ] const Expert = [ - "AHEIDCFGBiBFGaedchcdghbfIEADfHEIACBgbeADCGHfiGCibFHaDEeaBcHDGIFHIdFgBeAcFGCaeIBhD", - "AHEIFGcbDDgBacefhIFIcBdHGeACbdHIFAgehfgEAcIDbEaIGBDHFCIEAFGbdcHBDFchaeiGgCHDEIbAF", - "aIBCFDeHGcGFHaeIdbdHEIGBafCFDGahcbieBeaGDIHcFICHEBfdGAHADFEgcbIgBIdcaFEHEFCbiHGAd", - "AIBHEFDcGEFcaDGihbHDGBCIAefGHFiadEBCBCAeFHGIdIEDGBcHFaCAiFGebdhfbHdIaCgedgECHbfAi", - "aiDHBEfCGCGEFIdhBABFHCaGEdiIDGEHbcAfHABifcdgeECFgDaIHBFBaDEHGiCdECbGIafHGhiacFBed", - "aIgdfbhcEdBEHCiGFAFCHEGaBdIIFbCAGDEHcHABDeFigegdIHFCabBDiFEHAGcHACGIDEBFGefabcihd", - "AIGdFebCHBfHiaCdGEEDcgHbIaFgcBfeAHIdiHecgDfBAfaDbIhgeccbfaDIeHGhGIECFadbdeAHBGCFI", - "baDEHGIFCGIHDCfABEceFAIBgdhfdchGIEABIgAbdEHcFEHbfaCDGIABeGFhciddFiCEabhGHCgIBdFEA", - "baicHdegFHEdIFGcABGFCaebhidfbadGCIHEICEfAhBDGdGHBIeaFCAHBEDfGCICDGHBifEaeiFGCADBh", - "BaiGFcdEHdFCHEAIGBhEgbDIcfaCidFAeBHGFBACGhEIdghEDibAcfEdBIHFgAcaGHECdFBIICfabGHDe", - "bCFIGHADeHAGdFebCIDIEaBcFGHEbHGAFDIcgdCbhieFaafiCEDHBGCEBHdGIafIHAFcbgeDfgDeiACHb", - "BdaHFIEGCicHDgEafBEGFBACDIHfbDcEgIHAHAIFBdgceCeGihAbDFDIbEchFaggFCadbHEIaHEGIfcBD", - "BDCEFiGAHIHacGBeDFGEFHADIBcEIdfHACgBhCGbDEaFIFABgicdHeaFhiEgbCdDbiaChfeGCGEdbFHIa", - "bdEcFAHIGCAIegHFBDFGHBDICaEehfaBDIGCDCgiHeaFBIBAFcgedhaicgEbDHFGeDhAFbcIHFbDiCGEa", - "BEaihfcdgCFIGEDAHBgDHACBIFeFIdhaeGbcAHGcBIDEfebcdFGHAIDgeBIHFCaHCbFGAeiDIAfEdcbGH", - "BehdIcaFgCfGeAHIbdaIdfBGCheEgcIDFHAbdAFHeBGCiIHBGcaDefFCIBHdeGAHbeaGIFDCGDACfEBIH", - "BfHCEGADIIdchAFGbeGaEiBdCHFFBigCADEHHEGBdIfaCDCafhEiGBeGFDIHbCacHdaFBEiGaIbegcHFd", + "AHEIDCFGBiBFGaedchcdghbfIEADfHEIACBgbeADCGHfiGCibFHaDEeaBcHDGIFHIdFgBeAcFGCaeIBhD", + "AHEIFGcbDDgBacefhIFIcBdHGeACbdHIFAgehfgEAcIDbEaIGBDHFCIEAFGbdcHBDFchaeiGgCHDEIbAF", + "aIBCFDeHGcGFHaeIdbdHEIGBafCFDGahcbieBeaGDIHcFICHEBfdGAHADFEgcbIgBIdcaFEHEFCbiHGAd", + "AIBHEFDcGEFcaDGihbHDGBCIAefGHFiadEBCBCAeFHGIdIEDGBcHFaCAiFGebdhfbHdIaCgedgECHbfAi", + "aiDHBEfCGCGEFIdhBABFHCaGEdiIDGEHbcAfHABifcdgeECFgDaIHBFBaDEHGiCdECbGIafHGhiacFBed", + "aIgdfbhcEdBEHCiGFAFCHEGaBdIIFbCAGDEHcHABDeFigegdIHFCabBDiFEHAGcHACGIDEBFGefabcihd", + "AIGdFebCHBfHiaCdGEEDcgHbIaFgcBfeAHIdiHecgDfBAfaDbIhgeccbfaDIeHGhGIECFadbdeAHBGCFI", + "baDEHGIFCGIHDCfABEceFAIBgdhfdchGIEABIgAbdEHcFEHbfaCDGIABeGFhciddFiCEabhGHCgIBdFEA", + "baicHdegFHEdIFGcABGFCaebhidfbadGCIHEICEfAhBDGdGHBIeaFCAHBEDfGCICDGHBifEaeiFGCADBh", + "BaiGFcdEHdFCHEAIGBhEgbDIcfaCidFAeBHGFBACGhEIdghEDibAcfEdBIHFgAcaGHECdFBIICfabGHDe", + "bCFIGHADeHAGdFebCIDIEaBcFGHEbHGAFDIcgdCbhieFaafiCEDHBGCEBHdGIafIHAFcbgeDfgDeiACHb", + "BdaHFIEGCicHDgEafBEGFBACDIHfbDcEgIHAHAIFBdgceCeGihAbDFDIbEchFaggFCadbHEIaHEGIfcBD", + "BDCEFiGAHIHacGBeDFGEFHADIBcEIdfHACgBhCGbDEaFIFABgicdHeaFhiEgbCdDbiaChfeGCGEdbFHIa", + "bdEcFAHIGCAIegHFBDFGHBDICaEehfaBDIGCDCgiHeaFBIBAFcgedhaicgEbDHFGeDhAFbcIHFbDiCGEa", + "BEaihfcdgCFIGEDAHBgDHACBIFeFIdhaeGbcAHGcBIDEfebcdFGHAIDgeBIHFCaHCbFGAeiDIAfEdcbGH", + "BehdIcaFgCfGeAHIbdaIdfBGCheEgcIDFHAbdAFHeBGCiIHBGcaDefFCIBHdeGAHbeaGIFDCGDACfEBIH", + "BfHCEGADIIdchAFGbeGaEiBdCHFFBigCADEHHEGBdIfaCDCafhEiGBeGFDIHbCacHdaFBEiGaIbegcHFd" ] const Extreme = [ - "BGDiEAfchahcFBDIGEEIFhgCDabFAHGibedcDEGACHbIFCbIEdfGHagDACfEHBihFBDAIcegICEbHGaFd", - "BGFAIHDCEDHicegBAfEACFDbIGHidhbCEgFAaEGIhfcDBFCbgadeHIHIedGafBCcbdhFiAEGGFAEbcHID", - "BGFHIAdECaiCdBEFGHhDeFcgbaiGFBeAICHdICAGdHEFbdeHCFBGIAFhIBGDACEeBGaHcIDfcadiefhbg", - "BhAcGEIDFIGdBaFCHefeCHiDGbaeaBFcIdGHcDGEHAFIBhifgdBEACAcIDFHbEGGbHIEcaFDdFeabGhcI", - "BHeadfiCGICAgbHDEFdFgIEcHabgEHdFabICcadBHIfGEFBICGEAdHeiBFAGcHdHdCeIBGfAaGfHcDEBI", - "BHFcEdgaigIDAfbEHcCEaIGHBfDdfIGHCAeBhCBeIADGFAGedbFcihFdHBaGIceIacfDEHBGEbGHCIFdA", - "biADChGFEEHFIagbDCcGDBFEAHIIaeFHDCGBFBHgIcdEadcGebAhIFHfBAGIECDgDICEbFahaechdFibg", - "bICEGDHFAHFeaICdbGaDGbFHEcIEadfcgIHbFGHIbECAdICBhdAfGEcHiDAbgefGBFceiadhDEAGHFBIC", - "bieDFaGHcgcaeHiDbFHfDGcBiAECHIBgEFdaDGBHafEciAEFIDcbghFBcaIdheGIdHCEGAFBEAGFBHCID", - "BIFCAdhGeDhAEbgFCICEgFHiBDaFBEGDAIHCADHicBEfggciHFeDabHGDBicaefiacdeFGbHEFBaGHCID", - "bihCGEADfFAGIbDchEedCfahbigCFDEIGHbaIbEHdaFGCHGaBCfIEdGcFdHbeAIAEBGFIDcHdhIAEcGFB", - "CaBhedgfiidHcFGAEbEFGbiahCDAEIGDbFHcFGdIhcebahBCFaEDiGDHAECIBGFbCEdGFIAHGIfaBhCDE", - "cbFDEGiAHGIacFHdebdeHibAgFcfdIBCehGABHgAIFECdACEgHdfBIIGbFDCahEeAdHGBCIFHfceAIBDG", - "cbgHEaFdIaIdcbfGEHEHFigDBACbFEAIHdCGhcAEDGIBFDGIBFCehaGDCFABHIEiabGHecfdFehdcIaGB", - "CbhdAEIGfaEFgibCdhIGDHCFBEafDEBHaGICGibcfdhAehcAIeGFbddFIEbHAcGEHCagIDFBBAGfDCEHI", - "CDabGEHIFeFhIaCGDbbgIHdFcAEAcEGhbifdGIbCFdaEHdHfaEiBGciaDFCHEbghEgDbafCIFbceiGDha", - "cdgeAIBfhhbFDCgIAeAiEHbFcDGBFICGEdHAdGhBFaECIeACIdHGbfIedFHcagBGhbaEdficfCagiBHed", - "cDgIbFEAHehbdGaFICiafecHgDBACIGEBhfdgbdfhiCeAHFECAdbGIBIHAFedcgfGABdCIheDechIGabF", - "CEBIAFHGDIhAdEgbcfgFdCbheaIFGHACIDEbeBCGFdIhADaIbHEcFgBIEFGcAdHHdGEiaFbcAcFHDBgie", - "cEHGfdIABFIgCAbhedAbDeIHcGfeABFcGdHIHDFBEIACGigChdafbEbFaDHEgIcGCIAbfeDHDHeIGcBFA", - "ceIBaDGfhHaGcfiDEbBdFhGEIaCAHbFICEgDGiCdEahbFEfDGhbACIfbhEDGcIAiCeabHFdgdgaIcFBhe", - "CeiBaGHDfADGfeHIBCbFHidcegAdHCeFagIBIGECHBAFDFBAgIdcHEEaFHBIDcGgidacfBEHHCBdGefaI", - "cEIDAGFHbgDBEFhICAFHAIBCeGdbGFhIeadCACDBGFHIehIecDAGBFdacGEiBfHIfHAcbDEgEbgfhdCai", - "CFeabGHIDGBdHEIfcaihACDFBegEGIBadcHFbDcGFHEAIHAFEICgDBAcGihbDFEFIHdgeabcdebfCAIGH", - "CFEIAdbgHaHicbgDeFGDBEFhcIAeGHADCIfBIcFghbAdEBADFIEhcGFbcHGIeaDHEADCFGbidigBEaFHc", - "CGaBfHIdEHEiacDFBGDbFIgEHcaadcFBgEIHfhECDIGaBBiGHEadFcgCdEIBAHFiAbgHfCEdEFHdacBGI", - "CGhAIbfEDFAIEdhcBgDEBCGfHaIIDgbheACFHFcDaIbgeebAGFcIDHGCFibdEHABHDFEaGicaIeHcgDFB", - "cHbEFDGAIAdIcgBEFHegfhIAcbDHACbDGfieIbEACFDHgGFdIheACBBCaGEHidfdEhfaIBGcFIGDbCHEa", - "cidGHEBFAFaeBDcIGHbHgAFIECdgeIHafdbcAdfecbHIGHbCDIGAEFEFaCBHgDIDCbIGaFheighFEDCAB", - "cIFDHAEbgebHgicAfdaGDEFbhCIBDacGFIEHFHIABEGDCgcehdIFABdeGBAHCIFhfciEdbgAIABFCGDhe", - "CIFeBahdGHGDIcFebabaegDHIcfdhAbEcFGiIfcaHgdEbEBGDFIcAHFcbhaEgidaEIfGDBhCGdHciBAFE", - "DAeFBIHGcFiCHGeBadhGBadCFeIabgIHDECFIEDGCFabhChFBEAdIGbcadfGIHEEdhCiBgFAGfiEAHCdb", - "dafibcGHEHIEFdgcbaBCGAHEDIfeHcDgbfaIGBAHIFECDIFdEcAHGbaGBceDIfHFehGaIBdCCdIBfHAEG", - "DaFIcbHgebeHGDFAiccgiEAHDFBEBcAHgFDIGHdCfibEaIFabEdGcHHIGfBeCAdFCbDIAehGAdEHGcIBF", - "DaibFEGHCGHECIDaBFcFbGHaIDeHiAedbFcGEgFicHBAdBCDAgFheIIEHdAGcfBFDchBIEGAabgFecDiH", - "DaIbGFHeCFChaiebdGGeBdCHIFaCbGFADEHIHFAIEbGCdIDEcHgAbFBGcHDafiEEIFGbcdahahdEFiCGB", - "dAIcebGFHgBEHFaCiDhcFdgIAbeIDBFaGeHcCeAIDHFgBfGhBcEIdABFgAHCDEIAHdeIFBcGeICGbDhaf", - "dbFECIAgHIGaFDHBCeHEcAGbDiFFDBgheiacECGIAFHBDaIHDbceFGcHEbfaGDibfdHIGCEAgaiCEDFhb", - "DbgiCFaehcaehbdIGFHIfAEGCBDgfCeIHDABIHAbDCGFEEdbFGAhCIBEDcaiFHGaGHDfBEIcFciGhEbdA", - "DEbfcgaHIFaIHDbCegcHGaiEFbDAfebhdIGcidCEGABFHgBHcFIdAEhgfibceDaeIdGafHcBBCaDEhGIF", - "dEGHAfIbCBIHcEGFDACFABDIEGhFhbagCdIEEDCfibhAGGAIeHdBCFIGfdcHaEbHCeibaGFDAbdgFechI", - "DFACBhGIEgchaIeFDbBEIFDGaChAHFbgidEcedcHAfbGIIGbdecHAFFBGECDIHAcadIHbefGHiEgFACBD", - "dfbeahiCgECgiDbfHAAihGFCdeBGbFHCDEAihDIAgecBFcaEBIFgDHFGDCHaBIEIeADBGHFcBHcFEIaGd", - "dfeGchaIBICAFbeHgdgBHdAIfceCHIAeBGdfAGBIFDEHcFEDHGCIBaEDgcIFBAHHIfbdAceGbACehGDFi", - "dGaICHBFEFBIAedHcGCEhgBFIADHcEdfagBiaIbeHGCDfgDFciBEHAEAdHGCFIbbhgFdIaEcIFcbAEDGh", - "dGeihbaCFHFBCADgIECiaeFGBDHEDIgBHcfAbACFDiHEGGHFaEcibdaehBIFDGcFBGdcaEhIICDHgEfaB", - "dHcIFGABEIegCABFdHFbADHEIgCaGFebdCHIEDHaCIBFgciBHGFEadbaDGechiFhCIFDageBGfEBiHDca", - "dHGaicbeFEacFHBIDgIbFeDghcAHeIDcAFGBFdbHgECaIGcABFIDHeaIHcEFgbDBfDGAHEiCCGEIbdAFh", - "DICbAEhgfFaGIHDBCEbEHFCGADIEcBGDIFAhaDFCeHibggHiAFBdECIbehGAcFdcGadIFEhBhFDebcGia", - "diGbCEaHFAfCIdhEBghBeAGFCdiCEbDHGFIAIgdfEaBcHFaHcIBgedgcAhBdIFEEDiGfchabbHFEaidgc", - "diGEHFBCAHcaIBGEdfeFbCadIhgiGEDFAHBCaHFBcEDGICBDHGIfAegdcFEBAIHbehAIcGfDFaIGdhceb", - "eaBdfIHGcIGdCHbFAEfHCAGEDBigcebdHAIFhFAiECGdBBdifAGECHabFecdIHGDiHGBFCeaCEgHIabFD", - "EABFHiGcDHdICgaebfcGFBdeAHIaCDHIgBFEbFeaCDIGHiHGEFBdACfbaDECHIGgEHiBfcdadICGahFeB", - "eacIBFhdgGHBecDaFIDIfgAhCBECFGHDEiabIdHaGBECFabeCFIGHDfCiBHGdeAHgdFEabIcBEADiCFGh", - "EadCFbIhGbGCiahdeffhiGedcABGDbEiFHCACEadhgbFIIfHBcAeGddCfabegiHaBEHGIFDChIGFDcaBE", + "BGDiEAfchahcFBDIGEEIFhgCDabFAHGibedcDEGACHbIFCbIEdfGHagDACfEHBihFBDAIcegICEbHGaFd", + "BGFAIHDCEDHicegBAfEACFDbIGHidhbCEgFAaEGIhfcDBFCbgadeHIHIedGafBCcbdhFiAEGGFAEbcHID", + "BGFHIAdECaiCdBEFGHhDeFcgbaiGFBeAICHdICAGdHEFbdeHCFBGIAFhIBGDACEeBGaHcIDfcadiefhbg", + "BhAcGEIDFIGdBaFCHefeCHiDGbaeaBFcIdGHcDGEHAFIBhifgdBEACAcIDFHbEGGbHIEcaFDdFeabGhcI", + "BHeadfiCGICAgbHDEFdFgIEcHabgEHdFabICcadBHIfGEFBICGEAdHeiBFAGcHdHdCeIBGfAaGfHcDEBI", + "BHFcEdgaigIDAfbEHcCEaIGHBfDdfIGHCAeBhCBeIADGFAGedbFcihFdHBaGIceIacfDEHBGEbGHCIFdA", + "biADChGFEEHFIagbDCcGDBFEAHIIaeFHDCGBFBHgIcdEadcGebAhIFHfBAGIECDgDICEbFahaechdFibg", + "bICEGDHFAHFeaICdbGaDGbFHEcIEadfcgIHbFGHIbECAdICBhdAfGEcHiDAbgefGBFceiadhDEAGHFBIC", + "bieDFaGHcgcaeHiDbFHfDGcBiAECHIBgEFdaDGBHafEciAEFIDcbghFBcaIdheGIdHCEGAFBEAGFBHCID", + "BIFCAdhGeDhAEbgFCICEgFHiBDaFBEGDAIHCADHicBEfggciHFeDabHGDBicaefiacdeFGbHEFBaGHCID", + "bihCGEADfFAGIbDchEedCfahbigCFDEIGHbaIbEHdaFGCHGaBCfIEdGcFdHbeAIAEBGFIDcHdhIAEcGFB", + "CaBhedgfiidHcFGAEbEFGbiahCDAEIGDbFHcFGdIhcebahBCFaEDiGDHAECIBGFbCEdGFIAHGIfaBhCDE", + "cbFDEGiAHGIacFHdebdeHibAgFcfdIBCehGABHgAIFECdACEgHdfBIIGbFDCahEeAdHGBCIFHfceAIBDG", + "cbgHEaFdIaIdcbfGEHEHFigDBACbFEAIHdCGhcAEDGIBFDGIBFCehaGDCFABHIEiabGHecfdFehdcIaGB", + "CbhdAEIGfaEFgibCdhIGDHCFBEafDEBHaGICGibcfdhAehcAIeGFbddFIEbHAcGEHCagIDFBBAGfDCEHI", + "CDabGEHIFeFhIaCGDbbgIHdFcAEAcEGhbifdGIbCFdaEHdHfaEiBGciaDFCHEbghEgDbafCIFbceiGDha", + "cdgeAIBfhhbFDCgIAeAiEHbFcDGBFICGEdHAdGhBFaECIeACIdHGbfIedFHcagBGhbaEdficfCagiBHed", + "cDgIbFEAHehbdGaFICiafecHgDBACIGEBhfdgbdfhiCeAHFECAdbGIBIHAFedcgfGABdCIheDechIGabF", + "CEBIAFHGDIhAdEgbcfgFdCbheaIFGHACIDEbeBCGFdIhADaIbHEcFgBIEFGcAdHHdGEiaFbcAcFHDBgie", + "cEHGfdIABFIgCAbhedAbDeIHcGfeABFcGdHIHDFBEIACGigChdafbEbFaDHEgIcGCIAbfeDHDHeIGcBFA", + "ceIBaDGfhHaGcfiDEbBdFhGEIaCAHbFICEgDGiCdEahbFEfDGhbACIfbhEDGcIAiCeabHFdgdgaIcFBhe", + "CeiBaGHDfADGfeHIBCbFHidcegAdHCeFagIBIGECHBAFDFBAgIdcHEEaFHBIDcGgidacfBEHHCBdGefaI", + "cEIDAGFHbgDBEFhICAFHAIBCeGdbGFhIeadCACDBGFHIehIecDAGBFdacGEiBfHIfHAcbDEgEbgfhdCai", + "CFeabGHIDGBdHEIfcaihACDFBegEGIBadcHFbDcGFHEAIHAFEICgDBAcGihbDFEFIHdgeabcdebfCAIGH", + "CFEIAdbgHaHicbgDeFGDBEFhcIAeGHADCIfBIcFghbAdEBADFIEhcGFbcHGIeaDHEADCFGbidigBEaFHc", + "CGaBfHIdEHEiacDFBGDbFIgEHcaadcFBgEIHfhECDIGaBBiGHEadFcgCdEIBAHFiAbgHfCEdEFHdacBGI", + "CGhAIbfEDFAIEdhcBgDEBCGfHaIIDgbheACFHFcDaIbgeebAGFcIDHGCFibdEHABHDFEaGicaIeHcgDFB", + "cHbEFDGAIAdIcgBEFHegfhIAcbDHACbDGfieIbEACFDHgGFdIheACBBCaGEHidfdEhfaIBGcFIGDbCHEa", + "cidGHEBFAFaeBDcIGHbHgAFIECdgeIHafdbcAdfecbHIGHbCDIGAEFEFaCBHgDIDCbIGaFheighFEDCAB", + "cIFDHAEbgebHgicAfdaGDEFbhCIBDacGFIEHFHIABEGDCgcehdIFABdeGBAHCIFhfciEdbgAIABFCGDhe", + "CIFeBahdGHGDIcFebabaegDHIcfdhAbEcFGiIfcaHgdEbEBGDFIcAHFcbhaEgidaEIfGDBhCGdHciBAFE", + "DAeFBIHGcFiCHGeBadhGBadCFeIabgIHDECFIEDGCFabhChFBEAdIGbcadfGIHEEdhCiBgFAGfiEAHCdb", + "dafibcGHEHIEFdgcbaBCGAHEDIfeHcDgbfaIGBAHIFECDIFdEcAHGbaGBceDIfHFehGaIBdCCdIBfHAEG", + "DaFIcbHgebeHGDFAiccgiEAHDFBEBcAHgFDIGHdCfibEaIFabEdGcHHIGfBeCAdFCbDIAehGAdEHGcIBF", + "DaibFEGHCGHECIDaBFcFbGHaIDeHiAedbFcGEgFicHBAdBCDAgFheIIEHdAGcfBFDchBIEGAabgFecDiH", + "DaIbGFHeCFChaiebdGGeBdCHIFaCbGFADEHIHFAIEbGCdIDEcHgAbFBGcHDafiEEIFGbcdahahdEFiCGB", + "dAIcebGFHgBEHFaCiDhcFdgIAbeIDBFaGeHcCeAIDHFgBfGhBcEIdABFgAHCDEIAHdeIFBcGeICGbDhaf", + "dbFECIAgHIGaFDHBCeHEcAGbDiFFDBgheiacECGIAFHBDaIHDbceFGcHEbfaGDibfdHIGCEAgaiCEDFhb", + "DbgiCFaehcaehbdIGFHIfAEGCBDgfCeIHDABIHAbDCGFEEdbFGAhCIBEDcaiFHGaGHDfBEIcFciGhEbdA", + "DEbfcgaHIFaIHDbCegcHGaiEFbDAfebhdIGcidCEGABFHgBHcFIdAEhgfibceDaeIdGafHcBBCaDEhGIF", + "dEGHAfIbCBIHcEGFDACFABDIEGhFhbagCdIEEDCfibhAGGAIeHdBCFIGfdcHaEbHCeibaGFDAbdgFechI", + "DFACBhGIEgchaIeFDbBEIFDGaChAHFbgidEcedcHAfbGIIGbdecHAFFBGECDIHAcadIHbefGHiEgFACBD", + "dfbeahiCgECgiDbfHAAihGFCdeBGbFHCDEAihDIAgecBFcaEBIFgDHFGDCHaBIEIeADBGHFcBHcFEIaGd", + "dfeGchaIBICAFbeHgdgBHdAIfceCHIAeBGdfAGBIFDEHcFEDHGCIBaEDgcIFBAHHIfbdAceGbACehGDFi", + "dGaICHBFEFBIAedHcGCEhgBFIADHcEdfagBiaIbeHGCDfgDFciBEHAEAdHGCFIbbhgFdIaEcIFcbAEDGh", + "dGeihbaCFHFBCADgIECiaeFGBDHEDIgBHcfAbACFDiHEGGHFaEcibdaehBIFDGcFBGdcaEhIICDHgEfaB", + "dHcIFGABEIegCABFdHFbADHEIgCaGFebdCHIEDHaCIBFgciBHGFEadbaDGechiFhCIFDageBGfEBiHDca", + "dHGaicbeFEacFHBIDgIbFeDghcAHeIDcAFGBFdbHgECaIGcABFIDHeaIHcEFgbDBfDGAHEiCCGEIbdAFh", + "DICbAEhgfFaGIHDBCEbEHFCGADIEcBGDIFAhaDFCeHibggHiAFBdECIbehGAcFdcGadIFEhBhFDebcGia", + "diGbCEaHFAfCIdhEBghBeAGFCdiCEbDHGFIAIgdfEaBcHFaHcIBgedgcAhBdIFEEDiGfchabbHFEaidgc", + "diGEHFBCAHcaIBGEdfeFbCadIhgiGEDFAHBCaHFBcEDGICBDHGIfAegdcFEBAIHbehAIcGfDFaIGdhceb", + "eaBdfIHGcIGdCHbFAEfHCAGEDBigcebdHAIFhFAiECGdBBdifAGECHabFecdIHGDiHGBFCeaCEgHIabFD", + "EABFHiGcDHdICgaebfcGFBdeAHIaCDHIgBFEbFeaCDIGHiHGEFBdACfbaDECHIGgEHiBfcdadICGahFeB", + "eacIBFhdgGHBecDaFIDIfgAhCBECFGHDEiabIdHaGBECFabeCFIGHDfCiBHGdeAHgdFEabIcBEADiCFGh", + "EadCFbIhGbGCiahdeffhiGedcABGDbEiFHCACEadhgbFIIfHBcAeGddCfabegiHaBEHGIFDChIGFDcaBE" ] export class LevelManager { + private static instance: LevelManager + public static getInstance(): LevelManager { + if (!LevelManager.instance) { + LevelManager.instance = new LevelManager() + } + return LevelManager.instance + } - private static instance: LevelManager - public static getInstance(): LevelManager { - if (!LevelManager.instance) { - LevelManager.instance = new LevelManager() + private levelMap: Map> = new Map() + + public init(): void { + this.levelMap.set(config.DIFFICULTY_TYPE.Easy, Easy) + this.levelMap.set(config.DIFFICULTY_TYPE.Medium, Medium) + this.levelMap.set(config.DIFFICULTY_TYPE.Hard, Hard) + this.levelMap.set(config.DIFFICULTY_TYPE.Expert, Expert) + this.levelMap.set(config.DIFFICULTY_TYPE.Extreme, Extreme) + // 检查关卡配置 + this.levelMap.forEach((list, key) => { + for (let i = 0; i < list.length; i++) { + if (list[i].length != 81) { + console.error("关卡配置有误>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", key, i) } - return LevelManager.instance - } + } + }) + } - private levelMap: Map> = new Map() - - public init(): void { - this.levelMap.set(config.DIFFICULTY_TYPE.Easy, Easy) - this.levelMap.set(config.DIFFICULTY_TYPE.Medium, Medium) - this.levelMap.set(config.DIFFICULTY_TYPE.Hard, Hard) - this.levelMap.set(config.DIFFICULTY_TYPE.Expert, Expert) - this.levelMap.set(config.DIFFICULTY_TYPE.Extreme, Extreme) - //检查关卡配置 - this.levelMap.forEach((list, key)=>{ - for (var i=0; i>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", key, i) - } - } - }) - } + public getLevelList(difficulty: string): Array { + const list = this.levelMap.get(difficulty) + return list + } - public getLevelList(difficulty: string): Array { - var list = this.levelMap.get(difficulty) - return list + public getLevelStr(difficulty: string, index: number): string { + const list = this.levelMap.get(difficulty) + if (list) { + return list[index] } - - public getLevelStr(difficulty: string, index: number): string { - var list = this.levelMap.get(difficulty) - if (list) { - return list[index] - } - return "" - } - + return "" + } } diff --git a/src/models/StorageManager.ts b/src/models/StorageManager.ts index 9ff7850..c450d83 100644 --- a/src/models/StorageManager.ts +++ b/src/models/StorageManager.ts @@ -1,14 +1,11 @@ - - +import type { DataStage } from "../types/global" import { config } from "../constants/config" -import { DataStage, createDataStage } from "../types/global" +import { createDataStage } from "../types/global" import { DOStage } from "./DOStage" import { DOUser } from "./DOUser" import { LevelManager } from "./LevelManager" - export class StorageManager { - private static instance: StorageManager public static getInstance(): StorageManager { if (!StorageManager.instance) { @@ -17,23 +14,21 @@ export class StorageManager { return StorageManager.instance } - private user: DOUser; + private user: DOUser private userChanged = false - private stageID: string = ""; + private stageID: string = "" private stageChanged = false - private stageMap: Map = new Map(); + private stageMap: Map = new Map() - public init(): void { if (!this.user) { - var jsonStr = Laya.LocalStorage.getItem("user") - if (jsonStr) { - this.user = new DOUser(JSON.parse(jsonStr)) - } - else { - this.user = new DOUser({dones: new Array(), trophy_records: new Array(), progresses: new Array()}) - } + const jsonStr = Laya.LocalStorage.getItem("user") + if (jsonStr) { + this.user = new DOUser(JSON.parse(jsonStr)) + } else { + this.user = new DOUser({ dones: [], trophy_records: [], progresses: [] }) + } } this.userChanged = false @@ -41,72 +36,70 @@ export class StorageManager { this.stageChanged = false } - public getUser(): DOUser { return this.user } + public saveUser(): void { if (this.userChanged) { this.userChanged = false if (this.user) { - var jsonStr = JSON.stringify(this.user.getData()) + const jsonStr = JSON.stringify(this.user.getData()) Laya.LocalStorage.setItem("user", jsonStr) } } } + public onUserChanged(): void { this.userChanged = true } - + public newStage(stageID: string, type: number, name: string, difficulty: string = config.DIFFICULTY_TYPE.Easy): DOStage { this.stageID = stageID this.stageChanged = true - var index - if (type == config.STAGE_TYPE.MAIN) {//主线关卡 + let index + if (type == config.STAGE_TYPE.MAIN) { // 主线关卡 index = this.user.get_progress(difficulty) - var levelStr = LevelManager.getInstance().getLevelStr(difficulty, index) - if (!levelStr || levelStr.length <= 0) {//说明当前难度已经打通了,所以给他从头开始 + const levelStr = LevelManager.getInstance().getLevelStr(difficulty, index) + if (!levelStr || levelStr.length <= 0) { // 说明当前难度已经打通了,所以给他从头开始 index = 0 this.user.update_progress(difficulty, index) } - } - else if (type == config.STAGE_TYPE.DC) {//每天调整如果已经创建过关卡那么就用之前的关卡配置 - var value = this.getStage(stageID) + } else if (type == config.STAGE_TYPE.DC) { // 每天调整如果已经创建过关卡那么就用之前的关卡配置 + const value = this.getStage(stageID) if (value) { difficulty = value.get_difficulty() index = value.get_stageIndex() - } - else { - var random = Math.random() - difficulty = config.DIFFICULTY_LIST[Math.floor(random*config.DIFFICULTY_LIST.length)] - var list = LevelManager.getInstance().getLevelList(difficulty) + } else { + let random = Math.random() + difficulty = config.DIFFICULTY_LIST[Math.floor(random * config.DIFFICULTY_LIST.length)] + const list = LevelManager.getInstance().getLevelList(difficulty) random = Math.random() - index = Math.floor(random*list.length) + index = Math.floor(random * list.length) console.log("每日挑战随机一个关卡", difficulty, index) } } - this.user.update_stage_done(this.stageID, 0)//重置关卡进度 - var dataStage: DataStage = createDataStage(stageID, type, name, difficulty, index) - var doStage: DOStage = new DOStage(dataStage) + this.user.update_stage_done(this.stageID, 0)// 重置关卡进度 + const dataStage: DataStage = createDataStage(stageID, type, name, difficulty, index) + const doStage: DOStage = new DOStage(dataStage) this.stageMap.set(stageID, doStage) return doStage } - public getStage(stageID: string): DOStage {//获取指定关卡数据对象,注意判空 + public getStage(stageID: string): DOStage { // 获取指定关卡数据对象,注意判空 if (this.stageMap.has(stageID)) { - var doStage: DOStage = this.stageMap.get(stageID) + var doStage: DOStage = this.stageMap.get(stageID) + return doStage + } else { + const jsonStr = Laya.LocalStorage.getItem(stageID) + if (jsonStr) { + const dataStage: DataStage = JSON.parse(jsonStr) + var doStage: DOStage = new DOStage(dataStage) + this.stageMap.set(stageID, doStage) return doStage - } - else { - var jsonStr = Laya.LocalStorage.getItem(stageID) - if (jsonStr) { - var dataStage: DataStage = JSON.parse(jsonStr) - var doStage: DOStage = new DOStage(dataStage) - this.stageMap.set(stageID, doStage) - return doStage - } + } } return null } @@ -118,8 +111,8 @@ export class StorageManager { Laya.LocalStorage.removeItem(stageID) } - public loadStage(stageID: string): DOStage {//载入关卡 - var doStage = this.getStage(stageID) + public loadStage(stageID: string): DOStage { // 载入关卡 + const doStage = this.getStage(stageID) if (doStage) { this.stageID = stageID this.stageChanged = false @@ -129,24 +122,23 @@ export class StorageManager { return null } - public saveStage(): void { if (this.stageChanged) { this.stageChanged = false if (this.stageMap.has(this.stageID)) { - var doStage = this.stageMap.get(this.stageID) - var jsonStr = JSON.stringify(doStage.getData()) - Laya.LocalStorage.setItem(this.stageID, jsonStr) + const doStage = this.stageMap.get(this.stageID) + const jsonStr = JSON.stringify(doStage.getData()) + Laya.LocalStorage.setItem(this.stageID, jsonStr) } } } + public onStageChanged(): void { this.stageChanged = true } - public cleanAll(): void { - this.user = new DOUser({dones: new Array(), trophy_records: new Array(), progresses: new Array()}) + this.user = new DOUser({ dones: [], trophy_records: [], progresses: [] }) this.userChanged = false this.stageID = "" @@ -155,5 +147,4 @@ export class StorageManager { Laya.LocalStorage.clear() } - -} \ No newline at end of file +} diff --git a/src/models/UIManager.ts b/src/models/UIManager.ts index 4c08b5e..b69e25d 100644 --- a/src/models/UIManager.ts +++ b/src/models/UIManager.ts @@ -1,18 +1,17 @@ -import { respath } from "../constants/respath" -import { StorageManager } from "./StorageManager" -import { Stage } from "../views/Stage" -import { DailyChallenge } from "../views/dc/DailyChallenge" -import { TrophyRecord } from "../types/global" -import { TrophyClaim } from "../views/dc/TrophyClaim" -import { TrophyShow } from "../views/dc/TrophyShow" +import type { TrophyRecord } from "../types/global" +import type { DOStage } from "./DOStage" import { config } from "../constants/config" +import { respath } from "../constants/respath" +import { DailyChallenge } from "../views/dc/DailyChallenge" +import { TrophyClaim } from "../views/dc/TrophyClaim" import { TrophyRoom } from "../views/dc/TrophyRoom" -import { DOStage } from "./DOStage" -import { GamePause } from "../views/GamePause" -import { GameOver } from "../views/GameOver" +import { TrophyShow } from "../views/dc/TrophyShow" import { GameDone } from "../views/GameDone" +import { GameOver } from "../views/GameOver" +import { GamePause } from "../views/GamePause" +import { Stage } from "../views/Stage" import { TopBar } from "../views/TopBar" - +import { StorageManager } from "./StorageManager" const { regClass, property } = Laya @@ -36,8 +35,7 @@ export class UIManager extends Laya.Script { if (config.H_SCREEN) { this.UIRoot.width = config.DESIGN_HEIGHT this.UIRoot.height = config.DESIGN_WIDTH - } - else { + } else { this.UIRoot.width = config.DESIGN_WIDTH this.UIRoot.height = config.DESIGN_HEIGHT } @@ -45,48 +43,47 @@ export class UIManager extends Laya.Script { return this.UIRoot } - private topbar : TopBar + private topbar: TopBar private stage: Stage private dc_ui: DailyChallenge private trophyRoom: TrophyRoom - onStart(): void { if (config.H_SCREEN) { this.loadTopBarUI() - } - else { + } else { this.loadHomeUI() } } - public loadHomeUI(): void { - Laya.loader.load(respath.home_ui_res).then((go)=>{ - var prefab = go.create() + Laya.loader.load(respath.home_ui_res).then((go) => { + const prefab = go.create() this.getUIRoot().addChild(prefab) }) } public loadTopBarUI(): void { - Laya.loader.load(respath.topbar_ui_res).then((go)=>{ - var prefab = go.create() + Laya.loader.load(respath.topbar_ui_res).then((go) => { + const prefab = go.create() this.topbar = this.getUIRoot().addChild(prefab).getComponent(TopBar) }) } + public setTopbarTo(isClassic: boolean): void { if (this.topbar) { this.topbar.onClickTab(isClassic) } } - + public loadDCUI(): void { - Laya.loader.load(respath.dc_ui_res()).then((go)=>{ - var prefab = go.create() + Laya.loader.load(respath.dc_ui_res()).then((go) => { + const prefab = go.create() this.dc_ui = this.getUIRoot().addChild(prefab).getComponent(DailyChallenge) this.dc_ui.loadWithMonth() }) } + public closeDCUI(): void { if (this.dc_ui) { this.dc_ui.owner.destroy() @@ -95,46 +92,47 @@ export class UIManager extends Laya.Script { } public loadTrophyClaimUI(record: TrophyRecord): void { - Laya.loader.load(respath.trophy_claim_ui_res()).then((go)=>{ - var prefab = go.create() - var obj = this.getUIRoot().addChild(prefab).getComponent(TrophyClaim) + Laya.loader.load(respath.trophy_claim_ui_res()).then((go) => { + const prefab = go.create() + const obj = this.getUIRoot().addChild(prefab).getComponent(TrophyClaim) obj.onSetShow(record) }) } public loadTrophyUI(): void { - Laya.loader.load(respath.trophy_ui_res()).then((go)=>{ - var prefab = go.create() + Laya.loader.load(respath.trophy_ui_res()).then((go) => { + const prefab = go.create() this.trophyRoom = this.getUIRoot().addChild(prefab).getComponent(TrophyRoom) }) } + public closeTrophyUI(): void { if (this.trophyRoom) { this.trophyRoom.owner.destroy() this.trophyRoom = null - } + } } public loadTrophyShowUI(record: TrophyRecord): void { - Laya.loader.load(respath.trophy_show_ui_res()).then((go)=>{ - var prefab = go.create() - var obj = this.getUIRoot().addChild(prefab).getComponent(TrophyShow) + Laya.loader.load(respath.trophy_show_ui_res()).then((go) => { + const prefab = go.create() + const obj = this.getUIRoot().addChild(prefab).getComponent(TrophyShow) obj.onSetShow(record) }) } public loadStageUI(stageID: string): void { if (this.stage) { - this.stage.onLoadStage(StorageManager.getInstance().loadStage(stageID)) - } - else { - Laya.loader.load(respath.stage_ui_res()).then((go)=>{ - var prefab = go.create() + this.stage.onLoadStage(StorageManager.getInstance().loadStage(stageID)) + } else { + Laya.loader.load(respath.stage_ui_res()).then((go) => { + const prefab = go.create() this.stage = this.getUIRoot().addChild(prefab).getComponent(Stage) this.stage.onLoadStage(StorageManager.getInstance().loadStage(stageID)) }) } } + public closeStageUI(): void { if (this.stage) { this.stage.owner.destroy() @@ -143,25 +141,26 @@ export class UIManager extends Laya.Script { } public loadGamePauseUI(doStage: DOStage): void { - Laya.loader.load(respath.gamepause_ui_res()).then((go)=>{ - var prefab = go.create() - var ui = this.getUIRoot().addChild(prefab).getComponent(GamePause) - ui.onSetStageInfo(doStage) - }) - } - public loadGameOverUI(doStage: DOStage): void { - Laya.loader.load(respath.gameover_ui_res()).then((go)=>{ - var prefab = go.create() - var ui = this.getUIRoot().addChild(prefab).getComponent(GameOver) - ui.onSetStageInfo(doStage) - }) - } - public loadGameDoneUI(isClassic: boolean, doStage: DOStage): void { - Laya.loader.load(respath.gamedone_ui_res(isClassic)).then((go)=>{ - var prefab = go.create() - var ui = this.getUIRoot().addChild(prefab).getComponent(GameDone) + Laya.loader.load(respath.gamepause_ui_res()).then((go) => { + const prefab = go.create() + const ui = this.getUIRoot().addChild(prefab).getComponent(GamePause) ui.onSetStageInfo(doStage) }) } + public loadGameOverUI(doStage: DOStage): void { + Laya.loader.load(respath.gameover_ui_res()).then((go) => { + const prefab = go.create() + const ui = this.getUIRoot().addChild(prefab).getComponent(GameOver) + ui.onSetStageInfo(doStage) + }) + } + + public loadGameDoneUI(isClassic: boolean, doStage: DOStage): void { + Laya.loader.load(respath.gamedone_ui_res(isClassic)).then((go) => { + const prefab = go.create() + const ui = this.getUIRoot().addChild(prefab).getComponent(GameDone) + ui.onSetStageInfo(doStage) + }) + } } diff --git a/src/types/global.ts b/src/types/global.ts index 66ed790..89571a1 100644 --- a/src/types/global.ts +++ b/src/types/global.ts @@ -1,69 +1,66 @@ - - -//格子持久化数据结构 +// 格子持久化数据结构 export interface DataBlock { - index: number, - show: number, - score: number - notes: Array, + index: number + show: number + score: number + notes: Array } -//撤回数据结构 +// 撤回数据结构 export interface DataUndo { - index: number, - show: number, - notes?: Array, + index: number + show: number + notes?: Array } -//关卡数据 +// 关卡数据 export interface DataStage { - id: string,//关卡ID dc关卡格式为:年-月-日 - type: number, - name: string, - difficulty: string, - index: number, - mistake?: number, - score?: number, - duration?: number, - last_hit_time?: number,//上一次填对计时 - note_open?: boolean, - hint?: number, - select_index?: number, - blocks?: Array, - undos?: Array, + id: string// 关卡ID dc关卡格式为:年-月-日 + type: number + name: string + difficulty: string + index: number + mistake?: number + score?: number + duration?: number + last_hit_time?: number// 上一次填对计时 + note_open?: boolean + hint?: number + select_index?: number + blocks?: Array + undos?: Array } export function createDataStage(id: string, type: number, name: string, difficulty: string, index: number): DataStage { - var data: DataStage = {id: id, type: type, name: name, difficulty: difficulty, index: index} - data.mistake = 0 - data.score = 0 - data.duration = 0 - data.last_hit_time = 0 - data.note_open = false - data.hint = 2 - data.select_index = 0 - data.blocks = new Array() - data.undos = new Array() - return data + const data: DataStage = { id, type, name, difficulty, index } + data.mistake = 0 + data.score = 0 + data.duration = 0 + data.last_hit_time = 0 + data.note_open = false + data.hint = 2 + data.select_index = 0 + data.blocks = [] + data.undos = [] + return data } - -export interface StageProgress {//关卡完成进度 - stageID: string,//关卡ID dc关卡格式为:年-月-日 - progress: number, +export interface StageProgress { // 关卡完成进度 + stageID: string// 关卡ID dc关卡格式为:年-月-日 + progress: number } export interface TrophyRecord { - year: number, - month: number, - day: number, - isNew: boolean, - read: boolean, + year: number + month: number + day: number + isNew: boolean + read: boolean } -export interface DataProgress {//关卡难度进度 - difficulty: string, - index: number, +export interface DataProgress { // 关卡难度进度 + difficulty: string + index: number } export interface DataUser { - dones: Array,//关卡完成进度 - trophy_records: Array,//奖杯获得记录 - progresses: Array,//主线各个难度进度 + dones: Array// 关卡完成进度 + trophy_records: Array// 奖杯获得记录 + progresses: Array// 主线各个难度进度 } diff --git a/src/utils/utility.ts b/src/utils/utility.ts index 9389ef1..5ab19c5 100644 --- a/src/utils/utility.ts +++ b/src/utils/utility.ts @@ -1,39 +1,33 @@ import { config } from "../constants/config" - - export function Utility_ConvertSecondToString(second: number) { - var last = second - var hour = Math.floor(last/3600) - last = last - hour * 3600 - var minite = Math.floor(last/60) - last = last - minite * 60 - var second = Math.floor(last) - function format(value: number) { - return value>=10?value.toString():("0"+value) - } - return `${format(hour)}:${format(minite)}:${format(second)}` + let last = second + const hour = Math.floor(last / 3600) + last = last - hour * 3600 + const minite = Math.floor(last / 60) + last = last - minite * 60 + var second = Math.floor(last) + function format(value: number) { + return value >= 10 ? value.toString() : (`0${value}`) + } + return `${format(hour)}:${format(minite)}:${format(second)}` } -//计算积分 +// 计算积分 export function Utility_CalculateScore(difficulty: string, second: number): number { - var score = 0 - var currentTime = Math.min(120, second) - if (difficulty == config.DIFFICULTY_TYPE.Easy) { - score = 270 - currentTime - } - else if (difficulty == config.DIFFICULTY_TYPE.Medium) { - score = 420 - currentTime * 2 - } - else if (difficulty == config.DIFFICULTY_TYPE.Hard) { - score = 760 - currentTime * 3 - } - else if (difficulty == config.DIFFICULTY_TYPE.Expert) { - score = 1120 - currentTime * 3 - } - else if (difficulty == config.DIFFICULTY_TYPE.Extreme) { - score = 1320 - currentTime * 4 - } - // console.log("计算积分 >>>>>", difficulty, second, score) - return score -} \ No newline at end of file + let score = 0 + const currentTime = Math.min(120, second) + if (difficulty == config.DIFFICULTY_TYPE.Easy) { + score = 270 - currentTime + } else if (difficulty == config.DIFFICULTY_TYPE.Medium) { + score = 420 - currentTime * 2 + } else if (difficulty == config.DIFFICULTY_TYPE.Hard) { + score = 760 - currentTime * 3 + } else if (difficulty == config.DIFFICULTY_TYPE.Expert) { + score = 1120 - currentTime * 3 + } else if (difficulty == config.DIFFICULTY_TYPE.Extreme) { + score = 1320 - currentTime * 4 + } + // console.log("计算积分 >>>>>", difficulty, second, score) + return score +} diff --git a/src/views/Block.ts b/src/views/Block.ts index 3a83785..6fa05ce 100644 --- a/src/views/Block.ts +++ b/src/views/Block.ts @@ -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 = new Array(); - private label_show: Laya.Label; - private tips_labels: Array = 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 = [] + private label_show: Laya.Label + private tips_labels: Array = [] - var VBox = this.owner.getChildByName("VBox") - for (var i=0; i { 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): 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 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): void { - this.data.set_show(0) - this.data.clean_notes() - for (var i=0; i 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 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 = "" - } - } -} \ No newline at end of file + } +} diff --git a/src/views/CommonTips.ts b/src/views/CommonTips.ts index 2bdc9bf..307ba5f 100644 --- a/src/views/CommonTips.ts +++ b/src/views/CommonTips.ts @@ -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 - } -} \ No newline at end of file + @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() + }) + } +} diff --git a/src/views/Difficulty.ts b/src/views/Difficulty.ts index 78617a9..9cfa46b 100644 --- a/src/views/Difficulty.ts +++ b/src/views/Difficulty.ts @@ -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{ - 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() + }) } -} \ No newline at end of file + } +} diff --git a/src/views/GameDone.ts b/src/views/GameDone.ts index 86df978..a28e0e5 100644 --- a/src/views/GameDone.ts +++ b/src/views/GameDone.ts @@ -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() - }) - - } -} \ No newline at end of file + } else { + UIManager.getInstance().loadHomeUI() + UIManager.getInstance().closeStageUI() + } + this.owner.destroy() + }) + } +} diff --git a/src/views/GameOver.ts b/src/views/GameOver.ts index 298d8da..fd46ebc 100644 --- a/src/views/GameOver.ts +++ b/src/views/GameOver.ts @@ -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() - }) - } - } -} \ No newline at end of file + } +} diff --git a/src/views/GamePause.ts b/src/views/GamePause.ts index 0daf179..873ecfd 100644 --- a/src/views/GamePause.ts +++ b/src/views/GamePause.ts @@ -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() - }) - - } -} \ No newline at end of file + 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() + }) + } +} diff --git a/src/views/Home.ts b/src/views/Home.ts index 59d7a16..1c3e283 100644 --- a/src/views/Home.ts +++ b/src/views/Home.ts @@ -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() }) - } - - + }) + } } diff --git a/src/views/ScoreAdd.ts b/src/views/ScoreAdd.ts index 3248e8d..96e5945 100644 --- a/src/views/ScoreAdd.ts +++ b/src/views/ScoreAdd.ts @@ -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 - } - - -} \ No newline at end of file + public onSetText(text: string): void { + this.label.text = text + } +} diff --git a/src/views/Stage.ts b/src/views/Stage.ts index f6da110..a3695ca 100644 --- a/src/views/Stage.ts +++ b/src/views/Stage.ts @@ -1,587 +1,585 @@ +import type { DOStage } from "../models/DOStage" +import { config } from "../constants/config" +import { G_getMonthInfo } from "../models/DCManager" +import { EVENT_TYPES, EventManager } from "../models/EventManager" +import { StorageManager } from "../models/StorageManager" +import { UIManager } from "../models/UIManager" +import { Utility_CalculateScore, Utility_ConvertSecondToString } from "../utils/utility" +import { Block } from "./Block" +import { Candy } from "./Candy" -import { UIManager } from "../models/UIManager"; -import { Block } from "./Block"; -import { Candy } from "./Candy"; -import { DOStage } from "../models/DOStage"; -import { config } from "../constants/config"; -import { StorageManager } from "../models/StorageManager"; -import { Utility_CalculateScore, Utility_ConvertSecondToString } from "../utils/utility"; -import { EVENT_TYPES, EventManager } from "../models/EventManager"; -import { G_getMonthInfo } from "../models/DCManager"; - - -const { regClass, property } = Laya; +const { regClass, property } = Laya @regClass() export class Stage extends Laya.Script { - declare owner : Laya.Box; + declare owner: Laya.Box - @property(Laya.Box) - public btn_back: Laya.Box - @property(Laya.Box) - public btn_new: Laya.Box + @property(Laya.Box) + public btn_back: Laya.Box - @property(Laya.Button) - public btn_pause: Laya.Button - @property(Laya.Label) - public label_score: Laya.Label; - private score_last: number - private score_current: number - private score_step: number - private score_animation_wait_frame = 0 - @property(Laya.Label) - public label_mistake: Laya.Label; - @property(Laya.Label) - public label_name: Laya.Label; - @property(Laya.Label) - public label_time: Laya.Label; + @property(Laya.Box) + public btn_new: Laya.Box - @property(Laya.Box) - public obj_blocks: Laya.Box; - @property(Laya.Box) - public obj_block_labels: Laya.Box; - private blocks: Array = new Array(); + @property(Laya.Button) + public btn_pause: Laya.Button - @property(Laya.Box) - public obj_candys: Laya.Box; - @property(Laya.Box) - public obj_candy_labels: Laya.Box; - private candys: Array = new Array(); + @property(Laya.Label) + public label_score: Laya.Label - @property(Laya.Button) - public btn_undo: Laya.Button; - @property(Laya.Button) - public btn_erase: Laya.Button; - @property(Laya.Button) - public btn_note: Laya.Button; - private btn_note_normal: Laya.Box - private btn_note_checked: Laya.Box - private label_note: Laya.Label - @property(Laya.Button) - public btn_hint: Laya.Button; - private btn_hint_normal: Laya.Box - private btn_hint_ad: Laya.Box - private btn_hint_label: Laya.Label + private score_last: number + private score_current: number + private score_step: number + private score_animation_wait_frame = 0 + @property(Laya.Label) + public label_mistake: Laya.Label - private data: DOStage; - private selectedBlock: Block; - private paused: boolean + @property(Laya.Label) + public label_name: Laya.Label - private static _instance: Stage - onAwake(): void { - Stage._instance = this + @property(Laya.Label) + public label_time: Laya.Label - this.btn_back.on(Laya.Event.CLICK, this, ()=>{ - if (this.data.get_stageType() == config.STAGE_TYPE.MAIN) { - UIManager.getInstance().loadHomeUI(); - UIManager.getInstance().closeStageUI(); - } - else { - UIManager.getInstance().loadDCUI(); - UIManager.getInstance().closeStageUI(); - } - }) + @property(Laya.Box) + public obj_blocks: Laya.Box - if (this.btn_new) { - this.btn_new.on(Laya.Event.CLICK, this, ()=>{ - var user = StorageManager.getInstance().getUser() - user.update_progress(this.data.get_difficulty(), this.data.get_stageIndex()+1)//主线关卡更新难度进度 - StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, this.data.get_difficulty(), this.data.get_difficulty()) - UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID) - }) - } + @property(Laya.Box) + public obj_block_labels: Laya.Box + private blocks: Array = [] - this.btn_pause.on(Laya.Event.CLICK, this, ()=>{ - UIManager.getInstance().loadGamePauseUI(this.data); - }) - for (var i=0; i = [] + + @property(Laya.Button) + public btn_undo: Laya.Button + + @property(Laya.Button) + public btn_erase: Laya.Button + + @property(Laya.Button) + public btn_note: Laya.Button + + private btn_note_normal: Laya.Box + private btn_note_checked: Laya.Box + private label_note: Laya.Label + @property(Laya.Button) + public btn_hint: Laya.Button + + private btn_hint_normal: Laya.Box + private btn_hint_ad: Laya.Box + private btn_hint_label: Laya.Label + + private data: DOStage + private selectedBlock: Block + private paused: boolean + + private static _instance: Stage + onAwake(): void { + Stage._instance = this + + this.btn_back.on(Laya.Event.CLICK, this, () => { + if (this.data.get_stageType() == config.STAGE_TYPE.MAIN) { + UIManager.getInstance().loadHomeUI() + UIManager.getInstance().closeStageUI() + } else { + UIManager.getInstance().loadDCUI() + UIManager.getInstance().closeStageUI() + } + }) + + if (this.btn_new) { + this.btn_new.on(Laya.Event.CLICK, this, () => { + const user = StorageManager.getInstance().getUser() + user.update_progress(this.data.get_difficulty(), this.data.get_stageIndex() + 1)// 主线关卡更新难度进度 + StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, this.data.get_difficulty(), this.data.get_difficulty()) + UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID) + }) } - public static EventUpdateMistake(arg: any): void { - if (Stage._instance) { - Stage._instance.onUpdateMistake() - } + this.btn_pause.on(Laya.Event.CLICK, this, () => { + UIManager.getInstance().loadGamePauseUI(this.data) + }) + for (var i = 0; i < this.obj_blocks.numChildren; i++) { + var hbox = this.obj_blocks.getChildAt(i) + var l_hbox = this.obj_block_labels.getChildAt(i) + for (var j = 0; j < hbox.numChildren; j++) { + const block = hbox.getChildAt(j).getComponent(Block) + this.blocks.push(block) + let XGroup = 0 + if (j == 3 || j == 4 || j == 5) + XGroup = 1 + if (j == 6 || j == 7 || j == 8) + XGroup = 2 + let YGroup = 0 + if (i == 3 || i == 4 || i == 5) + YGroup = 1 + if (i == 6 || i == 7 || i == 8) + YGroup = 2 + const l_vbox = l_hbox.getChildAt(j) as Laya.Box + block.onInit(j, i, XGroup, YGroup, l_vbox, this, this.onClickBlock) + } } - public static EventUpdatePause(arg: any): void { - if (Stage._instance) { - Stage._instance.paused = arg - } + for (var i = 0; i < this.obj_candys.numChildren; i++) { + hbox = this.obj_candys.getChildAt(i) + l_hbox = this.obj_candy_labels.getChildAt(i) + for (var j = 0; j < hbox.numChildren; j++) { + const candy = hbox.getChildAt(j).getComponent(Candy) + this.candys.push(candy) + const box = l_hbox.getChildAt(j) as Laya.Box + candy.onInit(box, this, this.onClickCandy) + } } - public onLoadStage(doStage: DOStage): void { - this.data = doStage - this.paused = false + this.btn_undo.on(Laya.Event.CLICK, this, this.onClickUndo) + this.btn_erase.on(Laya.Event.CLICK, this, this.onClickErase) + this.btn_note.on(Laya.Event.CLICK, this, this.onClickNote) + this.btn_note_normal = this.btn_note.getChildByName("normal") as Laya.Box + this.btn_note_checked = this.btn_note.getChildByName("checked") as Laya.Box + this.label_note = this.btn_note.getChildByName("label") as Laya.Label + this.btn_hint.on(Laya.Event.CLICK, this, this.onClickHint) + this.btn_hint_normal = this.btn_hint.getChildByName("Image").getChildByName("normal") as Laya.Box + this.btn_hint_ad = this.btn_hint.getChildByName("Image").getChildByName("ad") as Laya.Box + this.btn_hint_label = this.btn_hint.getChildByName("Image").getChildByName("normal").getChildByName("label") as Laya.Label - if (config.H_SCREEN) { - this.btn_back.visible = this.data.get_stageType() == config.STAGE_TYPE.DC - this.btn_new.visible = this.data.get_stageType() == config.STAGE_TYPE.MAIN + EventManager.getInstance().RegisterEvent(EVENT_TYPES.NOT_UPDATE_MISTAKE, Stage.EventUpdateMistake) + EventManager.getInstance().RegisterEvent(EVENT_TYPES.NOT_UPDATE_PAUSE, Stage.EventUpdatePause) + } + + onDestroy(): void { + EventManager.getInstance().UnregisterEvent(EVENT_TYPES.NOT_UPDATE_MISTAKE, Stage.EventUpdateMistake) + EventManager.getInstance().UnregisterEvent(EVENT_TYPES.NOT_UPDATE_PAUSE, Stage.EventUpdatePause) + } + + public static EventUpdateMistake(arg: any): void { + if (Stage._instance) { + Stage._instance.onUpdateMistake() + } + } + + public static EventUpdatePause(arg: any): void { + if (Stage._instance) { + Stage._instance.paused = arg + } + } + + public onLoadStage(doStage: DOStage): void { + this.data = doStage + this.paused = false + + if (config.H_SCREEN) { + this.btn_back.visible = this.data.get_stageType() == config.STAGE_TYPE.DC + this.btn_new.visible = this.data.get_stageType() == config.STAGE_TYPE.MAIN + } + + this.score_last = 0 + this.score_current = 0 + this.onUpdateScore() + this.score_last = this.score_current + this.label_score.text = `Score: ${this.score_last}` + + this.label_name.text = this.data.get_stageName() + if (this.data.get_stageType() == config.STAGE_TYPE.MAIN && config.H_SCREEN) + this.label_name.text = "" + this.onUpdateMistake() + + this.label_time.text = Utility_ConvertSecondToString(this.data.get_duration()) + Laya.timer.clearAll(this) + Laya.timer.loop(1000, this, () => { + if (this.paused) { + return + } + let last = this.data.get_duration() + last++ + this.data.set_duration(last) + this.label_time.text = Utility_ConvertSecondToString(last) + }) + + const blocks = doStage.get_blocks() + for (let i = 0; i < blocks.length; i++) { + const doBlock = blocks[i] + const block = this.blocks[i] + block.setBlockColor(config.BLOCK_COLOR.WHITE) + block.setBlock(doBlock) + block.setTipsBgColor(false) + block.setSelected(false) + } + this.onUpdateCandys() + this.onClickNote(null) + this.onUpdateHintStatus() + + this.selectedBlock = this.blocks[this.data.get_select_index()] + this.onApplyBlock(this.selectedBlock) + } + + onUpdateScore(): void { + let score = 0 + const blocks = this.data.get_blocks() + for (let i = 0; i < blocks.length; i++) { + score += blocks[i].get_score() + } + if (this.score_current != score) { // 分数发生变化 + this.score_current = score + this.score_step = Math.ceil((this.score_current - this.score_last) / 24) + if (this.score_current > this.score_last) + this.score_animation_wait_frame = 54 + else + this.score_animation_wait_frame = 0 + this.data.set_score(score) + } + } + + onLateUpdate(): void { + this.score_animation_wait_frame-- + if (this.score_animation_wait_frame < 0) + this.score_animation_wait_frame = 0 + if (this.score_animation_wait_frame <= 0) { + if (this.score_current != this.score_last) { + if (this.score_current > this.score_last) { + this.score_last += this.score_step + if (this.score_last > this.score_current) + this.score_last = this.score_current + this.label_score.text = `Score: ${this.score_last}` + } else { + this.label_score.text = `Score: ${this.score_current}` + this.score_last = this.score_current } + } + } + } - this.score_last = 0 - this.score_current = 0 + onUpdateMistake(): void { + this.label_mistake.text = `Mistake: ${this.data.get_mistake()}/${config.MISTAKE_MAX}` + } + + onSetBlock(block: Block, animated: boolean = false): void { + // 全部格子还原 + for (var i = 0; i < this.blocks.length; i++) { + this.blocks[i].setBlockColor(config.BLOCK_COLOR.WHITE) + this.blocks[i].setTipsBgColor(false) + } + // 相关格子置灰 + const relateds = this.findRelatedBlocks(block) + for (var i = 0; i < relateds.length; i++) + relateds[i].setBlockColor(config.BLOCK_COLOR.GREY) + + // 选中空白格子 + if (block.getData().get_show() <= 0) { + block.setBlockColor(config.BLOCK_COLOR.BLUE) + } else { + var sames = this.findSameNumberBlocks(block)// 相同数字的格子 + for (var i = 0; i < sames.length; i++) { + sames[i].setBlockColor(config.BLOCK_COLOR.BLUE, 0.4) + } + var sames = this.findSameNoteBlocks(block)// 相同数字的铅笔格子 + for (var i = 0; i < sames.length; i++) { + sames[i].setTipsBgColor(true, block.getData().get_show(), config.BLOCK_COLOR.BLUE, 0.4) + } + // 正确 + if (block.getData().get_checked()) { + block.setBlockColor(config.BLOCK_COLOR.BLUE) + } else { // 错误 + if (animated) { // 填数状态播放闪动效果 + for (var i = 0; i < relateds.length; i++) { // 相关且数字相同 + if (relateds[i].getData().get_show() == block.getData().get_show()) { // 播放变红动效 + if (relateds[i].getData().get_index() != block.getData().get_index()) { + // relateds[i].setBlockColor(config.BLOCK_COLOR.WHITE) + relateds[i].setBlockColor(config.BLOCK_COLOR.RED, 0.4, true, config.BLOCK_COLOR.GREY, 1) + } + } + } + } else { + for (var i = 0; i < relateds.length; i++) { // 相关且数字相同 + if (relateds[i].getData().get_show() == block.getData().get_show()) { // 直接变红 + if (relateds[i].getData().get_index() != block.getData().get_index()) { + relateds[i].setBlockColor(config.BLOCK_COLOR.RED, 0.4) + } + } + } + } + block.setBlockColor(config.BLOCK_COLOR.RED) + } + } + } + + onApplyBlock(block: Block): void { + this.selectedBlock.setSelected(false) + this.selectedBlock = block + this.selectedBlock.setSelected(true) + this.onSetBlock(this.selectedBlock) + this.data.set_select_index(this.selectedBlock.getData().get_index()) + } + + onClickBlock(evt: Laya.Event): void { + const block = evt.target.getComponent(Block) + this.onApplyBlock(block) + } + + onClickUndo(evt: Laya.Event): void { + const undo = this.data.pop_undo() + if (undo) { + console.log("onClickUndo>>>>", JSON.stringify(undo)) + this.selectedBlock = this.blocks[undo.index] + this.onApplyBlock(this.selectedBlock) + if (undo.notes && undo.notes.length > 0) { + this.selectedBlock.setNotes(undo.notes) + } else { + this.selectedBlock.setShowNumber(undo.show, 0) + } + // this.onSetBlock(this.selectedBlock) + this.onUpdateScore() + const undos = this.data.get_undos() + if (undos.length > 0) { + const last = undos[undos.length - 1] + this.selectedBlock = this.blocks[last.index] + this.onApplyBlock(this.selectedBlock) + } + } + } + + onClickErase(evt: Laya.Event): void { + if (this.selectedBlock.getData().get_checked() == false) { // 未完成且有数字或者笔记才可以使用橡皮 + const show = this.selectedBlock.getData().get_show() + const notes = this.selectedBlock.getData().get_notes() + if (show > 0 || notes.length > 0) { + this.data.add_undo(this.selectedBlock.getData().get_index(), show, notes) + this.selectedBlock.setShowNumber(0, 0) this.onUpdateScore() - this.score_last = this.score_current - this.label_score.text = `Score: ${this.score_last}` + this.onSetBlock(this.selectedBlock) + } + } + } - this.label_name.text = this.data.get_stageName() - if (this.data.get_stageType() == config.STAGE_TYPE.MAIN && config.H_SCREEN) - this.label_name.text = "" - this.onUpdateMistake() - - this.label_time.text = Utility_ConvertSecondToString(this.data.get_duration()) - Laya.timer.clearAll(this) - Laya.timer.loop(1000, this, ()=>{ - if (this.paused) { - return + onClickNote(evt: Laya.Event): void { + if (evt != null) { + this.data.set_note_open(!this.data.get_note_open()) + } + this.btn_note_normal.visible = this.data.get_note_open() == false + this.btn_note_checked.visible = this.data.get_note_open() + this.label_note.color = this.data.get_note_open() ? "#1d5cdc" : "#545962" + for (let i = 0; i < this.candys.length; i++) { + this.candys[i].setNoteStatus(this.data.get_note_open()) + } + } + + onClickHint(evt: Laya.Event): void { + const hint = this.data.get_hint() + if (hint > 0) { + if (this.selectedBlock.getData().get_checked() == false) { // 当前选中的格子没有完成 + var correct = this.selectedBlock.getData().get_correct() + this.onApplyCandy(correct, true) + this.data.set_hint(hint - 1) + this.onUpdateHintStatus() + } else { + const list: Array = [] + for (let i = 0; i < this.blocks.length; i++) { + var block = this.blocks[i] + if (block.getData().get_checked() == false) + list.push(block) + } + if (list.length > 0) { + const random = Math.random() + let index = Math.round(random * list.length) + if (index >= list.length) + index = list.length - 1 + var block = list[index] + this.onApplyBlock(block) + var correct = block.getData().get_correct() + this.onApplyCandy(correct, true) + this.data.set_hint(hint - 1) + this.onUpdateHintStatus() + } + } + } else { + // 这里播放广告 现在每个广告每次点击+9 + this.data.set_hint(9) + this.onUpdateHintStatus() + } + } + + onUpdateHintStatus(): void { + const hint = this.data.get_hint() + this.btn_hint_normal.visible = hint > 0 + this.btn_hint_ad.visible = hint <= 0 + this.btn_hint_label.text = hint.toString() + } + + public onApplyCandy(showNumber: number, hint: boolean): void { + const show = this.selectedBlock.getData().get_show() + const notes = this.selectedBlock.getData().get_notes() + if (this.selectedBlock.getData().get_checked() == false) { + if (this.data.get_note_open() && hint == false) { + const relateds = this.findRelatedBlocks(this.selectedBlock) + let find = false + for (var i = 0; i < relateds.length; i++) { + if (relateds[i].getData().get_show() == showNumber) { + find = true + break + } + } + if (find == false) { + this.data.add_undo(this.selectedBlock.getData().get_index(), show, notes) + this.selectedBlock.addNoteNumber(showNumber) + this.onSetBlock(this.selectedBlock) + } else { + for (var i = 0; i < relateds.length; i++) { + const obj = relateds[i] + if (obj.getData().get_show() == showNumber && obj.getData().get_index() != this.selectedBlock.getData().get_index()) { + obj.setFadeAnimation() } - var last = this.data.get_duration() - last ++ - this.data.set_duration(last) - this.label_time.text = Utility_ConvertSecondToString(last) - }) - - var blocks = doStage.get_blocks() - for (var i=0; i= 1) { // 完成每日挑战关卡检查是否或者当月奖杯 + const now = new Date() + const nowYear = now.getFullYear() + const nowMonth = now.getMonth() + 1 + const doneCount = user.get_doneCountByDate(nowYear, nowMonth) + let dayCount = 0 + const info = G_getMonthInfo(nowYear, nowMonth) + if (info) + dayCount = info.dayCount + console.log("dc完成信息>>>>>>>>>>>>>>>", nowYear, nowMonth, doneCount, dayCount) + if (doneCount >= dayCount) { // 当月每日挑战全部完成 + user.add_trophy_record(nowYear, nowMonth, now.getDate()) + } + } + UIManager.getInstance().loadGameDoneUI(false, this.data) + } + } + } else { // 失败 + this.data.set_mistake(this.data.get_mistake() + 1) + this.onUpdateMistake() + if (this.data.get_mistake() >= config.MISTAKE_MAX) { + console.log("关卡失败") + this.paused = true + UIManager.getInstance().loadGameOverUI(this.data) + } + } } this.onUpdateCandys() - this.onClickNote(null) - this.onUpdateHintStatus() - - this.selectedBlock = this.blocks[this.data.get_select_index()] - this.onApplyBlock(this.selectedBlock) + } } + } - onUpdateScore(): void { - var score = 0 - var blocks = this.data.get_blocks() - for (var i=0; i this.score_last) - this.score_animation_wait_frame = 54 - else - this.score_animation_wait_frame = 0 - this.data.set_score(score) - } + public onClickCandy(evt: Laya.Event): void { + const candy = evt.target.getComponent(Candy) + this.onApplyCandy(candy.get_show(), false) + const sp = evt.target.getChildByName("Sprite") as Laya.Sprite + Laya.Tween.to(sp, { scaleX: 0.9, scaleY: 0.9 }, 100, Laya.Ease.linearIn) + Laya.Tween.to(sp, { scaleX: 1, scaleY: 1 }, 100, Laya.Ease.linearInOut, null, 100) + } + + onKeyUp(evt: Laya.Event): void { + const n = Number(evt.key) + if (n && n > 0) { + this.onApplyCandy(n, false) } + } - onLateUpdate(): void { - this.score_animation_wait_frame -- - if (this.score_animation_wait_frame < 0) - this.score_animation_wait_frame = 0 - if (this.score_animation_wait_frame <= 0) { - if (this.score_current != this.score_last) { - if (this.score_current > this.score_last) { - this.score_last += this.score_step - if (this.score_last > this.score_current) - this.score_last = this.score_current - this.label_score.text = `Score: ${this.score_last}` - } - else { - this.label_score.text = `Score: ${this.score_current}` - this.score_last = this.score_current - } - } - } + onUpdateCandys(): void { + const list: Map = new Map() + for (var i = 1; i <= 9; i++) + list.set(i, 0) + for (var i = 0; i < this.blocks.length; i++) { + const block = this.blocks[i] + if (block.getData().get_checked() == false) { + const correct = block.getData().get_correct() + list.set(correct, list.get(correct) + 1) + } } - - onUpdateMistake(): void { - this.label_mistake.text = `Mistake: ${this.data.get_mistake()}/${config.MISTAKE_MAX}` + for (var i = 0; i < this.candys.length; i++) { + const candy = this.candys[i] + const show = i + 1 + const left = list.get(show) + candy.setCandy(show, left) } + } - onSetBlock(block: Block, animated: boolean = false): void { - //全部格子还原 - for (var i=0; i { + const list: Array = [] + for (let i = 0; i < this.blocks.length; i++) { + const block = this.blocks[i] + if (block.XIndex == obj.XIndex) + list.push(block) + else if (block.YIndex == obj.YIndex) + list.push(block) + else if (block.XGroup == obj.XGroup && block.YGroup == obj.YGroup) + list.push(block) } + return list + } - onApplyBlock(block: Block): void { - this.selectedBlock.setSelected(false) - this.selectedBlock = block - this.selectedBlock.setSelected(true) - this.onSetBlock(this.selectedBlock) - this.data.set_select_index(this.selectedBlock.getData().get_index()) + findSameNumberBlocks(obj: Block): Array { + const list: Array = [] + for (let i = 0; i < this.blocks.length; i++) { + const block = this.blocks[i] + if (block.getData().get_show() == obj.getData().get_show()) + list.push(block) } - onClickBlock(evt: Laya.Event): void { - var block = evt.target.getComponent(Block) - this.onApplyBlock(block) + return list + } + + findSameNoteBlocks(obj: Block): Array { + const list: Array = [] + for (let i = 0; i < this.blocks.length; i++) { + const block = this.blocks[i] + const note_numbers = block.getData().get_notes() + if (note_numbers.includes(obj.getData().get_show())) + list.push(block) } + return list + } - onClickUndo(evt: Laya.Event): void { - var undo = this.data.pop_undo() - if (undo) { - console.log("onClickUndo>>>>", JSON.stringify(undo)) - this.selectedBlock = this.blocks[undo.index] - this.onApplyBlock(this.selectedBlock) - if (undo.notes && undo.notes.length > 0) { - this.selectedBlock.setNotes(undo.notes) - } - else { - this.selectedBlock.setShowNumber(undo.show, 0) - } - // this.onSetBlock(this.selectedBlock) - this.onUpdateScore() - var undos = this.data.get_undos() - if (undos.length > 0) { - var last = undos[undos.length-1] - this.selectedBlock = this.blocks[last.index] - this.onApplyBlock(this.selectedBlock) - } - } - } - - onClickErase(evt: Laya.Event): void { - if (this.selectedBlock.getData().get_checked() == false) {//未完成且有数字或者笔记才可以使用橡皮 - var show = this.selectedBlock.getData().get_show() - var notes = this.selectedBlock.getData().get_notes() - if (show > 0 || notes.length > 0) { - this.data.add_undo(this.selectedBlock.getData().get_index(), show, notes) - this.selectedBlock.setShowNumber(0, 0) - this.onUpdateScore() - this.onSetBlock(this.selectedBlock) - } - } - } - - onClickNote(evt: Laya.Event): void { - if (evt != null) { - this.data.set_note_open(!this.data.get_note_open()) - } - this.btn_note_normal.visible = this.data.get_note_open() == false - this.btn_note_checked.visible = this.data.get_note_open() - this.label_note.color = this.data.get_note_open() ? "#1d5cdc" : "#545962" - for (var i=0; i 0) { - if (this.selectedBlock.getData().get_checked() == false) {//当前选中的格子没有完成 - var correct = this.selectedBlock.getData().get_correct() - this.onApplyCandy(correct, true) - this.data.set_hint(hint-1) - this.onUpdateHintStatus() - } - else { - var list: Array = new Array() - for (var i=0; i 0) { - var random = Math.random() - var index = Math.round(random*list.length) - if (index >= list.length) - index = list.length -1 - var block = list[index] - this.onApplyBlock(block) - var correct = block.getData().get_correct() - this.onApplyCandy(correct, true) - this.data.set_hint(hint-1) - this.onUpdateHintStatus() - } - } - } - else { - //这里播放广告 现在每个广告每次点击+9 - this.data.set_hint(9) - this.onUpdateHintStatus() - } - - } - onUpdateHintStatus(): void { - var hint = this.data.get_hint() - this.btn_hint_normal.visible = hint > 0 - this.btn_hint_ad.visible = hint <= 0 - this.btn_hint_label.text = hint.toString() + getIsComplete(): boolean { + let b = true + for (let i = 1; i < this.blocks.length; i++) { + const block = this.blocks[i] + if (block.getData().get_checked() == false) { + b = false + break + } } - - public onApplyCandy(showNumber: number, hint: boolean): void { - var show = this.selectedBlock.getData().get_show() - var notes = this.selectedBlock.getData().get_notes() - if (this.selectedBlock.getData().get_checked() == false) { - if (this.data.get_note_open() && hint == false) { - var relateds = this.findRelatedBlocks(this.selectedBlock) - var find = false - for (var i=0; i= 1) {//完成每日挑战关卡检查是否或者当月奖杯 - var now = new Date() - var nowYear = now.getFullYear() - var nowMonth = now.getMonth() + 1 - var doneCount = user.get_doneCountByDate(nowYear, nowMonth) - var dayCount = 0 - var info = G_getMonthInfo(nowYear, nowMonth) - if (info) - dayCount = info.dayCount - console.log("dc完成信息>>>>>>>>>>>>>>>", nowYear, nowMonth, doneCount, dayCount) - if (doneCount >= dayCount) {//当月每日挑战全部完成 - user.add_trophy_record(nowYear, nowMonth, now.getDate()) - } - } - UIManager.getInstance().loadGameDoneUI(false, this.data) - } - } - } - else {//失败 - this.data.set_mistake(this.data.get_mistake()+1) - this.onUpdateMistake() - if (this.data.get_mistake() >= config.MISTAKE_MAX) { - console.log("关卡失败") - this.paused = true - UIManager.getInstance().loadGameOverUI(this.data) - } - } - } - this.onUpdateCandys() - } - } - } - - public onClickCandy(evt: Laya.Event): void { - var candy = evt.target.getComponent(Candy); - this.onApplyCandy(candy.get_show(), false) - var sp = evt.target.getChildByName("Sprite") as Laya.Sprite - Laya.Tween.to(sp, {scaleX: 0.9, scaleY: 0.9}, 100, Laya.Ease.linearIn) - Laya.Tween.to(sp, {scaleX: 1, scaleY: 1}, 100, Laya.Ease.linearInOut, null, 100) - } - - onKeyUp(evt: Laya.Event): void { - var n = Number(evt.key) - if (n && n > 0) { - this.onApplyCandy(n, false) - } - } - - onUpdateCandys(): void { - var list: Map = new Map() - for (var i=1; i<=9; i++) - list.set(i, 0) - for (var i=0; i { - var list: Array = new Array() - for (var i=0; i { - var list: Array = new Array() - for (var i=0; i { - var list: Array = new Array() - for (var i=0; i= 0) - list.push(block) - } - return list - } - - getIsComplete(): boolean { - var b = true; - for (var i=1; i = 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{ - 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 = 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") } -} \ No newline at end of file + + 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" + } +} diff --git a/src/views/common/AutoDestroy.ts b/src/views/common/AutoDestroy.ts index c1162a5..a1892f2 100644 --- a/src/views/common/AutoDestroy.ts +++ b/src/views/common/AutoDestroy.ts @@ -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 } -} \ No newline at end of file + Laya.timer.once(this.lifeTime * 1000, this, () => { + this.owner.destroy() + }) + } +} diff --git a/src/views/common/CommonData.ts b/src/views/common/CommonData.ts index b2ba271..3c61221 100644 --- a/src/views/common/CommonData.ts +++ b/src/views/common/CommonData.ts @@ -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 = ""; - -} \ No newline at end of file + @property(String) + public strValue: string = "" +} diff --git a/src/views/common/GUITips.ts b/src/views/common/GUITips.ts index 4acf3e4..b37acb9 100644 --- a/src/views/common/GUITips.ts +++ b/src/views/common/GUITips.ts @@ -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) + }) } diff --git a/src/views/dc/CalendarUnit.ts b/src/views/dc/CalendarUnit.ts index 4d495c2..c0de497 100644 --- a/src/views/dc/CalendarUnit.ts +++ b/src/views/dc/CalendarUnit.ts @@ -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 - } - } - } -} \ No newline at end of file + } +} diff --git a/src/views/dc/DailyChallenge.ts b/src/views/dc/DailyChallenge.ts index dc4a0ab..47ae725 100644 --- a/src/views/dc/DailyChallenge.ts +++ b/src/views/dc/DailyChallenge.ts @@ -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 = 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{ - 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 = [] + + 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>>>>>>>>>>>>>>", 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= 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) } -} \ No newline at end of file + } +} diff --git a/src/views/dc/TrophyClaim.ts b/src/views/dc/TrophyClaim.ts index 20534b5..08ac8d2 100644 --- a/src/views/dc/TrophyClaim.ts +++ b/src/views/dc/TrophyClaim.ts @@ -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{ - 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 + } } -} \ No newline at end of file + 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() + }) + } +} diff --git a/src/views/dc/TrophyRoom.ts b/src/views/dc/TrophyRoom.ts index 24512c0..f29bf00 100644 --- a/src/views/dc/TrophyRoom.ts +++ b/src/views/dc/TrophyRoom.ts @@ -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 = new Array() - var now = new Date() - var nowYear = now.getFullYear() - var nowMonth = now.getMonth() + 1 - for (var i=0; i = new Array() - var monthMap: Map> = new Map() - for (var i=0; i>>>>>>>>>>>years=", years) - Laya.loader.load(respath.trophy_year_ui_res()).then((go)=>{ - for (var i=1; i{ - var itemsHeight = 0 - for (var i=0; i = [] + 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 = [] + const monthMap: Map> = 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) } -} \ No newline at end of file + 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) + } +} diff --git a/src/views/dc/TrophyShow.ts b/src/views/dc/TrophyShow.ts index 8ecfb77..51687a1 100644 --- a/src/views/dc/TrophyShow.ts +++ b/src/views/dc/TrophyShow.ts @@ -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{ - 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 + } } -} \ No newline at end of file + + 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() + }) + } +} diff --git a/src/views/dc/TrophyUnit.ts b/src/views/dc/TrophyUnit.ts index c2e7265..b8a8417 100644 --- a/src/views/dc/TrophyUnit.ts +++ b/src/views/dc/TrophyUnit.ts @@ -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" } -} \ No newline at end of file + + this.icon.on(Laya.Event.CLICK, this, () => { + const find = user.get_trophyRecord(info.year, info.month) + if (find) { + UIManager.getInstance().loadTrophyShowUI(find) + } + }) + } +} diff --git a/tsconfig.json b/tsconfig.json index e92fa68..0def4ab 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,24 +1,24 @@ { "compilerOptions": { - "module": "es6", "target": "es6", - "strict": true, - "strictNullChecks": false, - "noEmitHelpers": true, - "sourceMap": false, "experimentalDecorators": true, - "skipLibCheck": true, + "module": "es6", "moduleResolution": "node", - "allowSyntheticDefaultImports": true, "paths": { "~/packages/*": [ "./library/packages/*" ] - } + }, + "strict": true, + "strictNullChecks": false, + "noEmitHelpers": true, + "sourceMap": false, + "allowSyntheticDefaultImports": true, + "skipLibCheck": true }, "include": [ "./assets", "./src", "./engine" ] -} \ No newline at end of file +}