Added UI for DunGenExtender
Made DevOnly fields readonly
This commit is contained in:
		
							parent
							
								
									894645d85c
								
							
						
					
					
						commit
						32cebc67d6
					
				
					 12 changed files with 295 additions and 41 deletions
				
			
		
							
								
								
									
										137
									
								
								DunGenPlus/DunGenPlusEditor/DunGenExtenderPropertyDrawer.cs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										137
									
								
								DunGenPlus/DunGenPlusEditor/DunGenExtenderPropertyDrawer.cs
									
										
									
									
									
										Normal file
									
								
							|  | @ -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; | ||||
|     } | ||||
| 
 | ||||
|   } | ||||
| 
 | ||||
| } | ||||
|  | @ -72,8 +72,11 @@ | |||
|     </Reference> | ||||
|   </ItemGroup> | ||||
|   <ItemGroup> | ||||
|     <Compile Include="DunGenExtenderPropertyDrawer.cs" /> | ||||
|     <Compile Include="Properties\AssemblyInfo.cs" /> | ||||
|     <Compile Include="PropertyDrawerUtility.cs" /> | ||||
|     <Compile Include="PropertyOverridePropertyDrawer.cs" /> | ||||
|     <Compile Include="ReadOnlyPropertyDrawer.cs" /> | ||||
|   </ItemGroup> | ||||
|   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||||
|   <PropertyGroup> | ||||
|  |  | |||
							
								
								
									
										116
									
								
								DunGenPlus/DunGenPlusEditor/PropertyDrawerUtility.cs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										116
									
								
								DunGenPlus/DunGenPlusEditor/PropertyDrawerUtility.cs
									
										
									
									
									
										Normal file
									
								
							|  | @ -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<SerializedProperty, bool> getDisplayStateFunction){ | ||||
|        | ||||
|       SerializedProperty toggleSerializedProperty = null; | ||||
|       PropertyField togglePropertyField = null;   | ||||
|       var childrenPropertyFields = new List<VisualElement>(); | ||||
| 
 | ||||
|       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); | ||||
|       } | ||||
|     } | ||||
|   } | ||||
| } | ||||
|  | @ -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; | ||||
|  |  | |||
							
								
								
									
										22
									
								
								DunGenPlus/DunGenPlusEditor/ReadOnlyPropertyDrawer.cs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								DunGenPlus/DunGenPlusEditor/ReadOnlyPropertyDrawer.cs
									
										
									
									
									
										Normal file
									
								
							|  | @ -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; | ||||
|     } | ||||
|   } | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue