Compare commits

..

7 Commits

Author SHA1 Message Date
8accabe9e5 Fix FAR incompatability 2020-11-13 02:22:56 -08:00
981a167864 Revert "Add fallbacks to all fonts, even squad ones"
This reverts commit ac1289a46e.
2020-11-13 01:55:42 -08:00
d4978b1b3c Update changelog 2020-11-13 01:44:52 -08:00
c42e443b4b Add minimum size for text decals 2020-11-13 01:43:08 -08:00
a6e2edc475 use URL-style string escaping 2020-11-13 01:42:55 -08:00
e82b02b0e5 Fix overlapping text and add text escaping 2020-11-12 21:25:24 -08:00
ea8c069d68 Fix issues with fallback fonts
Fixed TMP subobjects being deleted, causing fallback fonts to fail in some situations.
closes #24
2020-11-12 20:10:40 -08:00
11 changed files with 51 additions and 39 deletions

View File

@ -0,0 +1,5 @@
@PART[*]:HAS[@MODULE[ModuleConformalDecal]|@MODULE[ModuleConformalFlag]|@MODULE[ModuleConformalText]]:After[FerramAerospaceResearch]
{
// Decals are just paint, so they shouldnt affect a vessel's aerodynamics at all
!MODULE[GeometryPartModule] {}
}

View File

@ -21,8 +21,6 @@ CONFORMALDECALS {
shader = Solid Color (Alpha) shader = Solid Color (Alpha)
} }
fallbackFont = NotoSans-Regular SDF
FONT { FONT {
name = LiberationSans SDF name = LiberationSans SDF
title = Liberation Sans title = Liberation Sans

View File

@ -6,7 +6,7 @@
{ {
"MAJOR":0, "MAJOR":0,
"MINOR":2, "MINOR":2,
"PATCH":2, "PATCH":3,
"BUILD":0 "BUILD":0
}, },
"KSP_VERSION": "KSP_VERSION":

View File

@ -1,4 +1,4 @@
# Conformal Decals v0.2.2 # Conformal Decals v0.2.3
[![Build Status](https://travis-ci.org/drewcassidy/KSP-Conformal-Decals.svg?branch=release)](https://travis-ci.org/drewcassidy/KSP-Conformal-Decals) [![Art: CC BY-SA 4.0](https://img.shields.io/badge/Art%20License-CC%20BY--SA%204.0-orange.svg)](https://creativecommons.org/licenses/by-sa/4.0/) [![Code: GPL v3](https://img.shields.io/badge/Code%20License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) [![Build Status](https://travis-ci.org/drewcassidy/KSP-Conformal-Decals.svg?branch=release)](https://travis-ci.org/drewcassidy/KSP-Conformal-Decals) [![Art: CC BY-SA 4.0](https://img.shields.io/badge/Art%20License-CC%20BY--SA%204.0-orange.svg)](https://creativecommons.org/licenses/by-sa/4.0/) [![Code: GPL v3](https://img.shields.io/badge/Code%20License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
![Screenshot](http://pileof.rocks/KSP/images/ConformalDecalsHeader.png) ![Screenshot](http://pileof.rocks/KSP/images/ConformalDecalsHeader.png)

View File

@ -13,7 +13,6 @@ namespace ConformalDecals {
private static Dictionary<string, DecalFont> _fontList; private static Dictionary<string, DecalFont> _fontList;
private static int _decalLayer = 31; private static int _decalLayer = 31;
private static bool _selectableInFlight; private static bool _selectableInFlight;
private static string _fallbackFontName = "NotoSans-Regular SDF";
private struct LegacyShaderEntry { private struct LegacyShaderEntry {
public string name; public string name;
@ -51,8 +50,8 @@ namespace ConformalDecals {
public static bool SelectableInFlight => _selectableInFlight; public static bool SelectableInFlight => _selectableInFlight;
public static IEnumerable<DecalFont> Fonts => _fontList.Values; public static IEnumerable<DecalFont> Fonts => _fontList.Values;
public static TMP_FontAsset FallbackFont { get; private set; } public static DecalFont FallbackFont { get; private set; }
public static bool IsBlacklisted(Shader shader) { public static bool IsBlacklisted(Shader shader) {
return IsBlacklisted(shader.name); return IsBlacklisted(shader.name);
@ -93,29 +92,16 @@ namespace ConformalDecals {
_shaderBlacklist.Add(shaderName); _shaderBlacklist.Add(shaderName);
} }
} }
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}");
var allFonts = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
foreach (var fontNode in node.GetNodes("FONT")) { foreach (var fontNode in node.GetNodes("FONT")) {
try { try {
var name = ParseUtil.ParseString(fontNode, "name"); var font = new DecalFont(fontNode, allFonts);
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); _fontList.Add(font.Name, font);
} }
catch (Exception e) { catch (Exception e) {
Logging.LogException($"Exception parsing font node:\n{fontNode.ToString()}\n", e); Debug.LogException(e);
} }
} }
} }

View File

@ -1,4 +1,5 @@
using System.Collections; using System.Collections;
using System.Net;
using ConformalDecals.MaterialProperties; using ConformalDecals.MaterialProperties;
using ConformalDecals.Text; using ConformalDecals.Text;
using ConformalDecals.UI; using ConformalDecals.UI;
@ -27,7 +28,7 @@ namespace ConformalDecals {
[KSPEvent(guiName = "#LOC_ConformalDecals_gui-set-text", guiActive = false, guiActiveEditor = true)] [KSPEvent(guiName = "#LOC_ConformalDecals_gui-set-text", guiActive = false, guiActiveEditor = true)]
public void SetText() { public void SetText() {
if (_textEntryController == null) { if (_textEntryController == null) {
_textEntryController = TextEntryController.Create(text, _font, _style, lineSpacingRange, charSpacingRange, OnTextUpdate); _textEntryController = TextEntryController.Create(_text, _font, _style, lineSpacingRange, charSpacingRange, OnTextUpdate);
} }
else { else {
_textEntryController.Close(); _textEntryController.Close();
@ -75,6 +76,7 @@ namespace ConformalDecals {
} }
} }
private string _text;
private DecalTextStyle _style; private DecalTextStyle _style;
private DecalFont _font; private DecalFont _font;
private Color32 _fillColor; private Color32 _fillColor;
@ -130,7 +132,7 @@ namespace ConformalDecals {
} }
public void OnTextUpdate(string newText, DecalFont newFont, DecalTextStyle newStyle) { public void OnTextUpdate(string newText, DecalFont newFont, DecalTextStyle newStyle) {
text = newText; _text = newText;
_font = newFont; _font = newFont;
_style = newStyle; _style = newStyle;
UpdateTextRecursive(); UpdateTextRecursive();
@ -201,6 +203,7 @@ namespace ConformalDecals {
} }
public void OnBeforeSerialize() { public void OnBeforeSerialize() {
text = WebUtility.UrlEncode(_text);
fontName = _font.Name; fontName = _font.Name;
style = (int) _style.FontStyle; style = (int) _style.FontStyle;
vertical = _style.Vertical; vertical = _style.Vertical;
@ -211,6 +214,7 @@ namespace ConformalDecals {
} }
public void OnAfterDeserialize() { public void OnAfterDeserialize() {
_text = WebUtility.UrlDecode(text);
_font = DecalConfig.GetFont(fontName); _font = DecalConfig.GetFont(fontName);
_style = new DecalTextStyle((FontStyles) style, vertical, lineSpacing, charSpacing); _style = new DecalTextStyle((FontStyles) style, vertical, lineSpacing, charSpacing);
@ -245,7 +249,7 @@ namespace ConformalDecals {
foreach (var counterpart in part.symmetryCounterparts) { foreach (var counterpart in part.symmetryCounterparts) {
var decal = counterpart.GetComponent<ModuleConformalText>(); var decal = counterpart.GetComponent<ModuleConformalText>();
decal.text = text; decal._text = _text;
decal._font = _font; decal._font = _font;
decal._style = _style; decal._style = _style;
@ -262,7 +266,7 @@ namespace ConformalDecals {
private void UpdateText() { private void UpdateText() {
// Render text // Render text
var newText = new DecalText(text, _font, _style); var newText = new DecalText(_text, _font, _style);
var output = TextRenderer.UpdateTextNow(_currentText, newText); var output = TextRenderer.UpdateTextNow(_currentText, newText);
_currentText = newText; _currentText = newText;

View File

@ -40,15 +40,19 @@ namespace ConformalDecals.Text {
public bool SmallCapsMask => (FontStyleMask & FontStyles.SmallCaps) != 0; public bool SmallCapsMask => (FontStyleMask & FontStyles.SmallCaps) != 0;
public DecalFont(string name, ConfigNode node, TMP_FontAsset font) { public DecalFont(ConfigNode node, IEnumerable<TMP_FontAsset> fontAssets) {
if (name == null) throw new ArgumentNullException(nameof(name));
if (node == null) throw new ArgumentNullException(nameof(node)); if (node == null) throw new ArgumentNullException(nameof(node));
if (font == null) throw new ArgumentNullException(nameof(font)); 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}");
}
Title = ParseUtil.ParseString(node, "title", true, name); Title = ParseUtil.ParseString(node, "title", true, name);
FontStyle = (FontStyles) ParseUtil.ParseInt(node, "style", true); FontStyle = (FontStyles) ParseUtil.ParseInt(node, "style", true);
FontStyleMask = (FontStyles) ParseUtil.ParseInt(node, "styleMask", true); FontStyleMask = (FontStyles) ParseUtil.ParseInt(node, "styleMask", true);
FontAsset = font;
} }

View File

@ -11,13 +11,12 @@ namespace ConformalDecals.Text {
[DatabaseLoaderAttrib(new[] {"decalfont"})] [DatabaseLoaderAttrib(new[] {"decalfont"})]
public class FontLoader : DatabaseLoader<GameDatabase.TextureInfo> { public class FontLoader : DatabaseLoader<GameDatabase.TextureInfo> {
private const string FallbackName = "NotoSans-Regular SDF"; 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) { public override IEnumerator Load(UrlDir.UrlFile urlFile, FileInfo fileInfo) {
if (FallbackFont == null) { if (_fallbackFont == null) {
FallbackFont = Resources.FindObjectsOfTypeAll<TMP_FontAsset>().First(o => o.name == FallbackName); _fallbackFont = Resources.FindObjectsOfTypeAll<TMP_FontAsset>().First(o => o.name == FallbackName);
if (FallbackFont == null) Logging.LogError($"Could not find fallback font '{FallbackName}'"); if (_fallbackFont == null) Logging.LogError($"Could not find fallback font '{FallbackName}'");
} }
Logging.Log($"Loading font file '{urlFile.fullPath}'"); Logging.Log($"Loading font file '{urlFile.fullPath}'");
@ -29,7 +28,7 @@ namespace ConformalDecals.Text {
var loadedFonts = bundle.LoadAllAssets<TMP_FontAsset>(); var loadedFonts = bundle.LoadAllAssets<TMP_FontAsset>();
foreach (var font in loadedFonts) { foreach (var font in loadedFonts) {
Logging.Log($"Adding font {font.name}"); Logging.Log($"Adding font {font.name}");
font.fallbackFontAssets.Add(FallbackFont); font.fallbackFontAssets.Add(_fallbackFont);
} }
} }

View File

@ -89,9 +89,11 @@ namespace ConformalDecals.Text {
if (SystemInfo.graphicsDeviceType == GraphicsDeviceType.Direct3D11 || SystemInfo.graphicsDeviceType == GraphicsDeviceType.Direct3D12) { if (SystemInfo.graphicsDeviceType == GraphicsDeviceType.Direct3D11 || SystemInfo.graphicsDeviceType == GraphicsDeviceType.Direct3D12) {
textRenderTextureFormat = RenderTextureFormat.ARGB32; // DirectX is dumb textRenderTextureFormat = RenderTextureFormat.ARGB32; // DirectX is dumb
} }
if (!SystemInfo.SupportsTextureFormat(textTextureFormat)) { if (!SystemInfo.SupportsTextureFormat(textTextureFormat)) {
Logging.LogError($"Text texture format {textTextureFormat} not supported on this platform."); Logging.LogError($"Text texture format {textTextureFormat} not supported on this platform.");
} }
if (!SystemInfo.SupportsRenderTextureFormat(textRenderTextureFormat)) { if (!SystemInfo.SupportsRenderTextureFormat(textRenderTextureFormat)) {
Logging.LogError($"Text texture format {textRenderTextureFormat} not supported on this platform."); Logging.LogError($"Text texture format {textRenderTextureFormat} not supported on this platform.");
} }
@ -205,6 +207,9 @@ namespace ConformalDecals.Text {
// CALCULATE SIZES // CALCULATE SIZES
var size = bounds.size * PixelDensity; var size = bounds.size * PixelDensity;
size.x = Mathf.Max(size.x, 0.1f);
size.y = Mathf.Max(size.y, 0.1f);
var textureSize = new Vector2Int { var textureSize = new Vector2Int {
x = Mathf.NextPowerOfTwo((int) size.x), x = Mathf.NextPowerOfTwo((int) size.x),
y = Mathf.NextPowerOfTwo((int) size.y) y = Mathf.NextPowerOfTwo((int) size.y)
@ -278,8 +283,11 @@ namespace ConformalDecals.Text {
RenderTexture.ReleaseTemporary(renderTex); RenderTexture.ReleaseTemporary(renderTex);
// CLEAR SUBMESHES // CLEAR SUBMESHES
_tmp.text = "";
for (int i = 0; i < transform.childCount; i++) { for (int i = 0; i < transform.childCount; i++) {
Destroy(transform.GetChild(i).gameObject); var child = transform.GetChild(i);
Destroy(child.gameObject);
} }
return new TextRenderOutput(texture, window); return new TextRenderOutput(texture, window);

View File

@ -1,3 +1,11 @@
v0.2.3
------
- Fixes:
- Fixed TMP subobjects being deleted, causing fallback fonts to fail in some situations.
- Started using URL-style encoding for text decals behind the scenes to prevent issues with certain characters.
- Fixed text decals having zero size when they had only whitespace or an empty string
- Fixed decals having drag and causing issues when using FAR
v0.2.2 v0.2.2
------ ------
- Fixes: - Fixes: