diff --git a/GameData/ConformalDecals/Plugins/ConformalDecals.dll b/GameData/ConformalDecals/Plugins/ConformalDecals.dll
index ff5f0d4..75f17c6 100644
Binary files a/GameData/ConformalDecals/Plugins/ConformalDecals.dll and b/GameData/ConformalDecals/Plugins/ConformalDecals.dll differ
diff --git a/Source/ConformalDecals/ConformalDecals.csproj b/Source/ConformalDecals/ConformalDecals.csproj
index 6d11eb6..633ca50 100644
--- a/Source/ConformalDecals/ConformalDecals.csproj
+++ b/Source/ConformalDecals/ConformalDecals.csproj
@@ -104,6 +104,7 @@
+
diff --git a/Source/ConformalDecals/ModuleConformalText.cs b/Source/ConformalDecals/ModuleConformalText.cs
index baca9ea..3b8e5d2 100644
--- a/Source/ConformalDecals/ModuleConformalText.cs
+++ b/Source/ConformalDecals/ModuleConformalText.cs
@@ -1,14 +1,13 @@
using ConformalDecals.MaterialProperties;
using ConformalDecals.Text;
using ConformalDecals.UI;
+using ConformalDecals.Util;
using TMPro;
using UnityEngine;
namespace ConformalDecals {
public class ModuleConformalText : ModuleConformalDecal, ISerializationCallbackReceiver {
- [KSPField(isPersistant = true)] public string text = "Text";
- [KSPField(isPersistant = true)] public Color fillColor = Color.black;
- [KSPField(isPersistant = true)] public Color outlineColor = Color.white;
+ [KSPField(isPersistant = true)] public string text = "Text";
[KSPField] public Vector2 lineSpacingRange = new Vector2(-50, 50);
[KSPField] public Vector2 charSpacingRange = new Vector2(-50, 50);
@@ -19,6 +18,8 @@ namespace ConformalDecals {
[KSPField(isPersistant = true)] public bool vertical;
[KSPField(isPersistant = true)] public float lineSpacing;
[KSPField(isPersistant = true)] public float charSpacing;
+ [KSPField(isPersistant = true)] public string fillColor = "000000FF";
+ [KSPField(isPersistant = true)] public string outlineColor = "FFFFFFFF";
// KSP TWEAKABLES
@@ -43,7 +44,7 @@ namespace ConformalDecals {
guiActive = false, guiActiveEditor = true)]
public void SetFillColor() {
if (_fillColorPickerController == null) {
- _fillColorPickerController = ColorPickerController.Create(fillColor, OnFillColorUpdate);
+ _fillColorPickerController = ColorPickerController.Create(_fillColor, OnFillColorUpdate);
}
else {
_fillColorPickerController.Close();
@@ -66,7 +67,7 @@ namespace ConformalDecals {
guiActive = false, guiActiveEditor = true)]
public void SetOutlineColor() {
if (_outlineColorPickerController == null) {
- _outlineColorPickerController = ColorPickerController.Create(outlineColor, OnOutlineColorUpdate);
+ _outlineColorPickerController = ColorPickerController.Create(_outlineColor, OnOutlineColorUpdate);
}
else {
_outlineColorPickerController.Close();
@@ -75,6 +76,8 @@ namespace ConformalDecals {
private DecalTextStyle _style;
private DecalFont _font;
+ private Color32 _fillColor;
+ private Color32 _outlineColor;
private TextEntryController _textEntryController;
private ColorPickerController _fillColorPickerController;
@@ -131,23 +134,23 @@ namespace ConformalDecals {
}
public void OnFillColorUpdate(Color rgb, Util.ColorHSV hsv) {
- fillColor = rgb;
+ _fillColor = rgb;
UpdateMaterials();
foreach (var counterpart in part.symmetryCounterparts) {
var decal = counterpart.GetComponent();
- decal.fillColor = fillColor;
+ decal._fillColor = _fillColor;
decal.UpdateMaterials();
}
}
public void OnOutlineColorUpdate(Color rgb, Util.ColorHSV hsv) {
- outlineColor = rgb;
+ _outlineColor = rgb;
UpdateMaterials();
foreach (var counterpart in part.symmetryCounterparts) {
var decal = counterpart.GetComponent();
- decal.outlineColor = outlineColor;
+ decal._outlineColor = _outlineColor;
decal.UpdateMaterials();
}
}
@@ -200,11 +203,23 @@ namespace ConformalDecals {
vertical = _style.Vertical;
lineSpacing = _style.LineSpacing;
charSpacing = _style.CharSpacing;
+ fillColor = _fillColor.ToHexString();
+ outlineColor = _outlineColor.ToHexString();
}
public void OnAfterDeserialize() {
_font = DecalConfig.GetFont(fontName);
_style = new DecalTextStyle((FontStyles) style, vertical, lineSpacing, charSpacing);
+
+ if (!ParseUtil.TryParseColor32(fillColor, out _fillColor)) {
+ Logging.LogWarning($"Improperly formatted color value for fill: '{fillColor}'");
+ _fillColor = Color.magenta;
+ }
+
+ if (!ParseUtil.TryParseColor32(outlineColor, out _outlineColor)) {
+ Logging.LogWarning($"Improperly formatted color value for outline: '{outlineColor}'");
+ _outlineColor = Color.magenta;
+ }
}
public override void OnDestroy() {
@@ -261,10 +276,10 @@ namespace ConformalDecals {
protected override void UpdateMaterials() {
_fillEnabledProperty.value = fillEnabled;
- _fillColorProperty.color = fillColor;
+ _fillColorProperty.color = _fillColor;
_outlineEnabledProperty.value = outlineEnabled;
- _outlineColorProperty.color = outlineColor;
+ _outlineColorProperty.color = _outlineColor;
_outlineWidthProperty.value = outlineWidth;
base.UpdateMaterials();
diff --git a/Source/ConformalDecals/Util/ColorUtil.cs b/Source/ConformalDecals/Util/ColorUtil.cs
new file mode 100644
index 0000000..0ef1403
--- /dev/null
+++ b/Source/ConformalDecals/Util/ColorUtil.cs
@@ -0,0 +1,22 @@
+using UnityEngine;
+
+namespace ConformalDecals.Util {
+ public static class ColorUtil {
+ /// Returns an RGBA 32-bit hex string
+ public static string ToHexString(this Color32 color) {
+ return $"#{color.r:x2}{color.g:x2}{color.b:x2}{color.a:x2}";
+ }
+
+ // Returns an RGBA 32-bit unsigned integer representation of the color
+ public static uint ToUint(this Color32 color) {
+ uint rgba = color.r;
+ rgba <<= 8;
+ rgba |= color.g;
+ rgba <<= 8;
+ rgba |= color.b;
+ rgba <<= 8;
+ rgba |= color.a;
+ return rgba;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Source/ConformalDecals/Util/ParseUtil.cs b/Source/ConformalDecals/Util/ParseUtil.cs
index 1e02b06..5a712c7 100644
--- a/Source/ConformalDecals/Util/ParseUtil.cs
+++ b/Source/ConformalDecals/Util/ParseUtil.cs
@@ -142,7 +142,7 @@ namespace ConformalDecals.Util {
public static bool TryParseHexColor(string valueString, out Color32 value) {
value = new Color32(0, 0, 0, byte.MaxValue);
- if (!int.TryParse(valueString, System.Globalization.NumberStyles.HexNumber, null, out var hexColor)) return false;
+ if (!uint.TryParse(valueString, System.Globalization.NumberStyles.HexNumber, null, out var hexColor)) return false;
switch (valueString.Length) {
case 8: // RRGGBBAA
@@ -216,7 +216,14 @@ namespace ConformalDecals.Util {
value.g = (byte) (green * 0xFF);
value.b = (byte) (blue * 0xFF);
return true;
-
+ case 1: // try again for hex color
+ if (TryParseHexColor(split[0], out var hexcolor)) {
+ value = hexcolor;
+ return true;
+ }
+ else {
+ return false;
+ }
default:
return false;
}