mirror of
https://github.com/GabsPuNs/Project-Zenith-Main.git
synced 2026-08-06 01:11:18 +00:00
Update Localisation
* Stringtables now support IDs and Strings at the same time. DLCs have a new branch for RMLUI now.
* Removed hardcoded StringTableNameMap for use Strings instead of IDs for RMLUI.
* Strings in RMLUI now uses [] since {} is used for data and it could affect future menus.
* Removed GetStringTable. app.GetString now support WStrings.
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
#include "StringTable.h"
|
||||
|
||||
StringTable::StringTable(void)
|
||||
{
|
||||
|
||||
}
|
||||
StringTable::StringTable(void) {}
|
||||
|
||||
// Load string table from a binary blob, filling out with the current localisation data only
|
||||
StringTable::StringTable(PBYTE pbData, DWORD dwSize)
|
||||
@@ -23,7 +20,6 @@ void StringTable::Reset(void)
|
||||
m_stringsMap.clear();
|
||||
m_stringsVec.clear();
|
||||
m_langSizeMap.clear();
|
||||
isStatic = false;
|
||||
currentLanguage.clear();
|
||||
}
|
||||
|
||||
@@ -69,10 +65,6 @@ void StringTable::ReadAllFromStream(DataInputStream* dis)
|
||||
dis->skip(bytesToSkip);
|
||||
ReadLanguageFromStream(dis, dataSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
isStatic = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool StringTable::FindLanguage(wstring& outLangId, int64_t& outBytesToSkip, int& outDataSize)
|
||||
@@ -107,44 +99,26 @@ bool StringTable::FindLanguage(wstring& outLangId, int64_t& outBytesToSkip, int&
|
||||
|
||||
void StringTable::ReadLanguageFromStream(DataInputStream* dis, int dataSize)
|
||||
{
|
||||
byteArray langData(dataSize);
|
||||
dis->read(langData);
|
||||
|
||||
ByteArrayInputStream bais2(langData);
|
||||
DataInputStream dis2(&bais2);
|
||||
|
||||
// Read the language file for the selected language
|
||||
int langVersion = dis2.readInt();
|
||||
int langVersion = dis->readInt();
|
||||
wstring langId = dis->readUTF();
|
||||
int totalStrings = dis->readInt();
|
||||
|
||||
isStatic = false;
|
||||
if (langVersion > 0)
|
||||
isStatic = dis2.readBoolean();
|
||||
app.DebugPrintf("StringTable:: Hybrid Mode. totalStrings = %d\n", totalStrings);
|
||||
|
||||
wstring langId = dis2.readUTF();
|
||||
int totalStrings = dis2.readInt();
|
||||
m_stringsVec.reserve(totalStrings);
|
||||
m_stringsMap.reserve(totalStrings);
|
||||
|
||||
app.DebugPrintf("IsStatic=%s totalStrings = %d\n", isStatic ? "TRUE" : "FALSE", totalStrings);
|
||||
|
||||
if (!isStatic)
|
||||
for(int i = 0; i < totalStrings; ++i)
|
||||
{
|
||||
for(int i = 0; i < totalStrings; ++i)
|
||||
{
|
||||
wstring stringId = dis2.readUTF();
|
||||
wstring stringValue = dis2.readUTF();
|
||||
wstring stringId = dis->readUTF();
|
||||
wstring stringValue = dis->readUTF();
|
||||
|
||||
m_stringsMap.insert(unordered_map<wstring, wstring>::value_type(stringId, stringValue));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int i = 0; i < totalStrings; ++i)
|
||||
{
|
||||
m_stringsVec.push_back(dis2.readUTF());
|
||||
}
|
||||
}
|
||||
m_stringsVec.push_back(std::move(stringValue));
|
||||
|
||||
dis2.close();
|
||||
bais2.reset();
|
||||
size_t indexInVector = m_stringsVec.size() - 1;
|
||||
m_stringsMap.emplace(std::move(stringId), indexInVector);
|
||||
}
|
||||
}
|
||||
|
||||
void StringTable::write(DataOutputStream* dos)
|
||||
@@ -155,25 +129,14 @@ void StringTable::write(DataOutputStream* dos)
|
||||
int langVersion = 1;
|
||||
|
||||
dos->writeInt(langVersion);
|
||||
dos->writeBoolean(isStatic);
|
||||
dos->writeUTF(currentLanguage.empty() ? L"en_US" : currentLanguage);
|
||||
|
||||
if (!isStatic)
|
||||
dos->writeInt(m_stringsMap.size());
|
||||
|
||||
for (auto const& [key, index] : m_stringsMap)
|
||||
{
|
||||
dos->writeInt(m_stringsMap.size());
|
||||
for (auto const& [key, val] : m_stringsMap)
|
||||
{
|
||||
dos->writeUTF(key);
|
||||
dos->writeUTF(val);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dos->writeInt(m_stringsVec.size());
|
||||
for (auto const& val : m_stringsVec)
|
||||
{
|
||||
dos->writeUTF(val);
|
||||
}
|
||||
dos->writeUTF(key);
|
||||
dos->writeUTF(m_stringsVec[index]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,20 +151,16 @@ LPCWSTR StringTable::getString(const wstring &id)
|
||||
auto it = m_stringsMap.find(id);
|
||||
|
||||
if(it != m_stringsMap.end())
|
||||
{
|
||||
return it->second.c_str();
|
||||
}
|
||||
return m_stringsVec[it->second].c_str();
|
||||
else
|
||||
{
|
||||
return L"";
|
||||
}
|
||||
}
|
||||
|
||||
LPCWSTR StringTable::getString(int id)
|
||||
{
|
||||
if (id >= 0 && id < m_stringsVec.size())
|
||||
{
|
||||
LPCWSTR pwchString=m_stringsVec.at(id).c_str();
|
||||
LPCWSTR pwchString=m_stringsVec[id].c_str();
|
||||
return pwchString;
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user