finished rest of DunGenPlus dev panel

This commit is contained in:
LadyAliceMargatroid 2024-08-24 08:27:19 -07:00
parent fdb1767890
commit 101e2c3904
9 changed files with 256 additions and 82 deletions

View File

@ -5,6 +5,18 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace DunGenPlus.Collections { namespace DunGenPlus.Collections {
public struct EventCallbackScenario {
public bool IsDevDebug;
public EventCallbackScenario(bool isDevDebug){
IsDevDebug = isDevDebug;
}
}
public class ExtenderEvent<T> { public class ExtenderEvent<T> {
internal event ParameterEvent onParameterEvent; internal event ParameterEvent onParameterEvent;
@ -13,8 +25,8 @@ namespace DunGenPlus.Collections {
/// Calls listeners. /// Calls listeners.
/// </summary> /// </summary>
/// <param name="param"></param> /// <param name="param"></param>
public void Invoke(T param) { public void Invoke(T param1, EventCallbackScenario param2) {
onParameterEvent?.Invoke(param); onParameterEvent?.Invoke(param1, param2);
} }
/// <summary> /// <summary>
@ -33,6 +45,7 @@ namespace DunGenPlus.Collections {
onParameterEvent -= listener; onParameterEvent -= listener;
} }
public delegate void ParameterEvent(T param); public delegate void ParameterEvent(T param1, EventCallbackScenario param2);
} }
} }

View File

@ -127,6 +127,11 @@ namespace DunGenPlus.DevTools {
return CreateOptionsUIField(parentTransform, titleParameter, 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 CreateTileSetsOptionsUIField(Transform parentTransform, TitleParameter titleParameter, int baseValue, Action<TileSet> setAction){
var assetCache = DunGenPlusPanel.Instance.selectedAssetCache;
return CreateOptionsUIField(parentTransform, titleParameter, baseValue, setAction, (i) => assetCache.tileSets.list[i].Item, assetCache.tileSets.options);
}
public DropdownInputField CreateArchetypeOptionsUIField(Transform parentTransform, TitleParameter titleParameter, int baseValue, Action<DungeonArchetype> setAction){ public DropdownInputField CreateArchetypeOptionsUIField(Transform parentTransform, TitleParameter titleParameter, int baseValue, Action<DungeonArchetype> setAction){
var assetCache = DunGenPlusPanel.Instance.selectedAssetCache; var assetCache = DunGenPlusPanel.Instance.selectedAssetCache;
return CreateOptionsUIField(parentTransform, titleParameter, 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);
@ -137,5 +142,39 @@ namespace DunGenPlus.DevTools {
return CreateOptionsUIField(parentTransform, titleParameter, baseValue, setAction, (i) => (DunGenExtenderProperties.CopyNodeBehaviour)i, options); return CreateOptionsUIField(parentTransform, titleParameter, baseValue, setAction, (i) => (DunGenExtenderProperties.CopyNodeBehaviour)i, options);
} }
public DropdownInputField CreateAnimationCurveOptionsUIField(Transform parentTransform, TitleParameter titleParameter, AnimationCurve baseValue, Action<AnimationCurve> setAction){
var result = CreateAnimationCurves(baseValue);
var curves = result.animationCurves;
var options = result.options;
setAction.Invoke(curves[0]);
return CreateOptionsUIField(parentTransform, titleParameter, 0, setAction, (i) => curves[i], options);
}
private (List<AnimationCurve> animationCurves, List<string> options) CreateAnimationCurves(AnimationCurve custom){
var curves = new List<AnimationCurve>();
var options = new List<string>();
if (custom != null){
curves.Add(custom);
options.Add("Custom");
}
curves.Add(AnimationCurve.Constant(0f, 1f, 1f));
options.Add("Constant 1");
curves.Add(AnimationCurve.Linear(0f, 0f, 1f, 1f));
options.Add("Linear 0-1");
curves.Add(AnimationCurve.Linear(1f, 1f, 0f, 0f));
options.Add("Linear 1-0");
curves.Add(AnimationCurve.EaseInOut(0f, 0f, 1f, 1f));
options.Add("EaseInOut 0-1");
curves.Add(AnimationCurve.EaseInOut(1f, 1f, 0f, 0f));
options.Add("EaseInOut 1-0");
return (curves, options);
}
} }
} }

View File

@ -0,0 +1,96 @@
using DunGen;
using DunGenPlus.Collections;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace DunGenPlus.DevTools.Panels.Collections {
internal class DungeonFlowCacheAssets {
public DunGenExtenderProperties originalProperties;
// Albino said that readonly is safer
public struct Collection<T> {
public ReadOnlyCollection<T> list;
public ReadOnlyDictionary<T, int> dictionary;
public ReadOnlyCollection<string> options;
public Collection(List<T> list) {
this.list = new ReadOnlyCollection<T>(list);
var tempDictionary = new Dictionary<T, int>();
for(var i = 0; i < list.Count; i++) {
tempDictionary.Add(list[i], i);
}
dictionary = new ReadOnlyDictionary<T, int>(tempDictionary);
options = new ReadOnlyCollection<string>(list.Select(l => l.ToString()).ToList());
}
}
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();
var tileSetsHashSet = new HashSet<NullObject<TileSet>>() { new NullObject<TileSet>(null) };
var tilesHashSet = new HashSet<NullObject<GameObject>>() { new NullObject<GameObject>(null) };
var archetypesHashSet = new HashSet<NullObject<DungeonArchetype>>() { new NullObject<DungeonArchetype>(null) };
foreach(var t in extender.DungeonFlow.Nodes) {
var label = t.Label.ToLowerInvariant();
if (label == "lchc gate" || label == "goal"){
foreach(var n in t.TileSets.SelectMany(x => x.TileWeights.Weights)) {
n.Value.GetComponent<Tile>().RepeatMode = TileRepeatMode.Allow;
}
}
}
foreach(var t in extender.DungeonFlow.Nodes.SelectMany(n => n.TileSets)) {
tileSetsHashSet.Add(t);
foreach(var x in t.TileWeights.Weights) {
tilesHashSet.Add(x.Value);
}
}
foreach(var a in extender.DungeonFlow.Lines.SelectMany(l => l.DungeonArchetypes)) {
archetypesHashSet.Add(a);
foreach(var t in a.TileSets) {
tileSetsHashSet.Add(t);
foreach(var x in t.TileWeights.Weights) {
tilesHashSet.Add(x.Value);
}
}
}
foreach(var n in extender.Properties.NormalNodeArchetypes) {
foreach(var a in n.archetypes){
archetypesHashSet.Add(a);
foreach(var t in a.TileSets){
tileSetsHashSet.Add(t);
foreach(var x in t.TileWeights.Weights){
tilesHashSet.Add(x.Value);
}
}
}
}
foreach(var t in extender.Properties.ForcedTileSets.SelectMany(l => l.Tilesets)){
tileSetsHashSet.Add(t);
foreach(var x in t.TileWeights.Weights){
tilesHashSet.Add(x.Value);
}
}
tileSets = new Collection<NullObject<TileSet>>(tileSetsHashSet.ToList());
tiles = new Collection<NullObject<GameObject>>(tilesHashSet.ToList());
archetypes = new Collection<NullObject<DungeonArchetype>>(archetypesHashSet.ToList());
}
}
}

View File

@ -12,7 +12,7 @@ using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using DunGenPlus.DevTools.UIElements; using DunGenPlus.DevTools.UIElements;
using DunGenPlus.DevTools.UIElements.Collections; using DunGenPlus.DevTools.UIElements.Collections;
using System.Collections.ObjectModel; using DunGenPlus.DevTools.Panels.Collections;
namespace DunGenPlus.DevTools.Panels { namespace DunGenPlus.DevTools.Panels {
internal class DunGenPlusPanel : BasePanel { internal class DunGenPlusPanel : BasePanel {
@ -26,87 +26,17 @@ namespace DunGenPlus.DevTools.Panels {
[Header("Panel References")] [Header("Panel References")]
public GameObject createGameObject; public GameObject createGameObject;
public GameObject selectedGameObject; public GameObject selectedGameObject;
public GameObject selectedListGameObject;
[Header("Dungeon Bounds Helper")] [Header("Dungeon Bounds Helper")]
public GameObject dungeonBoundsHelperGameObject; public GameObject dungeonBoundsHelperGameObject;
[Header("Selected Panel References")]
public Toggle activateDunGenPlusToggle;
private GameObject mainPathParentGameobject; private GameObject mainPathParentGameobject;
private GameObject dungeonBoundsParentGameobject; private GameObject dungeonBoundsParentGameobject;
private GameObject archetypesNodesParentGameobject; private GameObject archetypesNodesParentGameobject;
private GameObject forcedTilesParentGameobject;
public class DungeonFlowCacheAssets { private GameObject branchLoopBoostParentGameobject;
public DunGenExtenderProperties originalProperties; private GameObject maxShadowsParentGameobject;
// Albino said that readonly is safer
public struct Collection<T> {
public ReadOnlyCollection<T> list;
public ReadOnlyDictionary<T, int> dictionary;
public ReadOnlyCollection<string> options;
public Collection(List<T> list) {
this.list = new ReadOnlyCollection<T>(list);
var tempDictionary = new Dictionary<T, int>();
for(var i = 0; i < list.Count; i++) {
tempDictionary.Add(list[i], i);
}
dictionary = new ReadOnlyDictionary<T, int>(tempDictionary);
options = new ReadOnlyCollection<string>(list.Select(l => l.ToString()).ToList());
}
}
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();
var tileSetsHashSet = new HashSet<NullObject<TileSet>>() { new NullObject<TileSet>(null) };
var tilesHashSet = new HashSet<NullObject<GameObject>>() { new NullObject<GameObject>(null) };
var archetypesHashSet = new HashSet<NullObject<DungeonArchetype>>() { new NullObject<DungeonArchetype>(null) };
foreach(var t in extender.DungeonFlow.Nodes) {
var label = t.Label.ToLowerInvariant();
if (label == "lchc gate" || label == "goal"){
foreach(var n in t.TileSets.SelectMany(x => x.TileWeights.Weights)) {
n.Value.GetComponent<Tile>().RepeatMode = TileRepeatMode.Allow;
}
}
}
foreach(var t in extender.DungeonFlow.Nodes.SelectMany(n => n.TileSets)) {
tileSetsHashSet.Add(t);
foreach(var x in t.TileWeights.Weights) {
tilesHashSet.Add(x.Value);
}
}
foreach(var a in extender.DungeonFlow.Lines.SelectMany(l => l.DungeonArchetypes)) {
archetypesHashSet.Add(a);
foreach(var t in a.TileSets) {
tileSetsHashSet.Add(t);
foreach(var x in t.TileWeights.Weights) {
tilesHashSet.Add(x.Value);
}
}
}
foreach(var n in extender.Properties.NormalNodeArchetypes) {
foreach(var a in n.archetypes){
archetypesHashSet.Add(a);
}
}
tileSets = new Collection<NullObject<TileSet>>(tileSetsHashSet.ToList());
tiles = new Collection<NullObject<GameObject>>(tilesHashSet.ToList());
archetypes = new Collection<NullObject<DungeonArchetype>>(archetypesHashSet.ToList());
}
}
public Dictionary<DungeonFlow, DungeonFlowCacheAssets> cacheDictionary = new Dictionary<DungeonFlow, DungeonFlowCacheAssets>(); public Dictionary<DungeonFlow, DungeonFlowCacheAssets> cacheDictionary = new Dictionary<DungeonFlow, DungeonFlowCacheAssets>();
@ -160,7 +90,7 @@ namespace DunGenPlus.DevTools.Panels {
selectedExtenderer = extender; selectedExtenderer = extender;
selectedAssetCache = cache; selectedAssetCache = cache;
var parentTransform = selectedGameObject.transform; var parentTransform = selectedListGameObject.transform;
var properties = selectedExtenderer.Properties; var properties = selectedExtenderer.Properties;
manager.CreateBoolInputField(parentTransform, "Activate DunGenPlus", selectedExtenderer.Active, SetActivateDunGenPlus); manager.CreateBoolInputField(parentTransform, "Activate DunGenPlus", selectedExtenderer.Active, SetActivateDunGenPlus);
manager.CreateSpaceUIField(parentTransform); manager.CreateSpaceUIField(parentTransform);
@ -193,12 +123,43 @@ namespace DunGenPlus.DevTools.Panels {
manager.CreateListUIField(archetypesTransform, "Normal Node Archetypes", properties.NormalNodeArchetypes); manager.CreateListUIField(archetypesTransform, "Normal Node Archetypes", properties.NormalNodeArchetypes);
manager.CreateSpaceUIField(parentTransform); manager.CreateSpaceUIField(parentTransform);
var forcedTilesTransform = manager.CreateVerticalLayoutUIField(parentTransform);
forcedTilesParentGameobject = forcedTilesTransform.gameObject;
manager.CreateHeaderUIField(parentTransform, "Forced Tiles");
manager.CreateBoolInputField(parentTransform, "Use Forced Tiles", properties.UseForcedTiles, SetUseForcedTiles);
forcedTilesTransform.SetAsLastSibling();
manager.CreateListUIField(forcedTilesTransform, "Forced Tile Sets", properties.ForcedTileSets);
manager.CreateSpaceUIField(parentTransform);
var branchLoopTransform = manager.CreateVerticalLayoutUIField(parentTransform);
branchLoopBoostParentGameobject = branchLoopTransform.gameObject;
manager.CreateHeaderUIField(parentTransform, "Branch Loop Boost");
manager.CreateBoolInputField(parentTransform, "Use Branch Loop Boost", properties.UseBranchLoopBoost, SetUseBranchLoopBoost);
branchLoopTransform.SetAsLastSibling();
manager.CreateIntInputField(branchLoopTransform, "Tile Search Count", new IntParameter(properties.BranchLoopBoostTileSearch, 1, 100, 1), SetTileBoostSearch);
manager.CreateFloatInputField(branchLoopTransform, "Tile Boost Search", new FloatParameter(properties.BranchLoopBoostTileScale, 0f, 2f, 0f), SetTileBoostScale);
manager.CreateSpaceUIField(parentTransform);
var maxShadowsTransform = manager.CreateVerticalLayoutUIField(parentTransform);
maxShadowsParentGameobject = maxShadowsTransform.gameObject;
manager.CreateHeaderUIField(parentTransform, "Max Shadows Request");
manager.CreateBoolInputField(parentTransform, "Use Max Shadows Request", properties.UseMaxShadowsRequestUpdate, SetUseMaxShadows);
maxShadowsTransform.SetAsLastSibling();
manager.CreateIntInputField(maxShadowsTransform, "Shadows Request Amount", new IntParameter(properties.MaxShadowsRequestAmount, 4, 20, 4), SetMaxShadowsAmount);
manager.CreateSpaceUIField(parentTransform);
// miss
manager.CreateHeaderUIField(parentTransform, "Miscellaneous");
manager.CreateBoolInputField(parentTransform, "Use Doorway Sisters", properties.UseDoorwaySisters, SetUseDoorwaySisters);
manager.CreateBoolInputField(parentTransform, "Use Random Guaranteed Scrap", properties.UseRandomGuaranteedScrapSpawn, SetUseRandomGuaranteedScrap);
manager.CreateSpaceUIField(parentTransform);
dungeonBoundsHelperGameObject.SetActive(selectedExtenderer.Properties.UseDungeonBounds); dungeonBoundsHelperGameObject.SetActive(selectedExtenderer.Properties.UseDungeonBounds);
UpdateDungeonBoundsHelper(); UpdateDungeonBoundsHelper();
} }
public void ClearPanel(){ public void ClearPanel(){
manager.ClearTransformChildren(selectedGameObject.transform); manager.ClearTransformChildren(selectedListGameObject.transform);
} }
public void SetActivateDunGenPlus(bool state){ public void SetActivateDunGenPlus(bool state){
@ -258,5 +219,44 @@ namespace DunGenPlus.DevTools.Panels {
archetypesNodesParentGameobject.SetActive(state); archetypesNodesParentGameobject.SetActive(state);
} }
public void SetUseForcedTiles(bool state){
selectedExtenderer.Properties.UseForcedTiles = state;
forcedTilesParentGameobject.SetActive(state);
}
public void SetUseBranchLoopBoost(bool state){
selectedExtenderer.Properties.UseBranchLoopBoost = state;
branchLoopBoostParentGameobject.SetActive(state);
}
public void SetTileBoostSearch(int value){
selectedExtenderer.Properties.BranchLoopBoostTileSearch = value;
}
public void SetTileBoostScale(float value){
selectedExtenderer.Properties.BranchLoopBoostTileScale = value;
}
public void SetUseMaxShadows(bool state){
selectedExtenderer.Properties.UseMaxShadowsRequestUpdate = state;
maxShadowsParentGameobject.SetActive(state);
}
public void SetMaxShadowsAmount(int value){
selectedExtenderer.Properties.MaxShadowsRequestAmount = value;
}
public void SetUseDoorwaySisters(bool state){
selectedExtenderer.Properties.UseDoorwaySisters = state;
}
public void SetUseRandomGuaranteedScrap(bool state){
selectedExtenderer.Properties.UseRandomGuaranteedScrapSpawn = state;
}
public void RestoreOriginalState(){
selectedExtenderer.Properties.CopyFrom(selectedAssetCache.originalProperties);
}
} }
} }

View File

@ -26,6 +26,7 @@ namespace DunGenPlus.DevTools.UIElements {
private void SetValue(Action<int> setAction, float value) { private void SetValue(Action<int> setAction, float value) {
Plugin.logger.LogInfo($"Setting {title} to {value}"); Plugin.logger.LogInfo($"Setting {title} to {value}");
setAction.Invoke((int)value); setAction.Invoke((int)value);
textMesh.text = value.ToString();
} }
public override void Set(int value){ public override void Set(int value){

View File

@ -37,10 +37,14 @@ namespace DunGenPlus.DevTools.UIElements {
public void AddElement() { public void AddElement() {
object item = null; object item = null;
if (listType == typeof(DungeonArchetype)) { if (listType == typeof(DungeonArchetype) || listType == typeof(TileSet)) {
item = null; item = null;
} else if (listType == typeof(NodeArchetype)) { } else if (listType == typeof(NodeArchetype)) {
item = new NodeArchetype(); item = new NodeArchetype();
} else if (listType == typeof(ForcedTileSetList)){
var forcedTileset = new ForcedTileSetList();
forcedTileset.DepthWeightScale = null;
item = forcedTileset;
} }
list.Add(item); list.Add(item);
@ -63,12 +67,28 @@ namespace DunGenPlus.DevTools.UIElements {
DevDebugManager.Instance.CreateArchetypeOptionsUIField(copyParentTransform, new TitleParameter("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(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)) { else if (listType == typeof(NodeArchetype)) {
var entry = (NodeArchetype)list[index]; var entry = (NodeArchetype)list[index];
DevDebugManager.Instance.CreateStringInputField(copyParentTransform, new TitleParameter("Label", layoutOffset + 24f), entry.label, (t) => entry.label = t); 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); 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);
}
copy.SetActive(true); copy.SetActive(true);
} }
@ -78,5 +98,7 @@ namespace DunGenPlus.DevTools.UIElements {
return copy; return copy;
} }
} }
} }

View File

@ -149,6 +149,7 @@
<Compile Include="DevTools\DevDebugManagerUI.cs" /> <Compile Include="DevTools\DevDebugManagerUI.cs" />
<Compile Include="DevTools\DevDebugOpen.cs" /> <Compile Include="DevTools\DevDebugOpen.cs" />
<Compile Include="DevTools\Panels\BasePanel.cs" /> <Compile Include="DevTools\Panels\BasePanel.cs" />
<Compile Include="DevTools\Panels\Collections\DungeonFlowCacheAssets.cs" />
<Compile Include="DevTools\Panels\DunGenPlusPanel.cs" /> <Compile Include="DevTools\Panels\DunGenPlusPanel.cs" />
<Compile Include="DevTools\Panels\MainPanel.cs" /> <Compile Include="DevTools\Panels\MainPanel.cs" />
<Compile Include="DevTools\PanelTab.cs" /> <Compile Include="DevTools\PanelTab.cs" />

View File

@ -16,6 +16,7 @@ using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition; using UnityEngine.Rendering.HighDefinition;
using BepInEx.Logging; using BepInEx.Logging;
using static UnityEngine.Rendering.HighDefinition.ScalableSettingLevelParameter; using static UnityEngine.Rendering.HighDefinition.ScalableSettingLevelParameter;
using DunGenPlus.DevTools;
[assembly: SecurityPermission( SecurityAction.RequestMinimum, SkipVerification = true )] [assembly: SecurityPermission( SecurityAction.RequestMinimum, SkipVerification = true )]
namespace DunGenPlus.Generation { namespace DunGenPlus.Generation {
@ -34,7 +35,8 @@ namespace DunGenPlus.Generation {
ActiveAlternative = true; ActiveAlternative = true;
var props = extender.Properties.Copy(); var props = extender.Properties.Copy();
Instance.Events.OnModifyDunGenExtenderProperties.Invoke(props); var callback = new EventCallbackScenario(DevDebugManager.Instance);
Instance.Events.OnModifyDunGenExtenderProperties.Invoke(props, callback);
props.SetupProperties(generator); props.SetupProperties(generator);
Properties = props; Properties = props;

Binary file not shown.