mirror of
https://github.com/drewcassidy/KSP-Conformal-Decals.git
synced 2024-09-01 18:23:54 +00:00
Add fallbacks to all fonts, even squad ones
This commit is contained in:
parent
16ef53ea65
commit
ac1289a46e
Binary file not shown.
@ -21,6 +21,8 @@ CONFORMALDECALS {
|
||||
shader = Solid Color (Alpha)
|
||||
}
|
||||
|
||||
fallbackFont = NotoSans-Regular SDF
|
||||
|
||||
FONT {
|
||||
name = LiberationSans SDF
|
||||
title = Liberation Sans
|
||||
|
@ -13,6 +13,7 @@ namespace ConformalDecals {
|
||||
private static Dictionary<string, DecalFont> _fontList;
|
||||
private static int _decalLayer = 31;
|
||||
private static bool _selectableInFlight;
|
||||
private static string _fallbackFontName = "NotoSans-Regular SDF";
|
||||
|
||||
private struct LegacyShaderEntry {
|
||||
public string name;
|
||||
@ -50,8 +51,8 @@ namespace ConformalDecals {
|
||||
public static bool SelectableInFlight => _selectableInFlight;
|
||||
|
||||
public static IEnumerable<DecalFont> Fonts => _fontList.Values;
|
||||
|
||||
public static DecalFont FallbackFont { get; private set; }
|
||||
|
||||
public static TMP_FontAsset FallbackFont { get; private set; }
|
||||
|
||||
public static bool IsBlacklisted(Shader shader) {
|
||||
return IsBlacklisted(shader.name);
|
||||
@ -94,14 +95,27 @@ namespace ConformalDecals {
|
||||
}
|
||||
|
||||
var allFonts = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
|
||||
|
||||
ParseUtil.ParseStringIndirect(ref _fallbackFontName, node, "fallbackFont");
|
||||
FallbackFont = allFonts.First(o => o.name == _fallbackFontName);
|
||||
if (FallbackFont == null) Logging.LogError($"could not find find fallback font asset named {_fallbackFontName}");
|
||||
|
||||
foreach (var fontNode in node.GetNodes("FONT")) {
|
||||
try {
|
||||
var font = new DecalFont(fontNode, allFonts);
|
||||
var name = ParseUtil.ParseString(fontNode, "name");
|
||||
if (string.IsNullOrEmpty(name)) throw new FormatException();
|
||||
|
||||
var fontAsset = allFonts.First(o => o.name == name);
|
||||
if (fontAsset == null) throw new FormatException($"Could not find font asset named {name}");
|
||||
|
||||
if (!fontAsset.fallbackFontAssets.Contains(FallbackFont)) {
|
||||
fontAsset.fallbackFontAssets.Add(FallbackFont);
|
||||
}
|
||||
|
||||
var font = new DecalFont(name, fontNode, fontAsset);
|
||||
_fontList.Add(font.Name, font);
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.LogException(e);
|
||||
Logging.LogException($"Exception parsing font node:\n{fontNode.ToString()}\n", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,19 +40,15 @@ namespace ConformalDecals.Text {
|
||||
public bool SmallCapsMask => (FontStyleMask & FontStyles.SmallCaps) != 0;
|
||||
|
||||
|
||||
public DecalFont(ConfigNode node, IEnumerable<TMP_FontAsset> fontAssets) {
|
||||
public DecalFont(string name, ConfigNode node, TMP_FontAsset font) {
|
||||
if (name == null) throw new ArgumentNullException(nameof(name));
|
||||
if (node == null) throw new ArgumentNullException(nameof(node));
|
||||
if (fontAssets == null) throw new ArgumentNullException(nameof(fontAssets));
|
||||
|
||||
var name = ParseUtil.ParseString(node, "name");
|
||||
FontAsset = fontAssets.First(o => o.name == name);
|
||||
if (FontAsset == null) {
|
||||
throw new FormatException($"Could not find font asset named {name}");
|
||||
}
|
||||
if (font == null) throw new ArgumentNullException(nameof(font));
|
||||
|
||||
Title = ParseUtil.ParseString(node, "title", true, name);
|
||||
FontStyle = (FontStyles) ParseUtil.ParseInt(node, "style", true);
|
||||
FontStyleMask = (FontStyles) ParseUtil.ParseInt(node, "styleMask", true);
|
||||
FontAsset = font;
|
||||
}
|
||||
|
||||
|
||||
|
@ -11,12 +11,13 @@ namespace ConformalDecals.Text {
|
||||
[DatabaseLoaderAttrib(new[] {"decalfont"})]
|
||||
public class FontLoader : DatabaseLoader<GameDatabase.TextureInfo> {
|
||||
private const string FallbackName = "NotoSans-Regular SDF";
|
||||
private static TMP_FontAsset _fallbackFont;
|
||||
|
||||
public static TMP_FontAsset FallbackFont { get; private set; }
|
||||
|
||||
public override IEnumerator Load(UrlDir.UrlFile urlFile, FileInfo fileInfo) {
|
||||
if (_fallbackFont == null) {
|
||||
_fallbackFont = Resources.FindObjectsOfTypeAll<TMP_FontAsset>().First(o => o.name == FallbackName);
|
||||
if (_fallbackFont == null) Logging.LogError($"Could not find fallback font '{FallbackName}'");
|
||||
if (FallbackFont == null) {
|
||||
FallbackFont = Resources.FindObjectsOfTypeAll<TMP_FontAsset>().First(o => o.name == FallbackName);
|
||||
if (FallbackFont == null) Logging.LogError($"Could not find fallback font '{FallbackName}'");
|
||||
}
|
||||
|
||||
Logging.Log($"Loading font file '{urlFile.fullPath}'");
|
||||
@ -28,7 +29,7 @@ namespace ConformalDecals.Text {
|
||||
var loadedFonts = bundle.LoadAllAssets<TMP_FontAsset>();
|
||||
foreach (var font in loadedFonts) {
|
||||
Logging.Log($"Adding font {font.name}");
|
||||
font.fallbackFontAssets.Add(_fallbackFont);
|
||||
font.fallbackFontAssets.Add(FallbackFont);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user