模拟主题数据
This commit is contained in:
@@ -83,5 +83,12 @@ export class BaseConfig {
|
||||
*/
|
||||
protected getAllConfig(): any | null {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有配置 id,如果存在
|
||||
*/
|
||||
public getAllId(): any | null {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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<void>(r => setTimeout(r, ms)); }
|
||||
private ok<T>(data: T): ApiResponse<T> {
|
||||
return ({ ok: true, data } as unknown) as ApiResponse<T>;
|
||||
return ({ code: proto.cs.EnmRetCode.SUCCESS, data } as unknown) as ApiResponse<T>;
|
||||
}
|
||||
|
||||
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<ApiResponse<proto.cs.ICSHallThemeRes>> {
|
||||
// 延时
|
||||
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<ThemeConfig>(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);
|
||||
}
|
||||
|
||||
@@ -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<ThemeData>(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;
|
||||
|
||||
@@ -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<ThemeData>(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);
|
||||
|
||||
Reference in New Issue
Block a user