From 820c8c34972b962c5a353860fcb3520264d065bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=8B=E6=B0=B4?= <53346444+ArchiDog1998@users.noreply.github.com> Date: Wed, 10 Jul 2024 12:56:05 +0800 Subject: [PATCH] fix: ui fixes. --- .../Localization/Localization.json | 2 - ActionTimelineEx/Timeline/TimelineItem.cs | 2 +- ActionTimelineEx/Windows/ChangeLogItem.cs | 181 ++++++++++++++++++ ActionTimelineEx/Windows/SettingsWindow.cs | 43 ++--- XIVConfigUI | 2 +- 5 files changed, 194 insertions(+), 36 deletions(-) create mode 100644 ActionTimelineEx/Windows/ChangeLogItem.cs diff --git a/ActionTimelineEx/Localization/Localization.json b/ActionTimelineEx/Localization/Localization.json index 525096a..51536af 100644 --- a/ActionTimelineEx/Localization/Localization.json +++ b/ActionTimelineEx/Localization/Localization.json @@ -105,7 +105,5 @@ "XIVConfigUI.Attributes.ConfigUnitType.Percent": "Ratio Unit, as percentage.", "XIVConfigUI.Attributes.ConfigUnitType.Pixels": "Display Unit, in pixels.", "ActionTimelineEx.Punchline": "Show your actions in real-time.", - "ActionTimeline.Windows.SettingsWindow+AddOne": "AddOne", - "ActionTimeline.Windows.SettingsWindow+ChangeLog": "ChangeLog", "ActionTimelineEx.Description": "Configurable timeline display of all the actions you use." } \ No newline at end of file diff --git a/ActionTimelineEx/Timeline/TimelineItem.cs b/ActionTimelineEx/Timeline/TimelineItem.cs index 2ad0c98..5daee09 100644 --- a/ActionTimelineEx/Timeline/TimelineItem.cs +++ b/ActionTimelineEx/Timeline/TimelineItem.cs @@ -150,7 +150,7 @@ private void DrawItemWithCenter(ImDrawListPtr drawList, Vector2 centerPos, Vecto var leftBottom = centerPos + (lowPos * iconSize - iconSize / 2) * setting.RealDownDirection; var flag = ImDrawFlags.RoundCornersAll; - var min = centerPos + iconSize / 2 * setting.TimeDirection; + var min = centerPos - iconSize / 2 * setting.RealDownDirection + iconSize / 2 * setting.TimeDirection; //Background var GcdBackColor = ImGui.ColorConvertFloat4ToU32(setting.BackgroundColor); diff --git a/ActionTimelineEx/Windows/ChangeLogItem.cs b/ActionTimelineEx/Windows/ChangeLogItem.cs new file mode 100644 index 0000000..e65eca6 --- /dev/null +++ b/ActionTimelineEx/Windows/ChangeLogItem.cs @@ -0,0 +1,181 @@ +using Dalamud.Interface.Textures.TextureWraps; +using Dalamud.Interface.Utility.Raii; +using Dalamud.Utility; +using ImGuiNET; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using XIVConfigUI; + +namespace ActionTimelineEx.Windows; +[Description("ChangeLog")] +public partial class ChangeLogItem : ConfigWindowItem +{ + private static readonly string OpenLink = $"https://github.com/{XIVConfigUIMain.UserName}/{XIVConfigUIMain.RepoName}/blob/main/CHANGELOG.md", + DownloadLind = $"https://raw.githubusercontent.com/{XIVConfigUIMain.UserName}/{XIVConfigUIMain.RepoName}/main/CHANGELOG.md"; + + private enum LineType : byte + { + None, + Header, + Version, + Category, + Item, + } + + public override bool GetIcon(out IDalamudTextureWrap texture) + { + return ImageLoader.GetTexture(80, out texture); + } + + public override void Draw(ConfigWindow window) + { + using var color = ImRaii.PushColor(ImGuiCol.Button, 0); + var style = ImGui.GetStyle(); + + var changeLog = GetChangeLog(); + if (string.IsNullOrEmpty(changeLog)) return; + + var lines = changeLog.Split('\n') + .Where(s => !string.IsNullOrEmpty(s)); + + var padding = style.FramePadding; + style.FramePadding = default; + + var spacing = style.ItemSpacing; + style.ItemSpacing = default; + + foreach (var s in lines) + { + var line = s; + var type = GetLineType(ref line); + if (type == LineType.None) continue; + + var fontSize = type switch + { + LineType.Header => FontSize.Second, + LineType.Version => FontSize.Third, + LineType.Category => FontSize.Fourth, + _ => FontSize.Fifth, + }; + + IDisposable? font = null; + + if (fontSize != FontSize.Fifth) + { + font = ImRaii.PushFont(ImGuiHelper.GetFont(fontSize)); + } + + if (type == LineType.Header) + { + if (ImGui.Button(line)) + { + Util.OpenLink(OpenLink); + } + } + else + { + if (type == LineType.Item) + { + ImGui.Text(" "); + ImGui.SameLine(); + } + DrawLine(line); + } + + font?.Dispose(); + } + + style.FramePadding = padding; + style.ItemSpacing = spacing; + } + + private static void DrawLine(string text) + { + var regex = ButtonRegex(); + + Match matched = regex.Match(text); + + while (matched.Success) + { + var buttonStr = matched.Value; + ImGui.Text(text[..matched.Index]); + text = text[(matched.Index + matched.Length)..]; + ImGui.SameLine(); + DrawButton(buttonStr); + ImGui.SameLine(); + matched = regex.Match(text); + } + + ImGui.Text(text); + } + + private static void DrawButton(string buttonStr) + { + var name = ButtonName().Match(buttonStr).Value[1..^1]; + var link = ButtonLink().Match(buttonStr).Value[1..^1]; + + if (ImGui.Button(name + "##" + link)) + { + Util.OpenLink(link); + } + } + + private static LineType GetLineType(ref string line) + { + if (line.StartsWith("# ")) + { + line = line[2..]; + return LineType.Header; + } + else if (line.StartsWith("## ")) + { + line = line[3..]; + return LineType.Version; + } + else if (line.StartsWith("### ")) + { + line = line[4..]; + return LineType.Category; + } + else if (line.StartsWith("* ")) + { + line = line[2..]; + return LineType.Item; + } + else + { + return LineType.None; + } + } + + private static string ChangeLog = string.Empty; + private static bool IsDownload = false; + private static string GetChangeLog() + { + if (!string.IsNullOrEmpty(ChangeLog)) return ChangeLog; + if (IsDownload) return string.Empty; + IsDownload = true; + + Task.Run(async () => + { + using var client = new HttpClient(); + ChangeLog = await client.GetStringAsync(DownloadLind); + }); + + return string.Empty; + } + + [GeneratedRegex("\\[.+?\\]")] + private static partial Regex ButtonName(); + + [GeneratedRegex("\\(.+?\\)")] + private static partial Regex ButtonLink(); + + [GeneratedRegex("\\[.+?\\]\\(.+?\\)")] + private static partial Regex ButtonRegex(); +} \ No newline at end of file diff --git a/ActionTimelineEx/Windows/SettingsWindow.cs b/ActionTimelineEx/Windows/SettingsWindow.cs index 3f8db50..438a07a 100644 --- a/ActionTimelineEx/Windows/SettingsWindow.cs +++ b/ActionTimelineEx/Windows/SettingsWindow.cs @@ -1,6 +1,7 @@ using ActionTimeline.Helpers; using ActionTimeline.Timeline; using ActionTimelineEx.Configurations; +using ActionTimelineEx.Windows; using Dalamud.Interface; using Dalamud.Interface.Colors; using Dalamud.Interface.GameFonts; @@ -107,36 +108,6 @@ private bool RemoveValue(string name) } } - [Description("AddOne")] - public class AddOne(System.Action action) : ConfigWindowItem - { - public override string Description => UiString.AddOne.Local(); - - public override bool GetIcon(out IDalamudTextureWrap texture) - { - return ImageLoader.GetTexture(51, out texture); - } - public override bool OnClick() - { - Settings.TimelineSettings.Add(new DrawingSettings() - { - Name = (Settings.TimelineSettings.Count + 1).ToString(), - }); - action(); - return true; - } - } - - [Description("ChangeLog")] - public class ChangeLog : ConfigWindowItem - { - public override bool GetIcon(out IDalamudTextureWrap texture) - { - return ImageLoader.GetTexture(80, out texture); - } - public override string Link => $"https://github.com/{XIVConfigUIMain.UserName}/{XIVConfigUIMain.RepoName}/blob/main/CHANGELOG.md"; - } - private static float _scale => ImGuiHelpers.GlobalScale; public override SearchableCollection Collection { get; } = new(Settings); protected override bool ShowDonate => Settings.ShowDonate; @@ -173,6 +144,15 @@ protected override void DrawAbout() base.DrawAbout(); + if (ImGui.Button(UiString.AddOne.Local())) + { + Settings.TimelineSettings.Add(new DrawingSettings() + { + Name = (Settings.TimelineSettings.Count + 1).ToString(), + }); + ClearItems(); + } + _aboutHeaders.Draw(); } @@ -186,8 +166,7 @@ protected override ConfigWindowItem[] GetItems() return [ ..Settings.TimelineSettings.Select(i => new TimelineItem(i, ClearItems)), - new AddOne(ClearItems), - new ChangeLog(), + new ChangeLogItem(), ]; } diff --git a/XIVConfigUI b/XIVConfigUI index ef640bd..697d566 160000 --- a/XIVConfigUI +++ b/XIVConfigUI @@ -1 +1 @@ -Subproject commit ef640bd493163e6e883822b0f4bb18aeaa7b2a20 +Subproject commit 697d5669c905a6d7924b2a23e60f3dac0dce1760