Refresh localized text on gainFocus for RmlUI menus

This commit is contained in:
Zero
2026-06-12 15:06:50 +02:00
parent d33ac0e45e
commit 6399a965d6
6 changed files with 129 additions and 7 deletions

View File

@@ -20,6 +20,18 @@
#pragma pop_macro("GetNextSibling")
#pragma pop_macro("byte")
static std::string WStringToUTF8(LPCWSTR wstr)
{
if (!wstr) return {};
size_t wlen = wcslen(wstr);
if (wlen == 0) return {};
int len = WideCharToMultiByte(CP_UTF8, 0, wstr, (int)wlen, nullptr, 0, nullptr, nullptr);
if (len <= 0) return {};
std::string result(len, '\0');
WideCharToMultiByte(CP_UTF8, 0, wstr, (int)wlen, &result[0], len, nullptr, nullptr);
return result;
}
UIScene_HelpAndOptionsMenu::UIScene_HelpAndOptionsMenu(int iPad, void *initData, UILayer *parentLayer)
: UIScene(iPad, parentLayer)
, m_document(nullptr)
@@ -36,7 +48,7 @@ UIScene_HelpAndOptionsMenu::UIScene_HelpAndOptionsMenu(int iPad, void *initData,
{
m_document->Show();
bool bNotInGame = (Minecraft::GetInstance()->level == nullptr);
UpdateLocalizedText();
// Change Skin: hide if not full version
if (!ProfileManager.IsFullVersion())
@@ -60,7 +72,8 @@ UIScene_HelpAndOptionsMenu::UIScene_HelpAndOptionsMenu(int iPad, void *initData,
m_document->GetElementById("credits")->AddEventListener(Rml::EventId::Click, this);
// Focus first visible button
m_document->GetElementById("change_skin")->Focus();
auto* elFirst = m_document->GetElementById("change_skin");
if (elFirst) elFirst->Focus();
}
else
{
@@ -200,8 +213,27 @@ void UIScene_HelpAndOptionsMenu::updateTooltips()
{
}
void UIScene_HelpAndOptionsMenu::UpdateLocalizedText()
{
if (!m_document)
return;
auto setText = [this](const Rml::String& id, int ids) {
auto* el = m_document->GetElementById(id);
if (el) el->SetInnerRML(WStringToUTF8(app.GetString(ids)));
};
setText("change_skin", IDS_CHANGE_SKIN);
setText("how_to_play", IDS_HOW_TO_PLAY);
setText("controls", IDS_CONTROLS);
setText("settings", IDS_SETTINGS);
setText("credits", IDS_CREDITS);
}
void UIScene_HelpAndOptionsMenu::updateComponents()
{
UpdateLocalizedText();
bool bNotInGame = (Minecraft::GetInstance()->level == nullptr);
if (bNotInGame)
{