Switch to FontAtlas

This commit is contained in:
Asriel Camora
2024-02-22 22:36:24 -08:00
parent e9e4227313
commit 5f9bbc1cf0
4 changed files with 38 additions and 30 deletions
+13
View File
@@ -1,5 +1,6 @@
using Craftimizer.Utils; using Craftimizer.Utils;
using Dalamud.Interface; using Dalamud.Interface;
using Dalamud.Interface.ManagedFontAtlas;
using Dalamud.Interface.Utility.Raii; using Dalamud.Interface.Utility.Raii;
using ImGuiNET; using ImGuiNET;
using ImPlotNET; using ImPlotNET;
@@ -651,4 +652,16 @@ internal static class ImGuiUtils
AlignCentered(buttonWidth); AlignCentered(buttonWidth);
return ImGui.Button(text, buttonSize); return ImGui.Button(text, buttonSize);
} }
public static Vector2 CalcTextSize(this IFontHandle font, string text)
{
using (font.Push())
return ImGui.CalcTextSize(text);
}
public static void Text(this IFontHandle font, string text)
{
using (font.Push())
ImGui.TextUnformatted(text);
}
} }
+13 -16
View File
@@ -10,6 +10,7 @@ using Dalamud.Interface.Colors;
using Dalamud.Interface.GameFonts; using Dalamud.Interface.GameFonts;
using Dalamud.Interface.Internal; using Dalamud.Interface.Internal;
using Dalamud.Interface.Internal.Notifications; using Dalamud.Interface.Internal.Notifications;
using Dalamud.Interface.ManagedFontAtlas;
using Dalamud.Interface.Utility.Raii; using Dalamud.Interface.Utility.Raii;
using Dalamud.Interface.Windowing; using Dalamud.Interface.Windowing;
using Dalamud.Utility; using Dalamud.Utility;
@@ -100,7 +101,7 @@ public sealed class MacroEditor : Window, IDisposable
private IDalamudTextureWrap MedicatedBadge { get; } private IDalamudTextureWrap MedicatedBadge { get; }
private IDalamudTextureWrap InControlBadge { get; } private IDalamudTextureWrap InControlBadge { get; }
private IDalamudTextureWrap EatFromTheHandBadge { get; } private IDalamudTextureWrap EatFromTheHandBadge { get; }
private GameFontHandle AxisFont { get; } private IFontHandle AxisFont { get; }
private string popupSaveAsMacroName = string.Empty; private string popupSaveAsMacroName = string.Empty;
@@ -135,7 +136,7 @@ public sealed class MacroEditor : Window, IDisposable
MedicatedBadge = Service.IconManager.GetIcon(LuminaSheets.StatusSheet.GetRow(49)!.Icon); MedicatedBadge = Service.IconManager.GetIcon(LuminaSheets.StatusSheet.GetRow(49)!.Icon);
InControlBadge = Service.IconManager.GetIcon(LuminaSheets.StatusSheet.GetRow(356)!.Icon); InControlBadge = Service.IconManager.GetIcon(LuminaSheets.StatusSheet.GetRow(356)!.Icon);
EatFromTheHandBadge = Service.IconManager.GetIcon(LuminaSheets.StatusSheet.GetRow(357)!.Icon); EatFromTheHandBadge = Service.IconManager.GetIcon(LuminaSheets.StatusSheet.GetRow(357)!.Icon);
AxisFont = Service.PluginInterface.UiBuilder.GetGameFontHandle(new(GameFontFamilyAndSize.Axis14)); AxisFont = Service.PluginInterface.UiBuilder.FontAtlas.NewGameFontHandle(new(GameFontFamilyAndSize.Axis14));
IsOpen = true; IsOpen = true;
@@ -212,11 +213,7 @@ public sealed class MacroEditor : Window, IDisposable
ImGuiUtils.TextCentered("Crafter"); ImGuiUtils.TextCentered("Crafter");
var textClassName = RecipeData.ClassJob.GetAbbreviation(); var textClassName = RecipeData.ClassJob.GetAbbreviation();
Vector2 textClassSize; var textClassSize = AxisFont.CalcTextSize(textClassName);
{
var layout = AxisFont.LayoutBuilder(textClassName).Build();
textClassSize = new(layout.Width, layout.Height);
}
var imageSize = ImGui.GetFrameHeight(); var imageSize = ImGui.GetFrameHeight();
ImGuiUtils.AlignCentered( ImGuiUtils.AlignCentered(
@@ -709,10 +706,7 @@ public sealed class MacroEditor : Window, IDisposable
var textStars = new string('★', RecipeData!.Table.Stars); var textStars = new string('★', RecipeData!.Table.Stars);
var textStarsSize = Vector2.Zero; var textStarsSize = Vector2.Zero;
if (!string.IsNullOrEmpty(textStars)) if (!string.IsNullOrEmpty(textStars))
{ textStarsSize = AxisFont.CalcTextSize(textStars);
var layout = AxisFont.LayoutBuilder(textStars).Build();
textStarsSize = new(layout.Width, layout.Height);
}
var textLevel = SqText.LevelPrefix.ToIconChar() + SqText.ToLevelString(RecipeData.RecipeInfo.ClassJobLevel); var textLevel = SqText.LevelPrefix.ToIconChar() + SqText.ToLevelString(RecipeData.RecipeInfo.ClassJobLevel);
var isExpert = RecipeData.RecipeInfo.IsExpert; var isExpert = RecipeData.RecipeInfo.IsExpert;
var isCollectable = RecipeData.Recipe.ItemResult.Value!.IsCollectable; var isCollectable = RecipeData.Recipe.ItemResult.Value!.IsCollectable;
@@ -735,11 +729,12 @@ public sealed class MacroEditor : Window, IDisposable
ushort? newRecipe = null; ushort? newRecipe = null;
{ {
var recipe = RecipeData.Recipe; var recipe = RecipeData.Recipe;
using var fontHandle = AxisFont.Lock();
if (ImGuiUtils.SearchableCombo( if (ImGuiUtils.SearchableCombo(
"combo", "combo",
ref recipe, ref recipe,
LuminaSheets.RecipeSheet.Where(r => r.RecipeLevelTable.Row != 0 && r.ItemResult.Row != 0), LuminaSheets.RecipeSheet.Where(r => r.RecipeLevelTable.Row != 0 && r.ItemResult.Row != 0),
AxisFont.ImFont, fontHandle.ImFont,
ImGui.GetContentRegionAvail().X - rightSideWidth, ImGui.GetContentRegionAvail().X - rightSideWidth,
r => r.ItemResult.Value!.Name.ToDalamudString().ToString(), r => r.ItemResult.Value!.Name.ToDalamudString().ToString(),
r => r.RowId.ToString(), r => r.RowId.ToString(),
@@ -752,7 +747,7 @@ public sealed class MacroEditor : Window, IDisposable
var textLevelSize = ImGui.CalcTextSize(textLevel); var textLevelSize = ImGui.CalcTextSize(textLevel);
ImGui.SameLine(); ImGui.SameLine();
var imageSize = AxisFont.ImFont.FontSize; var imageSize = fontHandle.ImFont.FontSize;
ImGuiUtils.AlignRight( ImGuiUtils.AlignRight(
imageSize + 5 + imageSize + 5 +
textLevelSize.X, textLevelSize.X,
@@ -766,7 +761,7 @@ public sealed class MacroEditor : Window, IDisposable
ImGui.SetCursorPosY(ImGui.GetCursorPosY() + ImGui.GetStyle().FramePadding.Y / 2); ImGui.SetCursorPosY(ImGui.GetCursorPosY() + ImGui.GetStyle().FramePadding.Y / 2);
ImGui.Image(Service.IconManager.GetIcon(classJob.GetIconId()).ImGuiHandle, new Vector2(imageSize), uv0, uv1); ImGui.Image(Service.IconManager.GetIcon(classJob.GetIconId()).ImGuiHandle, new Vector2(imageSize), uv0, uv1);
ImGui.SameLine(0, 5); ImGui.SameLine(0, 5);
ImGui.SetCursorPosY(ImGui.GetCursorPosY() + (AxisFont.ImFont.FontSize - textLevelSize.Y) / 2); ImGui.SetCursorPosY(ImGui.GetCursorPosY() + (fontHandle.ImFont.FontSize - textLevelSize.Y) / 2);
ImGui.Text(textLevel); ImGui.Text(textLevel);
})) }))
{ {
@@ -782,7 +777,9 @@ public sealed class MacroEditor : Window, IDisposable
if (textStarsSize != Vector2.Zero) if (textStarsSize != Vector2.Zero)
{ {
ImGui.SameLine(0, 3); ImGui.SameLine(0, 3);
ImGui.SetCursorPosY(ImGui.GetCursorPosY() + (imageSize - textStarsSize.Y) / 2);
// Aligns better
ImGui.SetCursorPosY(ImGui.GetCursorPosY() - 1);
AxisFont.Text(textStars); AxisFont.Text(textStars);
} }
@@ -1080,7 +1077,7 @@ public sealed class MacroEditor : Window, IDisposable
using (var panel = ImRaii2.GroupPanel("Buffs", -1, out _)) using (var panel = ImRaii2.GroupPanel("Buffs", -1, out _))
{ {
using var _font = ImRaii.PushFont(AxisFont.ImFont); using var _font = AxisFont.Push();
var iconHeight = ImGui.GetFrameHeight() * 1.75f; var iconHeight = ImGui.GetFrameHeight() * 1.75f;
var durationShift = iconHeight * .2f; var durationShift = iconHeight * .2f;
+8 -11
View File
@@ -11,6 +11,7 @@ using Dalamud.Interface.Colors;
using Dalamud.Interface.Components; using Dalamud.Interface.Components;
using Dalamud.Interface.GameFonts; using Dalamud.Interface.GameFonts;
using Dalamud.Interface.Internal; using Dalamud.Interface.Internal;
using Dalamud.Interface.ManagedFontAtlas;
using Dalamud.Interface.Utility; using Dalamud.Interface.Utility;
using Dalamud.Interface.Utility.Raii; using Dalamud.Interface.Utility.Raii;
using Dalamud.Interface.Windowing; using Dalamud.Interface.Windowing;
@@ -69,7 +70,7 @@ public sealed unsafe class RecipeNote : Window, IDisposable
private IDalamudTextureWrap SplendorousBadge { get; } private IDalamudTextureWrap SplendorousBadge { get; }
private IDalamudTextureWrap SpecialistBadge { get; } private IDalamudTextureWrap SpecialistBadge { get; }
private IDalamudTextureWrap NoManipulationBadge { get; } private IDalamudTextureWrap NoManipulationBadge { get; }
private GameFontHandle AxisFont { get; } private IFontHandle AxisFont { get; }
public RecipeNote() : base("Craftimizer RecipeNote", WindowFlags) public RecipeNote() : base("Craftimizer RecipeNote", WindowFlags)
{ {
@@ -78,7 +79,7 @@ public sealed unsafe class RecipeNote : Window, IDisposable
SplendorousBadge = Service.IconManager.GetAssemblyTexture("Graphics.splendorous.png"); SplendorousBadge = Service.IconManager.GetAssemblyTexture("Graphics.splendorous.png");
SpecialistBadge = Service.IconManager.GetAssemblyTexture("Graphics.specialist.png"); SpecialistBadge = Service.IconManager.GetAssemblyTexture("Graphics.specialist.png");
NoManipulationBadge = Service.IconManager.GetAssemblyTexture("Graphics.no_manip.png"); NoManipulationBadge = Service.IconManager.GetAssemblyTexture("Graphics.no_manip.png");
AxisFont = Service.PluginInterface.UiBuilder.GetGameFontHandle(new(GameFontFamilyAndSize.Axis14)); AxisFont = Service.PluginInterface.UiBuilder.FontAtlas.NewGameFontHandle(new(GameFontFamilyAndSize.Axis14));
RespectCloseHotkey = false; RespectCloseHotkey = false;
DisableWindowSounds = true; DisableWindowSounds = true;
@@ -265,11 +266,7 @@ public sealed unsafe class RecipeNote : Window, IDisposable
var level = RecipeData!.ClassJob.GetPlayerLevel(); var level = RecipeData!.ClassJob.GetPlayerLevel();
{ {
var textClassName = RecipeData.ClassJob.GetAbbreviation(); var textClassName = RecipeData.ClassJob.GetAbbreviation();
Vector2 textClassSize; var textClassSize = AxisFont.CalcTextSize(textClassName);
{
var layout = AxisFont.LayoutBuilder(textClassName).Build();
textClassSize = new(layout.Width, layout.Height);
}
var levelText = string.Empty; var levelText = string.Empty;
if (level != 0) if (level != 0)
levelText = SqText.LevelPrefix.ToIconChar() + SqText.ToLevelString(level); levelText = SqText.LevelPrefix.ToIconChar() + SqText.ToLevelString(level);
@@ -308,7 +305,6 @@ public sealed unsafe class RecipeNote : Window, IDisposable
ImGui.SameLine(0, 3); ImGui.SameLine(0, 3);
} }
ImGui.SetCursorPosY(ImGui.GetCursorPosY() + (imageSize - textClassSize.Y) / 2);
AxisFont.Text(textClassName); AxisFont.Text(textClassName);
if (hasSplendorous) if (hasSplendorous)
@@ -477,8 +473,7 @@ public sealed unsafe class RecipeNote : Window, IDisposable
var textStars = new string('★', RecipeData!.Table.Stars); var textStars = new string('★', RecipeData!.Table.Stars);
var textStarsSize = Vector2.Zero; var textStarsSize = Vector2.Zero;
if (!string.IsNullOrEmpty(textStars)) { if (!string.IsNullOrEmpty(textStars)) {
var layout = AxisFont.LayoutBuilder(textStars).Build(); textStarsSize = AxisFont.CalcTextSize(textStars);
textStarsSize = new(layout.Width, layout.Height);
} }
var textLevel = SqText.LevelPrefix.ToIconChar() + SqText.ToLevelString(RecipeData.RecipeInfo.ClassJobLevel); var textLevel = SqText.LevelPrefix.ToIconChar() + SqText.ToLevelString(RecipeData.RecipeInfo.ClassJobLevel);
var isExpert = RecipeData.RecipeInfo.IsExpert; var isExpert = RecipeData.RecipeInfo.IsExpert;
@@ -507,7 +502,9 @@ public sealed unsafe class RecipeNote : Window, IDisposable
if (textStarsSize != Vector2.Zero) if (textStarsSize != Vector2.Zero)
{ {
ImGui.SameLine(0, 3); ImGui.SameLine(0, 3);
ImGui.SetCursorPosY(ImGui.GetCursorPosY() + (imageSize - textStarsSize.Y) / 2);
// Aligns better
ImGui.SetCursorPosY(ImGui.GetCursorPosY() - 1);
AxisFont.Text(textStars); AxisFont.Text(textStars);
} }
+4 -3
View File
@@ -6,6 +6,7 @@ using Craftimizer.Utils;
using Dalamud.Game.ClientState.Conditions; using Dalamud.Game.ClientState.Conditions;
using Dalamud.Interface.Colors; using Dalamud.Interface.Colors;
using Dalamud.Interface.GameFonts; using Dalamud.Interface.GameFonts;
using Dalamud.Interface.ManagedFontAtlas;
using Dalamud.Interface.Utility; using Dalamud.Interface.Utility;
using Dalamud.Interface.Utility.Raii; using Dalamud.Interface.Utility.Raii;
using Dalamud.Interface.Windowing; using Dalamud.Interface.Windowing;
@@ -66,11 +67,11 @@ public sealed unsafe class SynthHelper : Window, IDisposable
private Solver.Solver? HelperTaskObject { get; set; } private Solver.Solver? HelperTaskObject { get; set; }
private bool HelperTaskRunning => HelperTaskTokenSource != null; private bool HelperTaskRunning => HelperTaskTokenSource != null;
private GameFontHandle AxisFont { get; } private IFontHandle AxisFont { get; }
public SynthHelper() : base("Craftimizer SynthHelper", WindowFlags) public SynthHelper() : base("Craftimizer SynthHelper", WindowFlags)
{ {
AxisFont = Service.PluginInterface.UiBuilder.GetGameFontHandle(new(GameFontFamilyAndSize.Axis14)); AxisFont = Service.PluginInterface.UiBuilder.FontAtlas.NewGameFontHandle(new(GameFontFamilyAndSize.Axis14));
Service.Plugin.Hooks.OnActionUsed += OnUseAction; Service.Plugin.Hooks.OnActionUsed += OnUseAction;
@@ -267,7 +268,7 @@ public sealed unsafe class SynthHelper : Window, IDisposable
using (var panel = ImRaii2.GroupPanel("Buffs", -1, out _)) using (var panel = ImRaii2.GroupPanel("Buffs", -1, out _))
{ {
using var _font = ImRaii.PushFont(AxisFont.ImFont); using var _font = AxisFont.Push();
var iconHeight = ImGui.GetFrameHeight() * 1.75f; var iconHeight = ImGui.GetFrameHeight() * 1.75f;
var durationShift = iconHeight * .2f; var durationShift = iconHeight * .2f;