From 5fdf07aeada111e6ea30f5e2b657d1e39199d26f Mon Sep 17 00:00:00 2001 From: goat <16760685+goaaats@users.noreply.github.com> Date: Sat, 18 Sep 2021 18:23:10 +0200 Subject: [PATCH 1/5] style editor setup WIP --- Dalamud.CorePlugin/PluginImpl.cs | 2 + Dalamud.CorePlugin/StyleEditorWindow.cs | 192 +++++++++++ .../Internal/DalamudConfiguration.cs | 12 +- .../Interface/Internal/DalamudInterface.cs | 36 ++ .../Interface/Internal/InterfaceManager.cs | 37 +- .../Internal/Windows/ConsoleWindow.cs | 2 +- .../Windows/StyleEditor/StyleModel.cs | 320 ++++++++++++++++++ 7 files changed, 572 insertions(+), 29 deletions(-) create mode 100644 Dalamud.CorePlugin/StyleEditorWindow.cs create mode 100644 Dalamud/Interface/Internal/Windows/StyleEditor/StyleModel.cs diff --git a/Dalamud.CorePlugin/PluginImpl.cs b/Dalamud.CorePlugin/PluginImpl.cs index de7e66270..903f7c11a 100644 --- a/Dalamud.CorePlugin/PluginImpl.cs +++ b/Dalamud.CorePlugin/PluginImpl.cs @@ -3,6 +3,7 @@ using System.IO; using Dalamud.Configuration.Internal; using Dalamud.Game.Command; +using Dalamud.Interface.Internal.Windows; using Dalamud.Interface.Windowing; using Dalamud.Logging; using Dalamud.Plugin; @@ -62,6 +63,7 @@ namespace Dalamud.CorePlugin this.Interface = pluginInterface; this.windowSystem.AddWindow(new PluginWindow()); + this.windowSystem.AddWindow(new StyleEditorWindow()); this.Interface.UiBuilder.Draw += this.OnDraw; this.Interface.UiBuilder.OpenConfigUi += this.OnOpenConfigUi; diff --git a/Dalamud.CorePlugin/StyleEditorWindow.cs b/Dalamud.CorePlugin/StyleEditorWindow.cs new file mode 100644 index 000000000..f2541a713 --- /dev/null +++ b/Dalamud.CorePlugin/StyleEditorWindow.cs @@ -0,0 +1,192 @@ +using System; +using System.Linq; +using Dalamud.Configuration.Internal; +using Dalamud.Interface.Components; +using Dalamud.Interface.Internal.Windows.StyleEditor; +using Dalamud.Interface.Windowing; +using ImGuiNET; +using JetBrains.Annotations; + +namespace Dalamud.Interface.Internal.Windows +{ + public class StyleEditorWindow : Window + { + private ImGuiColorEditFlags alphaFlags = ImGuiColorEditFlags.None; + private StyleModel workStyle = StyleModel.DalamudStandard; + + public StyleEditorWindow() + : base("Dalamud Style Editor") + { + IsOpen = true; + } + + public override void Draw() + { + var config = Service.Get(); + var style = ImGui.GetStyle(); + + var a = 0; + ImGui.Text("Choose Style:"); + if (ImGui.Combo("###styleChooserCombo", ref a, new[] { "Dalamud Standard" }, 1)) + { + + } + + if (ImGui.Button("Add current style")) + { + + } + + ImGui.SameLine(); + + if (ImGuiComponents.IconButton(FontAwesomeIcon.Trash)) + { + + } + + if (ImGui.IsItemHovered()) + ImGui.SetTooltip("Delete current style"); + + ImGui.SameLine(); + + ImGuiHelpers.ScaledDummy(5); + ImGui.SameLine(); + + if (ImGuiComponents.IconButton(FontAwesomeIcon.FileExport)) + { + ImGui.SetClipboardText(StyleModel.Get().ToJsonEncoded()); + } + + if (ImGui.IsItemHovered()) + ImGui.SetTooltip("Copy style to clipboard for sharing"); + + ImGui.SameLine(); + + if (ImGuiComponents.IconButton(FontAwesomeIcon.FileImport)) + { + + } + + if (ImGui.IsItemHovered()) + ImGui.SetTooltip("Import style from clipboard"); + + ImGui.Separator(); + + ImGui.PushItemWidth(ImGui.GetWindowWidth() * 0.50f); + + if (ImGui.BeginTabBar("StyleEditorTabs")) + { + if (ImGui.BeginTabItem("Variables")) + { + ImGui.BeginChild($"ScrollingVars", ImGuiHelpers.ScaledVector2(0, -32), true, ImGuiWindowFlags.HorizontalScrollbar | ImGuiWindowFlags.NoBackground); + + ImGui.SetCursorPosY(ImGui.GetCursorPosY() - 5); + + ImGui.SliderFloat2("WindowPadding", ref style.WindowPadding, 0.0f, 20.0f, "%.0f"); + ImGui.SliderFloat2("FramePadding", ref style.FramePadding, 0.0f, 20.0f, "%.0f"); + ImGui.SliderFloat2("CellPadding", ref style.CellPadding, 0.0f, 20.0f, "%.0f"); + ImGui.SliderFloat2("ItemSpacing", ref style.ItemSpacing, 0.0f, 20.0f, "%.0f"); + ImGui.SliderFloat2("ItemInnerSpacing", ref style.ItemInnerSpacing, 0.0f, 20.0f, "%.0f"); + ImGui.SliderFloat2("TouchExtraPadding", ref style.TouchExtraPadding, 0.0f, 10.0f, "%.0f"); + ImGui.SliderFloat("IndentSpacing", ref style.IndentSpacing, 0.0f, 30.0f, "%.0f"); + ImGui.SliderFloat("ScrollbarSize", ref style.ScrollbarSize, 1.0f, 20.0f, "%.0f"); + ImGui.SliderFloat("GrabMinSize", ref style.GrabMinSize, 1.0f, 20.0f, "%.0f"); + ImGui.Text("Borders"); + ImGui.SliderFloat("WindowBorderSize", ref style.WindowBorderSize, 0.0f, 1.0f, "%.0f"); + ImGui.SliderFloat("ChildBorderSize", ref style.ChildBorderSize, 0.0f, 1.0f, "%.0f"); + ImGui.SliderFloat("PopupBorderSize", ref style.PopupBorderSize, 0.0f, 1.0f, "%.0f"); + ImGui.SliderFloat("FrameBorderSize", ref style.FrameBorderSize, 0.0f, 1.0f, "%.0f"); + ImGui.SliderFloat("TabBorderSize", ref style.TabBorderSize, 0.0f, 1.0f, "%.0f"); + ImGui.Text("Rounding"); + ImGui.SliderFloat("WindowRounding", ref style.WindowRounding, 0.0f, 12.0f, "%.0f"); + ImGui.SliderFloat("ChildRounding", ref style.ChildRounding, 0.0f, 12.0f, "%.0f"); + ImGui.SliderFloat("FrameRounding", ref style.FrameRounding, 0.0f, 12.0f, "%.0f"); + ImGui.SliderFloat("PopupRounding", ref style.PopupRounding, 0.0f, 12.0f, "%.0f"); + ImGui.SliderFloat("ScrollbarRounding", ref style.ScrollbarRounding, 0.0f, 12.0f, "%.0f"); + ImGui.SliderFloat("GrabRounding", ref style.GrabRounding, 0.0f, 12.0f, "%.0f"); + ImGui.SliderFloat("LogSliderDeadzone", ref style.LogSliderDeadzone, 0.0f, 12.0f, "%.0f"); + ImGui.SliderFloat("TabRounding", ref style.TabRounding, 0.0f, 12.0f, "%.0f"); + ImGui.Text("Alignment"); + ImGui.SliderFloat2("WindowTitleAlign", ref style.WindowTitleAlign, 0.0f, 1.0f, "%.2f"); + var window_menu_button_position = (int)style.WindowMenuButtonPosition + 1; + if (ImGui.Combo("WindowMenuButtonPosition", ref window_menu_button_position, "None\0Left\0Right\0")) + style.WindowMenuButtonPosition = (ImGuiDir)(window_menu_button_position - 1); + ImGui.SliderFloat2("ButtonTextAlign", ref style.ButtonTextAlign, 0.0f, 1.0f, "%.2f"); + ImGui.SameLine(); + ImGuiComponents.HelpMarker("Alignment applies when a button is larger than its text content."); + ImGui.SliderFloat2("SelectableTextAlign", ref style.SelectableTextAlign, 0.0f, 1.0f, "%.2f"); + ImGui.SameLine(); + ImGuiComponents.HelpMarker("Alignment applies when a selectable is larger than its text content."); + ImGui.SliderFloat2("DisplaySafeAreaPadding", ref style.DisplaySafeAreaPadding, 0.0f, 30.0f, "%.0f"); + ImGui.SameLine(); + ImGuiComponents.HelpMarker( + "Adjust if you cannot see the edges of your screen (e.g. on a TV where scaling has not been configured)."); + ImGui.EndTabItem(); + + ImGui.EndChild(); + + ImGui.EndTabItem(); + } + + if (ImGui.BeginTabItem("Colors")) + { + ImGui.BeginChild("ScrollingColors", ImGuiHelpers.ScaledVector2(0, -30), true, ImGuiWindowFlags.HorizontalScrollbar | ImGuiWindowFlags.NoBackground); + + ImGui.SetCursorPosY(ImGui.GetCursorPosY() - 5); + + if (ImGui.RadioButton("Opaque", this.alphaFlags == ImGuiColorEditFlags.None)) + this.alphaFlags = ImGuiColorEditFlags.None; + ImGui.SameLine(); + if (ImGui.RadioButton("Alpha", this.alphaFlags == ImGuiColorEditFlags.AlphaPreview)) + this.alphaFlags = ImGuiColorEditFlags.AlphaPreview; + ImGui.SameLine(); + if (ImGui.RadioButton("Both", this.alphaFlags == ImGuiColorEditFlags.AlphaPreviewHalf)) + this.alphaFlags = ImGuiColorEditFlags.AlphaPreviewHalf; + ImGui.SameLine(); + + ImGuiComponents.HelpMarker( + "In the color list:\n" + + "Left-click on color square to open color picker,\n" + + "Right-click to open edit options menu."); + + foreach (var imGuiCol in Enum.GetValues()) + { + if (imGuiCol == ImGuiCol.COUNT) + continue; + + ImGui.PushID(imGuiCol.ToString()); + + ImGui.ColorEdit4("##color", ref style.Colors[(int)imGuiCol], ImGuiColorEditFlags.AlphaBar | this.alphaFlags); + + ImGui.SameLine(0.0f, style.ItemInnerSpacing.X); + ImGui.TextUnformatted(imGuiCol.ToString()); + + ImGui.PopID(); + } + + ImGui.EndChild(); + + ImGui.EndTabItem(); + } + + ImGui.EndTabBar(); + } + + ImGui.PopItemWidth(); + + ImGui.Separator(); + + if (ImGui.Button("Close")) + { + + } + + ImGui.SameLine(); + + if (ImGui.Button("Save and Close")) + { + config.SavedStyles.Add(); + } + } + } +} diff --git a/Dalamud/Configuration/Internal/DalamudConfiguration.cs b/Dalamud/Configuration/Internal/DalamudConfiguration.cs index 4f3e4e59c..d06f8b305 100644 --- a/Dalamud/Configuration/Internal/DalamudConfiguration.cs +++ b/Dalamud/Configuration/Internal/DalamudConfiguration.cs @@ -1,8 +1,8 @@ using System; using System.Collections.Generic; using System.IO; - using Dalamud.Game.Text; +using Dalamud.Interface.Internal.Windows.StyleEditor; using Newtonsoft.Json; using Serilog; using Serilog.Events; @@ -195,6 +195,16 @@ namespace Dalamud.Configuration.Internal /// public bool PluginSafeMode { get; set; } + /// + /// Gets or sets a list of saved styles. + /// + public List? SavedStyles { get; set; } + + /// + /// Gets or sets the name of the currently chosen style. + /// + public string ChosenStyle { get; set; } = "Dalamud Standard"; + /// /// Load a configuration from the provided path. /// diff --git a/Dalamud/Interface/Internal/DalamudInterface.cs b/Dalamud/Interface/Internal/DalamudInterface.cs index c989b4393..35a13ea8b 100644 --- a/Dalamud/Interface/Internal/DalamudInterface.cs +++ b/Dalamud/Interface/Internal/DalamudInterface.cs @@ -1,7 +1,9 @@ using System; +using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Numerics; +using System.Reflection; using System.Runtime.InteropServices; using Dalamud.Configuration.Internal; @@ -11,12 +13,14 @@ using Dalamud.Game.Internal; using Dalamud.Interface.Internal.ManagedAsserts; using Dalamud.Interface.Internal.Windows; using Dalamud.Interface.Internal.Windows.SelfTest; +using Dalamud.Interface.Internal.Windows.StyleEditor; using Dalamud.Interface.Windowing; using Dalamud.Logging; using Dalamud.Logging.Internal; using Dalamud.Plugin.Internal; using Dalamud.Utility; using ImGuiNET; +using Newtonsoft.Json; using PInvoke; using Serilog.Events; @@ -496,6 +500,38 @@ namespace Dalamud.Interface.Internal ImGui.SetWindowFocus(null); } + if (ImGui.MenuItem("Dump style")) + { + var info = string.Empty; + var style = StyleModel.Get(); + + foreach (var propertyInfo in typeof(StyleModel).GetProperties(BindingFlags.Public | BindingFlags.Instance)) + { + if (propertyInfo.PropertyType == typeof(Vector2)) + { + var vec2 = (Vector2)propertyInfo.GetValue(style); + info += $"{propertyInfo.Name} = new Vector2({vec2.X}, {vec2.Y}),\n"; + } + else + { + info += $"{propertyInfo.Name} = {propertyInfo.GetValue(style)},\n"; + } + } + + info += "Colors = new Dictionary()\n"; + info += "{\n"; + + foreach (var color in style.Colors) + { + info += + $"{{\"{color.Key}\", new Vector4({color.Value.X}, {color.Value.Y}, {color.Value.Z}, {color.Value.W})}},\n"; + } + + info += "},"; + + Log.Information(info); + } + ImGui.EndMenu(); } diff --git a/Dalamud/Interface/Internal/InterfaceManager.cs b/Dalamud/Interface/Internal/InterfaceManager.cs index cefa34f5e..f203b69de 100644 --- a/Dalamud/Interface/Internal/InterfaceManager.cs +++ b/Dalamud/Interface/Internal/InterfaceManager.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; using System.IO; +using System.Linq; using System.Numerics; using System.Runtime.InteropServices; using System.Text; @@ -17,6 +18,7 @@ using Dalamud.Hooking; using Dalamud.Hooking.Internal; using Dalamud.Interface.Internal.ManagedAsserts; using Dalamud.Interface.Internal.Notifications; +using Dalamud.Interface.Internal.Windows.StyleEditor; using Dalamud.Interface.Windowing; using Dalamud.Utility; using ImGuiNET; @@ -336,34 +338,15 @@ namespace Dalamud.Interface.Internal this.SetupFonts(); - ImGui.GetStyle().GrabRounding = 3f; - ImGui.GetStyle().FrameRounding = 4f; - ImGui.GetStyle().WindowRounding = 4f; - ImGui.GetStyle().WindowBorderSize = 0f; - ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.Right; - ImGui.GetStyle().ScrollbarSize = 16f; + if (configuration.SavedStyles == null || configuration.SavedStyles.All(x => x.Name != StyleModel.DalamudStandard.Name)) + { + configuration.SavedStyles = new List(); + configuration.SavedStyles.Add(StyleModel.DalamudStandard); + configuration.ChosenStyle = StyleModel.DalamudStandard.Name; + } - ImGui.GetStyle().Colors[(int)ImGuiCol.WindowBg] = new Vector4(0.06f, 0.06f, 0.06f, 0.87f); - ImGui.GetStyle().Colors[(int)ImGuiCol.FrameBg] = new Vector4(0.29f, 0.29f, 0.29f, 0.54f); - ImGui.GetStyle().Colors[(int)ImGuiCol.FrameBgHovered] = new Vector4(0.54f, 0.54f, 0.54f, 0.40f); - ImGui.GetStyle().Colors[(int)ImGuiCol.FrameBgActive] = new Vector4(0.64f, 0.64f, 0.64f, 0.67f); - ImGui.GetStyle().Colors[(int)ImGuiCol.TitleBgActive] = new Vector4(0.29f, 0.29f, 0.29f, 1.00f); - ImGui.GetStyle().Colors[(int)ImGuiCol.CheckMark] = new Vector4(0.86f, 0.86f, 0.86f, 1.00f); - ImGui.GetStyle().Colors[(int)ImGuiCol.SliderGrab] = new Vector4(0.54f, 0.54f, 0.54f, 1.00f); - ImGui.GetStyle().Colors[(int)ImGuiCol.SliderGrabActive] = new Vector4(0.67f, 0.67f, 0.67f, 1.00f); - ImGui.GetStyle().Colors[(int)ImGuiCol.Button] = new Vector4(0.71f, 0.71f, 0.71f, 0.40f); - ImGui.GetStyle().Colors[(int)ImGuiCol.ButtonHovered] = new Vector4(0.47f, 0.47f, 0.47f, 1.00f); - ImGui.GetStyle().Colors[(int)ImGuiCol.ButtonActive] = new Vector4(0.74f, 0.74f, 0.74f, 1.00f); - ImGui.GetStyle().Colors[(int)ImGuiCol.Header] = new Vector4(0.59f, 0.59f, 0.59f, 0.31f); - ImGui.GetStyle().Colors[(int)ImGuiCol.HeaderHovered] = new Vector4(0.50f, 0.50f, 0.50f, 0.80f); - ImGui.GetStyle().Colors[(int)ImGuiCol.HeaderActive] = new Vector4(0.60f, 0.60f, 0.60f, 1.00f); - ImGui.GetStyle().Colors[(int)ImGuiCol.ResizeGrip] = new Vector4(0.79f, 0.79f, 0.79f, 0.25f); - ImGui.GetStyle().Colors[(int)ImGuiCol.ResizeGripHovered] = new Vector4(0.78f, 0.78f, 0.78f, 0.67f); - ImGui.GetStyle().Colors[(int)ImGuiCol.ResizeGripActive] = new Vector4(0.88f, 0.88f, 0.88f, 0.95f); - ImGui.GetStyle().Colors[(int)ImGuiCol.Tab] = new Vector4(0.23f, 0.23f, 0.23f, 0.86f); - ImGui.GetStyle().Colors[(int)ImGuiCol.TabHovered] = new Vector4(0.71f, 0.71f, 0.71f, 0.80f); - ImGui.GetStyle().Colors[(int)ImGuiCol.TabActive] = new Vector4(0.36f, 0.36f, 0.36f, 1.00f); - ImGui.GetStyle().Colors[(int)ImGuiCol.ScrollbarBg] = Vector4.Zero; + var style = configuration.SavedStyles.FirstOrDefault(x => x.Name == configuration.ChosenStyle) ?? StyleModel.DalamudStandard; + style.Apply(); ImGui.GetIO().FontGlobalScale = configuration.GlobalUiScale; diff --git a/Dalamud/Interface/Internal/Windows/ConsoleWindow.cs b/Dalamud/Interface/Internal/Windows/ConsoleWindow.cs index e5d82346f..50a5e7ce8 100644 --- a/Dalamud/Interface/Internal/Windows/ConsoleWindow.cs +++ b/Dalamud/Interface/Internal/Windows/ConsoleWindow.cs @@ -416,7 +416,7 @@ namespace Dalamud.Interface.Internal.Windows private void AddAndFilter(string line, LogEventLevel level, DateTimeOffset offset, bool isMultiline) { - if (line.StartsWith("TROUBLESHOOTING:") || line.StartsWith("EXCEPTION:")) + if (line.StartsWith("TROUBLESHOOTING:") || line.StartsWith("LASTEXCEPTION:")) return; var entry = new LogEntry diff --git a/Dalamud/Interface/Internal/Windows/StyleEditor/StyleModel.cs b/Dalamud/Interface/Internal/Windows/StyleEditor/StyleModel.cs new file mode 100644 index 000000000..48184c758 --- /dev/null +++ b/Dalamud/Interface/Internal/Windows/StyleEditor/StyleModel.cs @@ -0,0 +1,320 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.IO.Compression; +using System.Numerics; +using System.Text; + +using ImGuiNET; +using Newtonsoft.Json; + +namespace Dalamud.Interface.Internal.Windows.StyleEditor +{ + public class StyleModel + { + public static StyleModel DalamudStandard => new() + { + Name = "Dalamud Standard", + + Alpha = 1, + WindowPadding = new Vector2(8, 8), + WindowRounding = 4, + WindowBorderSize = 0, + WindowTitleAlign = new Vector2(0, 0.5f), + WindowMenuButtonPosition = ImGuiDir.Right, + ChildRounding = 0, + ChildBorderSize = 1, + PopupRounding = 0, + FramePadding = new Vector2(4, 3), + FrameRounding = 4, + FrameBorderSize = 0, + ItemSpacing = new Vector2(8, 4), + ItemInnerSpacing = new Vector2(4, 4), + CellPadding = new Vector2(4, 2), + TouchExtraPadding = new Vector2(0, 0), + IndentSpacing = 21, + ScrollbarSize = 16, + ScrollbarRounding = 9, + GrabMinSize = 10, + GrabRounding = 3, + LogSliderDeadzone = 4, + TabRounding = 4, + TabBorderSize = 0, + ButtonTextAlign = new Vector2(0.5f, 0.5f), + SelectableTextAlign = new Vector2(0, 0), + DisplaySafeAreaPadding = new Vector2(3, 3), + + Colors = new Dictionary + { + { "Text", new Vector4(1, 1, 1, 1) }, + { "TextDisabled", new Vector4(0.5f, 0.5f, 0.5f, 1) }, + { "WindowBg", new Vector4(0.06f, 0.06f, 0.06f, 0.87f) }, + { "ChildBg", new Vector4(0, 0, 0, 0) }, + { "PopupBg", new Vector4(0.08f, 0.08f, 0.08f, 0.94f) }, + { "Border", new Vector4(0.43f, 0.43f, 0.5f, 0.5f) }, + { "BorderShadow", new Vector4(0, 0, 0, 0) }, + { "FrameBg", new Vector4(0.29f, 0.29f, 0.29f, 0.54f) }, + { "FrameBgHovered", new Vector4(0.54f, 0.54f, 0.54f, 0.4f) }, + { "FrameBgActive", new Vector4(0.64f, 0.64f, 0.64f, 0.67f) }, + { "TitleBg", new Vector4(0.04f, 0.04f, 0.04f, 1) }, + { "TitleBgActive", new Vector4(0.29f, 0.29f, 0.29f, 1) }, + { "TitleBgCollapsed", new Vector4(0, 0, 0, 0.51f) }, + { "MenuBarBg", new Vector4(0.14f, 0.14f, 0.14f, 1) }, + { "ScrollbarBg", new Vector4(0, 0, 0, 0) }, + { "ScrollbarGrab", new Vector4(0.31f, 0.31f, 0.31f, 1) }, + { "ScrollbarGrabHovered", new Vector4(0.41f, 0.41f, 0.41f, 1) }, + { "ScrollbarGrabActive", new Vector4(0.51f, 0.51f, 0.51f, 1) }, + { "CheckMark", new Vector4(0.86f, 0.86f, 0.86f, 1) }, + { "SliderGrab", new Vector4(0.54f, 0.54f, 0.54f, 1) }, + { "SliderGrabActive", new Vector4(0.67f, 0.67f, 0.67f, 1) }, + { "Button", new Vector4(0.71f, 0.71f, 0.71f, 0.4f) }, + { "ButtonHovered", new Vector4(0.47f, 0.47f, 0.47f, 1) }, + { "ButtonActive", new Vector4(0.74f, 0.74f, 0.74f, 1) }, + { "Header", new Vector4(0.59f, 0.59f, 0.59f, 0.31f) }, + { "HeaderHovered", new Vector4(0.5f, 0.5f, 0.5f, 0.8f) }, + { "HeaderActive", new Vector4(0.6f, 0.6f, 0.6f, 1) }, + { "Separator", new Vector4(0.43f, 0.43f, 0.5f, 0.5f) }, + { "SeparatorHovered", new Vector4(0.1f, 0.4f, 0.75f, 0.78f) }, + { "SeparatorActive", new Vector4(0.1f, 0.4f, 0.75f, 1) }, + { "ResizeGrip", new Vector4(0.79f, 0.79f, 0.79f, 0.25f) }, + { "ResizeGripHovered", new Vector4(0.78f, 0.78f, 0.78f, 0.67f) }, + { "ResizeGripActive", new Vector4(0.88f, 0.88f, 0.88f, 0.95f) }, + { "Tab", new Vector4(0.23f, 0.23f, 0.23f, 0.86f) }, + { "TabHovered", new Vector4(0.71f, 0.71f, 0.71f, 0.8f) }, + { "TabActive", new Vector4(0.36f, 0.36f, 0.36f, 1) }, + { "TabUnfocused", new Vector4(0.068f, 0.10199998f, 0.14800003f, 0.9724f) }, + { "TabUnfocusedActive", new Vector4(0.13599998f, 0.26199996f, 0.424f, 1) }, + { "DockingPreview", new Vector4(0.26f, 0.59f, 0.98f, 0.7f) }, + { "DockingEmptyBg", new Vector4(0.2f, 0.2f, 0.2f, 1) }, + { "PlotLines", new Vector4(0.61f, 0.61f, 0.61f, 1) }, + { "PlotLinesHovered", new Vector4(1, 0.43f, 0.35f, 1) }, + { "PlotHistogram", new Vector4(0.9f, 0.7f, 0, 1) }, + { "PlotHistogramHovered", new Vector4(1, 0.6f, 0, 1) }, + { "TableHeaderBg", new Vector4(0.19f, 0.19f, 0.2f, 1) }, + { "TableBorderStrong", new Vector4(0.31f, 0.31f, 0.35f, 1) }, + { "TableBorderLight", new Vector4(0.23f, 0.23f, 0.25f, 1) }, + { "TableRowBg", new Vector4(0, 0, 0, 0) }, + { "TableRowBgAlt", new Vector4(1, 1, 1, 0.06f) }, + { "TextSelectedBg", new Vector4(0.26f, 0.59f, 0.98f, 0.35f) }, + { "DragDropTarget", new Vector4(1, 1, 0, 0.9f) }, + { "NavHighlight", new Vector4(0.26f, 0.59f, 0.98f, 1) }, + { "NavWindowingHighlight", new Vector4(1, 1, 1, 0.7f) }, + { "NavWindowingDimBg", new Vector4(0.8f, 0.8f, 0.8f, 0.2f) }, + { "ModalWindowDimBg", new Vector4(0.8f, 0.8f, 0.8f, 0.35f) }, + }, + }; + + [JsonProperty("name")] + public string Name { get; set; } + + [JsonProperty("a")] + public float Alpha { get; set; } + + [JsonProperty("b")] + public Vector2 WindowPadding { get; set; } + + [JsonProperty("c")] + public float WindowRounding { get; set; } + + [JsonProperty("d")] + public float WindowBorderSize { get; set; } + + [JsonProperty("e")] + public Vector2 WindowTitleAlign { get; set; } + + [JsonProperty("f")] + public ImGuiDir WindowMenuButtonPosition { get; set; } + + [JsonProperty("g")] + public float ChildRounding { get; set; } + + [JsonProperty("h")] + public float ChildBorderSize { get; set; } + + [JsonProperty("i")] + public float PopupRounding { get; set; } + + [JsonProperty("j")] + public Vector2 FramePadding { get; set; } + + [JsonProperty("k")] + public float FrameRounding { get; set; } + + [JsonProperty("l")] + public float FrameBorderSize { get; set; } + + [JsonProperty("m")] + public Vector2 ItemSpacing { get; set; } + + [JsonProperty("n")] + public Vector2 ItemInnerSpacing { get; set; } + + [JsonProperty("o")] + public Vector2 CellPadding { get; set; } + + [JsonProperty("p")] + public Vector2 TouchExtraPadding { get; set; } + + [JsonProperty("q")] + public float IndentSpacing { get; set; } + + [JsonProperty("r")] + public float ScrollbarSize { get; set; } + + [JsonProperty("s")] + public float ScrollbarRounding { get; set; } + + [JsonProperty("t")] + public float GrabMinSize { get; set; } + + [JsonProperty("u")] + public float GrabRounding { get; set; } + + [JsonProperty("v")] + public float LogSliderDeadzone { get; set; } + + [JsonProperty("w")] + public float TabRounding { get; set; } + + [JsonProperty("x")] + public float TabBorderSize { get; set; } + + [JsonProperty("y")] + public Vector2 ButtonTextAlign { get; set; } + + [JsonProperty("z")] + public Vector2 SelectableTextAlign { get; set; } + + [JsonProperty("aa")] + public Vector2 DisplaySafeAreaPadding { get; set; } + + [JsonProperty("col")] + public Dictionary Colors { get; set; } + + public static void CopyTo(Stream src, Stream dest) { + byte[] bytes = new byte[4096]; + + int cnt; + + while ((cnt = src.Read(bytes, 0, bytes.Length)) != 0) { + dest.Write(bytes, 0, cnt); + } + } + + public static byte[] Zip(string str) { + var bytes = Encoding.UTF8.GetBytes(str); + + using (var msi = new MemoryStream(bytes)) + using (var mso = new MemoryStream()) { + using (var gs = new GZipStream(mso, CompressionMode.Compress)) { + //msi.CopyTo(gs); + CopyTo(msi, gs); + } + + return mso.ToArray(); + } + } + + public static string Unzip(byte[] bytes) { + using (var msi = new MemoryStream(bytes)) + using (var mso = new MemoryStream()) { + using (var gs = new GZipStream(msi, CompressionMode.Decompress)) { + //gs.CopyTo(mso); + CopyTo(gs, mso); + } + + return Encoding.UTF8.GetString(mso.ToArray()); + } + } + + + public string ToJsonEncoded() => "DS1" + System.Convert.ToBase64String(Zip(JsonConvert.SerializeObject(this))); + + public void Apply() + { + var style = ImGui.GetStyle(); + + style.Alpha = this.Alpha; + style.WindowPadding = this.WindowPadding; + style.WindowRounding = this.WindowRounding; + style.WindowBorderSize = this.WindowBorderSize; + style.WindowTitleAlign = this.WindowTitleAlign; + style.WindowMenuButtonPosition = this.WindowMenuButtonPosition; + style.ChildRounding = this.ChildRounding; + style.ChildBorderSize = this.ChildBorderSize; + style.PopupRounding = this.PopupRounding; + style.FramePadding = this.FramePadding; + style.FrameRounding = this.FrameRounding; + style.FrameBorderSize = this.FrameBorderSize; + style.ItemSpacing = this.ItemSpacing; + style.ItemInnerSpacing = this.ItemInnerSpacing; + style.CellPadding = this.CellPadding; + style.TouchExtraPadding = this.TouchExtraPadding; + style.IndentSpacing = this.IndentSpacing; + style.ScrollbarSize = this.ScrollbarSize; + style.ScrollbarRounding = this.ScrollbarRounding; + style.GrabMinSize = this.GrabMinSize; + style.GrabRounding = this.GrabRounding; + style.LogSliderDeadzone = this.LogSliderDeadzone; + style.TabRounding = this.TabRounding; + style.TabBorderSize = this.TabBorderSize; + style.ButtonTextAlign = this.ButtonTextAlign; + style.SelectableTextAlign = this.SelectableTextAlign; + style.DisplaySafeAreaPadding = this.DisplaySafeAreaPadding; + } + + public static StyleModel Get() + { + var model = new StyleModel(); + var style = ImGui.GetStyle(); + + model.Alpha = style.Alpha; + model.WindowPadding = style.WindowPadding; + model.WindowRounding = style.WindowRounding; + model.WindowBorderSize = style.WindowBorderSize; + model.WindowTitleAlign = style.WindowTitleAlign; + model.WindowMenuButtonPosition = style.WindowMenuButtonPosition; + model.ChildRounding = style.ChildRounding; + model.ChildBorderSize = style.ChildBorderSize; + model.PopupRounding = style.PopupRounding; + model.FramePadding = style.FramePadding; + model.FrameRounding = style.FrameRounding; + model.FrameBorderSize = style.FrameBorderSize; + model.ItemSpacing = style.ItemSpacing; + model.ItemInnerSpacing = style.ItemInnerSpacing; + model.CellPadding = style.CellPadding; + model.TouchExtraPadding = style.TouchExtraPadding; + model.IndentSpacing = style.IndentSpacing; + model.ScrollbarSize = style.ScrollbarSize; + model.ScrollbarRounding = style.ScrollbarRounding; + model.GrabMinSize = style.GrabMinSize; + model.GrabRounding = style.GrabRounding; + model.LogSliderDeadzone = style.LogSliderDeadzone; + model.TabRounding = style.TabRounding; + model.TabBorderSize = style.TabBorderSize; + model.ButtonTextAlign = style.ButtonTextAlign; + model.SelectableTextAlign = style.SelectableTextAlign; + model.DisplaySafeAreaPadding = style.DisplaySafeAreaPadding; + + model.Colors = new Dictionary(); + + foreach (var imGuiCol in Enum.GetValues()) + { + if (imGuiCol == ImGuiCol.COUNT) + { + continue; + } + + model.Colors[imGuiCol.ToString()] = style.Colors[(int)imGuiCol]; + } + + return model; + } + + public static StyleModel FromJsonEncoded(string data) + { + var json = Unzip(Convert.FromBase64String(data.Substring(2))); + return JsonConvert.DeserializeObject(json); + } + } +} From 0f150bc54ba19e98581d045516862abbe06378e1 Mon Sep 17 00:00:00 2001 From: goat <16760685+goaaats@users.noreply.github.com> Date: Mon, 27 Sep 2021 17:00:24 +0200 Subject: [PATCH 2/5] feat: add style editor --- Dalamud.CorePlugin/PluginImpl.cs | 2 - .../Internal/DalamudConfiguration.cs | 1 + .../Interface/Internal/DalamudInterface.cs | 20 ++- .../Windows/StyleEditor}/StyleEditorWindow.cs | 134 ++++++++++++-- .../Windows/StyleEditor/StyleModel.cs | 163 +++++++++--------- Dalamud/Utility/Util.cs | 56 ++++++ 6 files changed, 280 insertions(+), 96 deletions(-) rename {Dalamud.CorePlugin => Dalamud/Interface/Internal/Windows/StyleEditor}/StyleEditorWindow.cs (71%) diff --git a/Dalamud.CorePlugin/PluginImpl.cs b/Dalamud.CorePlugin/PluginImpl.cs index 903f7c11a..de7e66270 100644 --- a/Dalamud.CorePlugin/PluginImpl.cs +++ b/Dalamud.CorePlugin/PluginImpl.cs @@ -3,7 +3,6 @@ using System.IO; using Dalamud.Configuration.Internal; using Dalamud.Game.Command; -using Dalamud.Interface.Internal.Windows; using Dalamud.Interface.Windowing; using Dalamud.Logging; using Dalamud.Plugin; @@ -63,7 +62,6 @@ namespace Dalamud.CorePlugin this.Interface = pluginInterface; this.windowSystem.AddWindow(new PluginWindow()); - this.windowSystem.AddWindow(new StyleEditorWindow()); this.Interface.UiBuilder.Draw += this.OnDraw; this.Interface.UiBuilder.OpenConfigUi += this.OnOpenConfigUi; diff --git a/Dalamud/Configuration/Internal/DalamudConfiguration.cs b/Dalamud/Configuration/Internal/DalamudConfiguration.cs index 2a0e0ce66..390d9c9e5 100644 --- a/Dalamud/Configuration/Internal/DalamudConfiguration.cs +++ b/Dalamud/Configuration/Internal/DalamudConfiguration.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; + using Dalamud.Game.Text; using Dalamud.Interface.Internal.Windows.StyleEditor; using Newtonsoft.Json; diff --git a/Dalamud/Interface/Internal/DalamudInterface.cs b/Dalamud/Interface/Internal/DalamudInterface.cs index 35a13ea8b..cfccedd39 100644 --- a/Dalamud/Interface/Internal/DalamudInterface.cs +++ b/Dalamud/Interface/Internal/DalamudInterface.cs @@ -46,6 +46,7 @@ namespace Dalamud.Interface.Internal private readonly ScratchpadWindow scratchpadWindow; private readonly SettingsWindow settingsWindow; private readonly SelfTestWindow selfTestWindow; + private readonly StyleEditorWindow styleEditorWindow; private ulong frameCount = 0; @@ -79,6 +80,7 @@ namespace Dalamud.Interface.Internal this.scratchpadWindow = new ScratchpadWindow() { IsOpen = false }; this.settingsWindow = new SettingsWindow() { IsOpen = false }; this.selfTestWindow = new SelfTestWindow() { IsOpen = false }; + this.styleEditorWindow = new StyleEditorWindow() { IsOpen = false }; this.WindowSystem.AddWindow(this.changelogWindow); this.WindowSystem.AddWindow(this.colorDemoWindow); @@ -93,12 +95,11 @@ namespace Dalamud.Interface.Internal this.WindowSystem.AddWindow(this.scratchpadWindow); this.WindowSystem.AddWindow(this.settingsWindow); this.WindowSystem.AddWindow(this.selfTestWindow); + this.WindowSystem.AddWindow(this.styleEditorWindow); ImGuiManagedAsserts.AssertsEnabled = true; Service.Get().Draw += this.OnDraw; - - Log.Information("Windows added"); } /// @@ -212,6 +213,11 @@ namespace Dalamud.Interface.Internal /// public void OpenSelfTest() => this.selfTestWindow.IsOpen = true; + /// + /// Opens the . + /// + public void OpenStyleEditor() => this.styleEditorWindow.IsOpen = true; + #endregion #region Close @@ -303,6 +309,11 @@ namespace Dalamud.Interface.Internal /// public void ToggleSelfTestWindow() => this.selfTestWindow.Toggle(); + /// + /// Toggles the . + /// + public void ToggleStyleEditorWindow() => this.selfTestWindow.Toggle(); + #endregion private void OnDraw() @@ -452,6 +463,11 @@ namespace Dalamud.Interface.Internal this.OpenSelfTest(); } + if (ImGui.MenuItem("Open Style Editor")) + { + this.OpenStyleEditor(); + } + ImGui.Separator(); if (ImGui.MenuItem("Unload Dalamud")) diff --git a/Dalamud.CorePlugin/StyleEditorWindow.cs b/Dalamud/Interface/Internal/Windows/StyleEditor/StyleEditorWindow.cs similarity index 71% rename from Dalamud.CorePlugin/StyleEditorWindow.cs rename to Dalamud/Interface/Internal/Windows/StyleEditor/StyleEditorWindow.cs index dba102d6f..32aa9ade8 100644 --- a/Dalamud.CorePlugin/StyleEditorWindow.cs +++ b/Dalamud/Interface/Internal/Windows/StyleEditor/StyleEditorWindow.cs @@ -1,58 +1,104 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Numerics; + +using CheapLoc; using Dalamud.Configuration.Internal; +using Dalamud.Data; using Dalamud.Interface.Colors; using Dalamud.Interface.Components; -using Dalamud.Interface.Internal.Windows.StyleEditor; using Dalamud.Interface.Windowing; using ImGuiNET; -using JetBrains.Annotations; +using Lumina.Excel.GeneratedSheets; using Serilog; -namespace Dalamud.Interface.Internal.Windows +namespace Dalamud.Interface.Internal.Windows.StyleEditor { + /// + /// Window for the Dalamud style editor. + /// public class StyleEditorWindow : Window { private ImGuiColorEditFlags alphaFlags = ImGuiColorEditFlags.None; private StyleModel workStyle = StyleModel.DalamudStandard; private int currentSel = 0; - private string initialStyle; + private string initialStyle = string.Empty; + private bool didSave = false; + private string renameText = string.Empty; + private bool renameModalDrawing = false; + + /// + /// Initializes a new instance of the class. + /// public StyleEditorWindow() : base("Dalamud Style Editor") { this.IsOpen = true; + this.SizeConstraints = new WindowSizeConstraints + { + MinimumSize = new Vector2(890, 560), + MaximumSize = new Vector2(10000, 10000), + }; + } + + /// + public override void OnOpen() + { + this.didSave = false; var config = Service.Get(); config.SavedStyles ??= new List(); this.currentSel = config.SavedStyles.FindIndex(x => x.Name == config.ChosenStyle); this.initialStyle = config.ChosenStyle; + + base.OnOpen(); } + /// + public override void OnClose() + { + if (!this.didSave) + { + var config = Service.Get(); + var newStyle = config.SavedStyles.FirstOrDefault(x => x.Name == this.initialStyle); + newStyle?.Apply(); + } + + base.OnClose(); + } + + /// public override void Draw() { var config = Service.Get(); + var renameModalTitle = Loc.Localize("RenameStyleModalTitle", "Rename Style"); - var style = ImGui.GetStyle(); + var appliedThisFrame = false; + var styleAry = config.SavedStyles.Select(x => x.Name).ToArray(); ImGui.Text("Choose Style:"); - if (ImGui.Combo("###styleChooserCombo", ref this.currentSel, config.SavedStyles.Select(x => x.Name).ToArray(), 1)) + if (ImGui.Combo("###styleChooserCombo", ref this.currentSel, styleAry, styleAry.Length)) { var newStyle = config.SavedStyles[this.currentSel]; newStyle.Apply(); + appliedThisFrame = true; } if (ImGui.Button("Add new style")) { var newStyle = StyleModel.DalamudStandard; - newStyle.Name = "New Style"; + newStyle.Name = GetRandomName(); config.SavedStyles.Add(newStyle); this.currentSel = config.SavedStyles.Count - 1; + newStyle.Apply(); + appliedThisFrame = true; + config.Save(); } @@ -63,6 +109,7 @@ namespace Dalamud.Interface.Internal.Windows this.currentSel--; var newStyle = config.SavedStyles[this.currentSel]; newStyle.Apply(); + appliedThisFrame = true; config.SavedStyles.RemoveAt(this.currentSel + 1); @@ -74,12 +121,27 @@ namespace Dalamud.Interface.Internal.Windows ImGui.SameLine(); + if (ImGuiComponents.IconButton(FontAwesomeIcon.Pen) && this.currentSel != 0) + { + var newStyle = config.SavedStyles[this.currentSel]; + this.renameText = newStyle.Name; + + this.renameModalDrawing = true; + ImGui.OpenPopup(renameModalTitle); + } + + if (ImGui.IsItemHovered()) + ImGui.SetTooltip("Rename style"); + + ImGui.SameLine(); + ImGuiHelpers.ScaledDummy(5); ImGui.SameLine(); if (ImGuiComponents.IconButton(FontAwesomeIcon.FileExport)) { - ImGui.SetClipboardText(StyleModel.Get().ToJsonEncoded()); + var newStyle = config.SavedStyles[this.currentSel]; + ImGui.SetClipboardText(newStyle.ToEncoded()); } if (ImGui.IsItemHovered()) @@ -93,10 +155,15 @@ namespace Dalamud.Interface.Internal.Windows try { - var newStyle = StyleModel.FromJsonEncoded(styleJson); + var newStyle = StyleModel.FromEncoded(styleJson); + + newStyle.Name ??= GetRandomName(); config.SavedStyles.Add(newStyle); newStyle.Apply(); + appliedThisFrame = true; + + Log.Information("Applying: " + newStyle.Name); this.currentSel = config.SavedStyles.Count - 1; @@ -119,8 +186,14 @@ namespace Dalamud.Interface.Internal.Windows { ImGui.TextColored(ImGuiColors.DalamudRed, "You cannot edit the \"Dalamud Standard\" style. Please add a new style first."); } + else if (appliedThisFrame) + { + ImGui.Text("Applying style..."); + } else if (ImGui.BeginTabBar("StyleEditorTabs")) { + var style = ImGui.GetStyle(); + if (ImGui.BeginTabItem("Variables")) { ImGui.BeginChild($"ScrollingVars", ImGuiHelpers.ScaledVector2(0, -32), true, ImGuiWindowFlags.HorizontalScrollbar | ImGuiWindowFlags.NoBackground); @@ -153,9 +226,9 @@ namespace Dalamud.Interface.Internal.Windows ImGui.SliderFloat("TabRounding", ref style.TabRounding, 0.0f, 12.0f, "%.0f"); ImGui.Text("Alignment"); ImGui.SliderFloat2("WindowTitleAlign", ref style.WindowTitleAlign, 0.0f, 1.0f, "%.2f"); - var window_menu_button_position = (int)style.WindowMenuButtonPosition + 1; - if (ImGui.Combo("WindowMenuButtonPosition", ref window_menu_button_position, "None\0Left\0Right\0")) - style.WindowMenuButtonPosition = (ImGuiDir)(window_menu_button_position - 1); + var windowMenuButtonPosition = (int)style.WindowMenuButtonPosition + 1; + if (ImGui.Combo("WindowMenuButtonPosition", ref windowMenuButtonPosition, "None\0Left\0Right\0")) + style.WindowMenuButtonPosition = (ImGuiDir)(windowMenuButtonPosition - 1); ImGui.SliderFloat2("ButtonTextAlign", ref style.ButtonTextAlign, 0.0f, 1.0f, "%.2f"); ImGui.SameLine(); ImGuiComponents.HelpMarker("Alignment applies when a button is larger than its text content."); @@ -223,9 +296,6 @@ namespace Dalamud.Interface.Internal.Windows if (ImGui.Button("Close")) { - var newStyle = config.SavedStyles.FirstOrDefault(x => x.Name == this.initialStyle); - newStyle?.Apply(); - this.IsOpen = false; } @@ -238,9 +308,43 @@ namespace Dalamud.Interface.Internal.Windows var newStyle = StyleModel.Get(); newStyle.Name = config.ChosenStyle; config.SavedStyles[this.currentSel] = newStyle; + newStyle.Apply(); config.Save(); + this.didSave = true; + + this.IsOpen = false; } + + if (ImGui.BeginPopupModal(renameModalTitle, ref this.renameModalDrawing, ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoScrollbar)) + { + ImGui.Text("Please enter the new name for this style."); + ImGui.Spacing(); + + ImGui.InputText("###renameModalInput", ref this.renameText, 255); + + const float buttonWidth = 120f; + ImGui.SetCursorPosX((ImGui.GetWindowWidth() - buttonWidth) / 2); + + if (ImGui.Button("OK", new Vector2(buttonWidth, 40))) + { + config.SavedStyles[this.currentSel].Name = this.renameText; + config.Save(); + + ImGui.CloseCurrentPopup(); + } + + ImGui.EndPopup(); + } + } + + private static string GetRandomName() + { + var data = Service.Get(); + var names = data.GetExcelSheet(ClientLanguage.English); + var rng = new Random(); + + return names.ElementAt(rng.Next(0, names.Count() - 1)).Singular.RawString; } } } diff --git a/Dalamud/Interface/Internal/Windows/StyleEditor/StyleModel.cs b/Dalamud/Interface/Internal/Windows/StyleEditor/StyleModel.cs index 48184c758..c8d43e775 100644 --- a/Dalamud/Interface/Internal/Windows/StyleEditor/StyleModel.cs +++ b/Dalamud/Interface/Internal/Windows/StyleEditor/StyleModel.cs @@ -1,17 +1,30 @@ using System; using System.Collections.Generic; -using System.IO; -using System.IO.Compression; using System.Numerics; -using System.Text; +using Dalamud.Utility; using ImGuiNET; using Newtonsoft.Json; namespace Dalamud.Interface.Internal.Windows.StyleEditor { + /// + /// Class representing a serializable ImGui style. + /// public class StyleModel { + /// + /// Initializes a new instance of the class. + /// + private StyleModel() + { + this.Colors = new Dictionary(); + this.Name = "Unknown"; + } + + /// + /// Gets the standard Dalamud look. + /// public static StyleModel DalamudStandard => new() { Name = "Dalamud Standard", @@ -104,6 +117,8 @@ namespace Dalamud.Interface.Internal.Windows.StyleEditor }, }; +#pragma warning disable SA1600 + [JsonProperty("name")] public string Name { get; set; } @@ -188,81 +203,18 @@ namespace Dalamud.Interface.Internal.Windows.StyleEditor [JsonProperty("aa")] public Vector2 DisplaySafeAreaPadding { get; set; } +#pragma warning restore SA1600 + + /// + /// Gets or sets a dictionary mapping ImGui color names to colors. + /// [JsonProperty("col")] public Dictionary Colors { get; set; } - public static void CopyTo(Stream src, Stream dest) { - byte[] bytes = new byte[4096]; - - int cnt; - - while ((cnt = src.Read(bytes, 0, bytes.Length)) != 0) { - dest.Write(bytes, 0, cnt); - } - } - - public static byte[] Zip(string str) { - var bytes = Encoding.UTF8.GetBytes(str); - - using (var msi = new MemoryStream(bytes)) - using (var mso = new MemoryStream()) { - using (var gs = new GZipStream(mso, CompressionMode.Compress)) { - //msi.CopyTo(gs); - CopyTo(msi, gs); - } - - return mso.ToArray(); - } - } - - public static string Unzip(byte[] bytes) { - using (var msi = new MemoryStream(bytes)) - using (var mso = new MemoryStream()) { - using (var gs = new GZipStream(msi, CompressionMode.Decompress)) { - //gs.CopyTo(mso); - CopyTo(gs, mso); - } - - return Encoding.UTF8.GetString(mso.ToArray()); - } - } - - - public string ToJsonEncoded() => "DS1" + System.Convert.ToBase64String(Zip(JsonConvert.SerializeObject(this))); - - public void Apply() - { - var style = ImGui.GetStyle(); - - style.Alpha = this.Alpha; - style.WindowPadding = this.WindowPadding; - style.WindowRounding = this.WindowRounding; - style.WindowBorderSize = this.WindowBorderSize; - style.WindowTitleAlign = this.WindowTitleAlign; - style.WindowMenuButtonPosition = this.WindowMenuButtonPosition; - style.ChildRounding = this.ChildRounding; - style.ChildBorderSize = this.ChildBorderSize; - style.PopupRounding = this.PopupRounding; - style.FramePadding = this.FramePadding; - style.FrameRounding = this.FrameRounding; - style.FrameBorderSize = this.FrameBorderSize; - style.ItemSpacing = this.ItemSpacing; - style.ItemInnerSpacing = this.ItemInnerSpacing; - style.CellPadding = this.CellPadding; - style.TouchExtraPadding = this.TouchExtraPadding; - style.IndentSpacing = this.IndentSpacing; - style.ScrollbarSize = this.ScrollbarSize; - style.ScrollbarRounding = this.ScrollbarRounding; - style.GrabMinSize = this.GrabMinSize; - style.GrabRounding = this.GrabRounding; - style.LogSliderDeadzone = this.LogSliderDeadzone; - style.TabRounding = this.TabRounding; - style.TabBorderSize = this.TabBorderSize; - style.ButtonTextAlign = this.ButtonTextAlign; - style.SelectableTextAlign = this.SelectableTextAlign; - style.DisplaySafeAreaPadding = this.DisplaySafeAreaPadding; - } - + /// + /// Get a instance via ImGui. + /// + /// The newly created instance. public static StyleModel Get() { var model = new StyleModel(); @@ -311,10 +263,67 @@ namespace Dalamud.Interface.Internal.Windows.StyleEditor return model; } - public static StyleModel FromJsonEncoded(string data) + /// + /// Get a instance from a compressed base64 string. + /// + /// The string to decode. + /// A decompressed . + public static StyleModel? FromEncoded(string data) { - var json = Unzip(Convert.FromBase64String(data.Substring(2))); + var json = Util.DecompressString(Convert.FromBase64String(data.Substring(3))); return JsonConvert.DeserializeObject(json); } + + /// + /// Get this instance as a encoded base64 string. + /// + /// The encoded base64 string. + public string ToEncoded() => "DS1" + Convert.ToBase64String(Util.CompressString(JsonConvert.SerializeObject(this))); + + /// + /// Apply this StyleModel via ImGui. + /// + public void Apply() + { + var style = ImGui.GetStyle(); + + style.Alpha = this.Alpha; + style.WindowPadding = this.WindowPadding; + style.WindowRounding = this.WindowRounding; + style.WindowBorderSize = this.WindowBorderSize; + style.WindowTitleAlign = this.WindowTitleAlign; + style.WindowMenuButtonPosition = this.WindowMenuButtonPosition; + style.ChildRounding = this.ChildRounding; + style.ChildBorderSize = this.ChildBorderSize; + style.PopupRounding = this.PopupRounding; + style.FramePadding = this.FramePadding; + style.FrameRounding = this.FrameRounding; + style.FrameBorderSize = this.FrameBorderSize; + style.ItemSpacing = this.ItemSpacing; + style.ItemInnerSpacing = this.ItemInnerSpacing; + style.CellPadding = this.CellPadding; + style.TouchExtraPadding = this.TouchExtraPadding; + style.IndentSpacing = this.IndentSpacing; + style.ScrollbarSize = this.ScrollbarSize; + style.ScrollbarRounding = this.ScrollbarRounding; + style.GrabMinSize = this.GrabMinSize; + style.GrabRounding = this.GrabRounding; + style.LogSliderDeadzone = this.LogSliderDeadzone; + style.TabRounding = this.TabRounding; + style.TabBorderSize = this.TabBorderSize; + style.ButtonTextAlign = this.ButtonTextAlign; + style.SelectableTextAlign = this.SelectableTextAlign; + style.DisplaySafeAreaPadding = this.DisplaySafeAreaPadding; + + foreach (var imGuiCol in Enum.GetValues()) + { + if (imGuiCol == ImGuiCol.COUNT) + { + continue; + } + + style.Colors[(int)imGuiCol] = this.Colors[imGuiCol.ToString()]; + } + } } } diff --git a/Dalamud/Utility/Util.cs b/Dalamud/Utility/Util.cs index db0056ec0..cded71473 100644 --- a/Dalamud/Utility/Util.cs +++ b/Dalamud/Utility/Util.cs @@ -1,5 +1,7 @@ using System; using System.Diagnostics; +using System.IO; +using System.IO.Compression; using System.Linq; using System.Reflection; using System.Text; @@ -205,6 +207,60 @@ namespace Dalamud.Utility return text; } + /// + /// Compress a string using GZip. + /// + /// The input string. + /// The compressed output bytes. + public static byte[] CompressString(string str) + { + var bytes = Encoding.UTF8.GetBytes(str); + + using (var msi = new MemoryStream(bytes)) + using (var mso = new MemoryStream()) + { + using (var gs = new GZipStream(mso, CompressionMode.Compress)) + { + CopyTo(msi, gs); + } + + return mso.ToArray(); + } + } + + /// + /// Decompress a string using GZip. + /// + /// The input bytes. + /// The compressed output string. + public static string DecompressString(byte[] bytes) + { + using (var msi = new MemoryStream(bytes)) + using (var mso = new MemoryStream()) + { + using (var gs = new GZipStream(msi, CompressionMode.Decompress)) + { + CopyTo(gs, mso); + } + + return Encoding.UTF8.GetString(mso.ToArray()); + } + } + + /// + /// Copy one stream to another. + /// + /// The source stream. + /// The destination stream. + /// The maximum length to copy. + public static void CopyTo(Stream src, Stream dest, int len = 4069) + { + var bytes = new byte[len]; + int cnt; + + while ((cnt = src.Read(bytes, 0, bytes.Length)) != 0) dest.Write(bytes, 0, cnt); + } + // TODO: Someone implement GetUTF8String with some IntPtr overloads. // while(Marshal.ReadByte(0, sz) != 0) { sz++; } } From a42a8a46c4e2038f219984be5553429a9705b6b7 Mon Sep 17 00:00:00 2001 From: goat <16760685+goaaats@users.noreply.github.com> Date: Mon, 27 Sep 2021 17:00:48 +0200 Subject: [PATCH 3/5] feat: add style editor to settings window --- Dalamud/Interface/Internal/Windows/SettingsWindow.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Dalamud/Interface/Internal/Windows/SettingsWindow.cs b/Dalamud/Interface/Internal/Windows/SettingsWindow.cs index b40971eb3..274d349a0 100644 --- a/Dalamud/Interface/Internal/Windows/SettingsWindow.cs +++ b/Dalamud/Interface/Internal/Windows/SettingsWindow.cs @@ -264,6 +264,15 @@ namespace Dalamud.Interface.Internal.Windows ImGuiHelpers.ScaledDummy(10, 16); + if (ImGui.Button(Loc.Localize("DalamudSettingsOpenStyleEditor", "Open Style Editor"))) + { + Service.Get().OpenStyleEditor(); + } + + ImGui.TextColored(this.hintTextColor, Loc.Localize("DalamudSettingsStyleEditorHint", "Modify the look & feel of Dalamud windows.")); + + ImGuiHelpers.ScaledDummy(10, 16); + ImGui.TextColored(this.hintTextColor, Loc.Localize("DalamudSettingToggleUiHideOptOutNote", "Plugins may independently opt out of the settings below.")); ImGui.Checkbox(Loc.Localize("DalamudSettingToggleUiHide", "Hide plugin UI when the game UI is toggled off"), ref this.doToggleUiHide); From e176cc7981904df1821031faa2f281a542122103 Mon Sep 17 00:00:00 2001 From: goat <16760685+goaaats@users.noreply.github.com> Date: Mon, 27 Sep 2021 17:05:22 +0200 Subject: [PATCH 4/5] loc: style editor --- .../Windows/StyleEditor/StyleEditorWindow.cs | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/Dalamud/Interface/Internal/Windows/StyleEditor/StyleEditorWindow.cs b/Dalamud/Interface/Internal/Windows/StyleEditor/StyleEditorWindow.cs index 32aa9ade8..aa62543aa 100644 --- a/Dalamud/Interface/Internal/Windows/StyleEditor/StyleEditorWindow.cs +++ b/Dalamud/Interface/Internal/Windows/StyleEditor/StyleEditorWindow.cs @@ -80,7 +80,7 @@ namespace Dalamud.Interface.Internal.Windows.StyleEditor var appliedThisFrame = false; var styleAry = config.SavedStyles.Select(x => x.Name).ToArray(); - ImGui.Text("Choose Style:"); + ImGui.Text(Loc.Localize("StyleEditorChooseStyle", "Choose Style:")); if (ImGui.Combo("###styleChooserCombo", ref this.currentSel, styleAry, styleAry.Length)) { var newStyle = config.SavedStyles[this.currentSel]; @@ -88,7 +88,7 @@ namespace Dalamud.Interface.Internal.Windows.StyleEditor appliedThisFrame = true; } - if (ImGui.Button("Add new style")) + if (ImGui.Button(Loc.Localize("StyleEditorAddNew", "Add new style"))) { var newStyle = StyleModel.DalamudStandard; newStyle.Name = GetRandomName(); @@ -117,7 +117,7 @@ namespace Dalamud.Interface.Internal.Windows.StyleEditor } if (ImGui.IsItemHovered()) - ImGui.SetTooltip("Delete current style"); + ImGui.SetTooltip(Loc.Localize("StyleEditorDeleteStyle", "Delete current style")); ImGui.SameLine(); @@ -131,7 +131,7 @@ namespace Dalamud.Interface.Internal.Windows.StyleEditor } if (ImGui.IsItemHovered()) - ImGui.SetTooltip("Rename style"); + ImGui.SetTooltip(Loc.Localize("StyleEditorRenameStyle", "Rename style")); ImGui.SameLine(); @@ -145,7 +145,7 @@ namespace Dalamud.Interface.Internal.Windows.StyleEditor } if (ImGui.IsItemHovered()) - ImGui.SetTooltip("Copy style to clipboard for sharing"); + ImGui.SetTooltip(Loc.Localize("StyleEditorCopy", "Copy style to clipboard for sharing")); ImGui.SameLine(); @@ -163,8 +163,6 @@ namespace Dalamud.Interface.Internal.Windows.StyleEditor newStyle.Apply(); appliedThisFrame = true; - Log.Information("Applying: " + newStyle.Name); - this.currentSel = config.SavedStyles.Count - 1; config.Save(); @@ -176,7 +174,7 @@ namespace Dalamud.Interface.Internal.Windows.StyleEditor } if (ImGui.IsItemHovered()) - ImGui.SetTooltip("Import style from clipboard"); + ImGui.SetTooltip(Loc.Localize("StyleEditorImport", "Import style from clipboard")); ImGui.Separator(); @@ -184,11 +182,11 @@ namespace Dalamud.Interface.Internal.Windows.StyleEditor if (this.currentSel == 0) { - ImGui.TextColored(ImGuiColors.DalamudRed, "You cannot edit the \"Dalamud Standard\" style. Please add a new style first."); + ImGui.TextColored(ImGuiColors.DalamudRed, Loc.Localize("StyleEditorNotAllowed", "You cannot edit the \"Dalamud Standard\" style. Please add a new style first.")); } else if (appliedThisFrame) { - ImGui.Text("Applying style..."); + ImGui.Text(Loc.Localize("StyleEditorApplying", "Applying style...")); } else if (ImGui.BeginTabBar("StyleEditorTabs")) { @@ -294,14 +292,14 @@ namespace Dalamud.Interface.Internal.Windows.StyleEditor ImGui.Separator(); - if (ImGui.Button("Close")) + if (ImGui.Button(Loc.Localize("Close", "Close"))) { this.IsOpen = false; } ImGui.SameLine(); - if (ImGui.Button("Save and Close")) + if (ImGui.Button(Loc.Localize("SaveAndClose", "Save and Close"))) { config.ChosenStyle = config.SavedStyles[this.currentSel].Name; @@ -318,7 +316,7 @@ namespace Dalamud.Interface.Internal.Windows.StyleEditor if (ImGui.BeginPopupModal(renameModalTitle, ref this.renameModalDrawing, ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoScrollbar)) { - ImGui.Text("Please enter the new name for this style."); + ImGui.Text(Loc.Localize("StyleEditorEnterName", "Please enter the new name for this style.")); ImGui.Spacing(); ImGui.InputText("###renameModalInput", ref this.renameText, 255); From dd96adc88d74f99a9c12b44294b707594d99e44a Mon Sep 17 00:00:00 2001 From: goat <16760685+goaaats@users.noreply.github.com> Date: Mon, 27 Sep 2021 17:09:22 +0200 Subject: [PATCH 5/5] bump client structs --- lib/FFXIVClientStructs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/FFXIVClientStructs b/lib/FFXIVClientStructs index 01e885aac..a33bfbc1e 160000 --- a/lib/FFXIVClientStructs +++ b/lib/FFXIVClientStructs @@ -1 +1 @@ -Subproject commit 01e885aacc68790d52329f5b3bdcba2838240e54 +Subproject commit a33bfbc1e81f0baa42827e952742289e32854308