mirror of
https://github.com/drewcassidy/KSP-Conformal-Decals.git
synced 2024-09-01 18:23:54 +00:00
Fix overlapping text and add text escaping
This commit is contained in:
parent
ea8c069d68
commit
e82b02b0e5
Binary file not shown.
@ -91,6 +91,7 @@
|
|||||||
<Compile Include="Text/TextRenderer.cs" />
|
<Compile Include="Text/TextRenderer.cs" />
|
||||||
<Compile Include="Text/DecalText.cs" />
|
<Compile Include="Text/DecalText.cs" />
|
||||||
<Compile Include="Text\DecalTextStyle.cs" />
|
<Compile Include="Text\DecalTextStyle.cs" />
|
||||||
|
<Compile Include="Text\TextEncoder.cs" />
|
||||||
<Compile Include="Text\TextRenderOutput.cs" />
|
<Compile Include="Text\TextRenderOutput.cs" />
|
||||||
<Compile Include="Text\TextRenderJob.cs" />
|
<Compile Include="Text\TextRenderJob.cs" />
|
||||||
<Compile Include="UI/ColorPickerController.cs" />
|
<Compile Include="UI/ColorPickerController.cs" />
|
||||||
|
@ -99,6 +99,7 @@ namespace ConformalDecals {
|
|||||||
public override void OnLoad(ConfigNode node) {
|
public override void OnLoad(ConfigNode node) {
|
||||||
base.OnLoad(node);
|
base.OnLoad(node);
|
||||||
OnAfterDeserialize();
|
OnAfterDeserialize();
|
||||||
|
text = TextEncoder.Decode(text);
|
||||||
|
|
||||||
if (HighLogic.LoadedSceneIsGame) {
|
if (HighLogic.LoadedSceneIsGame) {
|
||||||
// For some reason, rendering doesnt work right on the first frame a scene is loaded
|
// For some reason, rendering doesnt work right on the first frame a scene is loaded
|
||||||
@ -112,6 +113,7 @@ namespace ConformalDecals {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override void OnSave(ConfigNode node) {
|
public override void OnSave(ConfigNode node) {
|
||||||
|
text = TextEncoder.Encode(text);
|
||||||
OnBeforeSerialize();
|
OnBeforeSerialize();
|
||||||
base.OnSave(node);
|
base.OnSave(node);
|
||||||
}
|
}
|
||||||
|
31
Source/ConformalDecals/Text/TextEncoder.cs
Normal file
31
Source/ConformalDecals/Text/TextEncoder.cs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace ConformalDecals.Text {
|
||||||
|
public static class TextEncoder {
|
||||||
|
private static readonly Dictionary<string, string> _escapeSequences = new Dictionary<string, string>() {
|
||||||
|
{"\n", "\\n"},
|
||||||
|
{"\\", "\\\\"},
|
||||||
|
{"/", "\\/"},
|
||||||
|
{"=", "\\="}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static string Encode(string input) {
|
||||||
|
var builder = new StringBuilder(input);
|
||||||
|
foreach (var escapePair in _escapeSequences) {
|
||||||
|
builder.Replace(escapePair.Key, escapePair.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string Decode(string input) {
|
||||||
|
var builder = new StringBuilder(input);
|
||||||
|
foreach (var escapePair in _escapeSequences) {
|
||||||
|
builder.Replace(escapePair.Value, escapePair.Key);
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -280,25 +280,13 @@ 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++) {
|
||||||
var child = transform.GetChild(i);
|
var child = transform.GetChild(i);
|
||||||
var renderer = child.GetComponent<MeshRenderer>();
|
|
||||||
var filter = child.GetComponent<MeshFilter>();
|
|
||||||
if (filter == null || renderer == null) {
|
|
||||||
Logging.Log("TMP Sub object has no filter or renderer, destroying");
|
|
||||||
Destroy(child.gameObject);
|
Destroy(child.gameObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filter.mesh.vertexCount < 3) {
|
|
||||||
Logging.Log("TMP Sub object has no mesh, destroying");
|
|
||||||
Destroy(child.gameObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
renderer.enabled = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
_tmp.ClearMesh(true);
|
|
||||||
|
|
||||||
return new TextRenderOutput(texture, window);
|
return new TextRenderOutput(texture, window);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user