From a7687287fad3b7d094f9d9df486f6f18f6b40253 Mon Sep 17 00:00:00 2001 From: goat <16760685+goaaats@users.noreply.github.com> Date: Mon, 8 Jun 2020 18:07:43 +0200 Subject: [PATCH] feat: add language select to settings --- Dalamud/Dalamud.cs | 16 ++++++++-------- Dalamud/Interface/DalamudSettingsWindow.cs | 18 +++++++++++++++++- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/Dalamud/Dalamud.cs b/Dalamud/Dalamud.cs index 92778da89..4fabac63d 100644 --- a/Dalamud/Dalamud.cs +++ b/Dalamud/Dalamud.cs @@ -68,7 +68,7 @@ namespace Dalamud { public DataManager Data { get; private set; } - private Localization localizationMgr; + internal Localization LocalizationManager; public bool IsReady { get; private set; } @@ -100,11 +100,11 @@ namespace Dalamud { throw new Exception("Could not ensure assets.", task.Exception); } - this.localizationMgr = new Localization(this.StartInfo.WorkingDirectory); + this.LocalizationManager = new Localization(this.StartInfo.WorkingDirectory); if (!string.IsNullOrEmpty(this.Configuration.LanguageOverride)) { - this.localizationMgr.SetupWithLangCode(this.Configuration.LanguageOverride); + this.LocalizationManager.SetupWithLangCode(this.Configuration.LanguageOverride); } else { - this.localizationMgr.SetupWithUiCulture(); + this.LocalizationManager.SetupWithUiCulture(); } if (Environment.GetEnvironmentVariable("DALAMUD_NOT_HAVE_INTERFACE") != "True") { @@ -333,13 +333,13 @@ namespace Dalamud { } if (ImGui.MenuItem("From UICulture")) { - this.localizationMgr.SetupWithUiCulture(); + this.LocalizationManager.SetupWithUiCulture(); } foreach (var applicableLangCode in Localization.ApplicableLangCodes) { if (ImGui.MenuItem($"Applicable: {applicableLangCode}")) { - this.localizationMgr.SetupWithLangCode(applicableLangCode); + this.LocalizationManager.SetupWithLangCode(applicableLangCode); } } @@ -741,12 +741,12 @@ namespace Dalamud { private void OnSetLanguageCommand(string command, string arguments) { if (Localization.ApplicableLangCodes.Contains(arguments.ToLower())) { - this.localizationMgr.SetupWithLangCode(arguments.ToLower()); + this.LocalizationManager.SetupWithLangCode(arguments.ToLower()); this.Configuration.LanguageOverride = arguments.ToLower(); this.Framework.Gui.Chat.Print(string.Format(Loc.Localize("DalamudLanguageSetTo", "Language set to {0}"), arguments)); } else { - this.localizationMgr.SetupWithUiCulture(); + this.LocalizationManager.SetupWithUiCulture(); this.Configuration.LanguageOverride = null; this.Framework.Gui.Chat.Print(string.Format(Loc.Localize("DalamudLanguageSetTo", "Language set to {0}"), "default")); diff --git a/Dalamud/Interface/DalamudSettingsWindow.cs b/Dalamud/Interface/DalamudSettingsWindow.cs index fe10322d5..e91529c68 100644 --- a/Dalamud/Interface/DalamudSettingsWindow.cs +++ b/Dalamud/Interface/DalamudSettingsWindow.cs @@ -30,8 +30,14 @@ namespace Dalamud.Interface this.doPluginTest = this.dalamud.Configuration.DoPluginTest; this.doDalamudTest = this.dalamud.Configuration.DoDalamudTest; + + this.languages = Localization.ApplicableLangCodes.Prepend("en").ToArray(); + this.langIndex = string.IsNullOrEmpty(this.dalamud.Configuration.LanguageOverride) ? 0 : Array.IndexOf(this.languages, this.dalamud.Configuration.LanguageOverride); } + private string[] languages; + private int langIndex; + private string[] chatTypes; private Vector4 hintTextColor = new Vector4(0.70f, 0.70f, 0.70f, 1.00f); @@ -52,7 +58,7 @@ namespace Dalamud.Interface var isOpen = true; - if (!ImGui.Begin("XIVLauncher Settings", ref isOpen, ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoResize)) { + if (!ImGui.Begin("Dalamud Settings", ref isOpen, ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoResize)) { ImGui.End(); return false; } @@ -61,6 +67,13 @@ namespace Dalamud.Interface if (ImGui.BeginTabBar("SetTabBar")) { if (ImGui.BeginTabItem("General")) { + ImGui.Text("Language"); + ImGui.Combo("##XlLangCombo", ref this.langIndex, this.languages, + this.languages.Length); + ImGui.TextColored(this.hintTextColor, "Select the language Dalamud will be displayed in."); + + ImGui.Dummy(new Vector2(5f, 5f)); + ImGui.Text("General Chat Channel"); ImGui.Combo("##XlChatTypeCombo", ref this.dalamudMessagesChatType, this.chatTypes, this.chatTypes.Length); @@ -110,6 +123,9 @@ namespace Dalamud.Interface } private void Save() { + this.dalamud.LocalizationManager.SetupWithLangCode(this.languages[this.langIndex]); + this.dalamud.Configuration.LanguageOverride = this.languages[this.langIndex]; + this.dalamud.Configuration.GeneralChatType = (XivChatType) this.dalamudMessagesChatType; this.dalamud.Configuration.DutyFinderTaskbarFlash = this.doCfTaskBarFlash;