Add clickable links to community macros
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -190,6 +190,8 @@ public sealed class CommunityMacros
|
||||
public MapValue<RecipeFieldData>? 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<ActionType> 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)
|
||||
|
||||
@@ -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<ActionType>? Actions;
|
||||
public string? MacroName;
|
||||
public string? MacroUrl;
|
||||
public SimulationState? State;
|
||||
public Solver.Solver? Solver;
|
||||
public Action<IEnumerable<ActionType>>? 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)
|
||||
|
||||
Reference in New Issue
Block a user