Fix Custom Editors groups regression

This commit is contained in:
Wojtek Figat
2022-11-30 17:18:58 +01:00
parent 9e1692e3e0
commit a3a001633b
3 changed files with 34 additions and 14 deletions

View File

@@ -225,7 +225,8 @@ namespace FlaxEditor.CustomEditors.Editors
}
private static HashSet<PropertiesList> _visibleIfPropertiesListsCache;
private static Dictionary<string, GroupElement> _groups;
private static Stack<Dictionary<string, GroupElement>> _groups;
private static List<Dictionary<string, GroupElement>> _groupsPool;
private VisibleIfCache[] _visibleIfCaches;
private bool _isNull;
@@ -514,17 +515,38 @@ namespace FlaxEditor.CustomEditors.Editors
menu.Show(groupPanel, location);
}
internal static void OnGroupUsage()
internal static void OnGroupsBegin()
{
if (_groups != null)
_groups.Clear();
if (_groups == null)
_groups = new Stack<Dictionary<string, GroupElement>>();
if (_groupsPool == null)
_groupsPool = new List<Dictionary<string, GroupElement>>();
Dictionary<string, GroupElement> group;
if (_groupsPool.Count != 0)
{
group = _groupsPool[0];
_groupsPool.RemoveAt(0);
}
else
{
group = new Dictionary<string, GroupElement>();
}
_groups.Push(group);
}
internal static void OnGroupsEnd()
{
var groups = _groups.Pop();
groups.Clear();
_groupsPool.Add(groups);
}
internal static LayoutElementsContainer OnGroup(LayoutElementsContainer layout, EditorDisplayAttribute display)
{
if (display?.Group != null)
{
if (_groups != null && _groups.TryGetValue(display.Group, out var group))
var groups = _groups.Peek();
if (groups.TryGetValue(display.Group, out var group))
{
// Reuse group
layout = group;
@@ -532,12 +554,10 @@ namespace FlaxEditor.CustomEditors.Editors
else
{
// Add new group
if (_groups == null)
_groups = new Dictionary<string, GroupElement>();
group = layout.Group(display.Group);
group.Panel.Tag = group;
group.Panel.MouseButtonRightClicked += OnGroupPanelMouseButtonRightClicked;
_groups.Add(display.Group, group);
groups.Add(display.Group, group);
layout = group;
}
}
@@ -713,7 +733,7 @@ namespace FlaxEditor.CustomEditors.Editors
items.Sort();
// Add items
OnGroupUsage();
OnGroupsBegin();
for (int i = 0; i < items.Count; i++)
{
var item = items[i];
@@ -759,7 +779,7 @@ namespace FlaxEditor.CustomEditors.Editors
} while (c != null);
}
}
OnGroupUsage();
OnGroupsEnd();
}
/// <inheritdoc />

View File

@@ -285,7 +285,7 @@ namespace FlaxEditor.Surface
internal static void DisplayGraphParameters(LayoutElementsContainer layout, GraphParameterData[] data, GetGraphParameterDelegate getter, SetGraphParameterDelegate setter, ValueContainer values, GetGraphParameterDelegate defaultValueGetter = null, CustomPropertySpawnDelegate propertySpawn = null)
{
CustomEditors.Editors.GenericEditor.OnGroupUsage();
CustomEditors.Editors.GenericEditor.OnGroupsBegin();
for (int i = 0; i < data.Length; i++)
{
ref var e = ref data[i];
@@ -332,7 +332,7 @@ namespace FlaxEditor.Surface
else
propertySpawn(itemLayout, valueContainer, ref e);
}
CustomEditors.Editors.GenericEditor.OnGroupUsage();
CustomEditors.Editors.GenericEditor.OnGroupsEnd();
}
internal static string GetMethodDisplayName(string methodName)

View File

@@ -372,7 +372,7 @@ namespace FlaxEditor.Surface
return;
}
var parameters = window.VisjectSurface.Parameters;
CustomEditors.Editors.GenericEditor.OnGroupUsage();
CustomEditors.Editors.GenericEditor.OnGroupsBegin();
for (int i = 0; i < parameters.Count; i++)
{
var p = parameters[i];
@@ -429,7 +429,7 @@ namespace FlaxEditor.Surface
var property = itemLayout.AddPropertyItem(propertyLabel, tooltipText);
property.Property("Value", propertyValue);
}
CustomEditors.Editors.GenericEditor.OnGroupUsage();
CustomEditors.Editors.GenericEditor.OnGroupsEnd();
// Parameters creating
var newParameterTypes = window.NewParameterTypes;