From a3a001633b67fec052897df6203e2ae4f5c23d2a Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Wed, 30 Nov 2022 17:18:58 +0100 Subject: [PATCH] Fix Custom Editors groups regression --- .../CustomEditors/Editors/GenericEditor.cs | 40 ++++++++++++++----- Source/Editor/Surface/SurfaceUtils.cs | 4 +- Source/Editor/Surface/VisjectSurfaceWindow.cs | 4 +- 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/Source/Editor/CustomEditors/Editors/GenericEditor.cs b/Source/Editor/CustomEditors/Editors/GenericEditor.cs index 39b1ca531..8a3f98560 100644 --- a/Source/Editor/CustomEditors/Editors/GenericEditor.cs +++ b/Source/Editor/CustomEditors/Editors/GenericEditor.cs @@ -225,7 +225,8 @@ namespace FlaxEditor.CustomEditors.Editors } private static HashSet _visibleIfPropertiesListsCache; - private static Dictionary _groups; + private static Stack> _groups; + private static List> _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>(); + if (_groupsPool == null) + _groupsPool = new List>(); + Dictionary group; + if (_groupsPool.Count != 0) + { + group = _groupsPool[0]; + _groupsPool.RemoveAt(0); + } + else + { + group = new Dictionary(); + } + _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(); 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(); } /// diff --git a/Source/Editor/Surface/SurfaceUtils.cs b/Source/Editor/Surface/SurfaceUtils.cs index 59d90c916..c69dfdf52 100644 --- a/Source/Editor/Surface/SurfaceUtils.cs +++ b/Source/Editor/Surface/SurfaceUtils.cs @@ -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) diff --git a/Source/Editor/Surface/VisjectSurfaceWindow.cs b/Source/Editor/Surface/VisjectSurfaceWindow.cs index 788eb7a96..43a664866 100644 --- a/Source/Editor/Surface/VisjectSurfaceWindow.cs +++ b/Source/Editor/Surface/VisjectSurfaceWindow.cs @@ -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;