diff --git a/Craftimizer/ImGuiUtils.cs b/Craftimizer/ImGuiUtils.cs index b06e79a..30f3aec 100644 --- a/Craftimizer/ImGuiUtils.cs +++ b/Craftimizer/ImGuiUtils.cs @@ -569,16 +569,20 @@ internal static class ImGuiUtils } // https://gist.github.com/dougbinks/ef0962ef6ebe2cadae76c4e9f0586c69#file-imguiutils-h-L228 - public static unsafe void Hyperlink(string text, string url) + public static unsafe void Hyperlink(string text, string url, bool underline = true) { ImGui.TextUnformatted(text); - UnderlineLastItem(*ImGui.GetStyleColorVec4(ImGuiCol.Text)); + if (underline) + UnderlineLastItem(*ImGui.GetStyleColorVec4(ImGuiCol.Text)); if (ImGui.IsItemHovered()) { ImGui.SetMouseCursor(ImGuiMouseCursor.Hand); if (ImGui.IsItemClicked(ImGuiMouseButton.Left)) Process.Start(new ProcessStartInfo { FileName = url, UseShellExecute = true }); - Tooltip("Open in Browser"); + var urlWithoutScheme = url; + if (Uri.TryCreate(url, UriKind.Absolute, out var uri)) + urlWithoutScheme = uri.Host + (string.Equals(uri.PathAndQuery, "/", StringComparison.Ordinal) ? string.Empty : uri.PathAndQuery); + Tooltip(urlWithoutScheme); } } diff --git a/Craftimizer/Utils/CommunityMacros.cs b/Craftimizer/Utils/CommunityMacros.cs index 147de11..96665e8 100644 --- a/Craftimizer/Utils/CommunityMacros.cs +++ b/Craftimizer/Utils/CommunityMacros.cs @@ -190,6 +190,8 @@ public sealed class CommunityMacros public MapValue? Recipe { get; set; } } + public string? Name { get; set; } + public FieldData? Fields { get; set; } public ErrorData? Error { get; set; } @@ -230,6 +232,7 @@ public sealed class CommunityMacros public sealed record CommunityMacro { public string Name { get; } + public string? Url { get; } public IReadOnlyList Actions { get; } public CommunityMacro(TeamcraftMacro macro) @@ -291,6 +294,16 @@ public sealed class CommunityMacros } Actions = actions; + + if (!string.IsNullOrEmpty(macro.Name)) + { + if (Uri.TryCreate(macro.Name, UriKind.Relative, out var uri)) + { + var rotationId = macro.Name.Split('/')[^1]; + if (!string.IsNullOrEmpty(rotationId)) + Url = $"https://ffxivteamcraft.com/simulator/custom/{rotationId}"; + } + } } public CommunityMacro(CraftingwayMacro macro) diff --git a/Craftimizer/Windows/RecipeNote.cs b/Craftimizer/Windows/RecipeNote.cs index 8f37a13..1861829 100644 --- a/Craftimizer/Windows/RecipeNote.cs +++ b/Craftimizer/Windows/RecipeNote.cs @@ -395,6 +395,7 @@ public sealed unsafe class RecipeNote : Window, IDisposable Completed = CommunityMacroTask?.Completed ?? false, Actions = macroTaskResult?.Item1?.Actions, MacroName = macroTaskResult?.Item1?.Name, + MacroUrl = macroTaskResult?.Item1?.Url, State = macroTaskResult?.Item2, }; DrawMacro(in state, panelWidth); @@ -716,6 +717,7 @@ public sealed unsafe class RecipeNote : Window, IDisposable public bool Completed; public IReadOnlyList? Actions; public string? MacroName; + public string? MacroUrl; public SimulationState? State; public Solver.Solver? Solver; public Action>? MacroEditorSetter; @@ -840,7 +842,17 @@ public sealed unsafe class RecipeNote : Window, IDisposable throw new InvalidOperationException("Combo actions should be sanitized away"); if (state.MacroName is { } macroName) - ImGuiUtils.TextCentered(macroName, panelWidth); + { + if (state.MacroUrl is { } macroUrl) + { + ImGuiUtils.AlignCentered(ImGui.CalcTextSize(macroName).X, panelWidth); + ImGuiUtils.Hyperlink(macroName, macroUrl, false); + } + else + { + ImGuiUtils.TextCentered(macroName, panelWidth); + } + } using var table = ImRaii.Table("table", 3, ImGuiTableFlags.BordersInnerV | ImGuiTableFlags.SizingStretchSame); if (table)