模拟主题数据
This commit is contained in:
@@ -83,5 +83,12 @@ export class BaseConfig {
|
|||||||
*/
|
*/
|
||||||
protected getAllConfig(): any | null {
|
protected getAllConfig(): any | null {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取所有配置 id,如果存在
|
||||||
|
*/
|
||||||
|
public getAllId(): any | null {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -25,6 +25,20 @@ export class ThemeConfig extends BaseConfig {
|
|||||||
return ConfigManager.tables.TbThemes;
|
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
|
* 获取配置,根据 id
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,38 +1,43 @@
|
|||||||
import type { ApiResponse } from "../client/types";
|
import type { ApiResponse } from "../client/types";
|
||||||
import proto from "db://assets/Scripts/proto/proto.pb.js";
|
import proto from "db://assets/Scripts/proto/proto.pb.js";
|
||||||
import type { IThemeService } from "./IThemeService";
|
import type { IThemeService } from "./IThemeService";
|
||||||
|
import { ConfigManager, ConfigId } from "../../manager/ConfigManager";
|
||||||
|
import { ThemeConfig } from "../../config/ThemeConfig";
|
||||||
|
|
||||||
export class MockThemeService implements IThemeService {
|
export class MockThemeService implements IThemeService {
|
||||||
private delay(ms = 160) { return new Promise<void>(r => setTimeout(r, ms)); }
|
private delay(ms = 160) { return new Promise<void>(r => setTimeout(r, ms)); }
|
||||||
private ok<T>(data: T): ApiResponse<T> {
|
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 {
|
return {
|
||||||
id,
|
id,
|
||||||
key: `theme_${id}`,
|
key,
|
||||||
name,
|
name,
|
||||||
category,
|
category,
|
||||||
isRelease,
|
isRelease,
|
||||||
path: `https://dummy.local/theme/${id}.png`,
|
path,
|
||||||
};
|
};
|
||||||
// 若你使用资源服路径,可替换 path 为实际地址或 db:// 本地资源
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取大厅分类列表
|
// 获取大厅分类列表
|
||||||
async reqHallTheme(_req: proto.cs.ICSHallThemeReq): Promise<ApiResponse<proto.cs.ICSHallThemeRes>> {
|
async reqHallTheme(_req: proto.cs.ICSHallThemeReq): Promise<ApiResponse<proto.cs.ICSHallThemeRes>> {
|
||||||
|
// 延时
|
||||||
await this.delay();
|
await this.delay();
|
||||||
|
|
||||||
const themes: proto.cs.IHallTheme[] = [
|
const configData = ConfigManager.I.getDataById<ThemeConfig>(ConfigId.Theme);
|
||||||
this.makeTheme(1, "Hot", 1, true),
|
const allId = configData.getAllId();
|
||||||
this.makeTheme(2, "New", 2, true),
|
let themes: proto.cs.IHallTheme[] = [];
|
||||||
this.makeTheme(3, "Popular", 3, true),
|
for (let oneId of allId) {
|
||||||
this.makeTheme(4, "VIP Only", 4, false),
|
let key = configData.getLanKeyById(oneId);
|
||||||
this.makeTheme(5, "Classic", 5, true),
|
let name = configData.getNameById(oneId);
|
||||||
this.makeTheme(6, "Editor Pick",6, true),
|
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 };
|
const res: proto.cs.ICSHallThemeRes = { themes };
|
||||||
return this.ok(res);
|
return this.ok(res);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ import { ConfigManager } from "../../manager/ConfigManager";
|
|||||||
import LanguageUtils from "../../../Main/Common/LanguageUtils";
|
import LanguageUtils from "../../../Main/Common/LanguageUtils";
|
||||||
import { ViewManager } from "../../../Main/Manager/ViewManager";
|
import { ViewManager } from "../../../Main/Manager/ViewManager";
|
||||||
import { InnerMsgCode } from "../../../Main/Config/InnerMsgCode";
|
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;
|
const { ccclass, property } = _decorator;
|
||||||
|
|
||||||
@@ -51,7 +54,7 @@ export class ThemePanel extends li_BaseView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
rectNameKey: string;
|
rectNameKey: string;
|
||||||
Show() {
|
async Show() {
|
||||||
//some temp data
|
//some temp data
|
||||||
this.coinNum.string = (50.0).toString();
|
this.coinNum.string = (50.0).toString();
|
||||||
this.recId = 1;
|
this.recId = 1;
|
||||||
@@ -60,16 +63,23 @@ export class ThemePanel extends li_BaseView {
|
|||||||
this.cache[i].node.destroy();
|
this.cache[i].node.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const cfgs = ConfigManager.tables.TbThemes.getDataList();
|
// 请求主题数据
|
||||||
for (let i = 0; i < cfgs.length; i++) {
|
const reqData = {
|
||||||
const cfg = cfgs[i];
|
|
||||||
if (!cfg) return;
|
};
|
||||||
|
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 newNode = instantiate(this.itemInst.node);
|
||||||
let item = newNode.getComponent(ThemeItem);
|
let item = newNode.getComponent(ThemeItem);
|
||||||
item.refresh(cfg);
|
item.refresh(id);
|
||||||
newNode.active = true;
|
newNode.active = true;
|
||||||
this.cache.push(item);
|
this.cache.push(item);
|
||||||
this.content.addChild(newNode);
|
this.content.addChild(newNode);
|
||||||
}
|
}
|
||||||
const rectInfo = ConfigManager.tables.TbGirls.get(10001);
|
const rectInfo = ConfigManager.tables.TbGirls.get(10001);
|
||||||
this.recId = rectInfo.id;
|
this.recId = rectInfo.id;
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import { NavigationManager } from "../manager/NavigationManager";
|
|||||||
import { TbThemes, Theme } from "../../schema/schema";
|
import { TbThemes, Theme } from "../../schema/schema";
|
||||||
import LanguageUtils from "../../Main/Common/LanguageUtils";
|
import LanguageUtils from "../../Main/Common/LanguageUtils";
|
||||||
import { InnerMsgCode } from "../../Main/Config/InnerMsgCode";
|
import { InnerMsgCode } from "../../Main/Config/InnerMsgCode";
|
||||||
|
import { DataManager, DataId } from "../data/DataManager";
|
||||||
|
import { ThemeData } from "../data/ThemeData";
|
||||||
const { ccclass, property } = _decorator;
|
const { ccclass, property } = _decorator;
|
||||||
|
|
||||||
@ccclass("ThemeItem")
|
@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 =
|
this.lockImg.node.active = this.lockCover.node.active =
|
||||||
!themeData.isRelease;
|
!themeData.getIsReleaseById(themeId);
|
||||||
this.isLocked = !themeData.isRelease;
|
this.isLocked = !themeData.getIsReleaseById(themeId);
|
||||||
this.key = themeData.key;
|
this.key = themeData.getLanKeyById(themeId);
|
||||||
this.titleName.string = LanguageUtils.getText(themeData.key);
|
this.titleName.string = LanguageUtils.getText(themeData.getLanKeyById(themeId));
|
||||||
this.category = themeData.category;
|
this.category = themeData.getCategoryById(themeId);
|
||||||
ResManager.I.changeBundleSpriteFrame(
|
ResManager.I.changeBundleSpriteFrame(
|
||||||
this.img,
|
this.img,
|
||||||
themeData.path,
|
themeData.getPathById(themeId),
|
||||||
"Chat18x",
|
"Chat18x",
|
||||||
() => {
|
() => {
|
||||||
let sizeTran = this.img.node.parent.getComponent(UITransform);
|
let sizeTran = this.img.node.parent.getComponent(UITransform);
|
||||||
|
|||||||
Reference in New Issue
Block a user