Skip to content

Commit

Permalink
Remove Obsolete for Dalamud provided font.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kurochi51 committed Apr 27, 2024
1 parent a7f76db commit b851f37
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 55 deletions.
41 changes: 0 additions & 41 deletions PetScale/Helpers/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
});
});
}
5 changes: 0 additions & 5 deletions PetScale/PetScale.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -57,9 +56,6 @@ public sealed class PetScale : IDalamudPlugin
public Queue<string> 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; }
Expand Down Expand Up @@ -107,7 +103,6 @@ public sealed class PetScale : IDalamudPlugin
stopwatch.Start();

_ = Task.Run(InitSheet);
IconFont = Utilities.CreateIconFont(pluginInterface);
ConfigWindow.ProcessPetData(save: false);
QueueOnlyExistingData();
}
Expand Down
2 changes: 1 addition & 1 deletion PetScale/PetScale.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

<ItemGroup>
<PackageReference Include="DalamudPackager" Version="2.1.12" />
<PackageReference Include="Meziantou.Analyzer" Version="2.0.146">
<PackageReference Include="Meziantou.Analyzer" Version="2.0.149">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
13 changes: 8 additions & 5 deletions PetScale/Windows/ConfigWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public sealed class ConfigWindow : Window, IDisposable
public Dictionary<string, PetModel> petMap { get; } = new(StringComparer.Ordinal);
private Queue<string> players => plugin.players;
private IList<PetStruct> 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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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),
Expand Down
6 changes: 3 additions & 3 deletions PetScale/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -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=="
}
}
}
Expand Down

0 comments on commit b851f37

Please sign in to comment.