diff --git a/PetScale/Helpers/Utilities.cs b/PetScale/Helpers/Utilities.cs index 903cc35..ee5c6c4 100644 --- a/PetScale/Helpers/Utilities.cs +++ b/PetScale/Helpers/Utilities.cs @@ -4,10 +4,7 @@ using Dalamud; using Lumina.Excel; using Dalamud.Memory; -using Dalamud.Plugin; using Dalamud.Plugin.Services; -using Dalamud.Interface.Utility; -using Dalamud.Interface.ManagedFontAtlas; using Dalamud.Game.ClientState.Objects.Enums; using FFXIVClientStructs.FFXIV.Client.Game.Character; using FFXIVClientStructs.Interop; @@ -102,42 +99,4 @@ public unsafe bool PetVisible(BattleChara* pet) } return pet->Character.GameObject.GetDrawObject()->IsVisible; } - - public static IFontHandle CreateIconFont(DalamudPluginInterface pi) - => pi.UiBuilder.FontAtlas.NewDelegateFontHandle(e => - { - e.OnPreBuild(tk => tk.AddFontAwesomeIconFont(new() - { - SizePx = pi.UiBuilder.DefaultFontSpec.SizePx, - GlyphMinAdvanceX = pi.UiBuilder.DefaultFontSpec.SizePx, - GlyphMaxAdvanceX = pi.UiBuilder.DefaultFontSpec.SizePx, - })); - e.OnPostBuild(tk => - { - var font = tk.Font; - var fontSize = font.FontSize; - var glyphs = font.GlyphsWrapped(); - foreach (ref var glyph in glyphs.DataSpan) - { - var ratio = 1f; - if (glyph.X1 - glyph.X0 > fontSize) - { - ratio = Math.Max(ratio, (glyph.X1 - glyph.X0) / fontSize); - } - if (glyph.Y1 - glyph.Y0 > fontSize) - { - ratio = Math.Max(ratio, (glyph.Y1 - glyph.Y0) / fontSize); - } - var width = MathF.Round((glyph.X1 - glyph.X0) / ratio, MidpointRounding.ToZero); - var height = MathF.Round((glyph.Y1 - glyph.Y0) / ratio, MidpointRounding.AwayFromZero); - glyph.X0 = MathF.Round((fontSize - width) / 2f, MidpointRounding.ToZero); - glyph.Y0 = MathF.Round((fontSize - height) / 2f, MidpointRounding.AwayFromZero); - glyph.X1 = glyph.X0 + width; - glyph.Y1 = glyph.Y0 + height; - glyph.AdvanceX = fontSize; - } - - tk.BuildLookupTable(font); - }); - }); } diff --git a/PetScale/PetScale.cs b/PetScale/PetScale.cs index e2ee8b1..4f6d380 100644 --- a/PetScale/PetScale.cs +++ b/PetScale/PetScale.cs @@ -11,7 +11,6 @@ using Dalamud.Plugin.Services; using Dalamud.Interface.Windowing; using Lumina.Excel.GeneratedSheets2; -using Dalamud.Interface.ManagedFontAtlas; using Dalamud.Game.ClientState.Objects.Enums; using Dalamud.Game.ClientState.Objects.SubKinds; using BattleChara = FFXIVClientStructs.FFXIV.Client.Game.Character.BattleChara; @@ -57,9 +56,6 @@ public sealed class PetScale : IDalamudPlugin public Queue players { get; } = new(101); // 100 players + Others entry public bool requestedCache { get; set; } = true; public int lastIndexOfOthers { get; set; } = -1; - [Obsolete("Replace with Dalamud provided font once merged")] - public IFontHandle IconFont { get; set; } - private ConfigWindow ConfigWindow { get; init; } #if DEBUG private DevWindow DevWindow { get; init; } @@ -107,7 +103,6 @@ public PetScale(DalamudPluginInterface _pluginInterface, stopwatch.Start(); _ = Task.Run(InitSheet); - IconFont = Utilities.CreateIconFont(pluginInterface); ConfigWindow.ProcessPetData(save: false); QueueOnlyExistingData(); } diff --git a/PetScale/PetScale.csproj b/PetScale/PetScale.csproj index 043d452..a668c05 100644 --- a/PetScale/PetScale.csproj +++ b/PetScale/PetScale.csproj @@ -41,7 +41,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/PetScale/Windows/ConfigWindow.cs b/PetScale/Windows/ConfigWindow.cs index a335d9e..2d91281 100644 --- a/PetScale/Windows/ConfigWindow.cs +++ b/PetScale/Windows/ConfigWindow.cs @@ -51,6 +51,7 @@ public sealed class ConfigWindow : Window, IDisposable public Dictionary petMap { get; } = new(StringComparer.Ordinal); private Queue players => plugin.players; private IList petData => config.PetData; + private IFontHandle iconFont => pluginInterface.UiBuilder.IconFontFixedWidthHandle; private string petSelection = DefaultPetSelection, longestPetName = string.Empty, sizeSelection = DefaultSizeSelection, charaName = DefaultCharacterSelection; private string filterTemp = string.Empty; @@ -150,7 +151,7 @@ private void GeneralTab() ImGui.SameLine(); DrawComboBox("Sizes", sizeSelection, sizesWidth, out sizeSelection, sizeMap.Values, filter: false); ImGui.SameLine(); - if (IconButton(plugin.IconFont, addButtonIcon, "AddButton", 1)) + if (IconButton(iconFont, addButtonIcon, "AddButton", 1)) { buttonPressed = true; } @@ -194,10 +195,10 @@ private unsafe void DisplayEntries() ImGui.TableSetupColumn("Character", ImGuiTableColumnFlags.WidthFixed, charaWidth); ImGui.TableSetupColumn("Pet", ImGuiTableColumnFlags.WidthFixed, petWidth); ImGui.TableSetupColumn("PetSize", ImGuiTableColumnFlags.WidthFixed, sizesWidth); - ImGui.TableSetupColumn("DeleteButton", ImGuiTableColumnFlags.WidthFixed, IconButtonSize(plugin.IconFont, deleteButtonIcon).X); + ImGui.TableSetupColumn("DeleteButton", ImGuiTableColumnFlags.WidthFixed, IconButtonSize(iconFont, deleteButtonIcon).X); var itemRemoved = false; var clipper = new ImGuiListClipperPtr(ImGuiNative.ImGuiListClipper_ImGuiListClipper()); - var clipperHeight = IconButtonSize(plugin.IconFont, deleteButtonIcon).Y + (ImGui.GetStyle().FramePadding.Y * 2); + var clipperHeight = IconButtonSize(iconFont, deleteButtonIcon).Y + (ImGui.GetStyle().FramePadding.Y * 2); clipper.Begin(petData.Count, clipperHeight); var clipperBreak = false; @@ -226,7 +227,7 @@ private unsafe void DisplayEntries() ImGui.TextUnformatted(sizeMap[item.PetSize]); ImGui.TableSetColumnIndex(3); ImGui.SetCursorPosX(tableButtonAlignmentOffset); - if (IconButton(plugin.IconFont, deleteButtonIcon, buttonId + deleteButtonIcon, 1)) + if (IconButton(iconFont, deleteButtonIcon, buttonId + deleteButtonIcon, 1)) { petData.RemoveAt(i); CreateNotification("Entry " + item.CharacterName + ", " + petSelection + ", " + sizeMap[item.PetSize] + " was removed.", "Entry removed"); @@ -310,6 +311,8 @@ private static Vector2 IconButtonSize(IFontHandle fontHandle, string icon) } } + // widthOffset is a pain in the ass, at 100% you want 0, <100% you want 1 or more, >100% it entirely depends on whether you get a non-repeating divison or not... maybe? + // also this entirely varies for each icon, so good luck aligning everything private static bool IconButton(IFontHandle fontHandle, string icon, string buttonIDLabel, float widthOffset = 0f) { using (fontHandle.Push()) @@ -412,7 +415,7 @@ private void ResizeIfNeeded() tableButtonAlignmentOffset = charaWidth + petWidth + sizesWidth + (ImGui.GetStyle().ItemSpacing.X * 3); if (SizeConstraints.HasValue) { - var newWidth = tableButtonAlignmentOffset + IconButtonSize(plugin.IconFont, deleteButtonIcon).X + (ImGui.GetStyle().WindowPadding.X * 2) + ImGui.GetStyle().ScrollbarSize; + var newWidth = tableButtonAlignmentOffset + IconButtonSize(iconFont, deleteButtonIcon).X + (ImGui.GetStyle().WindowPadding.X * 2) + ImGui.GetStyle().ScrollbarSize; SizeConstraints = new WindowSizeConstraints() { MinimumSize = new Vector2(newWidth / ImGuiHelpers.GlobalScale, SizeConstraints.Value.MinimumSize.Y), diff --git a/PetScale/packages.lock.json b/PetScale/packages.lock.json index 1a854ef..3baf7b5 100644 --- a/PetScale/packages.lock.json +++ b/PetScale/packages.lock.json @@ -10,9 +10,9 @@ }, "Meziantou.Analyzer": { "type": "Direct", - "requested": "[2.0.146, )", - "resolved": "2.0.146", - "contentHash": "pJ3k+3UjD2WwPsZR7fkgVYviXP3PCQM0hjwN1TuM4C0u1TuGKC9WdZCo0RAPZ+azhRPmYGSUjkjsN2fkQByghQ==" + "requested": "[2.0.149, )", + "resolved": "2.0.149", + "contentHash": "nJaiWMp6AlosBpl3sJO/frbqiImPBHodaJpcwlA/ez3zwjj9ZF4oeH0tWHSRFW8+e5mJMswlc3Kwl8DFskVOCg==" } } }