Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
fix: ui fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Jul 10, 2024
1 parent 1a5c572 commit 820c8c3
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 36 deletions.
2 changes: 0 additions & 2 deletions ActionTimelineEx/Localization/Localization.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
2 changes: 1 addition & 1 deletion ActionTimelineEx/Timeline/TimelineItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
181 changes: 181 additions & 0 deletions ActionTimelineEx/Windows/ChangeLogItem.cs
Original file line number Diff line number Diff line change
@@ -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();
}
43 changes: 11 additions & 32 deletions ActionTimelineEx/Windows/SettingsWindow.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

Expand All @@ -186,8 +166,7 @@ protected override ConfigWindowItem[] GetItems()
return
[
..Settings.TimelineSettings.Select(i => new TimelineItem(i, ClearItems)),
new AddOne(ClearItems),
new ChangeLog(),
new ChangeLogItem(),
];
}

Expand Down
2 changes: 1 addition & 1 deletion XIVConfigUI

0 comments on commit 820c8c3

Please sign in to comment.