多语言模块

This commit is contained in:
2025-08-12 19:49:50 +08:00
parent 83370bd0ef
commit 707946304e
43 changed files with 1977 additions and 1305 deletions
+134
View File
@@ -0,0 +1,134 @@
import { _decorator, Component, Label, Node } from "cc";
import LanguageUtils, { LanguageType } from "./LanguageUtils";
const { ccclass, property, requireComponent } = _decorator;
@ccclass("LanguageLabel")
@requireComponent(Label)
export class LanguageLabel extends Component {
@property({
displayName: "Language Key",
tooltip: "多语言配置表中的key值",
})
private languageKey: string = "";
@property({
displayName: "Default Text",
tooltip: "如果找不到对应的翻译时显示的默认文本",
})
private defaultText: string = "";
@property({
displayName: "Auto Update",
tooltip: "是否自动监听语言变化并更新",
})
private autoUpdate: boolean = true;
private label: Label = null;
private params: { [key: string]: any } = null;
onLoad() {
this.label = this.getComponent(Label);
if (!this.label) {
console.error("LanguageLabel: Label component not found!");
return;
}
this.updateText();
if (this.autoUpdate) {
LanguageUtils.onLanguageChanged(this.onLanguageChanged, this);
}
}
onDestroy() {
if (this.autoUpdate) {
LanguageUtils.offLanguageChanged(this.onLanguageChanged, this);
}
}
onEnable() {
this.updateText();
}
private onLanguageChanged(language: LanguageType) {
this.updateText();
}
private updateText() {
if (!this.label || !this.languageKey) {
return;
}
let text: string;
if (this.params && Object.keys(this.params).length > 0) {
text = LanguageUtils.getTextWithParams(
this.languageKey,
this.params,
this.defaultText
);
} else {
text = LanguageUtils.getText(this.languageKey, this.defaultText);
}
this.label.string = text;
}
/**
* 设置语言key
*/
public setLanguageKey(key: string) {
this.languageKey = key;
this.updateText();
}
/**
* 设置文本参数(用于替换文本中的占位符)
* @param params 参数对象,如 {name: "玩家", score: 100}
*/
public setParams(params: { [key: string]: any }) {
this.params = params;
this.updateText();
}
/**
* 添加或更新单个参数
*/
public setParam(key: string, value: any) {
if (!this.params) {
this.params = {};
}
this.params[key] = value;
this.updateText();
}
/**
* 清除所有参数
*/
public clearParams() {
this.params = null;
this.updateText();
}
/**
* 手动刷新文本
*/
public refresh() {
this.updateText();
}
/**
* 获取当前的语言key
*/
public getLanguageKey(): string {
return this.languageKey;
}
/**
* 设置默认文本
*/
public setDefaultText(text: string) {
this.defaultText = text;
this.updateText();
}
}
@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "d7e4f3a2-8b9c-4d2e-a1f6-3c5e9d7b8a4f",
"files": [],
"subMetas": {},
"userData": {}
}
+201
View File
@@ -0,0 +1,201 @@
import { _decorator, sys } from "cc";
import { Language } from "../../schema/schema";
import ConfigManager from "../../chat18x/manager/ConfigManager";
import { CommonConfig } from "../Config/CommonConfig";
import li_EventManager from "./li_EventManager";
import Utils from "./Utils";
import { InnerMsgCode } from "../Config/InnerMsgCode";
const { ccclass } = _decorator;
export enum LanguageType {
EN = "en", // 英文
CN = "cn", // 中文
HI = "hi", // 印地语
FR = "fr", // 法语
DE = "de", //德语
}
export enum LanguageEvent {
LANGUAGE_CHANGED = "LANGUAGE_CHANGED",
}
@ccclass("LanguageUtils")
export default class LanguageUtils {
private static currentLanguage: LanguageType = LanguageType.EN;
private static languageCache: Map<string, string> = new Map();
private static isInitialized: boolean = false;
public static get CurrentLanguage(): LanguageType {
if (!this.isInitialized) {
this.init();
}
return this.currentLanguage;
}
private static init() {
if (this.isInitialized) return;
this.isInitialized = true;
this.loadLanguageSetting();
}
private static loadLanguageSetting() {
const savedLanguage = sys.localStorage.getItem(
CommonConfig.StorageConfig.LANGUAGE_SETTING
);
if (
savedLanguage &&
Object.values(LanguageType).includes(savedLanguage as LanguageType)
) {
this.currentLanguage = savedLanguage as LanguageType;
} else {
this.detectSystemLanguage();
}
console.log(
"LanguageUtils initialized with language:",
this.currentLanguage
);
}
private static detectSystemLanguage() {
const systemLanguage = sys.language;
if (systemLanguage.startsWith("zh")) {
this.currentLanguage = LanguageType.CN;
} else if (systemLanguage.startsWith("hi")) {
this.currentLanguage = LanguageType.HI;
} else if (systemLanguage.startsWith("fr")) {
this.currentLanguage = LanguageType.FR;
} else if (systemLanguage.startsWith("de")) {
this.currentLanguage = LanguageType.DE;
} else {
this.currentLanguage = LanguageType.EN;
}
}
public static setLanguage(language: LanguageType): void {
if (!this.isInitialized) {
this.init();
}
if (this.currentLanguage === language) {
return;
}
this.currentLanguage = language;
this.languageCache.clear();
sys.localStorage.setItem(
CommonConfig.StorageConfig.LANGUAGE_SETTING,
language
);
Utils.sendInnerMsg(InnerMsgCode.LanguageChange, language);
console.log("Language changed to:", language);
}
public static getText(key: string, defaultText: string = ""): string {
if (!this.isInitialized) {
this.init();
}
if (!key) {
return defaultText;
}
if (this.languageCache.has(key)) {
return this.languageCache.get(key);
}
if (!ConfigManager.tables || !ConfigManager.tables.TbLanguage) {
console.warn("Language table not loaded yet");
return defaultText || key;
}
const languageData = ConfigManager.tables.TbLanguage.get(key);
if (!languageData) {
console.warn(`Language key not found: ${key}`);
return defaultText || key;
}
let text: string = "";
switch (this.currentLanguage) {
case LanguageType.EN:
text = languageData.languageEn;
break;
case LanguageType.CN:
text = languageData.languageCn;
break;
case LanguageType.HI:
text = languageData.languageHi;
break;
case LanguageType.FR:
text = languageData.languageFr;
break;
case LanguageType.DE:
text = languageData.languageDe;
break;
default:
text = languageData.languageEn;
}
if (!text || text.length === 0) {
text = languageData.languageEn || defaultText || key;
}
this.languageCache.set(key, text);
return text;
}
public static getTextWithParams(
key: string,
params: { [key: string]: any },
defaultText: string = ""
): string {
let text = this.getText(key, defaultText);
for (let paramKey in params) {
const regex = new RegExp(`{${paramKey}}`, "g");
text = text.replace(regex, params[paramKey].toString());
}
return text;
}
public static getAvailableLanguages(): LanguageType[] {
return Object.values(LanguageType);
}
public static getLanguageDisplayName(language: LanguageType): string {
switch (language) {
case LanguageType.EN:
return "English";
case LanguageType.CN:
return "中文";
case LanguageType.HI:
return "हिंदी";
case LanguageType.FR:
return "Français";
case LanguageType.DE:
return "Deutsch";
default:
return language;
}
}
public static clearCache(): void {
this.languageCache.clear();
}
public static onLanguageChanged(
callback: (language: LanguageType) => void,
target: any
): void {
Utils.addInnerEL(InnerMsgCode.LanguageChange, target, callback);
}
public static offLanguageChanged(
callback: (language: LanguageType) => void,
target: any
): void {
Utils.removeInnerEL(InnerMsgCode.LanguageChange, target, callback);
}
}
@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "c8b5e7a2-4f3d-4e8b-9c2a-1d6f5e8a7b9c",
"files": [],
"subMetas": {},
"userData": {}
}
@@ -30,6 +30,7 @@ export namespace CommonConfig {
DD_LEVELOPER = StorageConfigUtil.BaseData + 16, //进入关卡且首次进度>0时(或第一次操作)
GUIDE_MAIN = StorageConfigUtil.BaseData + 17, //主界面引导是否完成
GUIDE_TALK = StorageConfigUtil.BaseData + 18, //聊天界面引导是否完成
LANGUAGE_SETTING = StorageConfigUtil.BaseData + 19, //语言设置
DOUYIN_SIDEBAR = StorageConfigUtil.Channel + 1, //抖音渠道侧边栏奖励是否领取
}
@@ -26,4 +26,5 @@ export enum InnerMsgCode {
Chat_DialogRefresh,
SimplePlayVide,
LanguageChange,
}
+222 -195
View File
@@ -1,213 +1,240 @@
import { _decorator, AssetManager, AudioClip, Button, Component, ImageAsset, JsonAsset, Label, Material, Node, Prefab, ProgressBar, Sprite, SpriteFrame } from 'cc';
import { GButton } from '../../Main/Common/GButton';
import ResManager from '../../Main/Manager/ResManager';
import Resource from '../../Main/Config/Resource';
import { SDKManager } from '../../Main/Channel/SDKManager';
import HttpUnit from '../../Main/Common/HttpUnit';
import GlobalValue from '../../Main/Common/GlobalValue';
import Utils from '../../Main/Common/Utils';
import { InnerMsgCode } from '../../Main/Config/InnerMsgCode';
import { promptItem } from '../Item/promptItem';
import {
_decorator,
AssetManager,
AudioClip,
Button,
Component,
ImageAsset,
JsonAsset,
Label,
Material,
Node,
Prefab,
ProgressBar,
Sprite,
SpriteFrame,
} from "cc";
import { GButton } from "../../Main/Common/GButton";
import ResManager from "../../Main/Manager/ResManager";
import Resource from "../../Main/Config/Resource";
import { SDKManager } from "../../Main/Channel/SDKManager";
import HttpUnit from "../../Main/Common/HttpUnit";
import GlobalValue from "../../Main/Common/GlobalValue";
import Utils from "../../Main/Common/Utils";
import { InnerMsgCode } from "../../Main/Config/InnerMsgCode";
import { promptItem } from "../Item/promptItem";
import LanguageUtils, { LanguageType } from "../../Main/Common/LanguageUtils";
const { ccclass, property } = _decorator;
@ccclass('PreloadUI')
@ccclass("PreloadUI")
export class PreloadUI extends Component {
private checkFinish = true; //检查完成
private preloadFinish = false; //资源加载完成
private loginFinish = false; //登录完成
private checkFinish = true; //检查完成
private preloadFinish = false; //资源加载完成
private loginFinish = false; //登录完成
private jinduBar: Node = null;
private jinduFilled: Sprite = null;
private LabProgress: Label = null;
//private btnLogin: Sprite = null; //登录按钮
private jinduBar: Node = null;
private jinduFilled: Sprite = null;
private LabProgress: Label = null;
//private btnLogin: Sprite = null; //登录按钮
start() {
//Utils.addInnerEL(InnerMsgCode.UI_ShowPrompt, this, this.resiveShowPrompt)
start() {
//Utils.addInnerEL(InnerMsgCode.UI_ShowPrompt, this, this.resiveShowPrompt)
this.jinduBar = this.node.getChildByName("jinduBar");
this.jinduFilled = this.jinduBar.getChildByName("jinduFilled").getComponent(Sprite);
this.LabProgress = this.node.getChildByName("LabProgress").getComponent(Label);
//this.btnLogin = this.node.getChildByName("btnLogin").getComponent(Sprite);
//适配背景图
let BG = this.node.getChildByName("BG");
Utils.adjustBgPixelRatio(BG, 1)
this.jinduBar = this.node.getChildByName("jinduBar");
this.jinduFilled = this.jinduBar
.getChildByName("jinduFilled")
.getComponent(Sprite);
this.LabProgress = this.node
.getChildByName("LabProgress")
.getComponent(Label);
//this.btnLogin = this.node.getChildByName("btnLogin").getComponent(Sprite);
this.jinduFilled.fillRange = 0;
//this.btnLogin.node.active = false;
//适配背景图
let BG = this.node.getChildByName("BG");
Utils.adjustBgPixelRatio(BG, 1);
this.preloadFiles()
this.jinduFilled.fillRange = 0;
//this.btnLogin.node.active = false;
this.preloadFiles();
LanguageUtils.setLanguage(LanguageType.CN);
}
protected onDestroy(): void {
Utils.removeInnerEL(
InnerMsgCode.UI_ShowPrompt,
this,
this.resiveShowPrompt
);
}
update(deltaTime: number) {
if (this.checkFinish) {
if (this.preloadFinish && this.loginFinish) {
this.checkFinish = false;
this.enterGame();
}
}
}
protected onDestroy(): void {
Utils.removeInnerEL(InnerMsgCode.UI_ShowPrompt, this, this.resiveShowPrompt)
}
/**收到飘字消息 */
resiveShowPrompt(data: any) {
let msg = data.text;
let self = this;
ResManager.I.loadSubpackagePrefab("item/promptItem", (n_node: Node) => {
self.node.addChild(n_node);
let pItem = n_node.getComponent(promptItem);
pItem.setLabel(msg);
});
}
update(deltaTime: number) {
if (this.checkFinish) {
if (this.preloadFinish && this.loginFinish) {
this.checkFinish = false
this.enterGame()
}
//预加载文件
preloadFiles() {
let preloadTab = [
{ path: "ChatPanel", bundleName: "Chat18x", ftype: Prefab },
{ path: "GirlDetailPanel", bundleName: "Chat18x", ftype: Prefab },
{ path: "GirlListPanel", bundleName: "Chat18x", ftype: Prefab },
// {path:"Music/music_interface", bundleName: "Audio", ftype: AudioClip},
// {path:"bg/mengli_stage_bg", bundleName: "Raw", ftype: ImageAsset},
// {path:"cg0/mengli_0_cg", bundleName: "Raw", ftype: ImageAsset},
// {path:"cg1/mengli_1_cg", bundleName: "Raw", ftype: ImageAsset},
// {path:"cg2/mengli_2_cg", bundleName: "Raw", ftype: ImageAsset},
// {path:"cg3/mengli_3_cg", bundleName: "Raw", ftype: ImageAsset},
// {path:"emo_1/mengli_shy", bundleName: "Raw", ftype: ImageAsset},
// {path:"emo_2/mengli_laugh", bundleName: "Raw", ftype: ImageAsset},
// {path:"emo_3/mengli_disgust", bundleName: "Raw", ftype: ImageAsset},
// {path:"role/mengli_default", bundleName: "Raw", ftype: ImageAsset},
// {path:"Zjm/raw1", bundleName: "Raw", ftype: ImageAsset},
// {path:"touming", bundleName: "common", ftype: ImageAsset},
// // {path:"chanpin_1_0", bundleName: "daoju", ftype: ImageAsset}, //有合图加载失败
// {path:"zjm_1", bundleName: "Zhujiemian", ftype: ImageAsset},
// {path:"zjm_19", bundleName: "Zhujiemian", ftype: ImageAsset},
// {path:"zjm_30", bundleName: "Zhujiemian", ftype: ImageAsset},
// {path:"mohu", bundleName: "Materials", ftype: Material},
// {path:"UI/Cross/Cross_UI", bundleName: "PB", ftype: Prefab},
// {path:"UI/StartUI/Start_UI", bundleName: "PB", ftype: Prefab},
// {path:"commonGlobal", bundleName: "DataTable", ftype: JsonAsset},
];
let num_prefab = 0; //已加载数量
let num_succeed = 0; //加载成功数量
let preloadFunc = () => {
if (num_prefab < preloadTab.length) {
let cfg = preloadTab[num_prefab];
ResManager.I.preLoadSubpackageFile(
cfg.path,
cfg.bundleName,
cfg.ftype,
(ret) => {
num_prefab++;
num_succeed++;
let percent = 0.45 * (num_prefab / preloadTab.length);
this.showLoadProgress(0.55 + percent);
console.log("加载成功:", cfg.path);
preloadFunc();
},
(err) => {
num_prefab++;
console.log("加载失败:", err);
}
);
} else {
if (num_succeed >= num_prefab) {
this.loadDataTable();
}
}
}
};
preloadFunc();
}
/**收到飘字消息 */
resiveShowPrompt(data: any) {
let msg = data.text
let self = this
ResManager.I.loadSubpackagePrefab("item/promptItem", (n_node: Node)=>{
self.node.addChild(n_node)
let pItem = n_node.getComponent(promptItem)
pItem.setLabel(msg)
})
}
//加载配置表
loadDataTable() {
let dataArr = [
//"commonGlobal",
// "levelHole",
//"Music",
//"Sound",
];
//配置表使用方法: let cfgs = Resource.getConfig("Sound")
let num_prefab = 0;
let preloadFunc = () => {
if (num_prefab < dataArr.length) {
let cfgname = dataArr[num_prefab];
ResManager.I.loadSubpackageDataTable(cfgname, (ret: JsonAsset) => {
num_prefab++;
Resource.addSubJsonConfig(cfgname, ret.json);
preloadFunc();
});
} else {
this.preloadFinish = true;
this.onLogin();
}
};
preloadFunc();
}
//预加载文件
preloadFiles() {
let preloadTab = [
{path:"ChatPanel", bundleName: "Chat18x", ftype: Prefab},
{path:"GirlDetailPanel", bundleName: "Chat18x", ftype: Prefab},
{path:"GirlListPanel", bundleName: "Chat18x", ftype: Prefab},
// {path:"Music/music_interface", bundleName: "Audio", ftype: AudioClip},
// {path:"bg/mengli_stage_bg", bundleName: "Raw", ftype: ImageAsset},
// {path:"cg0/mengli_0_cg", bundleName: "Raw", ftype: ImageAsset},
// {path:"cg1/mengli_1_cg", bundleName: "Raw", ftype: ImageAsset},
// {path:"cg2/mengli_2_cg", bundleName: "Raw", ftype: ImageAsset},
// {path:"cg3/mengli_3_cg", bundleName: "Raw", ftype: ImageAsset},
// {path:"emo_1/mengli_shy", bundleName: "Raw", ftype: ImageAsset},
// {path:"emo_2/mengli_laugh", bundleName: "Raw", ftype: ImageAsset},
// {path:"emo_3/mengli_disgust", bundleName: "Raw", ftype: ImageAsset},
// {path:"role/mengli_default", bundleName: "Raw", ftype: ImageAsset},
// {path:"Zjm/raw1", bundleName: "Raw", ftype: ImageAsset},
// {path:"touming", bundleName: "common", ftype: ImageAsset},
// // {path:"chanpin_1_0", bundleName: "daoju", ftype: ImageAsset}, //有合图加载失败
// {path:"zjm_1", bundleName: "Zhujiemian", ftype: ImageAsset},
// {path:"zjm_19", bundleName: "Zhujiemian", ftype: ImageAsset},
// {path:"zjm_30", bundleName: "Zhujiemian", ftype: ImageAsset},
// {path:"mohu", bundleName: "Materials", ftype: Material},
// {path:"UI/Cross/Cross_UI", bundleName: "PB", ftype: Prefab},
// {path:"UI/StartUI/Start_UI", bundleName: "PB", ftype: Prefab},
// {path:"commonGlobal", bundleName: "DataTable", ftype: JsonAsset},
];
let num_prefab = 0; //已加载数量
let num_succeed = 0;//加载成功数量
let preloadFunc = () => {
if (num_prefab < preloadTab.length) {
let cfg = preloadTab[num_prefab]
ResManager.I.preLoadSubpackageFile(cfg.path, cfg.bundleName, cfg.ftype, (ret) => {
num_prefab++;
num_succeed++;
let percent = 0.45 * (num_prefab / preloadTab.length)
this.showLoadProgress(0.55 + percent);
console.log("加载成功:", cfg.path);
preloadFunc();
}, (err)=>{
num_prefab++;
console.log("加载失败:", err);
});
} else {
if (num_succeed >= num_prefab) {
this.loadDataTable();
}
}
}
preloadFunc();
}
//显示加载进度
showLoadProgress(percent) {
this.jinduFilled.fillRange = percent;
}
//加载配置表
loadDataTable(){
let dataArr = [
//"commonGlobal",
// "levelHole",
//"Music",
//"Sound",
]
//登录
onLogin() {
//初始化SDK信息
// SDKManager.init(() => {
// //检测是否有授权,有授权直接登录,没有授权就先进主界面,到主界面获取权限
// SDKManager.checkAutoSetting("userInfo", (ishave) => {
// if (ishave) {
// console.log("有授权,直接登录")
// HttpUnit.ins.login((loginData) => {
// if (loginData == null) {
// //登录失败,这里处理重复登录的逻辑
// } else {
// this.loginFinish = true
// }
// })
// } else {
// console.log("没有授权,等待授权后登录")
// // this.loginFinish = true
// this.jinduBar.active = false
// this.LabProgress.node.active = false
// //登录按钮
// this.btnLogin.node.active = true
// let loginPath = ""
// if (SDKManager.isWenxin()) {
// loginPath = "login1"
// } else if (SDKManager.isByteDance()) {
// loginPath = "login2"
// } else if (SDKManager.isKuaishou()) {
// loginPath = "login3"
// }
// ResManager.I.changeResourceSpriteFrame(this.btnLogin, loginPath)
//
// HttpUnit.ins.login((loginData) => {
// if (loginData == null) {
// //登录失败,这里处理重复登录的逻辑
// } else {
// this.loginFinish = true
// }
// })
// }
// })
// })
this.loginFinish = true;
}
//配置表使用方法: let cfgs = Resource.getConfig("Sound")
let num_prefab = 0;
let preloadFunc = () => {
if (num_prefab < dataArr.length) {
let cfgname = dataArr[num_prefab]
ResManager.I.loadSubpackageDataTable(cfgname, (ret: JsonAsset) => {
num_prefab++;
Resource.addSubJsonConfig(cfgname, ret.json)
preloadFunc();
});
} else {
this.preloadFinish = true;
this.onLogin();
}
}
preloadFunc();
}
//显示加载进度
showLoadProgress(percent) {
this.jinduFilled.fillRange = percent;
}
//登录
onLogin() {
//初始化SDK信息
// SDKManager.init(() => {
// //检测是否有授权,有授权直接登录,没有授权就先进主界面,到主界面获取权限
// SDKManager.checkAutoSetting("userInfo", (ishave) => {
// if (ishave) {
// console.log("有授权,直接登录")
// HttpUnit.ins.login((loginData) => {
// if (loginData == null) {
// //登录失败,这里处理重复登录的逻辑
// } else {
// this.loginFinish = true
// }
// })
// } else {
// console.log("没有授权,等待授权后登录")
// // this.loginFinish = true
// this.jinduBar.active = false
// this.LabProgress.node.active = false
// //登录按钮
// this.btnLogin.node.active = true
// let loginPath = ""
// if (SDKManager.isWenxin()) {
// loginPath = "login1"
// } else if (SDKManager.isByteDance()) {
// loginPath = "login2"
// } else if (SDKManager.isKuaishou()) {
// loginPath = "login3"
// }
// ResManager.I.changeResourceSpriteFrame(this.btnLogin, loginPath)
//
// HttpUnit.ins.login((loginData) => {
// if (loginData == null) {
// //登录失败,这里处理重复登录的逻辑
// } else {
// this.loginFinish = true
// }
// })
// }
// })
// })
this.loginFinish = true;
}
enterGame() {
//let islogin = HttpUnit.IsLogin();
//console.log("进入游戏,登录状态:", islogin);
this.jinduBar.active = false
this.LabProgress.node.active = false
//this.btnLogin.node.active = false
// if (islogin) {
// } else {
// //没登录成功,先进主界面,在主界面里进行登录
// }
ResManager.I.goMainScene(); //进入下一个场景
// ResManager.I.goCustomScene("Test2DScene"); //进入自定义场景
}
enterGame() {
//let islogin = HttpUnit.IsLogin();
//console.log("进入游戏,登录状态:", islogin);
this.jinduBar.active = false;
this.LabProgress.node.active = false;
//this.btnLogin.node.active = false
// if (islogin) {
// } else {
// //没登录成功,先进主界面,在主界面里进行登录
// }
ResManager.I.goMainScene(); //进入下一个场景
// ResManager.I.goCustomScene("Test2DScene"); //进入自定义场景
}
}
+13 -1
View File
@@ -22,6 +22,7 @@ import { ImagePopup } from "../components/ImagePopup";
import ResManager from "db://assets/Scripts/Main/Manager/ResManager";
import { VideoRoleType } from "db://assets/Scripts/Main/Common/GlobalValue";
import ConfigManager from "../../manager/ConfigManager";
import LanguageUtils from "../../../Main/Common/LanguageUtils";
const { ccclass, property } = _decorator;
@ccclass("ChatPanel")
@@ -46,6 +47,7 @@ export class ChatPanel extends li_BaseView {
id: number;
private _nodeTab: any = {};
nameKey: string;
openUIDataCT(data) {
this.id = data;
// 设置当前聊天的角色ID
@@ -64,13 +66,23 @@ export class ChatPanel extends li_BaseView {
this,
this.onDialogUpdate
);
Utils.addInnerEL(InnerMsgCode.LanguageChange, this, () => {
this.girlName.string = LanguageUtils.getText(this.nameKey);
});
}
onDestroy(): void {
Utils.removeInnerEL(InnerMsgCode.LanguageChange, this, () => {
this.girlName.string = LanguageUtils.getText(this.nameKey);
});
}
refresh(id: number) {
this.id = id;
const data = ConfigManager.tables.TbGirls.get(this.id);
const dataDetail = ConfigManager.tables.TbGirlsDetail.get(this.id);
if (!data) return;
this.girlName.string = data.name;
this.nameKey = data.nameKey;
this.girlName.string = LanguageUtils.getText(data.nameKey);
ResManager.I.changeBundleSpriteFrame(
this.girlImg,
data.avatarPath,
@@ -4,6 +4,9 @@ import ResManager from "db://assets/Scripts/Main/Manager/ResManager";
import { DetailImageItem } from "./DetailImageItem";
import { NavigationManager } from "../../manager/NavigationManager";
import ConfigManager from "../../manager/ConfigManager";
import LanguageUtils from "../../../Main/Common/LanguageUtils";
import Utils from "../../../Main/Common/Utils";
import { InnerMsgCode } from "../../../Main/Config/InnerMsgCode";
const { ccclass, property } = _decorator;
@@ -47,6 +50,19 @@ export class GirlDetailPanel extends li_BaseView {
super.onLoadCT();
this.imgItemInst.node.active = false;
this.refresh(this.id);
Utils.addInnerEL(InnerMsgCode.LanguageChange, this, () => {
this.girlName.string = this.descName.string = LanguageUtils.getText(
this.nameKey
);
let desc = "";
const tags = LanguageUtils.getText(this.tagKey).split("|");
for (let i = 0; i < tags.length; i++) {
if (i != 0) desc += "\n";
desc += tags[i];
}
this.tags.string = desc;
});
}
setVideEnable(enable: boolean) {
@@ -55,12 +71,16 @@ export class GirlDetailPanel extends li_BaseView {
this.avatarVideo.play();
}
}
nameKey: string;
tagKey: string;
refresh(index: number) {
console.log(index);
const dataDetail = ConfigManager.tables.TbGirlsDetail.get(this.id);
const data = ConfigManager.tables.TbGirls.get(this.id);
this.girlName.string = this.descName.string = data.name;
this.nameKey = data.nameKey;
this.girlName.string = this.descName.string = LanguageUtils.getText(
data.nameKey
);
if (dataDetail.pics[0].endsWith("video")) {
ResManager.I.changeBundleVideo(
@@ -86,9 +106,11 @@ export class GirlDetailPanel extends li_BaseView {
this.desc.string = dataDetail.detailDesc;
let desc = "";
for (let i = 0; i < data.tag.length; i++) {
this.tagKey = data.tagKey;
const tags = LanguageUtils.getText(data.tagKey).split("|");
for (let i = 0; i < tags.length; i++) {
if (i != 0) desc += "\n";
desc += data.tag[i];
desc += tags[i];
}
this.tags.string = desc;
for (let i = 0; i < 5; i++) {
@@ -5,6 +5,8 @@ import ResManager from "db://assets/Scripts/Main/Manager/ResManager";
import Utils from "db://assets/Scripts/Main/Common/Utils";
import { NavigationManager } from "../../manager/NavigationManager";
import { Girl, PriceType } from "../../../schema/schema";
import LanguageUtils from "../../../Main/Common/LanguageUtils";
import { InnerMsgCode } from "../../../Main/Config/InnerMsgCode";
const { ccclass, property } = _decorator;
@@ -29,15 +31,49 @@ export class GirlListItem extends Component {
id: number = -1;
nameKey: string;
tagKey: string;
protected onLoad(): void {
Utils.addInnerEL(InnerMsgCode.LanguageChange, this, () => {
this.girlName.string = this.girlName.string = LanguageUtils.getText(
this.nameKey
);
let desc = "";
const tags = LanguageUtils.getText(this.tagKey).split("|");
for (let i = 0; i < tags.length; i++) {
if (i != 0) desc += "\n";
desc += tags[i];
}
this.tags.string = desc;
});
}
protected onDestroy(): void {
Utils.removeInnerEL(InnerMsgCode.LanguageChange, this, () => {
this.girlName.string = this.girlName.string = LanguageUtils.getText(
this.nameKey
);
let desc = "";
const tags = LanguageUtils.getText(this.tagKey).split("|");
for (let i = 0; i < tags.length; i++) {
if (i != 0) desc += "\n";
desc += tags[i];
}
this.tags.string = desc;
});
}
baseNode: Node;
refreshData(data: Girl, baseNode: Node) {
this.baseNode = baseNode;
this.id = data.id;
this.girlName.string = data.name;
this.nameKey = data.nameKey;
this.girlName.string = LanguageUtils.getText(data.nameKey);
this.tagKey = data.tagKey;
let desc = "";
for (let i = 0; i < data.tag.length; i++) {
if (i != 0) desc += "&";
desc += data.tag[i];
const tags = LanguageUtils.getText(data.tagKey).split("|");
for (let i = 0; i < tags.length; i++) {
if (i != 0) desc += "|";
desc += tags[i];
}
this.tags.string = desc;
this.price.node.active = data.priceType == PriceType.pay;
+17 -2
View File
@@ -4,6 +4,8 @@ import ResManager from "db://assets/Scripts/Main/Manager/ResManager";
import Utils from "db://assets/Scripts/Main/Common/Utils";
import { NavigationManager } from "../../manager/NavigationManager";
import { TbThemes, Theme } from "../../../schema/schema";
import LanguageUtils from "../../../Main/Common/LanguageUtils";
import { InnerMsgCode } from "../../../Main/Config/InnerMsgCode";
const { ccclass, property } = _decorator;
@ccclass("ThemeItem")
@@ -19,11 +21,24 @@ export class ThemeItem extends Component {
private category: number;
private isLocked: boolean;
start() {}
key: string;
protected onLoad(): void {
Utils.addInnerEL(InnerMsgCode.LanguageChange, this, () => {
this.titleName.string = LanguageUtils.getText(this.key);
});
}
protected onDestroy(): void {
Utils.removeInnerEL(InnerMsgCode.LanguageChange, this, () => {
this.titleName.string = LanguageUtils.getText(this.key);
});
}
refresh(themeData: Theme) {
this.lockImg.node.active = !themeData.isRelease;
this.isLocked = !themeData.isRelease;
this.titleName.string = themeData.name;
this.key = themeData.key;
this.titleName.string = LanguageUtils.getText(themeData.key);
this.category = themeData.category;
ResManager.I.changeBundleSpriteFrame(
this.img,
@@ -15,6 +15,7 @@ import { ThemeItem } from "./ThemeItem";
import { NavigationManager } from "../../manager/NavigationManager";
import { GirlListItem } from "./GirlListItem";
import ConfigManager from "../../manager/ConfigManager";
import LanguageUtils from "../../../Main/Common/LanguageUtils";
const { ccclass, property } = _decorator;
@@ -43,6 +44,7 @@ export class ThemePanel extends li_BaseView {
this.itemInst = this._nodeTab.ThemeItem.getComponent(ThemeItem);
this.itemInst.node.active = false;
this.content = this._nodeTab.AllThemesLayout;
this.Show();
}
@@ -50,7 +52,6 @@ export class ThemePanel extends li_BaseView {
//some temp data
this.coinNum.string = (50.0).toString();
this.recId = 1;
if (this.cache) {
for (let i = this.cache.length - 1; i >= 0; i--) {
this.cache[i].node.destroy();
+73 -137
View File
@@ -60,91 +60,15 @@ export enum PriceType {
export namespace demo {
export class item {
constructor(_buf_: ByteBuf) {
this.id = _buf_.readInt()
this.name = _buf_.readString()
this.desc = _buf_.readString()
this.count = _buf_.readInt()
}
/**
* id
*/
readonly id: number
/**
* 名称
*/
readonly name: string
/**
* 描述
*/
readonly desc: string
/**
* 个数
*/
readonly count: number
resolve(tables:Tables) {
}
}
}
export namespace demo {
export class Reward {
constructor(_buf_: ByteBuf) {
this.id = _buf_.readInt()
this.name = _buf_.readString()
this.desc = _buf_.readString()
this.count = _buf_.readInt()
}
/**
* id
*/
readonly id: number
/**
* 名称
*/
readonly name: string
/**
* 描述
*/
readonly desc: string
/**
* 个数
*/
readonly count: number
resolve(tables:Tables) {
}
}
}
export class Girl {
constructor(_buf_: ByteBuf) {
this.id = _buf_.readInt()
this.name = _buf_.readString()
this.nameKey = _buf_.readString()
this.age = _buf_.readString()
this.category = _buf_.readInt()
{ let n = Math.min(_buf_.readSize(), _buf_.size); this.tag = []; for(let i = 0 ; i < n ; i++) { let _e0 ;_e0 = _buf_.readString(); this.tag.push(_e0);}}
this.tagKey = _buf_.readString()
this.priceType = _buf_.readInt()
this.avatarPath = _buf_.readString()
this.starCount = _buf_.readInt()
@@ -155,9 +79,9 @@ export class Girl {
*/
readonly id: number
/**
* 名
* 名字键
*/
readonly name: string
readonly nameKey: string
/**
* 年龄
*/
@@ -167,9 +91,9 @@ export class Girl {
*/
readonly category: Category
/**
* 标签
* 标签
*/
readonly tag: string[]
readonly tagKey: string
/**
* 付费类型
*/
@@ -231,10 +155,55 @@ export class GirlDetail {
export class Language {
constructor(_buf_: ByteBuf) {
this.key = _buf_.readString()
this.languageEn = _buf_.readString()
this.languageCn = _buf_.readString()
this.languageHi = _buf_.readString()
this.languageFr = _buf_.readString()
this.languageDe = _buf_.readString()
}
/**
* key
*/
readonly key: string
readonly languageEn: string
readonly languageCn: string
/**
* 印地语翻译
*/
readonly languageHi: string
/**
* 法语翻译
*/
readonly languageFr: string
/**
* 德语翻译
*/
readonly languageDe: string
resolve(tables:Tables) {
}
}
export class Theme {
constructor(_buf_: ByteBuf) {
this.id = _buf_.readInt()
this.key = _buf_.readString()
this.name = _buf_.readString()
this.category = _buf_.readInt()
this.isRelease = _buf_.readBool()
@@ -245,6 +214,10 @@ export class Theme {
* id
*/
readonly id: number
/**
* 多语言键
*/
readonly key: string
/**
* 主题名称
*/
@@ -268,6 +241,7 @@ export class Theme {
}
}
@@ -344,25 +318,25 @@ export class vector4 {
export namespace demo {
export class TbReward {
private _dataMap: Map<number, demo.Reward>
private _dataList: demo.Reward[]
export class TbLanguage {
private _dataMap: Map<string, Language>
private _dataList: Language[]
constructor(_buf_: ByteBuf) {
this._dataMap = new Map<number, demo.Reward>()
this._dataMap = new Map<string, Language>()
this._dataList = []
for(let n = _buf_.readInt(); n > 0; n--) {
let _v: demo.Reward
_v = new demo.Reward(_buf_)
let _v: Language
_v = new Language(_buf_)
this._dataList.push(_v)
this._dataMap.set(_v.id, _v)
this._dataMap.set(_v.key, _v)
}
}
getDataMap(): Map<number, demo.Reward> { return this._dataMap; }
getDataList(): demo.Reward[] { return this._dataList; }
getDataMap(): Map<string, Language> { return this._dataMap; }
getDataList(): Language[] { return this._dataList; }
get(key: number): demo.Reward | undefined {
get(key: string): Language | undefined {
return this._dataMap.get(key);
}
@@ -374,7 +348,7 @@ export class TbReward {
}
}
}
@@ -476,76 +450,38 @@ export class TbThemes {
export namespace demo {
export class Tbitem {
private _dataMap: Map<number, demo.item>
private _dataList: demo.item[]
constructor(_buf_: ByteBuf) {
this._dataMap = new Map<number, demo.item>()
this._dataList = []
for(let n = _buf_.readInt(); n > 0; n--) {
let _v: demo.item
_v = new demo.item(_buf_)
this._dataList.push(_v)
this._dataMap.set(_v.id, _v)
}
}
getDataMap(): Map<number, demo.item> { return this._dataMap; }
getDataList(): demo.item[] { return this._dataList; }
get(key: number): demo.item | undefined {
return this._dataMap.get(key);
}
resolve(tables:Tables) {
for(let data of this._dataList)
{
data.resolve(tables)
}
}
}
}
type ByteBufLoader = (file: string) => ByteBuf
export class Tables {
private _TbReward: demo.TbReward
get TbReward(): demo.TbReward { return this._TbReward;}
private _TbLanguage: TbLanguage
get TbLanguage(): TbLanguage { return this._TbLanguage;}
private _TbGirls: TbGirls
get TbGirls(): TbGirls { return this._TbGirls;}
private _TbGirlsDetail: TbGirlsDetail
get TbGirlsDetail(): TbGirlsDetail { return this._TbGirlsDetail;}
private _TbThemes: TbThemes
get TbThemes(): TbThemes { return this._TbThemes;}
private _Tbitem: demo.Tbitem
get Tbitem(): demo.Tbitem { return this._Tbitem;}
static getTableNames(): string[] {
let names: string[] = [];
names.push('demo_tbreward');
names.push('tblanguage');
names.push('tbgirls');
names.push('tbgirlsdetail');
names.push('tbthemes');
names.push('demo_tbitem');
return names;
}
constructor(loader: ByteBufLoader) {
this._TbReward = new demo.TbReward(loader('demo_tbreward'))
this._TbLanguage = new TbLanguage(loader('tblanguage'))
this._TbGirls = new TbGirls(loader('tbgirls'))
this._TbGirlsDetail = new TbGirlsDetail(loader('tbgirlsdetail'))
this._TbThemes = new TbThemes(loader('tbthemes'))
this._Tbitem = new demo.Tbitem(loader('demo_tbitem'))
this._TbReward.resolve(this)
this._TbLanguage.resolve(this)
this._TbGirls.resolve(this)
this._TbGirlsDetail.resolve(this)
this._TbThemes.resolve(this)
this._Tbitem.resolve(this)
}
}