mirror of
https://github.com/GabsPuNs/Project-Zenith-Main.git
synced 2026-07-13 14:28:10 +00:00
Add StringTableNameMap.h (#4)
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
#include "UIFontData.h"
|
||||
#include "UISplitScreenHelpers.h"
|
||||
#include "..\..\Windows64\KeyboardMouseInput.h"
|
||||
#include "..\..\RmlManager.h"
|
||||
#include "../../BufferedImage.h"
|
||||
|
||||
// 4J Stu - Enable this to override the Iggy Allocator
|
||||
@@ -375,6 +376,7 @@ void UIController::SetupFont()
|
||||
app.m_dlcManager.LanguageChanged();
|
||||
|
||||
app.loadStringTable(); // Switch to use new string table,
|
||||
RmlManager::Get().OnLanguageChanged();
|
||||
|
||||
if (m_eTargetFont == m_eCurrentFont)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,18 @@
|
||||
#include "RmlManager.h"
|
||||
|
||||
#pragma push_macro("byte")
|
||||
#pragma push_macro("GetNextSibling")
|
||||
#pragma push_macro("GetFirstChild")
|
||||
#undef byte
|
||||
#undef GetNextSibling
|
||||
#undef GetFirstChild
|
||||
|
||||
#include <RmlUi/Core/ElementText.h>
|
||||
|
||||
#pragma pop_macro("GetFirstChild")
|
||||
#pragma pop_macro("GetNextSibling")
|
||||
#pragma pop_macro("byte")
|
||||
|
||||
extern ID3D11Device* g_pd3dDevice;
|
||||
extern ID3D11DeviceContext* g_pImmediateContext;
|
||||
extern ID3D11RenderTargetView* g_pRenderTargetView;
|
||||
@@ -190,4 +203,38 @@ void RmlManager::UpdateDpRatio()
|
||||
dp_ratio = 3.0f;
|
||||
|
||||
m_context->SetDensityIndependentPixelRatio(dp_ratio);
|
||||
}
|
||||
|
||||
static void ReTranslateElement(Rml::Element* elem, Rml::SystemInterface* system_if)
|
||||
{
|
||||
Rml::ElementText* text_elem = rmlui_dynamic_cast<Rml::ElementText*>(elem);
|
||||
if (text_elem)
|
||||
{
|
||||
const Rml::Variant* src = elem->GetAttribute("data-rml-source");
|
||||
if (src)
|
||||
{
|
||||
Rml::String original = src->Get<Rml::String>();
|
||||
Rml::String translated;
|
||||
system_if->TranslateString(translated, original);
|
||||
if (translated != text_elem->GetText())
|
||||
text_elem->SetText(translated);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < elem->GetNumChildren(true); i++)
|
||||
ReTranslateElement(elem->GetChild(i), system_if);
|
||||
}
|
||||
|
||||
void RmlManager::OnLanguageChanged()
|
||||
{
|
||||
if (!m_initialised || !m_context)
|
||||
return;
|
||||
|
||||
app.DebugPrintf("[RmlManager] Re-translating all documents\n");
|
||||
|
||||
for (int i = 0; i < m_context->GetNumDocuments(); i++)
|
||||
{
|
||||
Rml::ElementDocument* doc = m_context->GetDocument(i);
|
||||
if (doc)
|
||||
ReTranslateElement(doc, m_system_interface.get());
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,8 @@ public:
|
||||
void OnResize(int width, int height);
|
||||
void UpdateDpRatio();
|
||||
|
||||
void OnLanguageChanged();
|
||||
|
||||
private:
|
||||
RmlManager();
|
||||
~RmlManager();
|
||||
|
||||
@@ -412,6 +412,10 @@ bool Factory::InstanceElementText(Element* parent, const String& in_text)
|
||||
|
||||
text_element->SetText(text);
|
||||
|
||||
// Store original untranslated text for runtime re-translation support.
|
||||
if (in_text.size() > 2 && in_text[0] == '{')
|
||||
element->SetAttribute("data-rml-source", in_text);
|
||||
|
||||
// Add to active node.
|
||||
parent->AppendChild(std::move(element));
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
#include "..\Common\Consoles_App.h"
|
||||
#include "StringTable.h"
|
||||
#include "Windows64_App.h"
|
||||
#include "..\Assets\Localisation\strings.h"
|
||||
#include "StringTableNameMap.h"
|
||||
|
||||
SystemInterface_Win64::SystemInterface_Win64()
|
||||
{
|
||||
@@ -42,20 +44,24 @@ int SystemInterface_Win64::TranslateString(Rml::String& translated, const Rml::S
|
||||
if (end != Rml::String::npos)
|
||||
{
|
||||
Rml::String key = input.substr(i + 1, end - i - 1);
|
||||
// Convert UTF-8 key to wide string for StringTable lookup
|
||||
int wlen = MultiByteToWideChar(CP_UTF8, 0, key.c_str(), (int)key.size(), nullptr, 0);
|
||||
if (wlen > 0)
|
||||
{
|
||||
std::wstring wkey(wlen, L'\0');
|
||||
MultiByteToWideChar(CP_UTF8, 0, key.c_str(), (int)key.size(), &wkey[0], wlen);
|
||||
LPCWSTR wstr = st->getString(wkey);
|
||||
if (!wstr || wcslen(wstr) == 0)
|
||||
{
|
||||
int id = GetStringIDByName(wkey);
|
||||
if (id >= 0)
|
||||
wstr = st->getString(id);
|
||||
}
|
||||
if (wstr && wcslen(wstr) > 0)
|
||||
{
|
||||
// Convert wide result back to UTF-8
|
||||
int utf8len = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, nullptr, 0, nullptr, nullptr);
|
||||
if (utf8len > 0)
|
||||
{
|
||||
std::string utf8(utf8len - 1, '\0'); // -1 for null terminator
|
||||
std::string utf8(utf8len - 1, '\0');
|
||||
WideCharToMultiByte(CP_UTF8, 0, wstr, -1, &utf8[0], utf8len, nullptr, nullptr);
|
||||
result += utf8;
|
||||
count++;
|
||||
|
||||
2325
Minecraft.Client/Windows64/StringTableNameMap.h
Normal file
2325
Minecraft.Client/Windows64/StringTableNameMap.h
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user