diff --git a/Assets/Game/Addons/ModSupport/ModManager.cs b/Assets/Game/Addons/ModSupport/ModManager.cs index 7090faa988..a4e4d68ebe 100644 --- a/Assets/Game/Addons/ModSupport/ModManager.cs +++ b/Assets/Game/Addons/ModSupport/ModManager.cs @@ -133,10 +133,7 @@ void Awake() { if (string.IsNullOrEmpty(ModDirectory)) ModDirectory = Path.Combine(Application.streamingAssetsPath, "Mods"); - } - void Start() - { SetupSingleton(); if (Instance == this) diff --git a/Assets/Game/Addons/ModSupport/ModManager.cs.meta b/Assets/Game/Addons/ModSupport/ModManager.cs.meta index 6a0a2e3ef9..fda3743894 100644 --- a/Assets/Game/Addons/ModSupport/ModManager.cs.meta +++ b/Assets/Game/Addons/ModSupport/ModManager.cs.meta @@ -5,7 +5,7 @@ licenseType: Free MonoImporter: serializedVersion: 2 defaultReferences: [] - executionOrder: 0 + executionOrder: -5 icon: {instanceID: 0} userData: assetBundleName: diff --git a/Assets/Scripts/Game/UserInterface/DaggerfallFont.cs b/Assets/Scripts/Game/UserInterface/DaggerfallFont.cs index d651a66af1..653215ba34 100644 --- a/Assets/Scripts/Game/UserInterface/DaggerfallFont.cs +++ b/Assets/Scripts/Game/UserInterface/DaggerfallFont.cs @@ -16,6 +16,7 @@ using System.Text; using DaggerfallConnect; using DaggerfallConnect.Arena2; +using DaggerfallWorkshop.Game.Utility.ModSupport; using DaggerfallWorkshop.Utility; using TMPro; @@ -265,6 +266,7 @@ public float DrawSDFGlyph(SDFGlyphInfo glyph, Vector2 position, Vector2 scale, C { Graphics.DrawTexture(targetRect, sdfFontInfo.Value.atlasTexture, glyph.rect, 0, 0, 0, 0, color, DaggerfallUI.Instance.SDFFontMaterial); } + return GetGlyphWidth(glyph, scale, GlyphSpacing); } @@ -640,10 +642,9 @@ float GetGlyphSpacing() } /// - /// Replace TMP font asset using a .ttf or .otf font in StreamingAssets/Fonts. - /// TODO: Support loading font file from .dfmod. + /// Replace TMP font asset using a .ttf or .otf font in StreamingAssets/Fonts or in dfmod asset /// - /// Filename of replacement font including .ttf extension. Font file must be present in StreamingAssets/Fonts to load. + /// Filename of replacement font including .ttf extension. Font file must be present in StreamingAssets/Fonts or in dfmod asset to load. /// Source TMP font for initial character table population. /// Replacement TMP font output. /// True is successfully created replacement TMP font. @@ -651,22 +652,48 @@ bool ReplaceTMPFontFromFile(string filename, TMP_FontAsset source, out TMP_FontA { const string ttfExt = ".ttf"; const string otfExt = ".otf"; + replacement = null; + + Font otfFontFromMods = null; + Font ttfFontFromMods = null; + + // Seek font replacement file from mods + if (ModManager.Instance != null) + { + if (!ModManager.Instance.TryGetAsset(filename + otfExt, false, out otfFontFromMods)) + { + ModManager.Instance.TryGetAsset(filename + ttfExt, false, out ttfFontFromMods); + } + } + + if (otfFontFromMods != null) + { + replacement = TMP_FontAsset.CreateFontAsset(otfFontFromMods, 45, 6, UnityEngine.TextCore.LowLevel.GlyphRenderMode.SDFAA, 4096, 4096, AtlasPopulationMode.Dynamic); + } + else if (ttfFontFromMods != null) + { + replacement = TMP_FontAsset.CreateFontAsset(ttfFontFromMods, 45, 6, UnityEngine.TextCore.LowLevel.GlyphRenderMode.SDFAA, 4096, 4096, AtlasPopulationMode.Dynamic); + } // Compose path to font file - string path = Path.Combine(Application.streamingAssetsPath, "Fonts", filename); + var path = Path.Combine(Application.streamingAssetsPath, "Fonts", filename); - // Check file exists - replacement = null; - if (File.Exists(path + ttfExt)) - path += ttfExt; - else if (File.Exists(path + otfExt)) - path += otfExt; - else - return false; + if (replacement == null) + { + // Check file exists + replacement = null; + if (File.Exists(path + ttfExt)) + path += ttfExt; + else if (File.Exists(path + otfExt)) + path += otfExt; + else + return false; + + // Create replacement TMP font asset from path + Font replacementFont = new Font(path); + replacement = TMP_FontAsset.CreateFontAsset(replacementFont, 45, 6, UnityEngine.TextCore.LowLevel.GlyphRenderMode.SDFAA, 4096, 4096, AtlasPopulationMode.Dynamic); + } - // Create replacement TMP font asset from path - Font font = new Font(path); - replacement = TMP_FontAsset.CreateFontAsset(font, 45, 6, UnityEngine.TextCore.LowLevel.GlyphRenderMode.SDFAA, 4096, 4096, AtlasPopulationMode.Dynamic); if (replacement == null) return false;