- Possible nodes get filtered now depending on the available node ports

This commit is contained in:
Nils Hausfeld
2023-09-24 19:33:03 +02:00
parent 248304a78f
commit 038a3603e4
3 changed files with 86 additions and 10 deletions

View File

@@ -419,7 +419,7 @@ namespace FlaxEditor.Surface.ContextMenu
Profiler.BeginEvent("VisjectCM.OnSearchFilterChanged");
if (string.IsNullOrEmpty(_searchBox.Text))
if (string.IsNullOrEmpty(_searchBox.Text) && _selectedBox == null)
{
ResetView();
Profiler.EndEvent();
@@ -430,7 +430,7 @@ namespace FlaxEditor.Surface.ContextMenu
LockChildrenRecursive();
for (int i = 0; i < _groups.Count; i++)
{
_groups[i].UpdateFilter(_searchBox.Text);
_groups[i].UpdateFilter(_searchBox.Text, _selectedBox);
_groups[i].UpdateItemSort(_selectedBox);
}
SortGroups();
@@ -503,12 +503,19 @@ namespace FlaxEditor.Surface.ContextMenu
_searchBox.Clear();
SelectedItem = null;
for (int i = 0; i < _groups.Count; i++)
{
_groups[i].ResetView();
}
UnlockChildrenRecursive();
SortGroups();
PerformLayout();
for (int i = 0; i < _groups.Count; i++)
{
_groups[i].EvaluateVisibilityWithBox(_selectedBox);
}
Profiler.EndEvent();
}
@@ -626,10 +633,11 @@ namespace FlaxEditor.Surface.ContextMenu
// Prepare
UpdateSurfaceParametersGroup();
ResetView();
_panel1.VScrollBar.TargetValue = 0;
Focus();
_waitingForInput = true;
base.OnShow();
}

View File

@@ -66,7 +66,7 @@ namespace FlaxEditor.Surface.ContextMenu
{
if (_children[i] is VisjectCMItem item)
{
item.UpdateFilter(null);
item.UpdateFilter(null, null);
item.UpdateScore(null);
}
}
@@ -84,7 +84,7 @@ namespace FlaxEditor.Surface.ContextMenu
/// Updates the filter.
/// </summary>
/// <param name="filterText">The filter text.</param>
public void UpdateFilter(string filterText)
public void UpdateFilter(string filterText, Box selectedBox)
{
Profiler.BeginEvent("VisjectCMGroup.UpdateFilter");
@@ -94,13 +94,13 @@ namespace FlaxEditor.Surface.ContextMenu
{
if (_children[i] is VisjectCMItem item)
{
item.UpdateFilter(filterText);
item.UpdateFilter(filterText, selectedBox);
isAnyVisible |= item.Visible;
}
}
// Update header title
if (QueryFilterHelper.Match(filterText, HeaderText))
/*if (QueryFilterHelper.Match(filterText, HeaderText))
{
for (int i = 0; i < _children.Count; i++)
{
@@ -110,7 +110,7 @@ namespace FlaxEditor.Surface.ContextMenu
}
}
isAnyVisible = true;
}
}*/
// Update itself
if (isAnyVisible)
@@ -128,6 +128,35 @@ namespace FlaxEditor.Surface.ContextMenu
Profiler.EndEvent();
}
public void EvaluateVisibilityWithBox(Box selectedBox)
{
if (selectedBox == null)
{
Visible = true;
return;
}
bool isAnyVisible = false;
for (int i = 0; i < _children.Count; i++)
{
if (_children[i] is VisjectCMItem item)
{
isAnyVisible |= item.IsCompatibleWithBox(selectedBox);
}
}
// Update itself
if (isAnyVisible)
{
Visible = true;
}
else
{
// Hide group if none of the items matched the filter
Visible = false;
}
}
/// <summary>
/// Updates the sorting of the <see cref="VisjectCMItem"/>s of this <see cref="VisjectCMGroup"/>
/// Also updates the <see cref="SortScore"/>

View File

@@ -113,12 +113,51 @@ namespace FlaxEditor.Surface.ContextMenu
return false;
}
public bool IsCompatibleWithBox(Box box)
{
if (box == null)
return true;
if(_archetype?.Elements == null)
return false;
bool isCompatible = false;
foreach (NodeElementArchetype element in _archetype.Elements)
{
if(element.Type != NodeElementType.Output && element.Type != NodeElementType.Input)
continue;
if ((box.IsOutput && element.Type == NodeElementType.Output) || (!box.IsOutput && element.Type == NodeElementType.Input))
continue;
bool checkCompatibility = box.CanUseType(element.ConnectionsType);;
if (!checkCompatibility)
{
if ((element.ConnectionsType == null || element.ConnectionsType == typeof(void)) && box.CurrentType != typeof(FlaxEngine.Object))
checkCompatibility = true;
}
isCompatible |= checkCompatibility;
/*if(!isCompatible)
Debug.Log($"Is {_archetype.Title} cant connect type {element.ConnectionsType}");*/
}
Visible = isCompatible;
return isCompatible;
}
/// <summary>
/// Updates the filter.
/// </summary>
/// <param name="filterText">The filter text.</param>
public void UpdateFilter(string filterText)
public void UpdateFilter(string filterText, Box selectedBox)
{
if (selectedBox != null)
{
if (!IsCompatibleWithBox(selectedBox))
return;
}
_isStartsWithMatch = _isFullMatch = false;
if (filterText == null)
{
@@ -192,7 +231,7 @@ namespace FlaxEditor.Surface.ContextMenu
}
}
}
/// <inheritdoc />
public override void Draw()
{