From 12b16320e64aa8a86e475c6117a590f81c803ed2 Mon Sep 17 00:00:00 2001 From: yangwen Date: Mon, 26 May 2025 20:56:15 +0800 Subject: [PATCH] UIRoot --- assets/Scene.ls | 13 +++++++++++ assets/resources/GameDone.lh.meta | 3 --- assets/resources/GameOver.lh | 14 ++++++++++++ assets/resources/TopBar.lh | 2 -- src/Entry.ts | 10 ++++---- src/constants/config.ts | 2 ++ src/models/StorageManager.ts | 7 ++++++ src/models/UIManager.ts | 38 +++++++++++++++++++++---------- src/views/Stage.ts | 1 + src/views/dc/DailyChallenge.ts | 12 +++++++++- 10 files changed, 79 insertions(+), 23 deletions(-) delete mode 100644 assets/resources/GameDone.lh.meta diff --git a/assets/Scene.ls b/assets/Scene.ls index ef581e6..498c366 100644 --- a/assets/Scene.ls +++ b/assets/Scene.ls @@ -19,5 +19,18 @@ "_$type": "cd70cd5e-b4cd-4277-ac0a-2224cfbe89ac", "scriptPath": "../src/models/UIManager.ts" } + ], + "_$child": [ + { + "_$id": "4rxcl2w3", + "_$type": "Panel", + "name": "UIRoot", + "x": -420, + "y": 420, + "width": 1920, + "height": 1080, + "centerX": 0, + "centerY": 0 + } ] } \ No newline at end of file diff --git a/assets/resources/GameDone.lh.meta b/assets/resources/GameDone.lh.meta deleted file mode 100644 index e725f9e..0000000 --- a/assets/resources/GameDone.lh.meta +++ /dev/null @@ -1,3 +0,0 @@ -{ - "uuid": "c0e79324-cca6-4b1c-92fd-b0fb981a9766" -} \ No newline at end of file diff --git a/assets/resources/GameOver.lh b/assets/resources/GameOver.lh index 6c4730c..9264252 100644 --- a/assets/resources/GameOver.lh +++ b/assets/resources/GameOver.lh @@ -30,6 +30,20 @@ } ], "_$child": [ + { + "_$id": "unwnutvo", + "_$type": "Image", + "name": "Image", + "width": 1080, + "height": 1920, + "alpha": 0.6, + "left": 0, + "right": 0, + "top": 0, + "bottom": 0, + "skin": "res://a98f334e-ce04-4cd0-8fc5-bbdf9b048609", + "color": "#000000" + }, { "_$id": "0a0ovv4z", "_$type": "Box", diff --git a/assets/resources/TopBar.lh b/assets/resources/TopBar.lh index b732086..f4967cd 100644 --- a/assets/resources/TopBar.lh +++ b/assets/resources/TopBar.lh @@ -5,8 +5,6 @@ "name": "TopBar", "width": 1920, "height": 120, - "left": 0, - "right": 0, "top": 0, "_$comp": [ { diff --git a/src/Entry.ts b/src/Entry.ts index 9b0f3b7..f5e6ae5 100644 --- a/src/Entry.ts +++ b/src/Entry.ts @@ -5,14 +5,14 @@ Laya.addBeforeInitCallback((stageConfig) => { console.log(`window innerWidth=${window.innerWidth} innerHeight=${window.innerHeight}`) console.log(`stageConfig designWidth=${stageConfig.designWidth} designWidth=${stageConfig.designHeight}`) if (window.innerWidth > window.innerHeight) { - stageConfig.designWidth = 1920 - stageConfig.designHeight = 1080 - stageConfig.scaleMode = "fixedwidth" + stageConfig.designWidth = config.DESIGN_HEIGHT + stageConfig.designHeight = config.DESIGN_WIDTH + stageConfig.scaleMode = "fixedauto" config.H_SCREEN = true } else { - stageConfig.designWidth = 1080 - stageConfig.designHeight = 1920 + stageConfig.designWidth = config.DESIGN_WIDTH + stageConfig.designHeight = config.DESIGN_HEIGHT stageConfig.scaleMode = "fixedheight" config.H_SCREEN = false } diff --git a/src/constants/config.ts b/src/constants/config.ts index 8b7ef79..806b53a 100644 --- a/src/constants/config.ts +++ b/src/constants/config.ts @@ -3,6 +3,8 @@ export const config = { + DESIGN_WIDTH: 1080, + DESIGN_HEIGHT: 1920, H_SCREEN: false, // 是否横屏 DEBUG: false, diff --git a/src/models/StorageManager.ts b/src/models/StorageManager.ts index 8d586a9..0ee974d 100644 --- a/src/models/StorageManager.ts +++ b/src/models/StorageManager.ts @@ -103,6 +103,13 @@ export class StorageManager { return null } + public cleanStage(stageID: string): void { + if (this.stageMap.has(stageID)) { + this.stageMap.delete(stageID) + } + Laya.LocalStorage.removeItem(stageID) + } + public loadStage(stageID: string): DOStage {//载入关卡 var doStage = this.getStage(stageID) if (doStage) { diff --git a/src/models/UIManager.ts b/src/models/UIManager.ts index b64cc16..a2cbd82 100644 --- a/src/models/UIManager.ts +++ b/src/models/UIManager.ts @@ -20,10 +20,36 @@ export class UIManager extends Laya.Script { declare owner: Laya.Scene private static _instance: UIManager + public static getInstance(): UIManager { + return UIManager._instance + } + onAwake(): void { UIManager._instance = this } + private UIRoot: Laya.Panel + public getUIRoot(): Laya.Node { + if (this.UIRoot == null) { + this.UIRoot = this.owner.getChildByName("UIRoot") as Laya.Panel + if (config.H_SCREEN) { + this.UIRoot.width = config.DESIGN_HEIGHT + this.UIRoot.height = config.DESIGN_WIDTH + } + else { + this.UIRoot.width = config.DESIGN_WIDTH + this.UIRoot.height = config.DESIGN_HEIGHT + } + } + return this.UIRoot + } + + + private stage: Stage + private dc_ui: DailyChallenge + private trophyRoom: TrophyRoom + + onStart(): void { if (config.H_SCREEN) { this.loadTopBarUI() @@ -33,18 +59,6 @@ export class UIManager extends Laya.Script { } } - public static getInstance(): UIManager { - return UIManager._instance - } - - private stage: Stage - private dc_ui: DailyChallenge - private trophyRoom: TrophyRoom - - - public getUIRoot(): Laya.Node { - return this.owner - } public loadHomeUI(): void { Laya.loader.load(respath.home_ui_res).then((go)=>{ diff --git a/src/views/Stage.ts b/src/views/Stage.ts index bfb4c81..4a7776c 100644 --- a/src/views/Stage.ts +++ b/src/views/Stage.ts @@ -187,6 +187,7 @@ export class Stage extends Laya.Script { block.setBlockColor(config.BLOCK_COLOR.WHITE) block.setBlock(doBlock) block.setTipsBgColor(false) + block.setSelected(false) } this.onUpdateCandys() this.onClickNote(null) diff --git a/src/views/dc/DailyChallenge.ts b/src/views/dc/DailyChallenge.ts index bb2b005..1b5b35b 100644 --- a/src/views/dc/DailyChallenge.ts +++ b/src/views/dc/DailyChallenge.ts @@ -84,7 +84,7 @@ export class DailyChallenge extends Laya.Script { var stageID = `${year}-${month}-${dayNow}` var doStage = StorageManager.getInstance().getStage(stageID) console.log("play >>>>>>>>>>>>>>>>>>>>>>>", stageID, doStage) - if (!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) } @@ -190,6 +190,16 @@ export class DailyChallenge extends Laya.Script { } 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