diff --git a/Dalamud.Loc/Dalamud.Loc.csproj b/Dalamud.Loc/Dalamud.Loc.csproj index 6a4f192..062f538 100644 --- a/Dalamud.Loc/Dalamud.Loc.csproj +++ b/Dalamud.Loc/Dalamud.Loc.csproj @@ -53,6 +53,11 @@ /home/runner/Dalamud/Newtonsoft.Json.dll False + + $(AppData)\XIVLauncher\addon\Hooks\dev\ImGui.NET.dll + /home/runner/Dalamud/ImGui.NET.dll + False + diff --git a/Dalamud.Loc/ImGui/LocGui.cs b/Dalamud.Loc/ImGui/LocGui.cs new file mode 100644 index 0000000..d243b1d --- /dev/null +++ b/Dalamud.Loc/ImGui/LocGui.cs @@ -0,0 +1,138 @@ +using System.Numerics; + +using Dalamud.Interface; +using ImGuiNET; + +namespace Dalamud.Loc.ImGui; + +/// +/// Dalamud.Loc backed ImGui components. +/// +public static class LocGui +{ + private static Localization loc = null!; + + /// + /// Initialize LocGui. + /// + /// plugin localization. + public static void Initialize(Localization localization) => loc = localization; + + /// + /// Localized TextColored. + /// + /// primary key. + /// text color. + public static void TextColored(string key, Vector4 color) => ImGuiNET.ImGui.TextColored(color, loc.GetString(key)); + + /// + /// Localized Text. + /// + /// primary key. + public static void Text(string key) => ImGuiNET.ImGui.Text(loc.GetString(key)); + + /// + /// Localized ImGuiHelpers.SafeTextWrapped. + /// + /// primary key. + public static void SafeTextWrapped(string key) => ImGuiHelpers.SafeTextWrapped(loc.GetString(key)); + + /// + /// Localized InputText. + /// + /// primary key. + /// input text. + /// max length. + /// indicator if changed. + public static bool InputText(string key, ref string input, uint maxLength) => ImGuiNET.ImGui.InputText(loc.GetString(key), ref input, maxLength); + + /// + /// Localized InputTextWithHint. + /// + /// primary key. + /// hint text key. + /// text input. + /// max length. + /// Indicates if input text has changed. + public static bool InputTextWithHint(string key, string hintKey, ref string input, uint length) => + ImGuiNET.ImGui.InputTextWithHint($"###{key}", loc.GetString(hintKey), ref input, length); + + /// + /// Localized SmallButton. + /// + /// key for string/value. + /// indicator if button was clicked. + public static bool SmallButton(string key) => ImGuiNET.ImGui.SmallButton(loc.GetString(key)); + + /// + /// Localized Button. + /// + /// key for string/value. + /// indicator if button was clicked. + public static bool Button(string key) => ImGuiNET.ImGui.Button(loc.GetString(key)); + + /// + /// Localized Button with size. + /// + /// key for string/value. + /// vector2 size. + /// indicator if button was clicked. + public static bool Button(string key, Vector2 size) => ImGuiNET.ImGui.Button(loc.GetString(key), size); + + /// + /// Localized BeginMenu. + /// + /// key for string/value. + /// indicator if menu was clicked. + public static bool BeginMenu(string key) => ImGuiNET.ImGui.BeginMenu(loc.GetString(key)); + + /// + /// Localized MenuItem. + /// + /// key for string/value. + /// indicator if menu item was clicked. + public static bool MenuItem(string key) => ImGuiNET.ImGui.MenuItem(loc.GetString(key)); + + /// + /// Localized SetHoverTooltip. + /// + /// key for string/value. + public static void SetHoverTooltip(string key) + { + if (ImGuiNET.ImGui.IsItemHovered()) + { + ImGuiNET.ImGui.SetTooltip(loc.GetString(key)); + } + } + + /// + /// Localized BeginTabItem. + /// + /// primary key. + /// indicator whether tab selected. + public static bool BeginTabItem(string key) + { + if (ImGuiNET.ImGui.BeginTabItem(loc.GetString(key))) + { + return true; + } + + return false; + } + + /// + /// Localized CollapsingHeader. + /// + /// primary key. + /// tree node flags (defaults to none). + /// indicator whether header selected. + public static bool CollapsingHeader(string key, ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags.None) + { + if (ImGuiNET.ImGui.CollapsingHeader(loc.GetString(key), flags)) + { + return true; + } + + return false; + } +} diff --git a/README.md b/README.md index 9e38797..7e2a24e 100644 --- a/README.md +++ b/README.md @@ -50,3 +50,9 @@ loc.LoadLanguageFromAssembly(Language.French, "MyPlugin.Resource.translation.fr. loc.LoadLanguageFromUrl(Language.French, urlToJson); ``` + +### Using localized ImGui components + +```csharp +LocGui.Text("MyStringKey"); +```