Add Category attribute for types grouping in editor dialogs
This commit is contained in:
@@ -68,19 +68,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
|
|||||||
var cm = new ItemsListContextMenu(180);
|
var cm = new ItemsListContextMenu(180);
|
||||||
for (int i = 0; i < scripts.Count; i++)
|
for (int i = 0; i < scripts.Count; i++)
|
||||||
{
|
{
|
||||||
var scriptType = scripts[i];
|
cm.AddItem(new TypeSearchPopup.TypeItemView(scripts[i]));
|
||||||
var item = new ItemsListContextMenu.Item(scriptType.Name, scriptType)
|
|
||||||
{
|
|
||||||
TooltipText = scriptType.TypeName,
|
|
||||||
};
|
|
||||||
var attributes = scriptType.GetAttributes(false);
|
|
||||||
var tooltipAttribute = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute);
|
|
||||||
if (tooltipAttribute != null)
|
|
||||||
{
|
|
||||||
item.TooltipText += '\n';
|
|
||||||
item.TooltipText += tooltipAttribute.Text;
|
|
||||||
}
|
|
||||||
cm.AddItem(item);
|
|
||||||
}
|
}
|
||||||
cm.ItemClicked += item => AddScript((ScriptType)item.Tag);
|
cm.ItemClicked += item => AddScript((ScriptType)item.Tag);
|
||||||
cm.SortChildren();
|
cm.SortChildren();
|
||||||
|
|||||||
@@ -639,21 +639,8 @@ namespace FlaxEditor.CustomEditors.Dedicated
|
|||||||
var cm = new ItemsListContextMenu(180);
|
var cm = new ItemsListContextMenu(180);
|
||||||
for (int i = 0; i < controlTypes.Count; i++)
|
for (int i = 0; i < controlTypes.Count; i++)
|
||||||
{
|
{
|
||||||
var controlType = controlTypes[i];
|
cm.AddItem(new TypeSearchPopup.TypeItemView(controlTypes[i]));
|
||||||
var item = new ItemsListContextMenu.Item(controlType.Name, controlType)
|
|
||||||
{
|
|
||||||
TooltipText = controlType.TypeName,
|
|
||||||
};
|
|
||||||
var attributes = controlType.GetAttributes(false);
|
|
||||||
var tooltipAttribute = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute);
|
|
||||||
if (tooltipAttribute != null)
|
|
||||||
{
|
|
||||||
item.TooltipText += '\n';
|
|
||||||
item.TooltipText += tooltipAttribute.Text;
|
|
||||||
}
|
}
|
||||||
cm.AddItem(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
cm.ItemClicked += controlType => SetType((ScriptType)controlType.Tag);
|
cm.ItemClicked += controlType => SetType((ScriptType)controlType.Tag);
|
||||||
cm.SortChildren();
|
cm.SortChildren();
|
||||||
cm.Show(button.Parent, button.BottomLeft);
|
cm.Show(button.Parent, button.BottomLeft);
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ namespace FlaxEditor.GUI
|
|||||||
/// The label that contains events for mouse interaction.
|
/// The label that contains events for mouse interaction.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <seealso cref="FlaxEngine.GUI.Label" />
|
/// <seealso cref="FlaxEngine.GUI.Label" />
|
||||||
|
[HideInEditor]
|
||||||
public class ClickableLabel : Label
|
public class ClickableLabel : Label
|
||||||
{
|
{
|
||||||
private bool _leftClick;
|
private bool _leftClick;
|
||||||
|
|||||||
@@ -32,9 +32,14 @@ namespace FlaxEditor.GUI
|
|||||||
protected List<Rectangle> _highlights;
|
protected List<Rectangle> _highlights;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the name.
|
/// The item name.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Name { get; set; }
|
public string Name;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The item category name (optional).
|
||||||
|
/// </summary>
|
||||||
|
public string Category;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Occurs when items gets clicked by the user.
|
/// Occurs when items gets clicked by the user.
|
||||||
@@ -49,18 +54,6 @@ namespace FlaxEditor.GUI
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="Item"/> class.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="name">The item name.</param>
|
|
||||||
/// <param name="tag">The item tag object.</param>
|
|
||||||
public Item(string name, object tag = null)
|
|
||||||
: base(0, 0, 120, 12)
|
|
||||||
{
|
|
||||||
Name = name;
|
|
||||||
Tag = tag;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Updates the filter.
|
/// Updates the filter.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -181,6 +174,7 @@ namespace FlaxEditor.GUI
|
|||||||
}
|
}
|
||||||
|
|
||||||
private readonly TextBox _searchBox;
|
private readonly TextBox _searchBox;
|
||||||
|
private List<DropPanel> _categoryPanels;
|
||||||
private bool _waitingForInput;
|
private bool _waitingForInput;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -242,6 +236,23 @@ namespace FlaxEditor.GUI
|
|||||||
if (items[i] is Item item)
|
if (items[i] is Item item)
|
||||||
item.UpdateFilter(_searchBox.Text);
|
item.UpdateFilter(_searchBox.Text);
|
||||||
}
|
}
|
||||||
|
if (_categoryPanels != null)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _categoryPanels.Count; i++)
|
||||||
|
{
|
||||||
|
var category = _categoryPanels[i];
|
||||||
|
bool anyVisible = false;
|
||||||
|
for (int j = 0; j < category.Children.Count; j++)
|
||||||
|
{
|
||||||
|
if (category.Children[j] is Item item2)
|
||||||
|
{
|
||||||
|
item2.UpdateFilter(_searchBox.Text);
|
||||||
|
anyVisible |= item2.Visible;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
category.Visible = anyVisible;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
UnlockChildrenRecursive();
|
UnlockChildrenRecursive();
|
||||||
PerformLayout(true);
|
PerformLayout(true);
|
||||||
@@ -254,8 +265,33 @@ namespace FlaxEditor.GUI
|
|||||||
/// <param name="item">The item.</param>
|
/// <param name="item">The item.</param>
|
||||||
public void AddItem(Item item)
|
public void AddItem(Item item)
|
||||||
{
|
{
|
||||||
item.Parent = ItemsPanel;
|
|
||||||
item.Clicked += OnClickItem;
|
item.Clicked += OnClickItem;
|
||||||
|
ContainerControl parent = ItemsPanel;
|
||||||
|
if (!string.IsNullOrEmpty(item.Category))
|
||||||
|
{
|
||||||
|
if (_categoryPanels == null)
|
||||||
|
_categoryPanels = new List<DropPanel>();
|
||||||
|
for (int i = 0; i < _categoryPanels.Count; i++)
|
||||||
|
{
|
||||||
|
if (string.Equals(_categoryPanels[i].HeaderText, item.Category, StringComparison.Ordinal))
|
||||||
|
{
|
||||||
|
parent = _categoryPanels[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (parent == ItemsPanel)
|
||||||
|
{
|
||||||
|
var categoryPanel = new DropPanel
|
||||||
|
{
|
||||||
|
HeaderText = item.Category,
|
||||||
|
Parent = parent,
|
||||||
|
};
|
||||||
|
categoryPanel.Open(false);
|
||||||
|
_categoryPanels.Add(categoryPanel);
|
||||||
|
parent = categoryPanel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
item.Parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -281,6 +317,19 @@ namespace FlaxEditor.GUI
|
|||||||
if (items[i] is Item item)
|
if (items[i] is Item item)
|
||||||
item.UpdateFilter(null);
|
item.UpdateFilter(null);
|
||||||
}
|
}
|
||||||
|
if (_categoryPanels != null)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _categoryPanels.Count; i++)
|
||||||
|
{
|
||||||
|
var category = _categoryPanels[i];
|
||||||
|
for (int j = 0; j < category.Children.Count; j++)
|
||||||
|
{
|
||||||
|
if (category.Children[j] is Item item2)
|
||||||
|
item2.UpdateFilter(null);
|
||||||
|
}
|
||||||
|
category.Visible = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_searchBox.Clear();
|
_searchBox.Clear();
|
||||||
UnlockChildrenRecursive();
|
UnlockChildrenRecursive();
|
||||||
|
|||||||
@@ -27,6 +27,15 @@ namespace FlaxEditor.GUI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public ScriptType Type => _type;
|
public ScriptType Type => _type;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="TypeItemView"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="type">The type.</param>
|
||||||
|
public TypeItemView(ScriptType type)
|
||||||
|
: this(type, type.GetAttributes(false))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="TypeItemView"/> class.
|
/// Initializes a new instance of the <see cref="TypeItemView"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -38,12 +47,18 @@ namespace FlaxEditor.GUI
|
|||||||
|
|
||||||
Name = type.Name;
|
Name = type.Name;
|
||||||
TooltipText = type.TypeName;
|
TooltipText = type.TypeName;
|
||||||
|
Tag = type;
|
||||||
var tooltipAttribute = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute);
|
var tooltipAttribute = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute);
|
||||||
if (tooltipAttribute != null)
|
if (tooltipAttribute != null)
|
||||||
{
|
{
|
||||||
TooltipText += '\n';
|
TooltipText += '\n';
|
||||||
TooltipText += tooltipAttribute.Text;
|
TooltipText += tooltipAttribute.Text;
|
||||||
}
|
}
|
||||||
|
var categoryAttribute = (CategoryAttribute)attributes.FirstOrDefault(x => x is CategoryAttribute);
|
||||||
|
if (categoryAttribute != null)
|
||||||
|
{
|
||||||
|
Category = categoryAttribute.Name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -118,8 +118,10 @@ namespace FlaxEditor.Surface.Archetypes
|
|||||||
var cm = new ItemsListContextMenu(180);
|
var cm = new ItemsListContextMenu(180);
|
||||||
foreach (var module in modules)
|
foreach (var module in modules)
|
||||||
{
|
{
|
||||||
cm.AddItem(new ItemsListContextMenu.Item(module.Title, module.TypeID)
|
cm.AddItem(new ItemsListContextMenu.Item
|
||||||
{
|
{
|
||||||
|
Name = module.Title,
|
||||||
|
Tag = module.TypeID,
|
||||||
TooltipText = module.Description,
|
TooltipText = module.Description,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -447,18 +447,13 @@ namespace FlaxEditor.Surface
|
|||||||
var cm = new ItemsListContextMenu(180);
|
var cm = new ItemsListContextMenu(180);
|
||||||
foreach (var newParameterType in newParameterTypes)
|
foreach (var newParameterType in newParameterTypes)
|
||||||
{
|
{
|
||||||
var name = newParameterType.Type != null ? window.VisjectSurface.GetTypeName(newParameterType) : newParameterType.Name;
|
var item = new TypeSearchPopup.TypeItemView(newParameterType)
|
||||||
var item = new ItemsListContextMenu.Item(name, newParameterType)
|
|
||||||
{
|
{
|
||||||
|
Tag = newParameterType,
|
||||||
TooltipText = newParameterType.TypeName,
|
TooltipText = newParameterType.TypeName,
|
||||||
};
|
};
|
||||||
var attributes = newParameterType.GetAttributes(false);
|
if (newParameterType.Type != null)
|
||||||
var tooltipAttribute = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute);
|
item.Name = window.VisjectSurface.GetTypeName(newParameterType);
|
||||||
if (tooltipAttribute != null)
|
|
||||||
{
|
|
||||||
item.TooltipText += '\n';
|
|
||||||
item.TooltipText += tooltipAttribute.Text;
|
|
||||||
}
|
|
||||||
cm.AddItem(item);
|
cm.AddItem(item);
|
||||||
}
|
}
|
||||||
cm.ItemClicked += OnAddParameterItemClicked;
|
cm.ItemClicked += OnAddParameterItemClicked;
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace FlaxEngine
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Describes the category name for a type.
|
||||||
|
/// </summary>
|
||||||
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface)]
|
||||||
|
public sealed class CategoryAttribute : Attribute
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The category name.
|
||||||
|
/// </summary>
|
||||||
|
public string Name;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="CategoryAttribute"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">The category name.</param>
|
||||||
|
public CategoryAttribute(string name)
|
||||||
|
{
|
||||||
|
Name = name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user