From 9d2a1773252f0546881c3edd9db14e2b5ca70acc Mon Sep 17 00:00:00 2001 From: yangwen Date: Thu, 5 Jun 2025 14:57:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=9B=BE=E7=89=87=E9=A2=84?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/resources/Home.lh | 5 +- assets/resources/dc/DailyChallenge.lh | 4 +- assets/resources/dc/DailyChallenge_H.lh | 4 +- assets/resources/dc/TrophyClaim.lh | 2 +- assets/resources/dc/TrophyClaim_H.lh | 2 +- assets/resources/dc/TrophyShow.lh | 2 +- assets/resources/dc/TrophyShow_H.lh | 2 +- src/Main.ts | 16 +---- src/constants/respath.ts | 2 +- src/models/ResourceManager.ts | 92 +++++++++++++++++++++++++ src/views/Home.ts | 12 ++-- src/views/dc/DailyChallenge.ts | 7 +- src/views/dc/TrophyClaim.ts | 3 +- src/views/dc/TrophyShow.ts | 3 +- src/views/dc/TrophyUnit.ts | 7 +- 15 files changed, 123 insertions(+), 40 deletions(-) diff --git a/assets/resources/Home.lh b/assets/resources/Home.lh index 30b5f2b..9b36e12 100644 --- a/assets/resources/Home.lh +++ b/assets/resources/Home.lh @@ -62,10 +62,9 @@ "_$id": "7270vjom", "_$type": "Image", "name": "bg", - "width": 16, - "height": 16, + "width": 936, + "height": 468, "skin": "res://07b90718-84ee-4924-9098-8f0ee3663d92", - "useSourceSize": true, "color": "#ffffff" }, { diff --git a/assets/resources/dc/DailyChallenge.lh b/assets/resources/dc/DailyChallenge.lh index 6f2ec00..7167f4c 100644 --- a/assets/resources/dc/DailyChallenge.lh +++ b/assets/resources/dc/DailyChallenge.lh @@ -103,7 +103,7 @@ "left": 0, "right": 0, "top": 0, - "skin": "res://4182ef3f-6065-44dd-83c2-70490f02e9cb", + "skin": "res://07b90718-84ee-4924-9098-8f0ee3663d92", "color": "#ffffff" }, { @@ -129,7 +129,7 @@ "height": 468, "top": 110, "centerX": 225, - "skin": "res://09690a9b-3d5a-4da1-b457-1a3275cf5c14", + "skin": "res://07b90718-84ee-4924-9098-8f0ee3663d92", "color": "#ffffff" }, { diff --git a/assets/resources/dc/DailyChallenge_H.lh b/assets/resources/dc/DailyChallenge_H.lh index 2d58b4a..1472419 100644 --- a/assets/resources/dc/DailyChallenge_H.lh +++ b/assets/resources/dc/DailyChallenge_H.lh @@ -96,7 +96,7 @@ "height": 960, "left": 0, "top": 0, - "skin": "res://4182ef3f-6065-44dd-83c2-70490f02e9cb", + "skin": "res://07b90718-84ee-4924-9098-8f0ee3663d92", "color": "#ffffff" }, { @@ -123,7 +123,7 @@ "height": 600, "bottom": 30, "centerX": 0, - "skin": "res://09690a9b-3d5a-4da1-b457-1a3275cf5c14", + "skin": "res://07b90718-84ee-4924-9098-8f0ee3663d92", "color": "#ffffff" }, { diff --git a/assets/resources/dc/TrophyClaim.lh b/assets/resources/dc/TrophyClaim.lh index 60a13a7..e1a92b4 100644 --- a/assets/resources/dc/TrophyClaim.lh +++ b/assets/resources/dc/TrophyClaim.lh @@ -71,7 +71,7 @@ "height": 834, "centerX": 0, "centerY": 0, - "skin": "res://7d235ac1-6755-4409-ab86-23aaf41e1537", + "skin": "res://07b90718-84ee-4924-9098-8f0ee3663d92", "color": "#ffffff" }, { diff --git a/assets/resources/dc/TrophyClaim_H.lh b/assets/resources/dc/TrophyClaim_H.lh index 298c47d..3f37d32 100644 --- a/assets/resources/dc/TrophyClaim_H.lh +++ b/assets/resources/dc/TrophyClaim_H.lh @@ -73,7 +73,7 @@ "height": 600, "centerX": 0, "centerY": 0, - "skin": "res://7d235ac1-6755-4409-ab86-23aaf41e1537", + "skin": "res://07b90718-84ee-4924-9098-8f0ee3663d92", "color": "#ffffff" }, { diff --git a/assets/resources/dc/TrophyShow.lh b/assets/resources/dc/TrophyShow.lh index ce59fcb..bf3ddc9 100644 --- a/assets/resources/dc/TrophyShow.lh +++ b/assets/resources/dc/TrophyShow.lh @@ -71,7 +71,7 @@ "height": 834, "centerX": 0, "centerY": 0, - "skin": "res://7d235ac1-6755-4409-ab86-23aaf41e1537", + "skin": "res://07b90718-84ee-4924-9098-8f0ee3663d92", "color": "#ffffff" }, { diff --git a/assets/resources/dc/TrophyShow_H.lh b/assets/resources/dc/TrophyShow_H.lh index b1e19e3..9064352 100644 --- a/assets/resources/dc/TrophyShow_H.lh +++ b/assets/resources/dc/TrophyShow_H.lh @@ -73,7 +73,7 @@ "height": 600, "centerX": 0, "centerY": 0, - "skin": "res://7d235ac1-6755-4409-ab86-23aaf41e1537", + "skin": "res://07b90718-84ee-4924-9098-8f0ee3663d92", "color": "#ffffff" }, { diff --git a/src/Main.ts b/src/Main.ts index a39b1f9..ffbe819 100644 --- a/src/Main.ts +++ b/src/Main.ts @@ -1,6 +1,7 @@ import { respath } from "./constants/respath" import { DCManager } from "./models/DCManager" import { LevelManager } from "./models/LevelManager" +import { ResourceManager } from "./models/ResourceManager" import { StorageManager } from "./models/StorageManager" const { regClass } = Laya @@ -12,20 +13,7 @@ export class Main extends Laya.Script { DCManager.getInstance().init() LevelManager.getInstance().init() StorageManager.getInstance().init() - - const resources: Array<{ url: string, type?: any, lazy?: boolean }> = [ - { url: respath.score_add_ui_res() }, - - { url: respath.dc_top_bg_normal, type: Laya.Loader.IMAGE }, - { url: respath.dc_top_bg_month_finish, type: Laya.Loader.IMAGE }, - { url: respath.trophy_bg_light_gold, type: Laya.Loader.IMAGE }, - { url: respath.trophy_bg_light_grey, type: Laya.Loader.IMAGE } - ] - Laya.loader.load(resources, Laya.Handler.create(this, (success: object) => { // 第二个参数:成功回调 - console.log("预加载资源结束>>>>", success) - }), Laya.Handler.create(this, (resProg: number) => { // 第三个参数:进度回调 - console.log("预加载资源进度>>>>", resProg) - })) + ResourceManager.getInstance().init() } onLateUpdate(): void { diff --git a/src/constants/respath.ts b/src/constants/respath.ts index b4452ae..ebc6e0d 100644 --- a/src/constants/respath.ts +++ b/src/constants/respath.ts @@ -52,7 +52,7 @@ export const respath = { 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", + dc_top_bg_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", diff --git a/src/models/ResourceManager.ts b/src/models/ResourceManager.ts index 646a337..5ca66d2 100644 --- a/src/models/ResourceManager.ts +++ b/src/models/ResourceManager.ts @@ -1,3 +1,7 @@ +import { respath } from "../constants/respath" + + + export class ResourceManager { private static instance: ResourceManager public static getInstance(): ResourceManager { @@ -6,4 +10,92 @@ export class ResourceManager { } return ResourceManager.instance } + + private resources: Array<{ url: string, type?: any, lazy?: boolean }> = [] + private reqs: Map> = new Map() + + + public init(): void { + + this.resources.push({ url: respath.score_add_ui_res() }) + this.resources.push({ url: respath.dc_ui_res() }) + this.resources.push({ url: respath.trophy_ui_res() }) + + this.resources.push({ url: respath.home_top_dc_bg_normal, type: Laya.Loader.IMAGE }) + this.resources.push({ url: respath.home_top_dc_bg_finish, type: Laya.Loader.IMAGE }) + this.resources.push({ url: respath.dc_top_bg_normal, type: Laya.Loader.IMAGE }) + this.resources.push({ url: respath.dc_top_bg_finish, type: Laya.Loader.IMAGE }) + + this.resources.push({ url: respath.trophy_bg_light_gold, type: Laya.Loader.IMAGE }) + this.resources.push({ url: respath.trophy_bg_light_grey, type: Laya.Loader.IMAGE }) + this.resources.push({ url: respath.trophy_01, type: Laya.Loader.IMAGE }) + this.resources.push({ url: respath.trophy_02, type: Laya.Loader.IMAGE }) + this.resources.push({ url: respath.trophy_03, type: Laya.Loader.IMAGE }) + this.resources.push({ url: respath.trophy_04, type: Laya.Loader.IMAGE }) + this.resources.push({ url: respath.trophy_05, type: Laya.Loader.IMAGE }) + this.resources.push({ url: respath.trophy_06, type: Laya.Loader.IMAGE }) + this.resources.push({ url: respath.trophy_07, type: Laya.Loader.IMAGE }) + this.resources.push({ url: respath.trophy_08, type: Laya.Loader.IMAGE }) + this.resources.push({ url: respath.trophy_09, type: Laya.Loader.IMAGE }) + this.resources.push({ url: respath.trophy_10, type: Laya.Loader.IMAGE }) + this.resources.push({ url: respath.trophy_11, type: Laya.Loader.IMAGE }) + this.resources.push({ url: respath.trophy_12, type: Laya.Loader.IMAGE }) + + Laya.loader.load(this.resources, Laya.Handler.create(this, (obj: object) => { // 第二个参数:成功回调 + console.log("预加载资源结束>>>>", obj) + this.reqs.forEach((list: Array, path: string)=>{ + for (let i = 0; i < list.length; i++) { + const img = list[i] + if (img && img.parent) { + img.texture = Laya.loader.getRes(path) + } + } + }) + this.reqs.clear() + }), Laya.Handler.create(this, (resProg: number) => { // 第三个参数:进度回调 + // console.log("预加载资源进度>>>>", resProg) + })) + + } + + public loadTexture(path: string, image: Laya.Image): void { + const obj = Laya.loader.getRes(path) + // console.log("loadTexture obj", path, obj) + image.skin = "" + if (obj) { + image.texture = obj + } else { + if (!this.reqs.has(path)) { + this.reqs.set(path, new Array()) + } + let list = this.reqs.get(path) + list.push(image) + + let find = false + for (let i = 0; i < this.resources.length; i++) { + const info = this.resources[i] + if (info.url === path) { + find = true + break + } + } + // console.log("loadTexture find", path, find) + if (find === false) { + Laya.loader.load(path, Laya.Handler.create(this, (obj: Laya.Texture) => { // 第二个参数:成功回调 + // console.log("加载资源成功>>>>", path, obj, image, image.parent) + const list = this.reqs.get(path) + for (let i = 0; i < list.length; i++) { + const img = list[i] + if (img && img.parent) { + img.texture = obj + } + } + this.reqs.delete(path) + }), Laya.Handler.create(this, (resProg: number) => { // 第三个参数:进度回调 + // console.log("加载资源进度>>>>", path, resProg) + })) + } + + } + } } diff --git a/src/views/Home.ts b/src/views/Home.ts index d5a6c88..720db58 100644 --- a/src/views/Home.ts +++ b/src/views/Home.ts @@ -1,6 +1,7 @@ import { config } from "../constants/config" import { respath } from "../constants/respath" import { G_getMonthInfo } from "../models/DCManager" +import { ResourceManager } from "../models/ResourceManager" import { StorageManager } from "../models/StorageManager" import { UIManager } from "../models/UIManager" import { Utility_ConvertSecondToString } from "../utils/utility" @@ -42,8 +43,7 @@ export class Home extends Laya.Script { @property(Laya.Box) public btn_new_white: Laya.Box - // 组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次 - onAwake(): void { + onStart(): void { const user = StorageManager.getInstance().getUser() const now = new Date() const nowYear = now.getFullYear() @@ -51,18 +51,18 @@ export class Home extends Laya.Script { const nowDay = now.getDate() const find = G_getMonthInfo(nowYear, nowMonth) if (find) { - this.icon_dc.skin = find.icon_res + ResourceManager.getInstance().loadTexture(find.icon_res, this.icon_dc) if (user.get_trophyRecord(nowYear, nowMonth)) { - this.bg_dc.skin = respath.home_top_dc_bg_finish + ResourceManager.getInstance().loadTexture(respath.home_top_dc_bg_finish, this.bg_dc) this.label_dc_title.color = "#ffffff" this.label_dc_date.color = "#ffffff" } else { - this.bg_dc.skin = respath.home_top_dc_bg_normal + ResourceManager.getInstance().loadTexture(respath.home_top_dc_bg_normal, this.bg_dc) this.label_dc_title.color = "#2d3138" this.label_dc_date.color = "#2d3138" } } else { - this.bg_dc.skin = respath.home_top_dc_bg_normal + ResourceManager.getInstance().loadTexture(respath.home_top_dc_bg_normal, this.bg_dc) this.label_dc_title.color = "#2d3138" this.label_dc_date.color = "#2d3138" } diff --git a/src/views/dc/DailyChallenge.ts b/src/views/dc/DailyChallenge.ts index f9a6c2e..57836f3 100644 --- a/src/views/dc/DailyChallenge.ts +++ b/src/views/dc/DailyChallenge.ts @@ -2,6 +2,7 @@ import { config } from "../../constants/config" import { respath } from "../../constants/respath" import { MONTH_LIST } from "../../models/DCManager" import { EVENT_TYPES, EventManager } from "../../models/EventManager" +import { ResourceManager } from "../../models/ResourceManager" import { StorageManager } from "../../models/StorageManager" import { UIManager } from "../../models/UIManager" import { Utility_ConvertSecondToString } from "../../utils/utility" @@ -188,14 +189,14 @@ export class DailyChallenge extends Laya.Script { const nowMonth = now.getMonth() + 1 const nowDay = new Date().getDate() - this.trophy_icon.skin = info.icon_res + ResourceManager.getInstance().loadTexture(info.icon_res, this.trophy_icon) // 设置背景 if (user.get_trophyRecord(info.year, info.month)) { - this.bg_dc.skin = respath.dc_top_bg_month_finish + ResourceManager.getInstance().loadTexture(respath.dc_top_bg_finish, this.bg_dc) this.trophy_light.visible = true this.trophy_icon.gray = false } else { - this.bg_dc.skin = respath.dc_top_bg_normal + ResourceManager.getInstance().loadTexture(respath.dc_top_bg_normal, this.bg_dc) this.trophy_light.visible = false this.trophy_icon.gray = true } diff --git a/src/views/dc/TrophyClaim.ts b/src/views/dc/TrophyClaim.ts index d4101ef..120d7a5 100644 --- a/src/views/dc/TrophyClaim.ts +++ b/src/views/dc/TrophyClaim.ts @@ -1,6 +1,7 @@ import type { TrophyRecord } from "../../types/global" import { config } from "../../constants/config" import { MONTH_LIST } from "../../models/DCManager" +import { ResourceManager } from "../../models/ResourceManager" const { regClass, property } = Laya @@ -21,7 +22,7 @@ export class TrophyClaim extends Laya.Script { 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 + ResourceManager.getInstance().loadTexture(obj.icon_res, this.icon) break } } diff --git a/src/views/dc/TrophyShow.ts b/src/views/dc/TrophyShow.ts index c6c3771..ff3193b 100644 --- a/src/views/dc/TrophyShow.ts +++ b/src/views/dc/TrophyShow.ts @@ -1,6 +1,7 @@ import type { TrophyRecord } from "../../types/global" import { config } from "../../constants/config" import { MONTH_LIST } from "../../models/DCManager" +import { ResourceManager } from "../../models/ResourceManager" const { regClass, property } = Laya @@ -21,7 +22,7 @@ export class TrophyShow extends Laya.Script { 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 + ResourceManager.getInstance().loadTexture(obj.icon_res, this.icon) break } } diff --git a/src/views/dc/TrophyUnit.ts b/src/views/dc/TrophyUnit.ts index f43a95a..ce21eb8 100644 --- a/src/views/dc/TrophyUnit.ts +++ b/src/views/dc/TrophyUnit.ts @@ -1,5 +1,6 @@ import { config } from "../../constants/config" import { respath } from "../../constants/respath" +import { ResourceManager } from "../../models/ResourceManager" import { StorageManager } from "../../models/StorageManager" import { UIManager } from "../../models/UIManager" @@ -24,15 +25,15 @@ export class TrophyUnit extends Laya.Script { 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 + ResourceManager.getInstance().loadTexture(info.icon_res, this.icon) this.label_count.text = `${starCount}/${info.dayCount}` this.label_month.text = config.MONTH_ABBRS[info.month - 1] if (user.get_trophyRecord(info.year, info.month)) { - this.bg_light.skin = respath.trophy_bg_light_gold + ResourceManager.getInstance().loadTexture(respath.trophy_bg_light_gold, this.bg_light) this.icon.gray = false this.label_month.color = "#2d3138" } else { - this.bg_light.skin = respath.trophy_bg_light_grey + ResourceManager.getInstance().loadTexture(respath.trophy_bg_light_grey, this.bg_light) this.icon.gray = true this.label_month.color = "#a7abb3" }