Added exit button

Added DunFlow panel
Some UI improvements
This commit is contained in:
LadyAliceMargatroid 2024-08-26 11:31:02 -07:00
parent 1407e39703
commit e9c8da9c51
18 changed files with 427 additions and 130 deletions

View file

@ -0,0 +1,110 @@
using DunGen;
using DunGen.Graph;
using DunGenPlus.Collections;
using DunGenPlus.DevTools.Panels;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace DunGenPlus.DevTools.UIElements.Collections {
internal abstract class ListEntryType {
public abstract object CreateEmptyObject();
public abstract void CreateEntry(IList list, int index, Transform parentTransform, float layoutOffset);
}
internal class ListEntryDungeonArchetype : ListEntryType {
public override object CreateEmptyObject() => null;
public override void CreateEntry(IList list, int index, Transform parentTransform, float layoutOffset) {
var entry = (DungeonArchetype)list[index];
var baseValue = DevDebugManager.Instance.selectedAssetCache.archetypes.dictionary[entry];
DevDebugManager.Instance.CreateArchetypeOptionsUIField(parentTransform, new TitleParameter("Archetype", layoutOffset), baseValue, (t) => list[index] = t);
}
}
internal class ListEntryTileSet : ListEntryType {
public override object CreateEmptyObject() => null;
public override void CreateEntry(IList list, int index, Transform parentTransform, float layoutOffset) {
var entry = (TileSet)list[index];
var baseValue = DevDebugManager.Instance.selectedAssetCache.tileSets.dictionary[entry];
DevDebugManager.Instance.CreateTileSetsOptionsUIField(parentTransform, new TitleParameter("Tile Set", layoutOffset), baseValue, (t) => list[index] = t);
}
}
internal class ListEntryNodeArchetype : ListEntryType {
public override object CreateEmptyObject() => new NodeArchetype();
public override void CreateEntry(IList list, int index, Transform parentTransform, float layoutOffset) {
var entry = (NodeArchetype)list[index];
DevDebugManager.Instance.CreateStringInputField(parentTransform, new TitleParameter("Label", layoutOffset), entry.label, (t) => entry.label = t);
DevDebugManager.Instance.CreateListUIField(parentTransform, new TitleParameter("Archetypes", layoutOffset), entry.archetypes);
}
}
internal class ListEntryForcedTileSetList : ListEntryType {
public override object CreateEmptyObject() {
var forcedTileset = new ForcedTileSetList();
forcedTileset.DepthWeightScale = null;
return forcedTileset;
}
public override void CreateEntry(IList list, int index, Transform parentTransform, float layoutOffset) {
var entry = (ForcedTileSetList)list[index];
DevDebugManager.Instance.CreateFloatInputField(parentTransform, new TitleParameter("Main Path Weight", layoutOffset), entry.MainPathWeight, (t) => entry.MainPathWeight = t);
DevDebugManager.Instance.CreateFloatInputField(parentTransform, new TitleParameter("Branch Path Weight", layoutOffset), entry.BranchPathWeight, (t) => entry.BranchPathWeight = t);
// depth is weird cause we have to account for every entry's unique depth curve, even if they don't have one
DevDebugManager.Instance.CreateAnimationCurveOptionsUIField(parentTransform, new TitleParameter("Depth Weight Scale", layoutOffset), entry.DepthWeightScale, (t) => entry.DepthWeightScale = t);
DevDebugManager.Instance.CreateListUIField(parentTransform, new TitleParameter("Tile Sets", layoutOffset), entry.Tilesets);
}
}
internal class ListEntryTileInjectionRule : ListEntryType {
public override object CreateEmptyObject() => new TileInjectionRule();
public override void CreateEntry(IList list, int index, Transform parentTransform, float layoutOffset){
var entry = (TileInjectionRule)list[index];
var baseValue = DevDebugManager.Instance.selectedAssetCache.tileSets.dictionary[entry.TileSet];
DevDebugManager.Instance.CreateTileSetsOptionsUIField(parentTransform, "Tile Set", baseValue, (t) => entry.TileSet = t);
DevDebugManager.Instance.CreateFloatRangeInputField(parentTransform, "Norm. Path Depth", entry.NormalizedPathDepth, (t) => entry.NormalizedPathDepth = t);
DevDebugManager.Instance.CreateFloatRangeInputField(parentTransform, "Norm. Branch Depth", entry.NormalizedBranchDepth, (t) => entry.NormalizedBranchDepth = t);
DevDebugManager.Instance.CreateBoolInputField(parentTransform, "Appear On Main Path", entry.CanAppearOnMainPath, (t) => entry.CanAppearOnMainPath = t);
DevDebugManager.Instance.CreateBoolInputField(parentTransform, "Appear On Branch Path", entry.CanAppearOnBranchPath, (t) => entry.CanAppearOnBranchPath = t);
DevDebugManager.Instance.CreateBoolInputField(parentTransform, "Is Required", entry.IsRequired, (t) => entry.IsRequired = t);
}
}
internal class ListEntryGraphNode : ListEntryType {
public override object CreateEmptyObject() => new GraphNode(DevDebugManager.Instance.selectedDungeonFlow);
public override void CreateEntry(IList list, int index, Transform parentTransform, float layoutOffset){
var entry = (GraphNode)list[index];
DevDebugManager.Instance.CreateListUIField(parentTransform, "Tile Sets", entry.TileSets);
DevDebugManager.Instance.CreateEnumOptionsUIField<NodeType>(parentTransform, "Node Type", (int)entry.NodeType, (t) => entry.NodeType = t);
DevDebugManager.Instance.CreateFloatInputField(parentTransform, "Position", new FloatParameter(entry.Position, 0f, 1f), (t) => entry.Position = t);
DevDebugManager.Instance.CreateStringInputField(parentTransform, "Label", entry.Label, (t) => entry.Label = t);
}
}
internal class ListEntryGraphLine : ListEntryType {
public override object CreateEmptyObject() => new GraphLine(DevDebugManager.Instance.selectedDungeonFlow);
public override void CreateEntry(IList list, int index, Transform parentTransform, float layoutOffset){
var entry = (GraphLine)list[index];
DevDebugManager.Instance.CreateListUIField(parentTransform, "Dungeon Archetypes", entry.DungeonArchetypes);
DevDebugManager.Instance.CreateFloatInputField(parentTransform, "Position", new FloatParameter(entry.Position, 0f, 1f), (t) => entry.Position = t);
DevDebugManager.Instance.CreateFloatInputField(parentTransform, "Length", new FloatParameter(entry.Length, 0f, 1f), (t) => entry.Length = t);
}
}
}

View file

@ -5,6 +5,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace DunGenPlus.DevTools.UIElements
@ -16,8 +17,9 @@ namespace DunGenPlus.DevTools.UIElements
public void SetupDropdown<T>(TitleParameter titleParameter, int baseValue, Action<T> setAction, Func<int, T> convertIndex, IEnumerable<string> options) {
SetupBase(titleParameter);
var maxLength = (int)Mathf.LerpUnclamped(24f, 20f, layoutOffset / 24f);
dropDown.options = options.Select(c => {
return new TMP_Dropdown.OptionData(c.Substring(0, Math.Min(24, c.Length)));
return new TMP_Dropdown.OptionData(c.Substring(0, Math.Min(maxLength, c.Length)));
}).ToList();
dropDown.onValueChanged.AddListener((t) => SetValue(setAction, convertIndex, t));

View file

@ -0,0 +1,45 @@
using DunGen;
using DunGenPlus.DevTools.UIElements.Collections;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TMPro;
namespace DunGenPlus.DevTools.UIElements
{
internal class FloatRangeInputField : BaseInputField<FloatRange> {
public TMP_InputField minInputField;
public TMP_InputField maxInputField;
private FloatRange _value;
public void SetupInputField(TitleParameter titleParameter, FloatRange baseValue, Action<FloatRange> setAction) {
SetupBase(titleParameter);
minInputField.onValueChanged.AddListener((t) => SetMinValue(setAction, t));
maxInputField.onValueChanged.AddListener((t) => SetMaxValue(setAction, t));
Set(baseValue);
}
private void SetMinValue(Action<FloatRange> setAction, string text){
Plugin.logger.LogInfo($"Setting {title}.min to {text}");
_value.Min = ParseTextFloat(text);
setAction.Invoke(_value);
}
private void SetMaxValue(Action<FloatRange> setAction, string text){
Plugin.logger.LogInfo($"Setting {title}.max to {text}");
_value.Max = ParseTextFloat(text);
setAction.Invoke(_value);
}
public override void Set(FloatRange value){
_value = value;
minInputField.text = value.Min.ToString();
maxInputField.text = value.Max.ToString();
}
}
}

View file

@ -0,0 +1,47 @@
using DunGen;
using DunGenPlus.DevTools.UIElements.Collections;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TMPro;
using UnityEngine;
using UnityEngine.Rendering;
namespace DunGenPlus.DevTools.UIElements
{
internal class IntRangeInputField : BaseInputField<IntRange> {
public TMP_InputField minInputField;
public TMP_InputField maxInputField;
private IntRange _value;
public void SetupInputField(TitleParameter titleParameter, IntRange baseValue, Action<IntRange> setAction) {
SetupBase(titleParameter);
minInputField.onValueChanged.AddListener((t) => SetMinValue(setAction, t));
maxInputField.onValueChanged.AddListener((t) => SetMaxValue(setAction, t));
Set(baseValue);
}
private void SetMinValue(Action<IntRange> setAction, string text){
Plugin.logger.LogInfo($"Setting {title}.min to {text}");
_value.Min = ParseTextInt(text);
setAction.Invoke(_value);
}
private void SetMaxValue(Action<IntRange> setAction, string text){
Plugin.logger.LogInfo($"Setting {title}.max to {text}");
_value.Max = ParseTextInt(text);
setAction.Invoke(_value);
}
public override void Set(IntRange value){
_value = value;
minInputField.text = value.Min.ToString();
maxInputField.text = value.Max.ToString();
}
}
}

View file

@ -1,4 +1,5 @@
using DunGen;
using DunGen.Graph;
using DunGenPlus.Collections;
using DunGenPlus.DevTools.Panels;
using DunGenPlus.DevTools.UIElements.Collections;
@ -22,6 +23,16 @@ namespace DunGenPlus.DevTools.UIElements {
internal IList list;
internal Type listType;
public static readonly Dictionary<Type, ListEntryType> typeDictionary = new Dictionary<Type, ListEntryType>() {
{ typeof(DungeonArchetype), new ListEntryDungeonArchetype() },
{ typeof(TileSet), new ListEntryTileSet() },
{ typeof(NodeArchetype), new ListEntryNodeArchetype() },
{ typeof(ForcedTileSetList), new ListEntryForcedTileSetList() },
{ typeof(TileInjectionRule), new ListEntryTileInjectionRule() },
{ typeof(GraphNode), new ListEntryGraphNode() },
{ typeof(GraphLine), new ListEntryGraphLine() }
};
public void SetupList<T>(TitleParameter titleParameter, List<T> list) {
SetupBase(titleParameter);
@ -37,16 +48,10 @@ namespace DunGenPlus.DevTools.UIElements {
public void AddElement() {
object item = null;
if (listType == typeof(DungeonArchetype) || listType == typeof(TileSet)) {
item = null;
} else if (listType == typeof(NodeArchetype)) {
item = new NodeArchetype();
} else if (listType == typeof(ForcedTileSetList)){
var forcedTileset = new ForcedTileSetList();
forcedTileset.DepthWeightScale = null;
item = forcedTileset;
if (!typeDictionary.TryGetValue(listType, out var value)){
Plugin.logger.LogError($"Type {listType} does not has a defined list UI display");
}
item = value.CreateEmptyObject();
list.Add(item);
CreateEntry(list.Count - 1);
}
@ -61,34 +66,10 @@ namespace DunGenPlus.DevTools.UIElements {
var copy = CreateCopy(index);
var copyParentTransform = copy.transform.Find("Items");
if (listType == typeof(DungeonArchetype)){
var entry = (DungeonArchetype)list[index];
var baseValue = DunGenPlusPanel.Instance.selectedAssetCache.archetypes.dictionary[entry];
DevDebugManager.Instance.CreateArchetypeOptionsUIField(copyParentTransform, new TitleParameter("Archetype", layoutOffset + 24f), baseValue, (t) => list[index] = t);
if (!typeDictionary.TryGetValue(listType, out var value)){
Plugin.logger.LogError($"Type {listType} does not has a defined list UI display");
}
else if (listType == typeof(TileSet)){
var entry = (TileSet)list[index];
var baseValue = DunGenPlusPanel.Instance.selectedAssetCache.tileSets.dictionary[entry];
DevDebugManager.Instance.CreateTileSetsOptionsUIField(copyParentTransform, new TitleParameter("Tile Set", layoutOffset + 24f), baseValue, (t) => list[index] = t);
}
else if (listType == typeof(NodeArchetype)) {
var entry = (NodeArchetype)list[index];
DevDebugManager.Instance.CreateStringInputField(copyParentTransform, new TitleParameter("Label", layoutOffset + 24f), entry.label, (t) => entry.label = t);
DevDebugManager.Instance.CreateListUIField(copyParentTransform, new TitleParameter("Archetypes", layoutOffset + 24f), entry.archetypes);
}
else if (listType == typeof(ForcedTileSetList)) {
var entry = (ForcedTileSetList)list[index];
DevDebugManager.Instance.CreateFloatInputField(copyParentTransform, new TitleParameter("Main Path Weight", layoutOffset + 24f), entry.MainPathWeight, (t) => entry.MainPathWeight = t);
DevDebugManager.Instance.CreateFloatInputField(copyParentTransform, new TitleParameter("Branch Path Weight", layoutOffset + 24f), entry.BranchPathWeight, (t) => entry.BranchPathWeight = t);
// depth is weird cause we have to account for every entry's unique depth curve, even if they don't have one
DevDebugManager.Instance.CreateAnimationCurveOptionsUIField(copyParentTransform, new TitleParameter("Depth Weight Scale", layoutOffset + 24f), entry.DepthWeightScale, (t) => entry.DepthWeightScale = t);
DevDebugManager.Instance.CreateListUIField(copyParentTransform, new TitleParameter("Tile Sets", layoutOffset + 24f), entry.Tilesets);
}
value.CreateEntry(list, index, copyParentTransform, layoutOffset + 24f);
copy.SetActive(true);
}

View file

@ -52,7 +52,5 @@ namespace DunGenPlus.DevTools.UIElements {
yInputField.text = value.y.ToString();
zInputField.text = value.z.ToString();
}
}
}