Implement feature to use game resource fonts

This commit is contained in:
Soreepeong 2022-02-24 18:56:34 +09:00
parent b7c47b4c97
commit f3588dfe23
9 changed files with 1137 additions and 2 deletions

View file

@ -12,6 +12,7 @@ using Dalamud.Game.Gui.Dtr;
using Dalamud.Game.Text;
using Dalamud.Interface.Colors;
using Dalamud.Interface.Components;
using Dalamud.Interface.GameFonts;
using Dalamud.Interface.Windowing;
using Dalamud.Plugin.Internal;
using Dalamud.Utility;
@ -27,6 +28,8 @@ namespace Dalamud.Interface.Internal.Windows
private const float MinScale = 0.3f;
private const float MaxScale = 2.0f;
private readonly List<GameFont> validFontChoices;
private readonly string[] validFontNames;
private readonly string[] languages;
private readonly string[] locLanguages;
private int langIndex;
@ -66,6 +69,8 @@ namespace Dalamud.Interface.Internal.Windows
private bool doButtonsSystemMenu;
private bool disableRmtFiltering;
private int validFontIndex;
#region Experimental
private bool doPluginTest;
@ -111,6 +116,10 @@ namespace Dalamud.Interface.Internal.Windows
this.doButtonsSystemMenu = configuration.DoButtonsSystemMenu;
this.disableRmtFiltering = configuration.DisableRmtFiltering;
this.validFontChoices = Enum.GetValues<GameFont>().Where(x => x == GameFont.Undefined || GameFontManager.IsGenericPurposeFont(x)).ToList();
this.validFontNames = this.validFontChoices.Select(x => GameFontManager.DescribeFont(x)).ToArray();
this.validFontIndex = Math.Max(0, this.validFontChoices.IndexOf(configuration.DefaultFontFromGame));
this.languages = Localization.ApplicableLangCodes.Prepend("en").ToArray();
try
{
@ -286,6 +295,11 @@ namespace Dalamud.Interface.Internal.Windows
ImGuiHelpers.ScaledDummy(10, 16);
ImGui.Text(Loc.Localize("DalamudSettingsGlobalFont", "Global Font"));
ImGui.Combo("##DalamudSettingsGlobalFontDrag", ref this.validFontIndex, this.validFontNames, this.validFontNames.Length);
ImGuiHelpers.ScaledDummy(10, 16);
if (ImGui.Button(Loc.Localize("DalamudSettingsOpenStyleEditor", "Open Style Editor")))
{
Service<DalamudInterface>.Get().OpenStyleEditor();
@ -800,6 +814,8 @@ namespace Dalamud.Interface.Internal.Windows
configuration.IsFocusManagementEnabled = this.doFocus;
configuration.ShowTsm = this.doTsm;
configuration.DefaultFontFromGame = this.validFontChoices[this.validFontIndex];
// This is applied every frame in InterfaceManager::CheckViewportState()
configuration.IsDisableViewport = !this.doViewport;
@ -842,6 +858,8 @@ namespace Dalamud.Interface.Internal.Windows
configuration.Save();
Service<InterfaceManager>.Get().RebuildFonts();
_ = Service<PluginManager>.Get().ReloadPluginMastersAsync();
}
}