diff --git a/Dalamud/Game/Internal/Gui/GameGuiAddressResolver.cs b/Dalamud/Game/Internal/Gui/GameGuiAddressResolver.cs index f163df548..0592ca3f6 100644 --- a/Dalamud/Game/Internal/Gui/GameGuiAddressResolver.cs +++ b/Dalamud/Game/Internal/Gui/GameGuiAddressResolver.cs @@ -46,7 +46,7 @@ namespace Dalamud.Game.Internal.Gui { ToggleUiHide = sig.ScanText("48 89 5C 24 ?? 48 89 74 24 ?? 57 48 83 EC 20 0F B6 B9 ?? ?? ?? ?? B8 ?? ?? ?? ??"); GetBaseUIObject = sig.ScanText("E8 ?? ?? ?? ?? 41 B8 01 00 00 00 48 8D 15 ?? ?? ?? ?? 48 8B 48 20 E8 ?? ?? ?? ?? 48 8B CF"); GetUIObjectByName = sig.ScanText("E8 ?? ?? ?? ?? 48 8B CF 48 89 87 ?? ?? 00 00 E8 ?? ?? ?? ?? 41 B8 01 00 00 00"); - GetUIModule = sig.ScanText("E8 ?? ?? ?? ?? 83 3B 01"); + GetUIModule = sig.ScanText("E8 ?? ?? ?? ?? 48 8B C8 48 85 C0 75 2D"); } } } diff --git a/Dalamud/Interface/Components/ComponentDemoWindow.cs b/Dalamud/Interface/Components/ComponentDemoWindow.cs index 3751ddffa..e0d465c80 100644 --- a/Dalamud/Interface/Components/ComponentDemoWindow.cs +++ b/Dalamud/Interface/Components/ComponentDemoWindow.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Numerics; +using Dalamud.Interface.Colors; using Dalamud.Interface.Windowing; using ImGuiNET; @@ -13,6 +14,7 @@ namespace Dalamud.Interface.Components internal class ComponentDemoWindow : Window { private readonly List> componentDemos; + private Vector4 defaultColor = ImGuiColors.DalamudOrange; /// /// Initializes a new instance of the class. @@ -27,6 +29,8 @@ namespace Dalamud.Interface.Components Demo("Test", ImGuiComponents.Test), Demo("HelpMarker", HelpMarkerDemo), Demo("IconButton", IconButtonDemo), + Demo("TextWithLabel", TextWithLabelDemo), + Demo("ColorPickerWithPalette", this.ColorPickerWithPaletteDemo), }; } @@ -72,9 +76,21 @@ namespace Dalamud.Interface.Components ImGui.EndPopup(); } + private static void TextWithLabelDemo() + { + ImGuiComponents.TextWithLabel("Label", "Hover to see more", "more"); + } + private static KeyValuePair Demo(string name, Action func) { return new KeyValuePair(name, func); } + + private void ColorPickerWithPaletteDemo() + { + ImGui.Text("Click on the color button to use the picker."); + ImGui.SameLine(); + this.defaultColor = ImGuiComponents.ColorPickerWithPalette(1, "ColorPickerWithPalette Demo", this.defaultColor); + } } } diff --git a/Dalamud/Interface/Components/ImGuiComponents.ColorPickerWithPalette.cs b/Dalamud/Interface/Components/ImGuiComponents.ColorPickerWithPalette.cs new file mode 100644 index 000000000..447d0cf03 --- /dev/null +++ b/Dalamud/Interface/Components/ImGuiComponents.ColorPickerWithPalette.cs @@ -0,0 +1,70 @@ +using System.Numerics; + +using ImGuiNET; + +namespace Dalamud.Interface.Components +{ + /// + /// Class containing various methods providing ImGui components. + /// + public static partial class ImGuiComponents + { + /// + /// ColorPicker with palette. + /// + /// Id for the color picker. + /// The description of the color picker. + /// The current color. + /// Selected color. + public static Vector4 ColorPickerWithPalette(int id, string description, Vector4 originalColor) + { + const ImGuiColorEditFlags flags = ImGuiColorEditFlags.NoSidePreview | ImGuiColorEditFlags.NoSmallPreview; + return ColorPickerWithPalette(id, description, originalColor, flags); + } + + /// + /// ColorPicker with palette with color picker options. + /// + /// Id for the color picker. + /// The description of the color picker. + /// The current color. + /// Flags to customize color picker. + /// Selected color. + public static Vector4 ColorPickerWithPalette(int id, string description, Vector4 originalColor, ImGuiColorEditFlags flags) + { + var existingColor = originalColor; + var selectedColor = originalColor; + var colorPalette = ImGuiHelpers.DefaultColorPalette(36); + if (ImGui.ColorButton($"{description}###ColorPickerButton{id}", originalColor)) + { + ImGui.OpenPopup($"###ColorPickerPopup{id}"); + } + + if (ImGui.BeginPopup($"###ColorPickerPopup{id}")) + { + if (ImGui.ColorPicker4($"###ColorPicker{id}", ref existingColor, flags)) + { + selectedColor = existingColor; + } + + for (var i = 0; i < 4; i++) + { + ImGui.Spacing(); + for (var j = i * 9; j < (i * 9) + 9; j++) + { + if (ImGui.ColorButton($"###ColorPickerSwatch{id}{i}{j}", colorPalette[j])) + { + selectedColor = colorPalette[j]; + } + + ImGui.SameLine(); + } + } + + ImGui.EndPopup(); + } + + return selectedColor; + } + } +} diff --git a/Dalamud/Interface/Components/ImGuiComponents.TextWithLabel.cs b/Dalamud/Interface/Components/ImGuiComponents.TextWithLabel.cs new file mode 100644 index 000000000..feb127d2a --- /dev/null +++ b/Dalamud/Interface/Components/ImGuiComponents.TextWithLabel.cs @@ -0,0 +1,32 @@ +using ImGuiNET; + +namespace Dalamud.Interface.Components +{ + /// + /// Class containing various methods providing ImGui components. + /// + public static partial class ImGuiComponents + { + /// + /// TextWithLabel component to show labeled text. + /// + /// The label for text. + /// The text value. + /// The hint to show on hover. + public static void TextWithLabel( + string label, string value, string hint = "") + { + ImGui.Text(label + ": "); + ImGui.SameLine(); + if (string.IsNullOrEmpty(hint)) + { + ImGui.Text(value); + } + else + { + ImGui.Text(value + "*"); + if (ImGui.IsItemHovered()) ImGui.SetTooltip(hint); + } + } + } +} diff --git a/Dalamud/Interface/ImGuiHelpers.cs b/Dalamud/Interface/ImGuiHelpers.cs index 03f5eabc8..022663074 100644 --- a/Dalamud/Interface/ImGuiHelpers.cs +++ b/Dalamud/Interface/ImGuiHelpers.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using System.Numerics; using ImGuiNET; @@ -57,6 +58,23 @@ namespace Dalamud.Interface string name, Vector2 position, ImGuiCond condition = ImGuiCond.None) => ImGui.SetWindowPos(position + MainViewport.Pos, condition); + /// + /// Creates default color palette for use with color pickers. + /// + /// The total number of swatches to use. + /// Default color palette. + public static List DefaultColorPalette(int swatchCount = 32) + { + var colorPalette = new List(); + for (var i = 0; i < swatchCount; i++) + { + ImGui.ColorConvertHSVtoRGB(i / 31.0f, 0.7f, 0.8f, out var r, out var g, out var b); + colorPalette.Add(new Vector4(r, g, b, 1.0f)); + } + + return colorPalette; + } + /// /// Get data needed for each new frame. ///