From aacd18ee212d14e65fe5d8ad00306453d59e5748 Mon Sep 17 00:00:00 2001 From: chen wei bo <1025839511@qq.com> Date: Tue, 2 Sep 2025 11:33:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E6=8B=9F=E4=B8=BB=E9=A2=98=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/Scripts/chat18x/config/BaseConfig.ts | 9 ++++- assets/Scripts/chat18x/config/ThemeConfig.ts | 14 ++++++++ .../network/services/MockThemeService.ts | 33 +++++++++++-------- .../Scripts/chat18x/ui/panels/ThemePanel.ts | 24 ++++++++++---- assets/Scripts/chat18x/uiitems/ThemeItem.ts | 18 ++++++---- 5 files changed, 69 insertions(+), 29 deletions(-) diff --git a/assets/Scripts/chat18x/config/BaseConfig.ts b/assets/Scripts/chat18x/config/BaseConfig.ts index 1fc01f76..13392bb8 100644 --- a/assets/Scripts/chat18x/config/BaseConfig.ts +++ b/assets/Scripts/chat18x/config/BaseConfig.ts @@ -83,5 +83,12 @@ export class BaseConfig { */ protected getAllConfig(): any | null { return null; - } + } + + /** + * 获取所有配置 id,如果存在 + */ + public getAllId(): any | null { + return null; + } } \ No newline at end of file diff --git a/assets/Scripts/chat18x/config/ThemeConfig.ts b/assets/Scripts/chat18x/config/ThemeConfig.ts index 2decd8df..e597d030 100644 --- a/assets/Scripts/chat18x/config/ThemeConfig.ts +++ b/assets/Scripts/chat18x/config/ThemeConfig.ts @@ -25,6 +25,20 @@ export class ThemeConfig extends BaseConfig { return ConfigManager.tables.TbThemes; } + /** + * 获取所有配置 id,如果存在 + */ + public getAllId(): any | null { + let allData = this.getAllConfig(); + if (!allData) return null; + const dataArr = allData.getDataList(); + let allId = []; + for (let oneData of dataArr) { + allId.push(oneData.id); + } + return allId; + } + /** * 获取配置,根据 id */ diff --git a/assets/Scripts/chat18x/network/services/MockThemeService.ts b/assets/Scripts/chat18x/network/services/MockThemeService.ts index 95890057..5075b23a 100644 --- a/assets/Scripts/chat18x/network/services/MockThemeService.ts +++ b/assets/Scripts/chat18x/network/services/MockThemeService.ts @@ -1,38 +1,43 @@ import type { ApiResponse } from "../client/types"; import proto from "db://assets/Scripts/proto/proto.pb.js"; import type { IThemeService } from "./IThemeService"; +import { ConfigManager, ConfigId } from "../../manager/ConfigManager"; +import { ThemeConfig } from "../../config/ThemeConfig"; export class MockThemeService implements IThemeService { private delay(ms = 160) { return new Promise(r => setTimeout(r, ms)); } private ok(data: T): ApiResponse { - return ({ ok: true, data } as unknown) as ApiResponse; + return ({ code: proto.cs.EnmRetCode.SUCCESS, data } as unknown) as ApiResponse; } - private makeTheme(id: number, name: string, category: number, isRelease = true): proto.cs.IHallTheme { + private makeTheme(id: number, key: string, name: string, category: number, isRelease: boolean, path: string): proto.cs.IHallTheme { return { id, - key: `theme_${id}`, + key, name, category, isRelease, - path: `https://dummy.local/theme/${id}.png`, + path, }; - // 若你使用资源服路径,可替换 path 为实际地址或 db:// 本地资源 } // 获取大厅分类列表 async reqHallTheme(_req: proto.cs.ICSHallThemeReq): Promise> { + // 延时 await this.delay(); - const themes: proto.cs.IHallTheme[] = [ - this.makeTheme(1, "Hot", 1, true), - this.makeTheme(2, "New", 2, true), - this.makeTheme(3, "Popular", 3, true), - this.makeTheme(4, "VIP Only", 4, false), - this.makeTheme(5, "Classic", 5, true), - this.makeTheme(6, "Editor Pick",6, true), - ]; - + const configData = ConfigManager.I.getDataById(ConfigId.Theme); + const allId = configData.getAllId(); + let themes: proto.cs.IHallTheme[] = []; + for (let oneId of allId) { + let key = configData.getLanKeyById(oneId); + let name = configData.getNameById(oneId); + let category = configData.getCategoryById(oneId); + let isRelease = configData.getIsReleaseById(oneId); + let path = configData.getPathById(oneId); + let oneData = this.makeTheme(oneId, key, name, category, isRelease, path); + themes.push(oneData); + } const res: proto.cs.ICSHallThemeRes = { themes }; return this.ok(res); } diff --git a/assets/Scripts/chat18x/ui/panels/ThemePanel.ts b/assets/Scripts/chat18x/ui/panels/ThemePanel.ts index d6dbb8f5..24468b99 100644 --- a/assets/Scripts/chat18x/ui/panels/ThemePanel.ts +++ b/assets/Scripts/chat18x/ui/panels/ThemePanel.ts @@ -18,6 +18,9 @@ import { ConfigManager } from "../../manager/ConfigManager"; import LanguageUtils from "../../../Main/Common/LanguageUtils"; import { ViewManager } from "../../../Main/Manager/ViewManager"; import { InnerMsgCode } from "../../../Main/Config/InnerMsgCode"; +import { ThemeService } from "db://assets/Scripts/chat18x/network/services/ThemeService"; +import { DataManager, DataId } from "../../data/DataManager"; +import { ThemeData } from "../../data/ThemeData"; const { ccclass, property } = _decorator; @@ -51,7 +54,7 @@ export class ThemePanel extends li_BaseView { } rectNameKey: string; - Show() { + async Show() { //some temp data this.coinNum.string = (50.0).toString(); this.recId = 1; @@ -60,16 +63,23 @@ export class ThemePanel extends li_BaseView { this.cache[i].node.destroy(); } } - const cfgs = ConfigManager.tables.TbThemes.getDataList(); - for (let i = 0; i < cfgs.length; i++) { - const cfg = cfgs[i]; - if (!cfg) return; + // 请求主题数据 + const reqData = { + + }; + let res = await ThemeService.I.reqHallTheme(reqData); + // 保存数据 + const themeData = DataManager.I.getDataById(DataId.Theme); + themeData.themes = res.data; + // 根据数据,构建界面显示 + const themeIds = themeData.themeIds; + for (let id of themeIds) { let newNode = instantiate(this.itemInst.node); let item = newNode.getComponent(ThemeItem); - item.refresh(cfg); + item.refresh(id); newNode.active = true; this.cache.push(item); - this.content.addChild(newNode); + this.content.addChild(newNode); } const rectInfo = ConfigManager.tables.TbGirls.get(10001); this.recId = rectInfo.id; diff --git a/assets/Scripts/chat18x/uiitems/ThemeItem.ts b/assets/Scripts/chat18x/uiitems/ThemeItem.ts index ff79517f..98a668a4 100644 --- a/assets/Scripts/chat18x/uiitems/ThemeItem.ts +++ b/assets/Scripts/chat18x/uiitems/ThemeItem.ts @@ -6,6 +6,8 @@ import { NavigationManager } from "../manager/NavigationManager"; import { TbThemes, Theme } from "../../schema/schema"; import LanguageUtils from "../../Main/Common/LanguageUtils"; import { InnerMsgCode } from "../../Main/Config/InnerMsgCode"; +import { DataManager, DataId } from "../data/DataManager"; +import { ThemeData } from "../data/ThemeData"; const { ccclass, property } = _decorator; @ccclass("ThemeItem") @@ -36,16 +38,18 @@ export class ThemeItem extends Component { }); } - refresh(themeData: Theme) { + refresh(themeId: number) { + // 主题数据 + const themeData = DataManager.I.getDataById(DataId.Theme); this.lockImg.node.active = this.lockCover.node.active = - !themeData.isRelease; - this.isLocked = !themeData.isRelease; - this.key = themeData.key; - this.titleName.string = LanguageUtils.getText(themeData.key); - this.category = themeData.category; + !themeData.getIsReleaseById(themeId); + this.isLocked = !themeData.getIsReleaseById(themeId); + this.key = themeData.getLanKeyById(themeId); + this.titleName.string = LanguageUtils.getText(themeData.getLanKeyById(themeId)); + this.category = themeData.getCategoryById(themeId); ResManager.I.changeBundleSpriteFrame( this.img, - themeData.path, + themeData.getPathById(themeId), "Chat18x", () => { let sizeTran = this.img.node.parent.getComponent(UITransform);