Add features flags for Custom Editors presentation

This commit is contained in:
Wojciech Figat
2021-11-16 16:33:45 +01:00
parent 46934b086d
commit f69055d85a
6 changed files with 42 additions and 10 deletions

View File

@@ -9,6 +9,33 @@ using FlaxEngine.GUI;
namespace FlaxEditor.CustomEditors
{
/// <summary>
/// The per-feature flags for custom editors system.
/// </summary>
[HideInEditor, Flags]
public enum FeatureFlags
{
/// <summary>
/// Nothing.
/// </summary>
None = 0,
/// <summary>
/// Enables caching the expanded groups in this presenter. Used to preserve the expanded groups using project cache.
/// </summary>
CacheExpandedGroups = 1 << 0,
/// <summary>
/// Enables using prefab-related features of the properties editor (eg. revert to prefab option).
/// </summary>
UsePrefab = 1 << 1,
/// <summary>
/// Enables using default-value-related features of the properties editor (eg. revert to default option).
/// </summary>
UseDefault = 1 << 2,
}
/// <summary>
/// Main class for Custom Editors used to present selected objects properties and allow to modify them.
/// </summary>
@@ -205,9 +232,9 @@ namespace FlaxEditor.CustomEditors
public bool BuildOnUpdate => _buildOnUpdate;
/// <summary>
/// True if cache the expanded groups in this presenter, otherwise will disable this feature. Used to preserve the expanded groups using project cache.
/// The features to use for properties editor.
/// </summary>
public bool CacheExpandedGroups;
public FeatureFlags Features = FeatureFlags.UsePrefab | FeatureFlags.UseDefault;
/// <summary>
/// Occurs when before creating layout for the selected objects editor UI. Can be used to inject custom UI to the layout.

View File

@@ -613,7 +613,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
// Create group
var title = CustomEditorsUtil.GetPropertyNameUI(scriptType.Name);
var group = layout.Group(title, editor);
if (Presenter.CacheExpandedGroups)
if ((Presenter.Features & FeatureFlags.CacheExpandedGroups) != 0)
{
if (Editor.Instance.ProjectCache.IsCollapsedGroup(title))
group.Panel.Close(false);

View File

@@ -118,11 +118,15 @@ namespace FlaxEditor.CustomEditors.GUI
if (linkedEditor != null)
{
var revertToPrefab = menu.AddButton("Revert to Prefab", linkedEditor.RevertToReferenceValue);
revertToPrefab.Enabled = linkedEditor.CanRevertReferenceValue;
var resetToDefault = menu.AddButton("Reset to default", linkedEditor.RevertToDefaultValue);
resetToDefault.Enabled = linkedEditor.CanRevertDefaultValue;
menu.AddSeparator();
var features = linkedEditor.Presenter.Features;
if ((features & (FeatureFlags.UseDefault | FeatureFlags.UsePrefab)) != 0)
{
if ((features & FeatureFlags.UsePrefab) != 0)
menu.AddButton("Revert to Prefab", linkedEditor.RevertToReferenceValue).Enabled = linkedEditor.CanRevertReferenceValue;
if ((features & FeatureFlags.UseDefault) != 0)
menu.AddButton("Reset to default", linkedEditor.RevertToDefaultValue).Enabled = linkedEditor.CanRevertDefaultValue;
menu.AddSeparator();
}
menu.AddButton("Copy", linkedEditor.Copy);
var paste = menu.AddButton("Paste", linkedEditor.Paste);
paste.Enabled = linkedEditor.CanPaste;

View File

@@ -85,7 +85,7 @@ namespace FlaxEditor.CustomEditors
{
element.Panel.Close(false);
}
else if (this is CustomEditorPresenter presenter && presenter.CacheExpandedGroups)
else if (this is CustomEditorPresenter presenter && (presenter.Features & FeatureFlags.CacheExpandedGroups) != 0)
{
if (Editor.Instance.ProjectCache.IsCollapsedGroup(title))
element.Panel.Close(false);

View File

@@ -359,6 +359,7 @@ namespace FlaxEditor.Windows.Assets
// Properties editor
_propertiesEditor = new CustomEditorPresenter(_undo);
_propertiesEditor.Features = FeatureFlags.None;
_propertiesEditor.Panel.Parent = _split.Panel2;
_propertiesEditor.Modified += OnPropertyEdited;
_properties = new PropertiesProxy();

View File

@@ -34,7 +34,7 @@ namespace FlaxEditor.Windows
Presenter = new CustomEditorPresenter(editor.Undo, null, this);
Presenter.Panel.Parent = this;
Presenter.GetUndoObjects += GetUndoObjects;
Presenter.CacheExpandedGroups = true;
Presenter.Features |= FeatureFlags.CacheExpandedGroups;
Editor.SceneEditing.SelectionChanged += OnSelectionChanged;
}