| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | #include <gui/settings.hh> |
| 38 | #include <gui/consolelog.hh> |
| 39 | #include <util/structs.hh> |
| 40 | #include <database/locale.hh> |
| 41 | #include <imgui.h> |
| 42 | #include <gui/guiengine.hh> |
| 43 | |
| 44 | namespace gui { |
| 45 | void Settings::Draw(Info &info) { |
| 46 | if (!info.isSettings) return; |
| 47 | |
| 48 | ImGuiWindowFlags flags = 0; |
| 49 | ImGui::SetNextWindowSize({ 400, 300 }, ImGuiCond_Appearing); |
| 50 | ImGui::Begin(info.i18n->GetWord("settings").c_str(), &info.isSettings, flags); |
| 51 | if (GuiEngine::ShouldCloseWindowOnEscape()) info.isSettings = false; |
| 52 | |
| 53 | ImGui::Text("言語 / Language"); |
| 54 | ImGui::SameLine(); |
| 55 | cstr items[] = { "日本語 (ja_JP)", "English (en_US)" }; |
| 56 | const i32 itemCount = IM_COUNTOF(items); |
| 57 | i32 curId = info.i18n->GetCurrentLanguage().id; |
| 58 | static i32 sel = (curId >= 1) ? curId - 1 : 0; |
| 59 | |
| 60 | sel = (curId >= 1 && curId <= itemCount) ? curId - 1 : 0; |
| 61 | |
| 62 | const char *preview = items[sel]; |
| 63 | if (ImGui::BeginCombo("##Language", preview)) { |
| 64 | for (int n = 0; n < itemCount; ++n) { |
| 65 | const bool isSel = (sel == n); |
| 66 | if (ImGui::Selectable(items[n], isSel)) { |
| 67 | sel = n; |
| 68 | info.i18n->SetLanguage(n + 1); |
| 69 | gui::LogEntry entry; |
| 70 | entry.type = gui::LogType::Info; |
| 71 | entry.text = info.i18n->GetWord("consoleloginfolangchangeok"); |
| 72 | info.cmd->Add(entry); |
| 73 | } |
| 74 | |
| 75 | if (isSel) { |
| 76 | ImGui::SetItemDefaultFocus(); |
| 77 | } |
| 78 | } |
| 79 | ImGui::EndCombo(); |
| 80 | } |
| 81 | |
| 82 | f32 btnW = 80.f; |
| 83 | f32 btnH = 0.f; |
| 84 | |
| 85 | ImVec2 winSize = ImGui::GetWindowSize(); |
| 86 | ImVec2 cursorPos = ImGui::GetCursorPos(); |
| 87 | |
| 88 | ImGui::SetCursorPos({ |
| 89 | (winSize.x - btnW) * .5f, |
| 90 | winSize.y - 40.f |
| 91 | }); |
| 92 | |
| 93 | if (ImGui::Button("OK", { btnW, btnH })) info.isSettings = false; |
| 94 | ImGui::End(); |
| 95 | } |
| 96 | } |