Some code refactoring to make it easier on me
Make some collections deserving to be readonly, to be readonly List within lists contrast a bit better StringBuilder instead of list of strings Added dungen's generation stats to debug window
This commit is contained in:
parent
3160685123
commit
fdb1767890
|
@ -129,28 +129,38 @@ namespace DunGenPlus.DevTools {
|
|||
}
|
||||
|
||||
public void OnDungeonFinished(DungeonGenerator generator, GenerationStatus status) {
|
||||
var textList = new List<string>();
|
||||
// Albino said StringBuilder
|
||||
// I forget it even exists ngl
|
||||
var textList = new StringBuilder();
|
||||
|
||||
// seeds
|
||||
textList.AppendLine($"Initial seed: {MainPanel.Instance.seedInputField.inputField.text}");
|
||||
textList.AppendLine($"Last seed: {generator.ChosenSeed}");
|
||||
|
||||
if (status == GenerationStatus.Complete) {
|
||||
textList.Add($"Tiles: {generator.CurrentDungeon.AllTiles.Count}");
|
||||
textList.Add($"Main Tiles: {generator.CurrentDungeon.MainPathTiles.Count}");
|
||||
textList.Add($"Branch Tiles: {generator.CurrentDungeon.BranchPathTiles.Count}");
|
||||
textList.Add($"Doors: {generator.CurrentDungeon.Doors.Count}");
|
||||
textList.AppendLine($"Tiles: {generator.CurrentDungeon.AllTiles.Count}");
|
||||
textList.AppendLine($"Main Tiles: {generator.CurrentDungeon.MainPathTiles.Count}");
|
||||
textList.AppendLine($"Branch Tiles: {generator.CurrentDungeon.BranchPathTiles.Count}");
|
||||
textList.AppendLine($"Doors: {generator.CurrentDungeon.Doors.Count}");
|
||||
} else if (status == GenerationStatus.Failed) {
|
||||
textList.Add("<color=red>Failed</color>");
|
||||
textList.AppendLine("<color=red>Failed</color>");
|
||||
}
|
||||
textList.AppendLine();
|
||||
|
||||
var stats = generator.GenerationStats;
|
||||
textList.AppendLine("<u>DunGen</u>");
|
||||
textList.AppendLine($"Retrys: {stats.TotalRetries}");
|
||||
textList.AppendLine($"Pre Process Time: {stats.PreProcessTime:F2} ms");
|
||||
textList.AppendLine($"Main Path Time: {stats.MainPathGenerationTime:F2} ms");
|
||||
textList.AppendLine($"Branch Path Time: {stats.BranchPathGenerationTime:F2} ms");
|
||||
textList.AppendLine($"Post Process Time: {stats.PostProcessTime:F2} ms");
|
||||
textList.AppendLine($"Total Time: {stats.TotalTime:F2} ms");
|
||||
|
||||
statsTextMesh.text = textList.ToString();
|
||||
}
|
||||
|
||||
textList.Add("<u>DunGen</u>");
|
||||
textList.Add(generator.GenerationStats.ToString());
|
||||
|
||||
SetNewSeed();
|
||||
statsTextMesh.text = string.Join("\n", textList);
|
||||
}
|
||||
|
||||
private void SetNewSeed(){
|
||||
foreach(var p in panels) {
|
||||
var mainPanel = p as MainPanel;
|
||||
if (mainPanel) mainPanel.seedInputField.Set(dungeon.Generator.ChosenSeed);
|
||||
}
|
||||
public void RecordNewSeed(int seed){
|
||||
MainPanel.Instance.seedInputField.Set(seed);
|
||||
}
|
||||
|
||||
private void UpdatePlusPanel() {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
using DunGenPlus.Collections;
|
||||
using DunGenPlus.DevTools.Panels;
|
||||
using DunGenPlus.DevTools.UIElements;
|
||||
using DunGenPlus.DevTools.UIElements.Collections;
|
||||
using LethalLevelLoader;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
@ -37,17 +38,17 @@ namespace DunGenPlus.DevTools {
|
|||
public GameObject listUIPrefab;
|
||||
public GameObject optionsUIPrefab;
|
||||
|
||||
public TextUIElement CreateHeaderUIField(Transform parentTransform, string title, float offset) {
|
||||
public TextUIElement CreateHeaderUIField(Transform parentTransform, TitleParameter titleParameter) {
|
||||
var gameObject = Instantiate(headerUIPrefab, parentTransform);
|
||||
var field = gameObject.GetComponent<TextUIElement>();
|
||||
field.SetupBase(title, offset);
|
||||
field.SetupBase(titleParameter);
|
||||
return field;
|
||||
}
|
||||
|
||||
public TextUIElement CreateTextUIField(Transform parentTransform, string title, float offset) {
|
||||
public TextUIElement CreateTextUIField(Transform parentTransform, TitleParameter titleParameter) {
|
||||
var gameObject = Instantiate(textUIPrefab, parentTransform);
|
||||
var field = gameObject.GetComponent<TextUIElement>();
|
||||
field.SetupBase(title, offset);
|
||||
field.SetupBase(titleParameter);
|
||||
return field;
|
||||
}
|
||||
|
||||
|
@ -59,81 +60,81 @@ namespace DunGenPlus.DevTools {
|
|||
return Instantiate(verticalLayoutUIPrefab, parentTransform).transform;
|
||||
}
|
||||
|
||||
public IntInputField CreateIntInputField(Transform parentTransform, string title, float offset, int baseValue, Action<int> setAction, int defaultValue = 0){
|
||||
public IntInputField CreateIntInputField(Transform parentTransform, TitleParameter titleParameter, IntParameter intParameter, Action<int> setAction){
|
||||
var gameObject = Instantiate(intInputFieldPrefab, parentTransform);
|
||||
var field = gameObject.GetComponent<IntInputField>();
|
||||
field.SetupInputField(title, offset, baseValue, setAction, defaultValue);
|
||||
field.SetupInputField(titleParameter, intParameter, setAction);
|
||||
return field;
|
||||
}
|
||||
|
||||
public FloatInputField CreateFloatInputField(Transform parentTransform, string title, float offset, float baseValue, Action<float> setAction, float defaultValue = 0f){
|
||||
public FloatInputField CreateFloatInputField(Transform parentTransform, TitleParameter titleParameter, FloatParameter floatParameter, Action<float> setAction){
|
||||
var gameObject = Instantiate(floatInputFieldPrefab, parentTransform);
|
||||
var field = gameObject.GetComponent<FloatInputField>();
|
||||
field.SetupInputField(title, offset, baseValue, setAction, defaultValue);
|
||||
field.SetupInputField(titleParameter, floatParameter, setAction);
|
||||
return field;
|
||||
}
|
||||
|
||||
public BoolInputField CreateBoolInputField(Transform parentTransform, string title, float offset, bool baseValue, Action<bool> setAction){
|
||||
public BoolInputField CreateBoolInputField(Transform parentTransform, TitleParameter titleParameter, bool baseValue, Action<bool> setAction){
|
||||
var gameObject = Instantiate(boolInputFieldPrefab, parentTransform);
|
||||
var field = gameObject.GetComponent<BoolInputField>();
|
||||
field.SetupInputField(title, offset, baseValue, setAction, false);
|
||||
field.SetupInputField(titleParameter, baseValue, setAction);
|
||||
return field;
|
||||
}
|
||||
|
||||
public StringInputField CreateStringInputField(Transform parentTransform, string title, float offset, string baseValue, Action<string> setAction){
|
||||
public StringInputField CreateStringInputField(Transform parentTransform, TitleParameter titleParameter, string baseValue, Action<string> setAction){
|
||||
var gameObject = Instantiate(stringInputFieldPrefab, parentTransform);
|
||||
var field = gameObject.GetComponent<StringInputField>();
|
||||
field.SetupInputField(title, offset, baseValue, setAction, string.Empty);
|
||||
field.SetupInputField(titleParameter, baseValue, setAction);
|
||||
return field;
|
||||
}
|
||||
|
||||
public Vector3InputField CreateVector3InputField(Transform parentTransform, string title, float offset, Vector3 baseValue, Action<Vector3> setAction){
|
||||
public Vector3InputField CreateVector3InputField(Transform parentTransform, TitleParameter titleParameter, Vector3 baseValue, Action<Vector3> setAction){
|
||||
var gameObject = Instantiate(vector3InputFieldPrefab, parentTransform);
|
||||
var field = gameObject.GetComponent<Vector3InputField>();
|
||||
field.SetupInputField(title, offset, baseValue, setAction, Vector3.zero);
|
||||
field.SetupInputField(titleParameter, baseValue, setAction);
|
||||
return field;
|
||||
}
|
||||
|
||||
public IntSliderField CreateIntSliderField(Transform parentTransform, string title, float offset, int baseValue, Action<int> setAction, int defaultValue = 0){
|
||||
public IntSliderField CreateIntSliderField(Transform parentTransform, TitleParameter titleParameter, IntParameter intParameter, Action<int> setAction){
|
||||
var gameObject = Instantiate(intSliderFieldPrefab, parentTransform);
|
||||
var field = gameObject.GetComponent<IntSliderField>();
|
||||
field.SetupInputField(title, offset, baseValue, setAction, defaultValue);
|
||||
field.SetupInputField(titleParameter, intParameter, setAction);
|
||||
return field;
|
||||
}
|
||||
|
||||
public ListUIElement CreateListUIField<T>(Transform parentTransform, string title, float offset, List<T> list){
|
||||
public ListUIElement CreateListUIField<T>(Transform parentTransform, TitleParameter titleParameter, List<T> list){
|
||||
var gameObject = Instantiate(listUIPrefab, parentTransform);
|
||||
var field = gameObject.GetComponent<ListUIElement>();
|
||||
field.SetupList(title, offset, list);
|
||||
field.SetupList(titleParameter, list);
|
||||
return field;
|
||||
}
|
||||
|
||||
|
||||
public DropdownInputField CreateOptionsUIField<T>(Transform parentTransform, string title, float offset, int baseValue, Action<T> setAction, Func<int, T> convertIndex, IEnumerable<string> options){
|
||||
public DropdownInputField CreateOptionsUIField<T>(Transform parentTransform, TitleParameter titleParameter, int baseValue, Action<T> setAction, Func<int, T> convertIndex, IEnumerable<string> options){
|
||||
var gameObject = Instantiate(optionsUIPrefab, parentTransform);
|
||||
var field = gameObject.GetComponent<DropdownInputField>();
|
||||
field.SetupDropdown(title, offset, baseValue, setAction, convertIndex, options);
|
||||
field.SetupDropdown(titleParameter, baseValue, setAction, convertIndex, options);
|
||||
return field;
|
||||
}
|
||||
|
||||
public DropdownInputField CreateLevelOptionsUIField(Transform parentTransform, string title, float offset, int baseValue, Action<ExtendedLevel> setAction){
|
||||
public DropdownInputField CreateLevelOptionsUIField(Transform parentTransform, TitleParameter titleParameter, int baseValue, Action<ExtendedLevel> setAction){
|
||||
var mainPanel = MainPanel.Instance;
|
||||
return CreateOptionsUIField(parentTransform, title, offset, baseValue, setAction, (i) => mainPanel.levels[i], mainPanel.levelOptions);
|
||||
return CreateOptionsUIField(parentTransform, titleParameter, baseValue, setAction, (i) => mainPanel.levels[i], mainPanel.levelOptions);
|
||||
}
|
||||
|
||||
public DropdownInputField CreateTileOptionsUIField(Transform parentTransform, string title, float offset, int baseValue, Action<GameObject> setAction){
|
||||
public DropdownInputField CreateTileOptionsUIField(Transform parentTransform, TitleParameter titleParameter, int baseValue, Action<GameObject> setAction){
|
||||
var assetCache = DunGenPlusPanel.Instance.selectedAssetCache;
|
||||
return CreateOptionsUIField(parentTransform, title, offset, baseValue, setAction, (i) => assetCache.tiles.list[i].Item, assetCache.tiles.options);
|
||||
return CreateOptionsUIField(parentTransform, titleParameter, baseValue, setAction, (i) => assetCache.tiles.list[i].Item, assetCache.tiles.options);
|
||||
}
|
||||
|
||||
public DropdownInputField CreateArchetypeOptionsUIField(Transform parentTransform, string title, float offset, int baseValue, Action<DungeonArchetype> setAction){
|
||||
public DropdownInputField CreateArchetypeOptionsUIField(Transform parentTransform, TitleParameter titleParameter, int baseValue, Action<DungeonArchetype> setAction){
|
||||
var assetCache = DunGenPlusPanel.Instance.selectedAssetCache;
|
||||
return CreateOptionsUIField(parentTransform, title, offset, baseValue, setAction, (i) => assetCache.archetypes.list[i].Item, assetCache.archetypes.options);
|
||||
return CreateOptionsUIField(parentTransform, titleParameter, baseValue, setAction, (i) => assetCache.archetypes.list[i].Item, assetCache.archetypes.options);
|
||||
}
|
||||
|
||||
public DropdownInputField CreateCopyNodeBehaviourOptionsUIField(Transform parentTransform, string title, float offset, int baseValue, Action<DunGenExtenderProperties.CopyNodeBehaviour> setAction){
|
||||
public DropdownInputField CreateCopyNodeBehaviourOptionsUIField(Transform parentTransform, TitleParameter titleParameter, int baseValue, Action<DunGenExtenderProperties.CopyNodeBehaviour> setAction){
|
||||
var options = Enum.GetNames(typeof(DunGenExtenderProperties.CopyNodeBehaviour));
|
||||
return CreateOptionsUIField(parentTransform, title, offset, baseValue, setAction, (i) => (DunGenExtenderProperties.CopyNodeBehaviour)i, options);
|
||||
return CreateOptionsUIField(parentTransform, titleParameter, baseValue, setAction, (i) => (DunGenExtenderProperties.CopyNodeBehaviour)i, options);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,6 +11,8 @@ using TMPro;
|
|||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using DunGenPlus.DevTools.UIElements;
|
||||
using DunGenPlus.DevTools.UIElements.Collections;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace DunGenPlus.DevTools.Panels {
|
||||
internal class DunGenPlusPanel : BasePanel {
|
||||
|
@ -38,26 +40,28 @@ namespace DunGenPlus.DevTools.Panels {
|
|||
public class DungeonFlowCacheAssets {
|
||||
public DunGenExtenderProperties originalProperties;
|
||||
|
||||
// Albino said that readonly is safer
|
||||
public struct Collection<T> {
|
||||
public List<T> list;
|
||||
public Dictionary<T, int> dictionary;
|
||||
public IEnumerable<string> options;
|
||||
public ReadOnlyCollection<T> list;
|
||||
public ReadOnlyDictionary<T, int> dictionary;
|
||||
public ReadOnlyCollection<string> options;
|
||||
|
||||
public Collection(List<T> list) {
|
||||
this.list = list;
|
||||
this.list = new ReadOnlyCollection<T>(list);
|
||||
|
||||
dictionary = new Dictionary<T, int>();
|
||||
var tempDictionary = new Dictionary<T, int>();
|
||||
for(var i = 0; i < list.Count; i++) {
|
||||
dictionary.Add(list[i], i);
|
||||
tempDictionary.Add(list[i], i);
|
||||
}
|
||||
dictionary = new ReadOnlyDictionary<T, int>(tempDictionary);
|
||||
|
||||
options = list.Select(l => l.ToString());
|
||||
options = new ReadOnlyCollection<string>(list.Select(l => l.ToString()).ToList());
|
||||
}
|
||||
}
|
||||
|
||||
public Collection<NullObject<TileSet>> tileSets;
|
||||
public Collection<NullObject<GameObject>> tiles;
|
||||
public Collection<NullObject<DungeonArchetype>> archetypes;
|
||||
public readonly Collection<NullObject<TileSet>> tileSets;
|
||||
public readonly Collection<NullObject<GameObject>> tiles;
|
||||
public readonly Collection<NullObject<DungeonArchetype>> archetypes;
|
||||
|
||||
public DungeonFlowCacheAssets(DunGenExtender extender){
|
||||
originalProperties = extender.Properties.Copy();
|
||||
|
@ -158,35 +162,35 @@ namespace DunGenPlus.DevTools.Panels {
|
|||
|
||||
var parentTransform = selectedGameObject.transform;
|
||||
var properties = selectedExtenderer.Properties;
|
||||
manager.CreateBoolInputField(parentTransform, "Activate DunGenPlus", 0f, selectedExtenderer.Active, SetActivateDunGenPlus);
|
||||
manager.CreateBoolInputField(parentTransform, "Activate DunGenPlus", selectedExtenderer.Active, SetActivateDunGenPlus);
|
||||
manager.CreateSpaceUIField(parentTransform);
|
||||
|
||||
var mainPathTransform = manager.CreateVerticalLayoutUIField(parentTransform);
|
||||
mainPathParentGameobject = mainPathTransform.gameObject;
|
||||
manager.CreateHeaderUIField(parentTransform, "Main Path", 0f);
|
||||
manager.CreateIntSliderField(parentTransform, "Main Path Count", 0f, properties.MainPathCount, SetMainPathCount);
|
||||
manager.CreateHeaderUIField(parentTransform, "Main Path");
|
||||
manager.CreateIntSliderField(parentTransform, "Main Path Count", new IntParameter(properties.MainPathCount, 1, 10), SetMainPathCount);
|
||||
mainPathTransform.SetAsLastSibling();
|
||||
manager.CreateTileOptionsUIField(mainPathTransform, "Main Room Tile Prefab", 0f, selectedAssetCache.tiles.dictionary[properties.MainRoomTilePrefab], SetMainRoom);
|
||||
manager.CreateCopyNodeBehaviourOptionsUIField(mainPathTransform, "Copy Node Behaviour", 0f, (int)properties.MainPathCopyNodeBehaviour, SetCopyNodeBehaviour);
|
||||
manager.CreateTileOptionsUIField(mainPathTransform, "Main Room Tile Prefab", selectedAssetCache.tiles.dictionary[properties.MainRoomTilePrefab], SetMainRoom);
|
||||
manager.CreateCopyNodeBehaviourOptionsUIField(mainPathTransform, "Copy Node Behaviour", (int)properties.MainPathCopyNodeBehaviour, SetCopyNodeBehaviour);
|
||||
manager.CreateSpaceUIField(parentTransform);
|
||||
|
||||
var dungeonBoundsTransform = manager.CreateVerticalLayoutUIField(parentTransform);
|
||||
dungeonBoundsParentGameobject = dungeonBoundsTransform.gameObject;
|
||||
manager.CreateHeaderUIField(parentTransform, "Dungeon Bounds", 0f);
|
||||
manager.CreateBoolInputField(parentTransform, "Use Dungeon Bounds", 0f, properties.UseDungeonBounds, SetUseDungeonBounds);
|
||||
manager.CreateHeaderUIField(parentTransform, "Dungeon Bounds");
|
||||
manager.CreateBoolInputField(parentTransform, "Use Dungeon Bounds", properties.UseDungeonBounds, SetUseDungeonBounds);
|
||||
dungeonBoundsTransform.SetAsLastSibling();
|
||||
manager.CreateVector3InputField(dungeonBoundsTransform, "Size Base", 0f, properties.DungeonSizeBase, SetDungeonBoundsSizeBase);
|
||||
manager.CreateVector3InputField(dungeonBoundsTransform, "Size Factor", 0f, properties.DungeonSizeFactor, SetDungeonBoundsSizeFactor);
|
||||
manager.CreateVector3InputField(dungeonBoundsTransform, "Position Offset", 0f, properties.DungeonPositionOffset, SetDungeonBoundsPosOffset);
|
||||
manager.CreateVector3InputField(dungeonBoundsTransform, "Position Pivot", 0f, properties.DungeonPositionPivot, SetDungeonBoundsPosPivot);
|
||||
manager.CreateVector3InputField(dungeonBoundsTransform, "Size Base", properties.DungeonSizeBase, SetDungeonBoundsSizeBase);
|
||||
manager.CreateVector3InputField(dungeonBoundsTransform, "Size Factor", properties.DungeonSizeFactor, SetDungeonBoundsSizeFactor);
|
||||
manager.CreateVector3InputField(dungeonBoundsTransform, "Position Offset", properties.DungeonPositionOffset, SetDungeonBoundsPosOffset);
|
||||
manager.CreateVector3InputField(dungeonBoundsTransform, "Position Pivot", properties.DungeonPositionPivot, SetDungeonBoundsPosPivot);
|
||||
manager.CreateSpaceUIField(parentTransform);
|
||||
|
||||
var archetypesTransform = manager.CreateVerticalLayoutUIField(parentTransform);
|
||||
archetypesNodesParentGameobject = archetypesTransform.gameObject;
|
||||
manager.CreateHeaderUIField(parentTransform, "Archetypes Normal Nodes", 0f);
|
||||
manager.CreateBoolInputField(parentTransform, "Add Archetypes", 0f, properties.AddArchetypesToNormalNodes, SetAddArchetypes);
|
||||
manager.CreateHeaderUIField(parentTransform, "Archetypes Normal Nodes");
|
||||
manager.CreateBoolInputField(parentTransform, "Add Archetypes", properties.AddArchetypesToNormalNodes, SetAddArchetypes);
|
||||
archetypesTransform.SetAsLastSibling();
|
||||
manager.CreateListUIField(archetypesTransform, "Normal Node Archetypes", 0f, properties.NormalNodeArchetypes);
|
||||
manager.CreateListUIField(archetypesTransform, "Normal Node Archetypes", properties.NormalNodeArchetypes);
|
||||
manager.CreateSpaceUIField(parentTransform);
|
||||
|
||||
dungeonBoundsHelperGameObject.SetActive(selectedExtenderer.Properties.UseDungeonBounds);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using DunGen;
|
||||
using DunGenPlus.DevTools.UIElements;
|
||||
using DunGenPlus.DevTools.UIElements.Collections;
|
||||
using LethalLevelLoader;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
@ -29,22 +30,22 @@ namespace DunGenPlus.DevTools.Panels {
|
|||
var gen = dungeon.Generator;
|
||||
var parentTransform = mainGameObject.transform;
|
||||
|
||||
manager.CreateHeaderUIField(parentTransform, "Dungeon Generator", 0f);
|
||||
seedInputField = manager.CreateIntInputField(parentTransform, "Seed", 0f, gen.Seed, SetSeed);
|
||||
manager.CreateBoolInputField(parentTransform, "Randomize Seed", 0f, gen.ShouldRandomizeSeed, SetRandomSeed);
|
||||
manager.CreateHeaderUIField(parentTransform, "Dungeon Generator");
|
||||
seedInputField = manager.CreateIntInputField(parentTransform, "Seed", gen.Seed, SetSeed);
|
||||
manager.CreateBoolInputField(parentTransform, "Randomize Seed", gen.ShouldRandomizeSeed, SetRandomSeed);
|
||||
manager.CreateSpaceUIField(parentTransform);
|
||||
|
||||
manager.CreateIntInputField(parentTransform, "Max Attempts", 0f, gen.MaxAttemptCount, SetMaxAttempts, 10);
|
||||
manager.CreateIntInputField(parentTransform, "Max Attempts", new IntParameter(gen.MaxAttemptCount, 0, 500, 0), SetMaxAttempts);
|
||||
manager.CreateSpaceUIField(parentTransform);
|
||||
|
||||
manager.CreateBoolInputField(parentTransform, "Generate Async", 0f, gen.GenerateAsynchronously, SetGenerateAsync);
|
||||
manager.CreateFloatInputField(parentTransform, "Max Async (ms)", 0f, gen.MaxAsyncFrameMilliseconds, SetMaxAsync);
|
||||
manager.CreateFloatInputField(parentTransform, "Pause Betwoon Rooms", 0f, gen.PauseBetweenRooms, SetPauseBetweenRooms);
|
||||
manager.CreateBoolInputField(parentTransform, "Generate Async", gen.GenerateAsynchronously, SetGenerateAsync);
|
||||
manager.CreateFloatInputField(parentTransform, "Max Async (ms)", new FloatParameter(gen.MaxAsyncFrameMilliseconds, 0f, float.MaxValue), SetMaxAsync);
|
||||
manager.CreateFloatInputField(parentTransform, "Pause Between Rooms", new FloatParameter(gen.PauseBetweenRooms, 0f, float.MaxValue), SetPauseBetweenRooms);
|
||||
manager.CreateSpaceUIField(parentTransform);
|
||||
|
||||
manager.CreateHeaderUIField(parentTransform, "Levels", 0f);
|
||||
manager.CreateLevelOptionsUIField(parentTransform, "Level", 0f, 0, SetLevel);
|
||||
lengthMultiplierField = manager.CreateTextUIField(parentTransform, "Length Multiplier", 0f);
|
||||
manager.CreateHeaderUIField(parentTransform, "Levels");
|
||||
manager.CreateLevelOptionsUIField(parentTransform, "Level", 0, SetLevel);
|
||||
lengthMultiplierField = manager.CreateTextUIField(parentTransform, "Length Multiplier");
|
||||
SetLevel(levels[0]);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,10 +8,6 @@ using UnityEngine.UI;
|
|||
namespace DunGenPlus.DevTools.UIElements {
|
||||
internal abstract class BaseInputField<T> : BaseUIElement {
|
||||
|
||||
public virtual void SetupInputField(string titleText, float offset, T baseValue, Action<T> setAction, T defaultValue){
|
||||
SetupBase(titleText, offset);
|
||||
}
|
||||
|
||||
public abstract void Set(T value);
|
||||
|
||||
protected int ParseTextInt(string text, int defaultValue = 0) {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using DunGenPlus.DevTools.UIElements.Collections;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
@ -16,11 +17,11 @@ namespace DunGenPlus.DevTools.UIElements {
|
|||
public LayoutElement layoutElement;
|
||||
internal float layoutOffset;
|
||||
|
||||
public void SetupBase(string titleText, float offset) {
|
||||
title = titleText;
|
||||
public void SetupBase(TitleParameter titleParameter) {
|
||||
title = titleParameter.text;
|
||||
SetText(title);
|
||||
|
||||
layoutOffset = offset;
|
||||
layoutOffset = titleParameter.offset;
|
||||
if (layoutElement) {
|
||||
layoutElement.minWidth -= layoutOffset;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using DunGenPlus.DevTools.UIElements.Collections;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
@ -11,8 +12,8 @@ namespace DunGenPlus.DevTools.UIElements {
|
|||
|
||||
public Toggle toggle;
|
||||
|
||||
public override void SetupInputField(string title, float offset, bool baseValue, Action<bool> setAction, bool defaultValue) {
|
||||
base.SetupInputField(title, offset, baseValue, setAction, defaultValue);
|
||||
public void SetupInputField(TitleParameter titleParameter, bool baseValue, Action<bool> setAction) {
|
||||
SetupBase(titleParameter);
|
||||
|
||||
toggle.onValueChanged.AddListener((t) => SetValue(setAction, t));
|
||||
Set(baseValue);
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DunGenPlus.DevTools.UIElements.Collections {
|
||||
internal struct TitleParameter {
|
||||
public string text;
|
||||
public float offset;
|
||||
|
||||
public TitleParameter(string text, float offset = 0f) {
|
||||
this.text = text;
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
public static implicit operator TitleParameter(string text) => new TitleParameter(text);
|
||||
|
||||
}
|
||||
|
||||
internal struct IntParameter {
|
||||
public int baseValue;
|
||||
public int minValue;
|
||||
public int maxValue;
|
||||
public int defaultValue;
|
||||
|
||||
|
||||
public IntParameter(int baseValue, int defaultValue = 0) {
|
||||
this.baseValue = baseValue;
|
||||
this.minValue = int.MinValue;
|
||||
this.maxValue = int.MaxValue;
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
public IntParameter(int baseValue, int minValue, int maxValue, int defaultValue = 0) {
|
||||
this.baseValue = baseValue;
|
||||
this.minValue = minValue;
|
||||
this.maxValue = maxValue;
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
public static implicit operator IntParameter(int baseValue) => new IntParameter(baseValue);
|
||||
|
||||
}
|
||||
|
||||
internal struct FloatParameter {
|
||||
public float baseValue;
|
||||
public float minValue;
|
||||
public float maxValue;
|
||||
public float defaultValue;
|
||||
|
||||
|
||||
public FloatParameter(float baseValue, float defaultValue = 0f) {
|
||||
this.baseValue = baseValue;
|
||||
this.minValue = int.MinValue;
|
||||
this.maxValue = int.MaxValue;
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
public FloatParameter(float baseValue, float minValue, float maxValue, float defaultValue = 0f) {
|
||||
this.baseValue = baseValue;
|
||||
this.minValue = minValue;
|
||||
this.maxValue = maxValue;
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
public static implicit operator FloatParameter(float baseValue) => new FloatParameter(baseValue);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using DunGenPlus.DevTools.UIElements.Collections;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
@ -12,8 +13,8 @@ namespace DunGenPlus.DevTools.UIElements
|
|||
|
||||
public TMP_Dropdown dropDown;
|
||||
|
||||
public void SetupDropdown<T>(string titleText, float offset, int baseValue, Action<T> setAction, Func<int, T> convertIndex, IEnumerable<string> options) {
|
||||
SetupBase(titleText, offset);
|
||||
public void SetupDropdown<T>(TitleParameter titleParameter, int baseValue, Action<T> setAction, Func<int, T> convertIndex, IEnumerable<string> options) {
|
||||
SetupBase(titleParameter);
|
||||
|
||||
dropDown.options = options.Select(c => {
|
||||
return new TMP_Dropdown.OptionData(c.Substring(0, Math.Min(24, c.Length)));
|
||||
|
|
|
@ -1,28 +1,35 @@
|
|||
using System;
|
||||
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;
|
||||
|
||||
namespace DunGenPlus.DevTools.UIElements
|
||||
{
|
||||
internal class FloatInputField : BaseInputField<float> {
|
||||
|
||||
public TMP_InputField inputField;
|
||||
internal float defaultValue = 0f;
|
||||
internal float minValue;
|
||||
internal float maxValue;
|
||||
internal float defaultValue;
|
||||
|
||||
public override void SetupInputField(string title, float offset, float baseValue, Action<float> setAction , float defaultValue) {
|
||||
base.SetupInputField(title, offset, baseValue, setAction, defaultValue);
|
||||
this.defaultValue = defaultValue;
|
||||
public void SetupInputField(TitleParameter titleParameter, FloatParameter floatParameter, Action<float> setAction) {
|
||||
SetupBase(titleParameter);
|
||||
minValue = floatParameter.minValue;
|
||||
maxValue = floatParameter.maxValue;
|
||||
defaultValue = floatParameter.defaultValue;
|
||||
|
||||
inputField.onValueChanged.AddListener((t) => SetValue(setAction, t));
|
||||
Set(baseValue);
|
||||
Set(floatParameter.baseValue);
|
||||
}
|
||||
|
||||
private void SetValue(Action<float> setAction, string text) {
|
||||
Plugin.logger.LogInfo($"Setting {title} to {text}");
|
||||
setAction.Invoke(ParseTextFloat(text, defaultValue));
|
||||
var value = ParseTextFloat(text, defaultValue);
|
||||
setAction.Invoke(Mathf.Clamp(value, minValue, maxValue));
|
||||
}
|
||||
|
||||
public override void Set(float value){
|
||||
|
|
|
@ -1,27 +1,34 @@
|
|||
using System;
|
||||
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;
|
||||
|
||||
namespace DunGenPlus.DevTools.UIElements {
|
||||
internal class IntInputField : BaseInputField<int> {
|
||||
|
||||
public TMP_InputField inputField;
|
||||
internal int defaultValue = 0;
|
||||
internal int minValue;
|
||||
internal int maxValue;
|
||||
internal int defaultValue;
|
||||
|
||||
public override void SetupInputField(string title, float offset, int baseValue, Action<int> setAction , int defaultValue) {
|
||||
base.SetupInputField(title, offset, baseValue, setAction, defaultValue);
|
||||
this.defaultValue = defaultValue;
|
||||
public void SetupInputField(TitleParameter titleParameter, IntParameter intParameter, Action<int> setAction) {
|
||||
SetupBase(titleParameter);
|
||||
minValue = intParameter.minValue;
|
||||
maxValue = intParameter.maxValue;
|
||||
defaultValue = intParameter.defaultValue;
|
||||
|
||||
inputField.onValueChanged.AddListener((t) => SetValue(setAction, t));
|
||||
Set(baseValue);
|
||||
Set(intParameter.baseValue);
|
||||
}
|
||||
|
||||
private void SetValue(Action<int> setAction, string text) {
|
||||
Plugin.logger.LogInfo($"Setting {title} to {text}");
|
||||
setAction.Invoke(ParseTextInt(text, defaultValue));
|
||||
var value = ParseTextInt(text, defaultValue);
|
||||
setAction.Invoke(Mathf.Clamp(value, minValue, maxValue));
|
||||
}
|
||||
|
||||
public override void Set(int value){
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using DunGenPlus.DevTools.UIElements.Collections;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
@ -12,14 +13,14 @@ namespace DunGenPlus.DevTools.UIElements {
|
|||
|
||||
public Slider inputField;
|
||||
public TextMeshProUGUI textMesh;
|
||||
internal int defaultValue = 0;
|
||||
|
||||
public override void SetupInputField(string title, float offset, int baseValue, Action<int> setAction , int defaultValue) {
|
||||
base.SetupInputField(title, offset, baseValue, setAction, defaultValue);
|
||||
this.defaultValue = defaultValue;
|
||||
public void SetupInputField(TitleParameter titleParameter, IntParameter intParameter, Action<int> setAction) {
|
||||
SetupBase(titleParameter);
|
||||
|
||||
inputField.minValue = inputField.minValue;
|
||||
inputField.maxValue = inputField.maxValue;
|
||||
inputField.onValueChanged.AddListener((t) => SetValue(setAction, t));
|
||||
Set(baseValue);
|
||||
Set(intParameter.baseValue);
|
||||
}
|
||||
|
||||
private void SetValue(Action<int> setAction, float value) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using DunGen;
|
||||
using DunGenPlus.Collections;
|
||||
using DunGenPlus.DevTools.Panels;
|
||||
using DunGenPlus.DevTools.UIElements.Collections;
|
||||
using LethalLevelLoader;
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
@ -10,6 +11,7 @@ using System.Text;
|
|||
using System.Threading.Tasks;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace DunGenPlus.DevTools.UIElements {
|
||||
internal class ListUIElement : BaseUIElement {
|
||||
|
@ -20,8 +22,11 @@ namespace DunGenPlus.DevTools.UIElements {
|
|||
internal IList list;
|
||||
internal Type listType;
|
||||
|
||||
public void SetupList<T>(string titleText, float offset, List<T> list) {
|
||||
SetupBase(titleText, offset);
|
||||
public void SetupList<T>(TitleParameter titleParameter, List<T> list) {
|
||||
SetupBase(titleParameter);
|
||||
|
||||
var cValue = Mathf.LerpUnclamped(0.4f, 0.6f, titleParameter.offset / 100f);
|
||||
listTransform.GetComponent<Image>().color = new Color(cValue, cValue, cValue, 1f);
|
||||
|
||||
this.list = list;
|
||||
listType = typeof(T);
|
||||
|
@ -55,13 +60,13 @@ namespace DunGenPlus.DevTools.UIElements {
|
|||
if (listType == typeof(DungeonArchetype)){
|
||||
var entry = (DungeonArchetype)list[index];
|
||||
var baseValue = DunGenPlusPanel.Instance.selectedAssetCache.archetypes.dictionary[entry];
|
||||
DevDebugManager.Instance.CreateArchetypeOptionsUIField(copyParentTransform, "Archetype", layoutOffset + 24f, baseValue, (t) => list[index] = t);
|
||||
DevDebugManager.Instance.CreateArchetypeOptionsUIField(copyParentTransform, new TitleParameter("Archetype", layoutOffset + 24f), baseValue, (t) => list[index] = t);
|
||||
}
|
||||
|
||||
else if (listType == typeof(NodeArchetype)) {
|
||||
var entry = (NodeArchetype)list[index];
|
||||
DevDebugManager.Instance.CreateStringInputField(copyParentTransform, "Label", layoutOffset + 24f, entry.label, (t) => entry.label = t);
|
||||
DevDebugManager.Instance.CreateListUIField(copyParentTransform, "Archetypes", layoutOffset + 24f, entry.archetypes);
|
||||
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);
|
||||
}
|
||||
|
||||
copy.SetActive(true);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using DunGenPlus.DevTools.UIElements.Collections;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
@ -11,8 +12,8 @@ namespace DunGenPlus.DevTools.UIElements
|
|||
|
||||
public TMP_InputField inputField;
|
||||
|
||||
public override void SetupInputField(string title, float offset, string baseValue, Action<string> setAction, string defaultValue) {
|
||||
base.SetupInputField(title, offset, baseValue, setAction, defaultValue);
|
||||
public void SetupInputField(TitleParameter titleParameter, string baseValue, Action<string> setAction) {
|
||||
SetupBase(titleParameter);
|
||||
|
||||
inputField.onValueChanged.AddListener((t) => SetValue(setAction, t));
|
||||
Set(baseValue);
|
||||
|
|
|
@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace DunGenPlus.DevTools.UIElements {
|
||||
internal class TextUIElement : BaseUIElement {
|
||||
|
||||
// left empty cause abstract BaseUIElement is abstract, can't be a component
|
||||
// but this can be, and BaseUIElement gives it all the functionality required to work as a simple Text UI Element (as name implies jajajajaja)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using DunGenPlus.DevTools.UIElements.Collections;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
@ -17,8 +18,8 @@ namespace DunGenPlus.DevTools.UIElements {
|
|||
public TMP_InputField zInputField;
|
||||
private Vector3 _value;
|
||||
|
||||
public override void SetupInputField(string titleText, float offset, Vector3 baseValue, Action<Vector3> setAction, Vector3 defaultValue) {
|
||||
base.SetupInputField(titleText, offset, baseValue, setAction, defaultValue);
|
||||
public void SetupInputField(TitleParameter titleParameter, Vector3 baseValue, Action<Vector3> setAction) {
|
||||
SetupBase(titleParameter);
|
||||
|
||||
xInputField.onValueChanged.AddListener((t) => SetXValue(setAction, t));
|
||||
yInputField.onValueChanged.AddListener((t) => SetYValue(setAction, t));
|
||||
|
|
|
@ -160,6 +160,7 @@
|
|||
<Compile Include="DevTools\UIElements\IntInputField.cs" />
|
||||
<Compile Include="DevTools\UIElements\IntSliderField.cs" />
|
||||
<Compile Include="DevTools\UIElements\ListUIElement.cs" />
|
||||
<Compile Include="DevTools\UIElements\Collections\Parameters.cs" />
|
||||
<Compile Include="DevTools\UIElements\StringInputField.cs" />
|
||||
<Compile Include="DevTools\UIElements\TextUIElement.cs" />
|
||||
<Compile Include="DevTools\UIElements\Vector3InputField.cs" />
|
||||
|
|
|
@ -12,10 +12,19 @@ using DunGenPlus.Utils;
|
|||
using DunGenPlus.Generation;
|
||||
using DunGenPlus.Managers;
|
||||
using DunGenPlus.Collections;
|
||||
using DunGenPlus.DevTools;
|
||||
|
||||
namespace DunGenPlus.Patches {
|
||||
internal class DungeonGeneratorPatch {
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(DungeonGenerator), "InnerGenerate")]
|
||||
public static void InnerGeneratePatch(ref DungeonGenerator __instance, bool isRetry, ref IEnumerator __result){
|
||||
if (DevDebugManager.Instance && !isRetry) {
|
||||
DevDebugManager.Instance.RecordNewSeed(__instance.ChosenSeed);
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(DungeonGenerator), "GenerateMainPath")]
|
||||
public static void GenerateMainPathPatch(ref DungeonGenerator __instance, ref IEnumerator __result){
|
||||
|
@ -34,6 +43,8 @@ namespace DunGenPlus.Patches {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(DungeonGenerator), "GenerateMainPath", MethodType.Enumerator)]
|
||||
public static IEnumerable<CodeInstruction> GenerateMainPathPatch(IEnumerable<CodeInstruction> instructions){
|
||||
|
|
Loading…
Reference in New Issue