Added UI for DunGenExtender

Made DevOnly fields readonly
This commit is contained in:
LadyAliceMargatroid 2024-09-10 23:06:32 -07:00
parent 894645d85c
commit 32cebc67d6
12 changed files with 295 additions and 41 deletions

View File

@ -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 {
}
}

View File

@ -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)")]

View File

@ -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;

View File

@ -129,6 +129,7 @@
<ItemGroup>
<Compile Include="API.cs" />
<Compile Include="Assets.cs" />
<Compile Include="Attributes\ReadOnlyAttribute.cs" />
<Compile Include="Collections\DunGenExtenderEvents.cs" />
<Compile Include="Collections\DunGenExtenderPropertiesCollection.cs" />
<Compile Include="Collections\ExtenderEvent.cs" />

View File

@ -33,6 +33,7 @@ namespace DunGenPlus {
public PropertyOverride<List<GraphLine>> Lines = new PropertyOverride<List<GraphLine>>(false, new List<GraphLine>());
[Header("DEV ONLY: DON'T TOUCH")]
[Attributes.ReadOnly]
public string Version = "0";
public static IntRange GetLength(MainPathExtender extender, DungeonFlow flow) {

View 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;
}
}
}

View File

@ -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>

View 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);
}
}
}
}

View File

@ -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;

View 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;
}
}
}