|
16 | 16 | using System.Text;
|
17 | 17 | using DaggerfallConnect;
|
18 | 18 | using DaggerfallConnect.Arena2;
|
| 19 | +using DaggerfallWorkshop.Game.Utility.ModSupport; |
19 | 20 | using DaggerfallWorkshop.Utility;
|
20 | 21 | using TMPro;
|
21 | 22 |
|
@@ -265,6 +266,7 @@ public float DrawSDFGlyph(SDFGlyphInfo glyph, Vector2 position, Vector2 scale, C
|
265 | 266 | {
|
266 | 267 | Graphics.DrawTexture(targetRect, sdfFontInfo.Value.atlasTexture, glyph.rect, 0, 0, 0, 0, color, DaggerfallUI.Instance.SDFFontMaterial);
|
267 | 268 | }
|
| 269 | + |
268 | 270 | return GetGlyphWidth(glyph, scale, GlyphSpacing);
|
269 | 271 | }
|
270 | 272 |
|
@@ -640,33 +642,58 @@ float GetGlyphSpacing()
|
640 | 642 | }
|
641 | 643 |
|
642 | 644 | /// <summary>
|
643 |
| - /// Replace TMP font asset using a .ttf or .otf font in StreamingAssets/Fonts. |
644 |
| - /// TODO: Support loading font file from .dfmod. |
| 645 | + /// Replace TMP font asset using a .ttf or .otf font in StreamingAssets/Fonts or in dfmod asset |
645 | 646 | /// </summary>
|
646 |
| - /// <param name="filename">Filename of replacement font including .ttf extension. Font file must be present in StreamingAssets/Fonts to load.</param> |
| 647 | + /// <param name="filename">Filename of replacement font including .ttf extension. Font file must be present in StreamingAssets/Fonts or in dfmod asset to load.</param> |
647 | 648 | /// <param name="source">Source TMP font for initial character table population.</param>
|
648 | 649 | /// <param name="replacement">Replacement TMP font output.</param>
|
649 | 650 | /// <returns>True is successfully created replacement TMP font.</returns>
|
650 | 651 | bool ReplaceTMPFontFromFile(string filename, TMP_FontAsset source, out TMP_FontAsset replacement)
|
651 | 652 | {
|
652 | 653 | const string ttfExt = ".ttf";
|
653 | 654 | const string otfExt = ".otf";
|
| 655 | + replacement = null; |
| 656 | + |
| 657 | + Font otfFontFromMods = null; |
| 658 | + Font ttfFontFromMods = null; |
| 659 | + |
| 660 | + // Seek font replacement file from mods |
| 661 | + if (ModManager.Instance != null) |
| 662 | + { |
| 663 | + if (!ModManager.Instance.TryGetAsset(filename + otfExt, false, out otfFontFromMods)) |
| 664 | + { |
| 665 | + ModManager.Instance.TryGetAsset(filename + ttfExt, false, out ttfFontFromMods); |
| 666 | + } |
| 667 | + } |
| 668 | + |
| 669 | + if (otfFontFromMods != null) |
| 670 | + { |
| 671 | + replacement = TMP_FontAsset.CreateFontAsset(otfFontFromMods, 45, 6, UnityEngine.TextCore.LowLevel.GlyphRenderMode.SDFAA, 4096, 4096, AtlasPopulationMode.Dynamic); |
| 672 | + } |
| 673 | + else if (ttfFontFromMods != null) |
| 674 | + { |
| 675 | + replacement = TMP_FontAsset.CreateFontAsset(ttfFontFromMods, 45, 6, UnityEngine.TextCore.LowLevel.GlyphRenderMode.SDFAA, 4096, 4096, AtlasPopulationMode.Dynamic); |
| 676 | + } |
654 | 677 |
|
655 | 678 | // Compose path to font file
|
656 |
| - string path = Path.Combine(Application.streamingAssetsPath, "Fonts", filename); |
| 679 | + var path = Path.Combine(Application.streamingAssetsPath, "Fonts", filename); |
657 | 680 |
|
658 |
| - // Check file exists |
659 |
| - replacement = null; |
660 |
| - if (File.Exists(path + ttfExt)) |
661 |
| - path += ttfExt; |
662 |
| - else if (File.Exists(path + otfExt)) |
663 |
| - path += otfExt; |
664 |
| - else |
665 |
| - return false; |
| 681 | + if (replacement == null) |
| 682 | + { |
| 683 | + // Check file exists |
| 684 | + replacement = null; |
| 685 | + if (File.Exists(path + ttfExt)) |
| 686 | + path += ttfExt; |
| 687 | + else if (File.Exists(path + otfExt)) |
| 688 | + path += otfExt; |
| 689 | + else |
| 690 | + return false; |
| 691 | + |
| 692 | + // Create replacement TMP font asset from path |
| 693 | + Font replacementFont = new Font(path); |
| 694 | + replacement = TMP_FontAsset.CreateFontAsset(replacementFont, 45, 6, UnityEngine.TextCore.LowLevel.GlyphRenderMode.SDFAA, 4096, 4096, AtlasPopulationMode.Dynamic); |
| 695 | + } |
666 | 696 |
|
667 |
| - // Create replacement TMP font asset from path |
668 |
| - Font font = new Font(path); |
669 |
| - replacement = TMP_FontAsset.CreateFontAsset(font, 45, 6, UnityEngine.TextCore.LowLevel.GlyphRenderMode.SDFAA, 4096, 4096, AtlasPopulationMode.Dynamic); |
670 | 697 | if (replacement == null)
|
671 | 698 | return false;
|
672 | 699 |
|
|
0 commit comments