From 8ad6c85ff2a817c9e331d2be9768fc0dd8151144 Mon Sep 17 00:00:00 2001 From: C-F0x Date: Sat, 25 Jul 2026 20:04:40 +0800 Subject: [PATCH] fix language change button btw i think its not a good idea to modify the window frame... --- src/components/bottombar.cc | 98 ++++++++++++++++++++++++++++++++++++- src/components/titlebar.cc | 4 ++ src/locales/brazilian.json | 3 +- src/locales/bulgarian.json | 3 +- src/locales/danish.json | 3 +- src/locales/dutch.json | 3 +- src/locales/english.json | 3 +- src/locales/french.json | 3 +- src/locales/german.json | 3 +- src/locales/hungarian.json | 3 +- src/locales/indonesian.json | 3 +- src/locales/italian.json | 3 +- src/locales/japanese.json | 3 +- src/locales/koreana.json | 3 +- src/locales/latam.json | 3 +- src/locales/polish.json | 3 +- src/locales/russian.json | 3 +- src/locales/schinese.json | 3 +- src/locales/spanish.json | 3 +- src/locales/swedish.json | 3 +- src/locales/tchinese.json | 3 +- src/locales/turkish.json | 3 +- src/locales/ukrainian.json | 3 +- src/locales/vietnamese.json | 3 +- 24 files changed, 145 insertions(+), 23 deletions(-) diff --git a/src/components/bottombar.cc b/src/components/bottombar.cc index 79d9be0..d681e49 100644 --- a/src/components/bottombar.cc +++ b/src/components/bottombar.cc @@ -38,6 +38,7 @@ #endif #include #include +#include using namespace ImGui; @@ -78,9 +79,104 @@ const void RenderBottomNavBar(const char* identifier, float xPos, std::function< const float buttonPos = GetCursorPosY(); - SetCursorPosX(xPos + GetCursorPosX() + GetContentRegionAvail().x - FooterContainerWidth); + SetCursorPosX(xPos + GetCursorPosX() + GetContentRegionAvail().x - FooterContainerWidth - ScaleX(55)); SetCursorPosY(GetCursorPosY() + ScaleY(10)); + // ── Language button ──────────────────────────────────────────────── + Image((ImTextureID)(intptr_t)languageIconTexture, ImVec2(ScaleX(30), ScaleY(30))); + + static bool isLangButtonHovered = false; + float langTooltipAlpha = EaseInOutFloat(std::format("##LangTooltipAlpha{}", identifier).c_str(), 0.f, 1.f, isLangButtonHovered, 0.3f); + + if (langTooltipAlpha != 0.f) { + SetMouseCursor(ImGuiMouseCursor_Hand); + PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f); + PushStyleColor(ImGuiCol_Border, ImVec4(0.18f, 0.184f, 0.192f, 1.0f)); + PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 1.0f, 1.0f, 1.0f)); + PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(ScaleX(10), ScaleY(10))); + PushStyleVar(ImGuiStyleVar_WindowRounding, 6); + PushStyleVar(ImGuiStyleVar_Alpha, langTooltipAlpha); + PushStyleColor(ImGuiCol_PopupBg, ImVec4(0.098f, 0.102f, 0.11f, 1.0f)); + SetTooltip("%s", Locale::Get("tooltipLanguage")); + PopStyleVar(4); + PopStyleColor(3); + } + + if (IsItemClicked()) + OpenPopup("##LangPopup"); + + isLangButtonHovered = IsItemHovered() || (IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem) && IsMouseDown(ImGuiMouseButton_Left)); + + // ── Language popup ───────────────────────────────────────────────── + { + ImGuiIO& io = GetIO(); + ImFont* vietItemFont = (io.Fonts->Fonts.Size > 2) ? io.Fonts->Fonts[2] : nullptr; + ImFont* dropdownFont = (io.Fonts->Fonts.Size > 3) ? io.Fonts->Fonts[3] : nullptr; + + const auto& langs = Locale::GetAvailableLanguages(); + const std::string& currentLangId = Locale::GetCurrentLanguageId(); + + const float popupWidth = ScaleX(400); + const float popupHeight = ScaleY(500); + float anim = EaseInOutFloat("##LangPopupAnim", 0.f, 1.f, IsPopupOpen("##LangPopup"), 0.35f); + + const float popupBtnY = viewport->Size.y - BottomNavBarHeight; + float popupY = popupBtnY - popupHeight + ScaleY(6) * (1.f - anim); + SetNextWindowPos({ viewport->Size.x - popupWidth - ScaleX(50), popupY }); + SetNextWindowSize({ popupWidth, popupHeight }); + SetNextWindowBgAlpha(anim); + + PushStyleColor(ImGuiCol_PopupBg, ImVec4(0.098f, 0.102f, 0.11f, 1.0f)); + PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 1.0f, 1.0f, 1.0f)); + PushStyleColor(ImGuiCol_Header, ImVec4(0.15f, 0.155f, 0.165f, 1.0f)); + PushStyleColor(ImGuiCol_HeaderHovered, ImVec4(0.22f, 0.225f, 0.235f, 1.0f)); + PushStyleColor(ImGuiCol_Border, ImVec4(0.18f, 0.184f, 0.192f, 1.0f)); + PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(ScaleX(10), ScaleY(10))); + PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(ScaleX(8), ScaleY(6))); + PushStyleVar(ImGuiStyleVar_PopupRounding, ScaleX(6)); + + if (dropdownFont) + PushFont(dropdownFont); + + if (BeginPopup("##LangPopup", ImGuiWindowFlags_NoMove)) { + if (!::IsWindowFocused()) + CloseCurrentPopup(); + PushStyleVar(ImGuiStyleVar_Alpha, anim); + for (const auto& lang : langs) { + bool isSelected = (lang.id == currentLangId); + bool useVietFont = (lang.id == "vietnamese") && (vietItemFont != nullptr); + if (useVietFont) { + if (dropdownFont) + PopFont(); + PushFont(vietItemFont); + } + if (Selectable(lang.displayName.c_str(), isSelected, 0, ImVec2(popupWidth, 0))) { + Locale::SetLanguage(lang.id); + RequestFontRebuild(); + CloseCurrentPopup(); + } + if (isSelected) + SetItemDefaultFocus(); + if (useVietFont) { + PopFont(); + if (dropdownFont) + PushFont(dropdownFont); + } + } + PopStyleVar(); + EndPopup(); + } + + if (dropdownFont) + PopFont(); + + PopStyleVar(3); + PopStyleColor(5); + } + + SameLine(0, ScaleX(25)); + SetCursorPosY(GetCursorPosY() - ScaleY(15)); + Image((ImTextureID)(intptr_t)discordIconTexture, ImVec2(ScaleX(30), ScaleY(30))); static bool isDiscordButtonHovered = false; diff --git a/src/components/titlebar.cc b/src/components/titlebar.cc index cd9d1ad..216a529 100644 --- a/src/components/titlebar.cc +++ b/src/components/titlebar.cc @@ -114,12 +114,14 @@ bool RenderTitleBarComponent(std::shared_ptr router) if (isLangButtonHovered) PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.f, 1.f, 1.f, 0.06f)); + /* Commented out — language icon moved to bottom bar (bottombar.cc) BeginChild("##LangButton", { langButtonDimensions.x, langButtonDimensions.y }, false, ImGuiWindowFlags_NoScrollbar); { SetCursorPos({ (langButtonDimensions.x - ScaleX(20)) * 0.5f, ScaleY(12) }); Image((ImTextureID)(intptr_t)languageIconTexture, { ScaleX(20), ScaleY(20) }); } EndChild(); + */ ImVec2 langBtnMin = GetItemRectMin(); ImVec2 langBtnMax = GetItemRectMax(); @@ -137,6 +139,7 @@ bool RenderTitleBarComponent(std::shared_ptr router) isLangButtonHovered = IsItemHovered(); + /*Migrate to BottomBar ImGuiIO& io = GetIO(); ImFont* vietItemFont = (io.Fonts->Fonts.Size > 2) ? io.Fonts->Fonts[2] : nullptr; ImFont* dropdownFont = (io.Fonts->Fonts.Size > 3) ? io.Fonts->Fonts[3] : nullptr; @@ -198,6 +201,7 @@ bool RenderTitleBarComponent(std::shared_ptr router) PopStyleVar(3); PopStyleColor(4); + */ SetCursorPos({ viewport->Size.x - closeButtonDimensions.x, 0 }); PushStyleVar(ImGuiStyleVar_ChildRounding, 0); diff --git a/src/locales/brazilian.json b/src/locales/brazilian.json index f012e1d..560dbf7 100644 --- a/src/locales/brazilian.json +++ b/src/locales/brazilian.json @@ -55,5 +55,6 @@ "titlebarTitle": "Steam Homebrew", "tooltipDiscord": "Entrar no servidor Discord", - "tooltipGithub": "Ver código-fonte" + "tooltipGithub": "Ver código-fonte", + "tooltipLanguage": "Mudar Idioma" } diff --git a/src/locales/bulgarian.json b/src/locales/bulgarian.json index 079cd5e..a9f0867 100644 --- a/src/locales/bulgarian.json +++ b/src/locales/bulgarian.json @@ -55,5 +55,6 @@ "titlebarTitle": "Steam Homebrew", "tooltipDiscord": "Присъединете се към Discord сървъра", - "tooltipGithub": "Вижте изходния код" + "tooltipGithub": "Вижте изходния код", + "tooltipLanguage": "Смяна на език" } diff --git a/src/locales/danish.json b/src/locales/danish.json index 365a5a8..48231ca 100644 --- a/src/locales/danish.json +++ b/src/locales/danish.json @@ -55,5 +55,6 @@ "titlebarTitle": "Steam Homebrew", "tooltipDiscord": "Tilmeld Discord-serveren", - "tooltipGithub": "Se kildekode" + "tooltipGithub": "Se kildekode", + "tooltipLanguage": "Skift Sprog" } diff --git a/src/locales/dutch.json b/src/locales/dutch.json index 963b459..281a8ad 100644 --- a/src/locales/dutch.json +++ b/src/locales/dutch.json @@ -55,5 +55,6 @@ "titlebarTitle": "Steam Homebrew", "tooltipDiscord": "Discord-server joinen", - "tooltipGithub": "Broncode bekijken" + "tooltipGithub": "Broncode bekijken", + "tooltipLanguage": "Taal Wijzigen" } diff --git a/src/locales/english.json b/src/locales/english.json index 470f5ae..5d78a7f 100644 --- a/src/locales/english.json +++ b/src/locales/english.json @@ -55,5 +55,6 @@ "titlebarTitle": "Steam Homebrew", "tooltipDiscord": "Join Discord Server", - "tooltipGithub": "View Source Code" + "tooltipGithub": "View Source Code", + "tooltipLanguage": "Change Language" } diff --git a/src/locales/french.json b/src/locales/french.json index 9d4e326..7856700 100644 --- a/src/locales/french.json +++ b/src/locales/french.json @@ -55,5 +55,6 @@ "titlebarTitle": "Steam Homebrew", "tooltipDiscord": "Rejoindre le serveur Discord", - "tooltipGithub": "Voir le code source" + "tooltipGithub": "Voir le code source", + "tooltipLanguage": "Changer de Langue" } diff --git a/src/locales/german.json b/src/locales/german.json index a7943cf..196b12c 100644 --- a/src/locales/german.json +++ b/src/locales/german.json @@ -55,5 +55,6 @@ "titlebarTitle": "Steam Homebrew", "tooltipDiscord": "Discord-Server beitreten", - "tooltipGithub": "Quellcode ansehen" + "tooltipGithub": "Quellcode ansehen", + "tooltipLanguage": "Sprache Ändern" } diff --git a/src/locales/hungarian.json b/src/locales/hungarian.json index d4e8800..ac64398 100644 --- a/src/locales/hungarian.json +++ b/src/locales/hungarian.json @@ -55,5 +55,6 @@ "titlebarTitle": "Steam Homebrew", "tooltipDiscord": "Csatlakozás a Discord-szerverhez", - "tooltipGithub": "Forráskód megtekintése" + "tooltipGithub": "Forráskód megtekintése", + "tooltipLanguage": "Nyelv Váltása" } diff --git a/src/locales/indonesian.json b/src/locales/indonesian.json index 7d3cf64..59a73b4 100644 --- a/src/locales/indonesian.json +++ b/src/locales/indonesian.json @@ -55,5 +55,6 @@ "titlebarTitle": "Steam Homebrew", "tooltipDiscord": "Bergabung dengan Server Discord", - "tooltipGithub": "Lihat Kode Sumber" + "tooltipGithub": "Lihat Kode Sumber", + "tooltipLanguage": "Ganti Bahasa" } diff --git a/src/locales/italian.json b/src/locales/italian.json index b2b0070..5b33a2a 100644 --- a/src/locales/italian.json +++ b/src/locales/italian.json @@ -55,5 +55,6 @@ "titlebarTitle": "Steam Homebrew", "tooltipDiscord": "Unisciti al server Discord", - "tooltipGithub": "Vedi il codice sorgente" + "tooltipGithub": "Vedi il codice sorgente", + "tooltipLanguage": "Cambia Lingua" } diff --git a/src/locales/japanese.json b/src/locales/japanese.json index abcb94e..527b54d 100644 --- a/src/locales/japanese.json +++ b/src/locales/japanese.json @@ -55,5 +55,6 @@ "titlebarTitle": "Steam Homebrew", "tooltipDiscord": "Discord サーバーに参加", - "tooltipGithub": "ソースコードを見る" + "tooltipGithub": "ソースコードを見る", + "tooltipLanguage": "言語を変更" } diff --git a/src/locales/koreana.json b/src/locales/koreana.json index 5cb8e66..cec2f6b 100644 --- a/src/locales/koreana.json +++ b/src/locales/koreana.json @@ -55,5 +55,6 @@ "titlebarTitle": "Steam Homebrew", "tooltipDiscord": "Discord 서버 참가", - "tooltipGithub": "소스 코드 보기" + "tooltipGithub": "소스 코드 보기", + "tooltipLanguage": "언어 변경" } diff --git a/src/locales/latam.json b/src/locales/latam.json index 24bcf2f..66fd5d9 100644 --- a/src/locales/latam.json +++ b/src/locales/latam.json @@ -55,5 +55,6 @@ "titlebarTitle": "Steam Homebrew", "tooltipDiscord": "Unirse al servidor de Discord", - "tooltipGithub": "Ver código fuente" + "tooltipGithub": "Ver código fuente", + "tooltipLanguage": "Cambiar Idioma" } diff --git a/src/locales/polish.json b/src/locales/polish.json index 5d80c91..af81837 100644 --- a/src/locales/polish.json +++ b/src/locales/polish.json @@ -55,5 +55,6 @@ "titlebarTitle": "Steam Homebrew", "tooltipDiscord": "Dołącz do serwera Discord", - "tooltipGithub": "Zobacz kod źródłowy" + "tooltipGithub": "Zobacz kod źródłowy", + "tooltipLanguage": "Zmień Język" } diff --git a/src/locales/russian.json b/src/locales/russian.json index 53b65b1..cdf5ee5 100644 --- a/src/locales/russian.json +++ b/src/locales/russian.json @@ -55,5 +55,6 @@ "titlebarTitle": "Steam Homebrew", "tooltipDiscord": "Присоединиться к Discord", - "tooltipGithub": "Посмотреть исходный код" + "tooltipGithub": "Посмотреть исходный код", + "tooltipLanguage": "Сменить Язык" } diff --git a/src/locales/schinese.json b/src/locales/schinese.json index 0d0f710..eb09125 100644 --- a/src/locales/schinese.json +++ b/src/locales/schinese.json @@ -55,5 +55,6 @@ "titlebarTitle": "Steam Homebrew", "tooltipDiscord": "加入 Discord 服务器", - "tooltipGithub": "查看源代码" + "tooltipGithub": "查看源代码", + "tooltipLanguage": "修改语言" } diff --git a/src/locales/spanish.json b/src/locales/spanish.json index e8cb0d6..e73c85b 100644 --- a/src/locales/spanish.json +++ b/src/locales/spanish.json @@ -55,5 +55,6 @@ "titlebarTitle": "Steam Homebrew", "tooltipDiscord": "Unirse al servidor de Discord", - "tooltipGithub": "Ver código fuente" + "tooltipGithub": "Ver código fuente", + "tooltipLanguage": "Cambiar Idioma" } diff --git a/src/locales/swedish.json b/src/locales/swedish.json index 5ab04b8..e221306 100644 --- a/src/locales/swedish.json +++ b/src/locales/swedish.json @@ -55,5 +55,6 @@ "titlebarTitle": "Steam Homebrew", "tooltipDiscord": "Gå med i Discord-servern", - "tooltipGithub": "Visa källkod" + "tooltipGithub": "Visa källkod", + "tooltipLanguage": "Ändra Språk" } diff --git a/src/locales/tchinese.json b/src/locales/tchinese.json index 5f8d828..f9d43c2 100644 --- a/src/locales/tchinese.json +++ b/src/locales/tchinese.json @@ -55,5 +55,6 @@ "titlebarTitle": "Steam Homebrew", "tooltipDiscord": "加入 Discord 伺服器", - "tooltipGithub": "檢視原始碼" + "tooltipGithub": "檢視原始碼", + "tooltipLanguage": "修改語言" } diff --git a/src/locales/turkish.json b/src/locales/turkish.json index 298d28c..9e9c51d 100644 --- a/src/locales/turkish.json +++ b/src/locales/turkish.json @@ -55,5 +55,6 @@ "titlebarTitle": "Steam Homebrew", "tooltipDiscord": "Discord Sunucusuna Katıl", - "tooltipGithub": "Kaynak Kodunu Görüntüle" + "tooltipGithub": "Kaynak Kodunu Görüntüle", + "tooltipLanguage": "Dili Değiştir" } diff --git a/src/locales/ukrainian.json b/src/locales/ukrainian.json index 7403d49..8f426bf 100644 --- a/src/locales/ukrainian.json +++ b/src/locales/ukrainian.json @@ -55,5 +55,6 @@ "titlebarTitle": "Steam Homebrew", "tooltipDiscord": "Приєднатися до Discord", - "tooltipGithub": "Переглянути вихідний код" + "tooltipGithub": "Переглянути вихідний код", + "tooltipLanguage": "Змінити Мову" } diff --git a/src/locales/vietnamese.json b/src/locales/vietnamese.json index dcba2a3..b1bb615 100644 --- a/src/locales/vietnamese.json +++ b/src/locales/vietnamese.json @@ -55,5 +55,6 @@ "titlebarTitle": "Steam Homebrew", "tooltipDiscord": "Tham gia máy chủ Discord", - "tooltipGithub": "Xem mã nguồn" + "tooltipGithub": "Xem mã nguồn", + "tooltipLanguage": "Đổi Ngôn Ngữ" }