mirror of
https://github.com/drewcassidy/KSP-Conformal-Decals.git
synced 2024-09-01 18:23:54 +00:00
Compare commits
7 Commits
ac1289a46e
...
8accabe9e5
Author | SHA1 | Date | |
---|---|---|---|
8accabe9e5 | |||
981a167864 | |||
d4978b1b3c | |||
c42e443b4b | |||
a6e2edc475 | |||
e82b02b0e5 | |||
ea8c069d68 |
5
GameData/ConformalDecals/Patches/FAR.cfg
Normal file
5
GameData/ConformalDecals/Patches/FAR.cfg
Normal 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] {}
|
||||
}
|
Binary file not shown.
@ -21,8 +21,6 @@ CONFORMALDECALS {
|
||||
shader = Solid Color (Alpha)
|
||||
}
|
||||
|
||||
fallbackFont = NotoSans-Regular SDF
|
||||
|
||||
FONT {
|
||||
name = LiberationSans SDF
|
||||
title = Liberation Sans
|
||||
|
@ -6,7 +6,7 @@
|
||||
{
|
||||
"MAJOR":0,
|
||||
"MINOR":2,
|
||||
"PATCH":2,
|
||||
"PATCH":3,
|
||||
"BUILD":0
|
||||
},
|
||||
"KSP_VERSION":
|
||||
|
@ -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)
|
||||
|
||||
![Screenshot](http://pileof.rocks/KSP/images/ConformalDecalsHeader.png)
|
||||
|
@ -13,7 +13,6 @@ 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;
|
||||
@ -52,7 +51,7 @@ namespace ConformalDecals {
|
||||
|
||||
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) {
|
||||
return IsBlacklisted(shader.name);
|
||||
@ -95,27 +94,14 @@ 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 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);
|
||||
var font = new DecalFont(fontNode, allFonts);
|
||||
_fontList.Add(font.Name, font);
|
||||
}
|
||||
catch (Exception e) {
|
||||
Logging.LogException($"Exception parsing font node:\n{fontNode.ToString()}\n", e);
|
||||
Debug.LogException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.Collections;
|
||||
using System.Net;
|
||||
using ConformalDecals.MaterialProperties;
|
||||
using ConformalDecals.Text;
|
||||
using ConformalDecals.UI;
|
||||
@ -27,7 +28,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();
|
||||
@ -75,6 +76,7 @@ namespace ConformalDecals {
|
||||
}
|
||||
}
|
||||
|
||||
private string _text;
|
||||
private DecalTextStyle _style;
|
||||
private DecalFont _font;
|
||||
private Color32 _fillColor;
|
||||
@ -130,7 +132,7 @@ namespace ConformalDecals {
|
||||
}
|
||||
|
||||
public void OnTextUpdate(string newText, DecalFont newFont, DecalTextStyle newStyle) {
|
||||
text = newText;
|
||||
_text = newText;
|
||||
_font = newFont;
|
||||
_style = newStyle;
|
||||
UpdateTextRecursive();
|
||||
@ -201,6 +203,7 @@ namespace ConformalDecals {
|
||||
}
|
||||
|
||||
public void OnBeforeSerialize() {
|
||||
text = WebUtility.UrlEncode(_text);
|
||||
fontName = _font.Name;
|
||||
style = (int) _style.FontStyle;
|
||||
vertical = _style.Vertical;
|
||||
@ -211,6 +214,7 @@ namespace ConformalDecals {
|
||||
}
|
||||
|
||||
public void OnAfterDeserialize() {
|
||||
_text = WebUtility.UrlDecode(text);
|
||||
_font = DecalConfig.GetFont(fontName);
|
||||
_style = new DecalTextStyle((FontStyles) style, vertical, lineSpacing, charSpacing);
|
||||
|
||||
@ -245,7 +249,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;
|
||||
|
||||
@ -262,7 +266,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;
|
||||
|
||||
|
@ -40,15 +40,19 @@ namespace ConformalDecals.Text {
|
||||
public bool SmallCapsMask => (FontStyleMask & FontStyles.SmallCaps) != 0;
|
||||
|
||||
|
||||
public DecalFont(string name, ConfigNode node, TMP_FontAsset font) {
|
||||
if (name == null) throw new ArgumentNullException(nameof(name));
|
||||
public DecalFont(ConfigNode node, IEnumerable<TMP_FontAsset> fontAssets) {
|
||||
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);
|
||||
FontStyle = (FontStyles) ParseUtil.ParseInt(node, "style", true);
|
||||
FontStyleMask = (FontStyles) ParseUtil.ParseInt(node, "styleMask", true);
|
||||
FontAsset = font;
|
||||
}
|
||||
|
||||
|
||||
|
@ -11,13 +11,12 @@ namespace ConformalDecals.Text {
|
||||
[DatabaseLoaderAttrib(new[] {"decalfont"})]
|
||||
public class FontLoader : DatabaseLoader<GameDatabase.TextureInfo> {
|
||||
private const string FallbackName = "NotoSans-Regular SDF";
|
||||
|
||||
public static TMP_FontAsset FallbackFont { get; private set; }
|
||||
private static TMP_FontAsset _fallbackFont;
|
||||
|
||||
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}'");
|
||||
@ -29,7 +28,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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,9 +89,11 @@ 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.");
|
||||
}
|
||||
@ -205,6 +207,9 @@ 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)
|
||||
@ -278,8 +283,11 @@ namespace ConformalDecals.Text {
|
||||
RenderTexture.ReleaseTemporary(renderTex);
|
||||
|
||||
// CLEAR SUBMESHES
|
||||
_tmp.text = "";
|
||||
|
||||
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);
|
||||
|
@ -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
|
||||
------
|
||||
- Fixes:
|
||||
|
Loading…
Reference in New Issue
Block a user