xvwyh / BuildPad

A build storage plugin for ArcDPS
https://buildpad.gw2archive.eu
MIT License
29 stars 3 forks source link

How to make it support Chinese? #1

Closed jiangyi0923 closed 4 years ago

jiangyi0923 commented 4 years ago

How to make it support Chinese? When it coexists with the SCT plugin (Chinese version) the pad plugin (Chinese version) characters become "?"

if i use imgui::text(u8"你好") It displays normally when only arcpds plugin is available . if io->fonts-addf... Will it report an error, or will it still be "?"

Can you give me some advice?

jiangyi0923 commented 4 years ago

addons.zip this is SCT plugin (Chinese version) with Chinese TTF

xvwyh commented 4 years ago

That's strange. It seems like SCT resets the global ImGui font, making it ignore arcdps_font.ttf. SCT author must have asked ArcDPS's author to account for that, because ArcDPS picks up and uses SCT's font, but all the other user-made plugins (Mechanics, Boon Table, and my BuildPad) don't. I'll ask ArcDPS's author about the workaround he's using and will try to incorporate it into my plugin as well.

Besides that, BuildPad doesn't support localization. You can only select Chinese as API language, to display specialization, skill, item, legend and pet names in Chinese, but the rest of the UI would be in English.

xvwyh commented 4 years ago

Alright, I'll fix it in the update that I'll probably release in a few days. If you want the fix right now and are willing to compile it yourself, here's the patch:

@@ -718,6 +718,7 @@ void Handler::Update()

     float const originalWindowTitleAlign = std::exchange(ImGui::GetStyle().WindowTitleAlign.x, 0.5f);
     ImGui::PushStyleColor(ImGuiCol_ModalWindowDarkening, { 0, 0, 0, ImGui::ColorConvertU32ToFloat4(ImGui::GetColorU32(ImGuiCol_ModalWindowDarkening)).w });
+    ImGui::PushFont(ImGui::GetIO().Fonts->Fonts.back());

     if (m_shown)
         RenderMainWindow(delta);
@@ -794,6 +795,7 @@ void Handler::Update()
         ImGui::End();
     }

+    ImGui::PopFont();
     ImGui::PopStyleColor();
     ImGui::GetStyle().WindowTitleAlign.x = originalWindowTitleAlign;
 }
jiangyi0923 commented 4 years ago

it`s work,That's great, thank you!

jiangyi0923 commented 4 years ago

You use a lot of ImGui::SetTooltip(); This will still make the text to "?" you need ImGui::BeginTooltip(), ImGui::Text(u8"只显示当前职业的配置"), ImGui::EndTooltip();

xvwyh commented 4 years ago

OK, I'll fix that.

BTW, upon further testing I found that the patch I gave above is slightly wrong. It breaks certain size calculations (I forgot that ImGui::CalcTextSize depends on font size). This would be a better way:

@@ -687,6 +687,7 @@ void Handler::Update()
         Sleep(10 - (DWORD)delta.count());
 #endif

+    ImGui::PushFont(ImGui::GetIO().Fonts->Fonts.back());
     LINE_SIZE = ImGui::CalcTextSize("");
     WINDOW_PADDING = ImGui::GetStyle().WindowPadding;
     FRAME_PADDING = ImGui::GetStyle().FramePadding;
@@ -796,6 +797,7 @@ void Handler::Update()

     ImGui::PopStyleColor();
     ImGui::GetStyle().WindowTitleAlign.x = originalWindowTitleAlign;
+    ImGui::PopFont();
 }

 void Handler::UpdateOptions()
xvwyh commented 4 years ago

Fixed in b7d93f7d0fa02deee1410a2e506de72a64f01d46. As for tooltips, I added a custom ImGui::Tooltip function which calls

ImGui::BeginTooltip();
ImGui::Text(...);
ImGui::EndTooltip();

so it will correctly inherit font from windows.