Pārlūkot izejas kodu

新增文本配置。

huangjinghao 2 mēneši atpakaļ
vecāks
revīzija
98ee54959c

+ 5 - 0
GameConfig/A_New_BuildAll.bat

@@ -0,0 +1,5 @@
+ExeclExport.exe auto
+copy /y ts\M_i18n.ts ..\..\Client\assets\Script\Config
+
+@echo off
+::if "%nopause%" == "true" (@echo on) else (pause)

+ 1 - 0
GameConfig/CFG.check

@@ -85,6 +85,7 @@ D:\git\newWork\FishConfig\GameConfig\M_ActivitySailingSignCFG.xls:-985513579
 D:\git\newWork\FishConfig\GameConfig\M_GiftGuideCFG.xls:-1061697936
 D:\git\newWork\FishConfig\GameConfig\M_ActivityCarnivalFullCFG.xls:1948480528
 D:\git\newWork\FishConfig\GameConfig\M_AbysmFishingKingCFG.xls:-549571053
+D:\git\newWork\FishConfig\GameConfig\M_i18n.xls:1542259671
 D:\git\newWork\FishConfig\GameConfig\M_LuckTurnCFG.xls:-1276518674
 D:\git\newWork\FishConfig\GameConfig\M_LevelCFG.xls:894748575
 D:\git\newWork\FishConfig\GameConfig\M_ActivityElevenSignCFG.xls:-1507218819

+ 105 - 0
GameConfig/Code/Client/M_i18n.cpp

@@ -0,0 +1,105 @@
+#include "stdafx.h"
+#include "tinyxml2/tinyxml2.h"
+#include "LuaCfgHelper.h"
+#include <iostream>
+#include <boost/algorithm/string.hpp>
+#include "M_i18n.h"
+std::auto_ptr<M_i18n> M_i18n::msSingleton(nullptr);
+
+int M_i18n::GetCount()
+{
+	return (int)mMapData.size();
+}
+
+const M_i18nData* M_i18n::GetData(std::string ID)
+{
+	auto it = mMapData.find(ID);
+	if (it != mMapData.end())
+	{
+		return &it->second;
+	}
+	return NULL;
+}
+
+const std::map<std::string, M_i18nData>& M_i18n::GetMapData()
+{
+	return mMapData;
+}
+
+void M_i18n::Load()
+{
+	tinyxml2::XMLDocument xmlDoc;
+	std::string content = FileUtils::getInstance()->getStringFromFile("Config/M_i18n.xml");
+	auto result = xmlDoc.Parse(content.c_str(), content.length());
+	if (result != tinyxml2::XML_SUCCESS)
+	{
+		CCLOGERROR("Result:%d", result);
+		CCASSERT(false, "result != tinyxml2::XML_SUCCESS");
+		return;
+	}
+	auto root = xmlDoc.RootElement();
+	if (root == NULL)
+	{
+		CCASSERT(false, "root == NULL");
+		return;
+	}
+	auto element = root->FirstChildElement("Data");
+	while (element != NULL)
+	{
+		M_i18nData data;
+		data.mID = element->Attribute("ID");
+		data.mzh = element->Attribute("zh");
+		data.men = element->Attribute("en");
+		if (mMapData.find(data.mID) != mMapData.end())std::cout <<"data refind:" << data.mID << std::endl;
+		CCASSERT(mMapData.find(data.mID) == mMapData.end(), "data.mID is exists");
+		mMapData.insert(std::make_pair(data.mID, data));
+		element = element->NextSiblingElement();
+	}
+	CCLOG("M_i18n Loaded. Load Data:%u", mMapData.size());
+}
+
+void M_i18n::LoadLua()
+{
+	LuaEngine::getInstance()->executeScriptFile("config/M_i18n");
+	lua_State* L = LuaEngine::getInstance()->getLuaStack()->getLuaState();
+	lua_getglobal(L, "M_i18n");
+	CCASSERT(lua_istable(L, -1) == 1, "is not table");
+	lua_pushstring(L, "datas");
+	lua_gettable(L, -2);
+	CCASSERT(lua_istable(L, -1) == 1, "is not table");
+	lua_pushnil(L);
+	while(lua_next(L, 2))
+	{
+		CCASSERT(lua_istable(L, -1) == 1, "is not table");
+		M_i18nData data;
+		LuaCfgHelper::readString(L, "ID", data.mID);
+		LuaCfgHelper::readString(L, "zh", data.mzh);
+		LuaCfgHelper::readString(L, "en", data.men);
+		if (mMapData.find(data.mID) != mMapData.end())std::cout <<"data refind:" << data.mID << std::endl;
+		CCASSERT(mMapData.find(data.mID) == mMapData.end(), "data.mID is exists");
+		mMapData.insert(std::make_pair(data.mID, data));
+		lua_pop(L, 1);
+	}
+	lua_settop(L, 0);
+	CCLOG("M_i18n Loaded. Load Data:%u", mMapData.size());
+}
+
+void M_i18n::Reload()
+{
+	mMapData.clear();
+	Load();
+}
+
+M_i18n* M_i18n::GetSingleton()
+{
+	if (msSingleton.get() == nullptr)
+	{
+		msSingleton.reset(new M_i18n());
+	}
+	return msSingleton.get();
+}
+
+void M_i18n::Release()
+{
+	msSingleton.reset(nullptr);
+}

+ 29 - 0
GameConfig/Code/Client/M_i18n.h

@@ -0,0 +1,29 @@
+#pragma once
+#include <map>
+struct M_i18nData
+{
+	//²ÎÊý±àºÅ
+	std::string mID;
+	//ÖÐÎÄ
+	std::string mzh;
+	//Ó¢ÎÄ
+	std::string men;
+};
+
+class M_i18n
+{
+public:
+private:
+	static std::auto_ptr<M_i18n> msSingleton;
+public:
+	int GetCount();
+	const M_i18nData* GetData(std::string ID);
+	const std::map<std::string, M_i18nData>& GetMapData();
+	void Load();
+	void LoadLua();
+	void Reload();
+	static M_i18n* GetSingleton();
+	static void Release();
+private:
+	std::map<std::string, M_i18nData> mMapData;
+};

+ 94 - 0
GameConfig/Code/Server/M_i18n.cpp

@@ -0,0 +1,94 @@
+#include "stdafx.h"
+#include <cassert>
+#include <fstream>
+#include <iostream>
+#include <iostream>
+#include <boost/smart_ptr.hpp>
+#include <boost/algorithm/string.hpp>
+#include "tinyxml2.h"
+#include "M_i18n.h"
+#include "FileEncrypt.h"
+std::auto_ptr<M_i18n> M_i18n::msSingleton(nullptr);
+
+int M_i18n::GetCount()
+{
+	return (int)mMapData.size();
+}
+
+const M_i18nData* M_i18n::GetData(std::string ID)
+{
+	auto it = mMapData.find(ID);
+	if (it != mMapData.end())
+	{
+		return &it->second;
+	}
+	return NULL;
+}
+
+boost::unordered_map<std::string, M_i18nData>& M_i18n::GetMapData()
+{
+	return mMapData;
+}
+
+void M_i18n::Reload()
+{
+	mMapData.clear();
+	Load();
+}
+
+void M_i18n::Load(const std::string& path)
+{
+	std::ifstream readStream(path, std::ios::binary);
+	if (!readStream.is_open())
+	{
+		assert(false);
+		return;
+	}
+	readStream.seekg(0, std::ios::end);
+	int fileSize = readStream.tellg();
+	boost::shared_array<char> buffer(new char[fileSize+1]);
+	buffer.get()[fileSize] = '\0';
+	readStream.seekg(0, std::ios::beg);
+	readStream.read(buffer.get(), fileSize);
+	readStream.close();
+	FileEncrypt::decryptBuffer( buffer, fileSize );
+	tinyxml2::XMLDocument xmlDoc;
+	auto result = xmlDoc.Parse(buffer.get(), fileSize);
+	if (result != tinyxml2::XML_SUCCESS)
+	{
+		assert(false);
+		return;
+	}
+	auto root = xmlDoc.RootElement();
+	if (root == NULL)
+	{
+		assert(false);
+		return;
+	}
+	auto element = root->FirstChildElement("Data");
+	while (element != NULL)
+	{
+		M_i18nData data;
+		data.mID = element->Attribute("ID");
+		data.mzh = element->Attribute("zh");
+		data.men = element->Attribute("en");
+		if (mMapData.find(data.mID) != mMapData.end())std::cout <<"data refind:" << data.mID << std::endl;
+		assert(mMapData.find(data.mID) == mMapData.end());
+		mMapData.insert(std::make_pair(data.mID, data));
+		element = element->NextSiblingElement();
+	}
+}
+
+void M_i18n::Load()
+{
+	Load("../Config/M_i18n.xml");
+}
+
+M_i18n* M_i18n::GetSingleton()
+{
+	if (msSingleton.get() == nullptr)
+	{
+		msSingleton.reset(new M_i18n());
+	}
+	return msSingleton.get();
+}

+ 29 - 0
GameConfig/Code/Server/M_i18n.h

@@ -0,0 +1,29 @@
+#pragma once
+#include <boost/unordered_map.hpp>
+#include <vector>
+struct M_i18nData
+{
+	//²ÎÊý±àºÅ
+	std::string mID;
+	//ÖÐÎÄ
+	std::string mzh;
+	//Ó¢ÎÄ
+	std::string men;
+};
+
+class M_i18n
+{
+public:
+private:
+	static std::auto_ptr<M_i18n> msSingleton;
+public:
+	int GetCount();
+	const M_i18nData* GetData(std::string ID);
+	boost::unordered_map<std::string, M_i18nData>& GetMapData();
+	void Reload();
+	void Load(const std::string& path);
+	void Load();
+	static M_i18n* GetSingleton();
+private:
+	boost::unordered_map<std::string, M_i18nData> mMapData;
+};

+ 19 - 0
GameConfig/Lua/M_i18n.lua

@@ -0,0 +1,19 @@
+M_i18n = {}
+
+function M_i18n:getData(key)
+	if self.datas == nil then
+		return nil
+	end
+	return self.datas[key]
+end
+
+function M_i18n:init()
+	self.datas = {}
+	self.datas["10002"] = {ID = "10002", zh = "今日剩余次数:#&0次", en = "Remaining times today: #&0 times"}
+	self.datas["10003"] = {ID = "10003", zh = "魔法转盘", en = "Magic Carousel"}
+	self.datas["10004"] = {ID = "10004", zh = "神秘事务司", en = "Division of Mystery Affairs"}
+	self.datas["1000000"] = {ID = "1000000", zh = "第一", en = "first"}
+	self.datas["1000001"] = {ID = "1000001", zh = "哈哈哈", en = "hahaha"}
+end
+
+M_i18n:init()

BIN
GameConfig/M_i18n.xls


+ 8 - 0
GameConfig/Xml/M_i18n.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Root>
+	<Data ID="10002" zh="今日剩余次数:#&amp;0次" en="Remaining times today: #&amp;0 times" />
+	<Data ID="10003" zh="魔法转盘" en="Magic Carousel" />
+	<Data ID="10004" zh="神秘事务司" en="Division of Mystery Affairs" />
+	<Data ID="1000000" zh="第一" en="first" />
+	<Data ID="1000001" zh="哈哈哈" en="hahaha" />
+</Root>

+ 11 - 0
GameConfig/json/M_i18n.json

@@ -0,0 +1,11 @@
+{"10002":{"ID":"10002","zh":"今日剩余次数:#&0次","en":"Remaining times today: #&0 times"}
+
+,"10003":{"ID":"10003","zh":"魔法转盘","en":"Magic Carousel"}
+
+,"10004":{"ID":"10004","zh":"神秘事务司","en":"Division of Mystery Affairs"}
+
+,"1000000":{"ID":"1000000","zh":"第一","en":"first"}
+
+,"1000001":{"ID":"1000001","zh":"哈哈哈","en":"hahaha"}
+
+}

+ 28 - 0
GameConfig/ts/M_i18n.ts

@@ -0,0 +1,28 @@
+// ID:参数编号, zh:中文, en:英文
+
+export default class M_i18n {
+  private static data =
+      {"10002":{"ID":"10002","zh":"今日剩余次数:#&0次","en":"Remaining times today: #&0 times"}
+
+      ,"10003":{"ID":"10003","zh":"魔法转盘","en":"Magic Carousel"}
+
+      ,"10004":{"ID":"10004","zh":"神秘事务司","en":"Division of Mystery Affairs"}
+
+      ,"1000000":{"ID":"1000000","zh":"第一","en":"first"}
+
+      ,"1000001":{"ID":"1000001","zh":"哈哈哈","en":"hahaha"}
+
+      }// ID:参数编号, zh:中文, en:英文
+
+
+    static getData(key: any): any {
+        if (key == null || key == undefined)
+            return null;
+        return this.data[key];
+    }
+
+    static getAllData(): any {
+        return this.data;
+    }
+
+}