diff --git a/DunGenPlus/DunGenPlus/Attributes/ReadOnlyAttribute.cs b/DunGenPlus/DunGenPlus/Attributes/ReadOnlyAttribute.cs new file mode 100644 index 0000000..cb3d277 --- /dev/null +++ b/DunGenPlus/DunGenPlus/Attributes/ReadOnlyAttribute.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +namespace DunGenPlus.Attributes { + public class ReadOnlyAttribute : PropertyAttribute { + + } +} diff --git a/DunGenPlus/DunGenPlus/Collections/DunGenExtenderProperties.cs b/DunGenPlus/DunGenPlus/Collections/DunGenExtenderProperties.cs index 9ff3ed9..68877cd 100644 --- a/DunGenPlus/DunGenPlus/Collections/DunGenExtenderProperties.cs +++ b/DunGenPlus/DunGenPlus/Collections/DunGenExtenderProperties.cs @@ -23,25 +23,18 @@ namespace DunGenPlus.Collections { CopyFromNodeList } - [Header("Main Path")] public MainPathProperties MainPathProperties = new MainPathProperties(); - [Header("Dungeon Bounds")] public DungeonBoundsProperties DungeonBoundsProperties = new DungeonBoundsProperties(); - [Header("Normal Nodes Archetypes")] public NormalNodeArchetypesProperties NormalNodeArchetypesProperties = new NormalNodeArchetypesProperties(); - [Header("Forced Tiles")] public ForcedTilesProperties ForcedTilesProperties = new ForcedTilesProperties(); - [Header("Branch Path Multi Simulation")] public BranchPathMultiSimulationProperties BranchPathMultiSimulationProperties = new BranchPathMultiSimulationProperties(); - [Header("Line Randomizer")] public LineRandomizerProperties LineRandomizerProperties = new LineRandomizerProperties(); - [Header("Miscellaneous")] public MiscellaneousProperties MiscellaneousProperties = new MiscellaneousProperties(); [Header("Asset Cache (FOR DEV DEBUG PURPOSES ONLY)")] diff --git a/DunGenPlus/DunGenPlus/DunGenExtender.cs b/DunGenPlus/DunGenPlus/DunGenExtender.cs index 8566545..c765c18 100644 --- a/DunGenPlus/DunGenPlus/DunGenExtender.cs +++ b/DunGenPlus/DunGenPlus/DunGenExtender.cs @@ -19,6 +19,7 @@ namespace DunGenPlus { public DunGenExtenderEvents Events = new DunGenExtenderEvents(); [Header("DEV ONLY: DON'T TOUCH")] + [Attributes.ReadOnly] public string Version = "0"; internal bool Active = true; diff --git a/DunGenPlus/DunGenPlus/DunGenPlus.csproj b/DunGenPlus/DunGenPlus/DunGenPlus.csproj index 71e7fed..863b79e 100644 --- a/DunGenPlus/DunGenPlus/DunGenPlus.csproj +++ b/DunGenPlus/DunGenPlus/DunGenPlus.csproj @@ -129,6 +129,7 @@ + diff --git a/DunGenPlus/DunGenPlus/DunGenPlus/DunGenPlus.dll b/DunGenPlus/DunGenPlus/DunGenPlus/DunGenPlus.dll index e4dae0a..bbcd90e 100644 Binary files a/DunGenPlus/DunGenPlus/DunGenPlus/DunGenPlus.dll and b/DunGenPlus/DunGenPlus/DunGenPlus/DunGenPlus.dll differ diff --git a/DunGenPlus/DunGenPlus/DunGenPlus/DunGenPlusEditor.dll b/DunGenPlus/DunGenPlus/DunGenPlus/DunGenPlusEditor.dll index f56643c..082303d 100644 Binary files a/DunGenPlus/DunGenPlus/DunGenPlus/DunGenPlusEditor.dll and b/DunGenPlus/DunGenPlus/DunGenPlus/DunGenPlusEditor.dll differ diff --git a/DunGenPlus/DunGenPlus/MainPathExtender.cs b/DunGenPlus/DunGenPlus/MainPathExtender.cs index 6e6d681..6cde072 100644 --- a/DunGenPlus/DunGenPlus/MainPathExtender.cs +++ b/DunGenPlus/DunGenPlus/MainPathExtender.cs @@ -33,6 +33,7 @@ namespace DunGenPlus { public PropertyOverride> Lines = new PropertyOverride>(false, new List()); [Header("DEV ONLY: DON'T TOUCH")] + [Attributes.ReadOnly] public string Version = "0"; public static IntRange GetLength(MainPathExtender extender, DungeonFlow flow) { diff --git a/DunGenPlus/DunGenPlusEditor/DunGenExtenderPropertyDrawer.cs b/DunGenPlus/DunGenPlusEditor/DunGenExtenderPropertyDrawer.cs new file mode 100644 index 0000000..e01e57f --- /dev/null +++ b/DunGenPlus/DunGenPlusEditor/DunGenExtenderPropertyDrawer.cs @@ -0,0 +1,137 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEditor; +using UnityEngine.UIElements; +using DunGenPlus; +using DunGenPlus.Collections; + +namespace DunGenPlusEditor { + + [CustomPropertyDrawer(typeof(DunGenExtenderProperties))] + public class DunGenExtenderPropertiesPropertyDrawer : PropertyDrawer { + + public override VisualElement CreatePropertyGUI(SerializedProperty property) { + + var container = new VisualElement(); + PropertyDrawerUtility.SetupItems(container, property); + return container; + } + + } + + [CustomPropertyDrawer(typeof(MainPathProperties))] + public class MainPathPropertiesPropertyDrawer : PropertyDrawer { + + public override VisualElement CreatePropertyGUI(SerializedProperty property) { + + var container = new VisualElement(); + + var box = PropertyDrawerUtility.CreateDropdown(property, "Main Path"); + PropertyDrawerUtility.SetupItemsMainPathProperty(box.container, property, "MainPathCount", "Generating the default one main path"); + container.Add(box.parent); + + return container; + } + + } + + [CustomPropertyDrawer(typeof(DungeonBoundsProperties))] + public class DungeonBoundsPropertiesPropertyDrawer : PropertyDrawer { + + public override VisualElement CreatePropertyGUI(SerializedProperty property) { + + var container = new VisualElement(); + + var box = PropertyDrawerUtility.CreateDropdown(property, "Dungeon Bounds"); + PropertyDrawerUtility.SetupItemsBoolProperty(box.container, property, "UseDungeonBounds", "Disabled"); + container.Add(box.parent); + + return container; + } + + } + + [CustomPropertyDrawer(typeof(NormalNodeArchetypesProperties))] + public class NormalNodeArchetypesPropertiesPropertyDrawer : PropertyDrawer { + + public override VisualElement CreatePropertyGUI(SerializedProperty property) { + + var container = new VisualElement(); + + var box = PropertyDrawerUtility.CreateDropdown(property, "Normal Nodes Archetypes"); + PropertyDrawerUtility.SetupItemsBoolProperty(box.container, property, "AddArchetypesToNormalNodes", "Disabled"); + container.Add(box.parent); + + return container; + } + + } + + [CustomPropertyDrawer(typeof(ForcedTilesProperties))] + public class ForcedTilesPropertiesPropertyDrawer : PropertyDrawer { + + public override VisualElement CreatePropertyGUI(SerializedProperty property) { + + var container = new VisualElement(); + + var box = PropertyDrawerUtility.CreateDropdown(property, "Forced Tiles"); + PropertyDrawerUtility.SetupItemsBoolProperty(box.container, property, "UseForcedTiles", "Disabled"); + container.Add(box.parent); + + return container; + } + + } + + [CustomPropertyDrawer(typeof(BranchPathMultiSimulationProperties))] + public class BranchPathMultiSimulationPropertiesPropertyDrawer : PropertyDrawer { + + public override VisualElement CreatePropertyGUI(SerializedProperty property) { + + var container = new VisualElement(); + + var box = PropertyDrawerUtility.CreateDropdown(property, "Branch Path Multi Simulation"); + PropertyDrawerUtility.SetupItemsBoolProperty(box.container, property, "UseBranchPathMultiSim", "Disabled"); + container.Add(box.parent); + + return container; + } + + } + + [CustomPropertyDrawer(typeof(LineRandomizerProperties))] + public class LineRandomizerPropertiesPropertyDrawer : PropertyDrawer { + + public override VisualElement CreatePropertyGUI(SerializedProperty property) { + + var container = new VisualElement(); + + var box = PropertyDrawerUtility.CreateDropdown(property, "Line Randomizer"); + PropertyDrawerUtility.SetupItemsBoolProperty(box.container, property, "UseLineRandomizer", "Disabled"); + container.Add(box.parent); + + return container; + } + + } + + [CustomPropertyDrawer(typeof(MiscellaneousProperties))] + public class MiscellaneousPropertiesPropertyDrawer : PropertyDrawer { + + public override VisualElement CreatePropertyGUI(SerializedProperty property) { + + var container = new VisualElement(); + + var box = PropertyDrawerUtility.CreateDropdown(property, "Miscellaneous"); + PropertyDrawerUtility.SetupItems(box.container, property); + container.Add(box.parent); + + return container; + } + + } + +} diff --git a/DunGenPlus/DunGenPlusEditor/DunGenPlusEditor.csproj b/DunGenPlus/DunGenPlusEditor/DunGenPlusEditor.csproj index 6c2a145..ef5f06b 100644 --- a/DunGenPlus/DunGenPlusEditor/DunGenPlusEditor.csproj +++ b/DunGenPlus/DunGenPlusEditor/DunGenPlusEditor.csproj @@ -72,8 +72,11 @@ + + + diff --git a/DunGenPlus/DunGenPlusEditor/PropertyDrawerUtility.cs b/DunGenPlus/DunGenPlusEditor/PropertyDrawerUtility.cs new file mode 100644 index 0000000..d43763c --- /dev/null +++ b/DunGenPlus/DunGenPlusEditor/PropertyDrawerUtility.cs @@ -0,0 +1,116 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEditor; +using UnityEditor.UIElements; +using UnityEngine.UIElements; + +namespace DunGenPlusEditor { + public static class PropertyDrawerUtility { + + public static VisualElement CreateBox(string displayName){ + var box = new Box(); + box.style.paddingBottom = 4f; + box.style.paddingLeft = 4f; + box.style.paddingRight = 4f; + box.style.paddingTop = 4f; + box.style.marginBottom = 8f; + + var label = new Label(displayName); + var weight = label.style.unityFontStyleAndWeight; + weight.value = UnityEngine.FontStyle.Bold; + label.style.unityFontStyleAndWeight = weight; + box.Add(label); + + return box; + } + + public static (VisualElement parent, VisualElement container) CreateDropdown(SerializedProperty property, string displayName){ + var box = new Box(); + box.style.paddingBottom = 4f; + box.style.paddingLeft = 4f; + box.style.paddingRight = 4f; + box.style.paddingTop = 4f; + box.style.marginBottom = 8f; + + var foldout = new Foldout(); + foldout.text = displayName; + foldout.style.marginLeft = 10f; + foldout.viewDataKey = $"{property.serializedObject.targetObject.GetInstanceID()}.{property.name}"; + + box.Add(foldout); + + return (box, foldout); + } + + + public static void SetupItemsBoolProperty(VisualElement container, SerializedProperty property, string togglePropertyName, string disabledLabelMessage) { + SetupItems(container, property, togglePropertyName, disabledLabelMessage, (prop) => prop.boolValue); + } + + public static void SetupItemsMainPathProperty(VisualElement container, SerializedProperty property, string togglePropertyName, string disabledLabelMessage) { + SetupItems(container, property, togglePropertyName, disabledLabelMessage, (prop) => prop.intValue > 1); + } + + public static void SetupItems(VisualElement container, SerializedProperty property, string togglePropertyName, string disabledLabelMessage, Func getDisplayStateFunction){ + + SerializedProperty toggleSerializedProperty = null; + PropertyField togglePropertyField = null; + var childrenPropertyFields = new List(); + + var enumerator = property.GetEnumerator(); + var depth = property.depth; + + while(enumerator.MoveNext()){ + var prop = enumerator.Current as SerializedProperty; + if (prop == null || prop.depth > depth + 1) continue; + + var item = new PropertyField(prop); + if (container is Box) item.style.marginLeft = 8f; + + if (prop.name == togglePropertyName) { + toggleSerializedProperty = prop.Copy(); + togglePropertyField = item; + } else { + childrenPropertyFields.Add(item); + } + + container.Add(item); + } + + var defaultItem = new Label(disabledLabelMessage); + if (container is Box) defaultItem.style.marginLeft = 11f; + else defaultItem.style.marginLeft = 3f; + container.Add(defaultItem); + + void SetDisplayState(bool state){ + foreach(var item in childrenPropertyFields){ + item.style.display = state ? DisplayStyle.Flex : DisplayStyle.None; + } + defaultItem.style.display = !state ? DisplayStyle.Flex : DisplayStyle.None; + } + + SetDisplayState(getDisplayStateFunction(toggleSerializedProperty)); + togglePropertyField.RegisterValueChangeCallback(evt => SetDisplayState(getDisplayStateFunction(evt.changedProperty))); + } + + public static void SetupItems(VisualElement container, SerializedProperty property){ + + var enumerator = property.GetEnumerator(); + var depth = property.depth; + + while(enumerator.MoveNext()){ + var prop = enumerator.Current as SerializedProperty; + if (prop == null || prop.depth > depth + 1) continue; + + var item = new PropertyField(prop); + if (container is Box) item.style.marginLeft = 8f; + + container.Add(item); + } + } + } +} diff --git a/DunGenPlus/DunGenPlusEditor/PropertyOverridePropertyDrawer.cs b/DunGenPlus/DunGenPlusEditor/PropertyOverridePropertyDrawer.cs index 82560cb..5a1d64e 100644 --- a/DunGenPlus/DunGenPlusEditor/PropertyOverridePropertyDrawer.cs +++ b/DunGenPlus/DunGenPlusEditor/PropertyOverridePropertyDrawer.cs @@ -16,40 +16,8 @@ namespace DunGenPlusEditor { var container = new VisualElement(); - var box = new Box(); - box.style.paddingBottom = 4f; - box.style.paddingLeft = 4f; - box.style.paddingRight = 4f; - box.style.paddingTop = 4f; - box.style.marginBottom = 8f; - - var label = new Label(property.displayName); - var weight = label.style.unityFontStyleAndWeight; - weight.value = UnityEngine.FontStyle.Bold; - label.style.unityFontStyleAndWeight = weight; - box.Add(label); - - var overrideProperty = property.FindPropertyRelative("Override"); - var valueProperty = property.FindPropertyRelative("Value"); - - var overrideItem = new PropertyField(overrideProperty); - overrideItem.style.marginLeft = 8f; - var valueItem = new PropertyField(valueProperty); - valueItem.style.marginLeft = 8f; - var valueDefaultItem = new Label("Using DungeonFlow's corresponding values"); - valueDefaultItem.style.marginLeft = 11f; - - void SetDisplayState(bool state){ - valueItem.style.display = state ? DisplayStyle.Flex : DisplayStyle.None; - valueDefaultItem.style.display = !state ? DisplayStyle.Flex : DisplayStyle.None; - } - SetDisplayState(overrideProperty.boolValue); - overrideItem.RegisterValueChangeCallback(evt => SetDisplayState(evt.changedProperty.boolValue)); - - box.Add(overrideItem); - box.Add(valueItem); - box.Add(valueDefaultItem); - + var box = PropertyDrawerUtility.CreateBox(property.displayName); + PropertyDrawerUtility.SetupItemsBoolProperty(box, property, "Override", "Using DungeonFlow's corresponding values"); container.Add(box); return container; diff --git a/DunGenPlus/DunGenPlusEditor/ReadOnlyPropertyDrawer.cs b/DunGenPlus/DunGenPlusEditor/ReadOnlyPropertyDrawer.cs new file mode 100644 index 0000000..a83684f --- /dev/null +++ b/DunGenPlus/DunGenPlusEditor/ReadOnlyPropertyDrawer.cs @@ -0,0 +1,22 @@ +using DunGenPlus.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEditor; +using UnityEngine; +using UnityEditor.UIElements; +using UnityEngine.UIElements; + +namespace DunGenPlusEditor { + [CustomPropertyDrawer(typeof(ReadOnlyAttribute))] + public class ReadOnlyPropertyDrawer : PropertyDrawer { + + public override VisualElement CreatePropertyGUI(SerializedProperty property) { + var item = new PropertyField(property); + item.SetEnabled(false); + return item; + } + } +}