Compare commits

..

No commits in common. "8accabe9e5a000f4e64083649ddf8b69ab51318b" and "ac1289a46ef44fa135c4252cdb0479cf3831fcbc" have entirely different histories.

11 changed files with 39 additions and 51 deletions

View File

@ -1,5 +0,0 @@
@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,6 +21,8 @@ CONFORMALDECALS {
shader = Solid Color (Alpha)
}
fallbackFont = NotoSans-Regular SDF
FONT {
name = LiberationSans SDF
title = Liberation Sans

View File

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

View File

@ -1,4 +1,4 @@
# Conformal Decals v0.2.3
# Conformal Decals v0.2.2
[![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)

View File

@ -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);
@ -92,16 +93,29 @@ namespace ConformalDecals {
_shaderBlacklist.Add(shaderName);
}
}
var allFonts = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
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);
}
}
}

View File

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

View File

@ -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;
}

View File

@ -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);
}
}

View File

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

View File

@ -1,11 +1,3 @@
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
------
- Fixes: