diff --git a/Assets/Textures/Decal-Back.afdesign b/Assets/Textures/Decal-Back.afdesign new file mode 100644 index 0000000..d5f9cf6 Binary files /dev/null and b/Assets/Textures/Decal-Back.afdesign differ diff --git a/Assets/Textures/Icons Generic.afdesign b/Assets/Textures/Icons Generic.afdesign new file mode 100644 index 0000000..2f5b96e Binary files /dev/null and b/Assets/Textures/Icons Generic.afdesign differ diff --git a/Assets/Textures/Munar.afdesign b/Assets/Textures/Munar.afdesign new file mode 100644 index 0000000..0e4a5be Binary files /dev/null and b/Assets/Textures/Munar.afdesign differ diff --git a/Assets/Textures/Semiotic.afdesign b/Assets/Textures/Semiotic.afdesign new file mode 100644 index 0000000..bb99dcd Binary files /dev/null and b/Assets/Textures/Semiotic.afdesign differ diff --git a/Source/ConformalDecals/ModuleConformalDecal.cs b/Source/ConformalDecals/ModuleConformalDecal.cs index 5056dbb..fa4636b 100644 --- a/Source/ConformalDecals/ModuleConformalDecal.cs +++ b/Source/ConformalDecals/ModuleConformalDecal.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using ConformalDecals.MaterialProperties; +using ConformalDecals.Targets; using ConformalDecals.Util; using UniLinq; using UnityEngine; diff --git a/Source/ConformalDecals/IProjectionTarget.cs b/Source/ConformalDecals/Targets/IProjectionTarget.cs similarity index 87% rename from Source/ConformalDecals/IProjectionTarget.cs rename to Source/ConformalDecals/Targets/IProjectionTarget.cs index 861833e..063128b 100644 --- a/Source/ConformalDecals/IProjectionTarget.cs +++ b/Source/ConformalDecals/Targets/IProjectionTarget.cs @@ -1,6 +1,6 @@ using UnityEngine; -namespace ConformalDecals { +namespace ConformalDecals.Targets { public interface IProjectionTarget { bool Project(Matrix4x4 orthoMatrix, Transform projector, Bounds projectionBounds); void Render(Material decalMaterial, MaterialPropertyBlock partMPB, Camera camera); diff --git a/Source/ConformalDecals/ProjectionMeshTarget.cs b/Source/ConformalDecals/Targets/ProjectionMeshTarget.cs similarity index 99% rename from Source/ConformalDecals/ProjectionMeshTarget.cs rename to Source/ConformalDecals/Targets/ProjectionMeshTarget.cs index 61c1bb9..c21388d 100644 --- a/Source/ConformalDecals/ProjectionMeshTarget.cs +++ b/Source/ConformalDecals/Targets/ProjectionMeshTarget.cs @@ -1,7 +1,7 @@ using UnityEngine; using UnityEngine.Rendering; -namespace ConformalDecals { +namespace ConformalDecals.Targets { public class ProjectionMeshTarget : IProjectionTarget { public const string NodeName = "MESH_TARGET"; diff --git a/Source/ConformalDecals/ProjectionPartTarget.cs b/Source/ConformalDecals/Targets/ProjectionPartTarget.cs similarity index 97% rename from Source/ConformalDecals/ProjectionPartTarget.cs rename to Source/ConformalDecals/Targets/ProjectionPartTarget.cs index 19dacca..0e0ac76 100644 --- a/Source/ConformalDecals/ProjectionPartTarget.cs +++ b/Source/ConformalDecals/Targets/ProjectionPartTarget.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using UnityEngine; -namespace ConformalDecals { +namespace ConformalDecals.Targets { public class ProjectionPartTarget : IProjectionTarget { public const string NodeName = "PART_TARGET"; diff --git a/Source/ConformalDecals/Tweakables/TweakableData.cs b/Source/ConformalDecals/Tweakables/TweakableData.cs new file mode 100644 index 0000000..9d3d7cf --- /dev/null +++ b/Source/ConformalDecals/Tweakables/TweakableData.cs @@ -0,0 +1,33 @@ +using System; +using ConformalDecals.Util; +using UnityEngine; + +namespace ConformalDecals.Tweakables { + [AttributeUsage(AttributeTargets.Field)] + public abstract class TweakableData : System.Attribute, ISerializationCallbackReceiver { + public string name; + + public bool adjustable = true; + public string adjustableKey; + + // public string fieldChangedCallback; + public bool useSymmetry = true; + + protected TweakableData(string name) { + this.name = name; + adjustableKey = name + "Adjustable"; + } + + public virtual void Load(ConfigNode node) { + ParseUtil.ParseBoolIndirect(ref adjustable, node, adjustableKey); + } + + public virtual void Apply(BaseField baseField, PartModule module) { + baseField.guiActiveEditor = adjustable; + } + + public void OnBeforeSerialize() { } + + public void OnAfterDeserialize() { } + } +} \ No newline at end of file diff --git a/Source/ConformalDecals/Tweakables/TweakableDataCollection.cs b/Source/ConformalDecals/Tweakables/TweakableDataCollection.cs new file mode 100644 index 0000000..9465172 --- /dev/null +++ b/Source/ConformalDecals/Tweakables/TweakableDataCollection.cs @@ -0,0 +1,30 @@ +using System.Collections; +using System.Collections.Generic; +using UniLinq; +using UnityEngine; + +namespace ConformalDecals.Tweakables { + public class TweakableDataCollection : IEnumerable, ISerializationCallbackReceiver { + public readonly Dictionary tweakables = new Dictionary(); + + [SerializeField] private TweakableData[] _serializedTweakables; + + public IEnumerator GetEnumerator() { + return tweakables.Values.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() { + return GetEnumerator(); + } + + public void OnBeforeSerialize() { + _serializedTweakables = tweakables.Values.ToArray(); + } + + public void OnAfterDeserialize() { + foreach (var tweakable in _serializedTweakables) { + tweakables.Add(tweakable.name, tweakable); + } + } + } +} \ No newline at end of file diff --git a/Source/ConformalDecals/Tweakables/TweakableSlider.cs b/Source/ConformalDecals/Tweakables/TweakableSlider.cs new file mode 100644 index 0000000..6ef28a8 --- /dev/null +++ b/Source/ConformalDecals/Tweakables/TweakableSlider.cs @@ -0,0 +1,56 @@ +using System; +using ConformalDecals.Util; +using UnityEngine; + +namespace ConformalDecals.Tweakables { + [AttributeUsage(AttributeTargets.Field)] + public class TweakableSlider : TweakableData { + // The default value for the slider + public float defaultValue; + public string defaultValueKey; + + // The range of the slider as a vector of + public float min = 0; + public float max = 1; + public string rangeKey; + + // The step size of the slider + public float step; + public string stepKey; + + public TweakableSlider(string name) : base(name) { + defaultValueKey = name + "Default"; + rangeKey = name + "Range"; + stepKey = name + "Step"; + } + + public override void Load(ConfigNode node) { + base.Load(node); + + var range = new Vector2(min, max); + ParseUtil.ParseVector2Indirect(ref range, node, rangeKey); + min = Mathf.Max(Mathf.Epsilon, range.x); + max = Mathf.Max(min, range.y); + + ParseUtil.ParseFloatIndirect(ref step, node, stepKey); + + if (!HighLogic.LoadedSceneIsEditor && !HighLogic.LoadedSceneIsFlight) { + ParseUtil.ParseFloatIndirect(ref defaultValue, node, defaultValueKey); + } + } + + public override void Apply(BaseField baseField, PartModule module) { + base.Apply(baseField, module); + var uiControlEditor = (UI_FloatRange) baseField.uiControlEditor; + + uiControlEditor.minValue = min; + uiControlEditor.maxValue = max; + uiControlEditor.stepIncrement = step; + + // Set the default value on first load + if (!HighLogic.LoadedSceneIsEditor && !HighLogic.LoadedSceneIsFlight) { + baseField.FieldInfo.SetValue(module, defaultValue); + } + } + } +} \ No newline at end of file diff --git a/Source/ConformalDecals/Tweakables/TweakableToggle.cs b/Source/ConformalDecals/Tweakables/TweakableToggle.cs new file mode 100644 index 0000000..00c968b --- /dev/null +++ b/Source/ConformalDecals/Tweakables/TweakableToggle.cs @@ -0,0 +1,34 @@ +using System; +using System.Reflection; +using ConformalDecals.Util; + +namespace ConformalDecals.Tweakables { + [AttributeUsage(AttributeTargets.Field)] + public class TweakableToggle : TweakableData { + // The default value for the toggle + public bool defaultValue; + public string defaultValueKey; + + public TweakableToggle(string name) : base(name) { + defaultValueKey = name + "Default"; + } + + public override void Load(ConfigNode node) { + base.Load(node); + + // Set the default value on first load + if (!HighLogic.LoadedSceneIsEditor && !HighLogic.LoadedSceneIsFlight) { + ParseUtil.ParseBoolIndirect(ref defaultValue, node, defaultValueKey); + } + } + + public override void Apply(BaseField baseField, PartModule module) { + base.Apply(baseField, module); + + // Set the default value on first load + if (!HighLogic.LoadedSceneIsEditor && !HighLogic.LoadedSceneIsFlight) { + baseField.FieldInfo.SetValue(module, defaultValue); + } + } + } +} \ No newline at end of file diff --git a/Source/ConformalDecals/Util/ParseUtil.cs b/Source/ConformalDecals/Util/ParseUtil.cs index 45a4e4a..4a07287 100644 --- a/Source/ConformalDecals/Util/ParseUtil.cs +++ b/Source/ConformalDecals/Util/ParseUtil.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Reflection; -using UniLinq; using UnityEngine; namespace ConformalDecals.Util { @@ -32,7 +31,7 @@ namespace ConformalDecals.Util { public static string ParseString(ConfigNode node, string valueName, bool isOptional = false, string defaultValue = "") { if (node.HasValue(valueName)) return node.GetValue(valueName); - + if (isOptional) { return defaultValue; } @@ -121,7 +120,6 @@ namespace ConformalDecals.Util { public static bool ParseMatrix4x4Indirect(ref Matrix4x4 value, ConfigNode node, string valueName) { return ParseValueIndirect(ref value, node, valueName, ParseUtil.TryParseMatrix4x4); - } public static T ParseValue(ConfigNode node, string valueName, TryParseDelegate tryParse, bool isOptional = false, T defaultValue = default) {