fix context menu
This commit is contained in:
@@ -229,20 +229,20 @@ namespace FlaxEditor.Surface
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnShowPrimaryMenu(VisjectCM activeCM, Float2 location, Box startBox)
|
||||
protected override void OnShowPrimaryMenu(VisjectCM activeCM, Float2 location, List<Box> startBoxes)
|
||||
{
|
||||
// Check if show additional nodes in the current surface context
|
||||
if (activeCM != _cmStateMachineMenu)
|
||||
{
|
||||
_nodesCache.Get(activeCM);
|
||||
|
||||
base.OnShowPrimaryMenu(activeCM, location, startBox);
|
||||
base.OnShowPrimaryMenu(activeCM, location, startBoxes);
|
||||
|
||||
activeCM.VisibleChanged += OnActiveContextMenuVisibleChanged;
|
||||
}
|
||||
else
|
||||
{
|
||||
base.OnShowPrimaryMenu(activeCM, location, startBox);
|
||||
base.OnShowPrimaryMenu(activeCM, location, startBoxes);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -101,12 +101,12 @@ namespace FlaxEditor.Surface
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnShowPrimaryMenu(VisjectCM activeCM, Float2 location, Box startBox)
|
||||
protected override void OnShowPrimaryMenu(VisjectCM activeCM, Float2 location, List<Box> startBoxes)
|
||||
{
|
||||
activeCM.ShowExpanded = true;
|
||||
_nodesCache.Get(activeCM);
|
||||
|
||||
base.OnShowPrimaryMenu(activeCM, location, startBox);
|
||||
base.OnShowPrimaryMenu(activeCM, location, startBoxes);
|
||||
|
||||
activeCM.VisibleChanged += OnActiveContextMenuVisibleChanged;
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ namespace FlaxEditor.Surface.ContextMenu
|
||||
/// Visject context menu item clicked delegate.
|
||||
/// </summary>
|
||||
/// <param name="clickedItem">The item that was clicked</param>
|
||||
/// <param name="selectedBox">The currently user-selected box. Can be null.</param>
|
||||
public delegate void ItemClickedDelegate(VisjectCMItem clickedItem, Elements.Box selectedBox);
|
||||
/// <param name="selectedBoxes">The currently user-selected boxes. Can be empty/ null.</param>
|
||||
public delegate void ItemClickedDelegate(VisjectCMItem clickedItem, List<Elements.Box> selectedBoxes);
|
||||
|
||||
/// <summary>
|
||||
/// Visject Surface node archetype spawn ability checking delegate.
|
||||
@@ -53,7 +53,7 @@ namespace FlaxEditor.Surface.ContextMenu
|
||||
private Panel _panel1;
|
||||
private VerticalPanel _groupsPanel;
|
||||
private readonly ParameterGetterDelegate _parametersGetter;
|
||||
private Elements.Box _selectedBox;
|
||||
private List<Elements.Box> _selectedBoxes = new List<Elements.Box>();
|
||||
private NodeArchetype _parameterGetNodeArchetype;
|
||||
private NodeArchetype _parameterSetNodeArchetype;
|
||||
|
||||
@@ -411,7 +411,8 @@ namespace FlaxEditor.Surface.ContextMenu
|
||||
if (!IsLayoutLocked)
|
||||
{
|
||||
group.UnlockChildrenRecursive();
|
||||
if (_contextSensitiveSearchEnabled && _selectedBox != null)
|
||||
// TODO: Improve filtering to be based on boxes with the most common things instead of first box
|
||||
if (_contextSensitiveSearchEnabled && _selectedBoxes[0] != null)
|
||||
UpdateFilters();
|
||||
else
|
||||
SortGroups();
|
||||
@@ -425,7 +426,8 @@ namespace FlaxEditor.Surface.ContextMenu
|
||||
}
|
||||
else if (_contextSensitiveSearchEnabled)
|
||||
{
|
||||
group.EvaluateVisibilityWithBox(_selectedBox);
|
||||
// TODO: Filtering could be improved here as well
|
||||
group.EvaluateVisibilityWithBox(_selectedBoxes[0]);
|
||||
}
|
||||
|
||||
Profiler.EndEvent();
|
||||
@@ -461,7 +463,7 @@ namespace FlaxEditor.Surface.ContextMenu
|
||||
};
|
||||
}
|
||||
if (_contextSensitiveSearchEnabled)
|
||||
group.EvaluateVisibilityWithBox(_selectedBox);
|
||||
group.EvaluateVisibilityWithBox(_selectedBoxes[0]);
|
||||
group.SortChildren();
|
||||
if (ShowExpanded)
|
||||
group.Open(false);
|
||||
@@ -474,7 +476,7 @@ namespace FlaxEditor.Surface.ContextMenu
|
||||
|
||||
if (!isLayoutLocked)
|
||||
{
|
||||
if (_contextSensitiveSearchEnabled && _selectedBox != null)
|
||||
if (_contextSensitiveSearchEnabled && _selectedBoxes[0] != null)
|
||||
UpdateFilters();
|
||||
else
|
||||
SortGroups();
|
||||
@@ -583,7 +585,7 @@ namespace FlaxEditor.Surface.ContextMenu
|
||||
|
||||
private void UpdateFilters()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_searchBox.Text) && _selectedBox == null)
|
||||
if (string.IsNullOrEmpty(_searchBox.Text) && _selectedBoxes[0] == null)
|
||||
{
|
||||
ResetView();
|
||||
Profiler.EndEvent();
|
||||
@@ -592,7 +594,7 @@ namespace FlaxEditor.Surface.ContextMenu
|
||||
|
||||
// Update groups
|
||||
LockChildrenRecursive();
|
||||
var contextSensitiveSelectedBox = _contextSensitiveSearchEnabled ? _selectedBox : null;
|
||||
var contextSensitiveSelectedBox = _contextSensitiveSearchEnabled ? _selectedBoxes[0] : null;
|
||||
for (int i = 0; i < _groups.Count; i++)
|
||||
{
|
||||
_groups[i].UpdateFilter(_searchBox.Text, contextSensitiveSelectedBox);
|
||||
@@ -640,7 +642,7 @@ namespace FlaxEditor.Surface.ContextMenu
|
||||
public void OnClickItem(VisjectCMItem item)
|
||||
{
|
||||
Hide();
|
||||
ItemClicked?.Invoke(item, _selectedBox);
|
||||
ItemClicked?.Invoke(item, _selectedBoxes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -666,12 +668,12 @@ namespace FlaxEditor.Surface.ContextMenu
|
||||
for (int i = 0; i < _groups.Count; i++)
|
||||
{
|
||||
_groups[i].ResetView();
|
||||
if (_contextSensitiveSearchEnabled)
|
||||
_groups[i].EvaluateVisibilityWithBox(_selectedBox);
|
||||
if (_contextSensitiveSearchEnabled && _selectedBoxes.Count > 0)
|
||||
_groups[i].EvaluateVisibilityWithBox(_selectedBoxes[0]);
|
||||
}
|
||||
UnlockChildrenRecursive();
|
||||
|
||||
if (_contextSensitiveSearchEnabled && _selectedBox != null)
|
||||
if (_contextSensitiveSearchEnabled && _selectedBoxes.Count > 0 && _selectedBoxes[0] != null)
|
||||
UpdateFilters();
|
||||
else
|
||||
SortGroups();
|
||||
@@ -772,10 +774,10 @@ namespace FlaxEditor.Surface.ContextMenu
|
||||
/// </summary>
|
||||
/// <param name="parent">Parent control to attach to it.</param>
|
||||
/// <param name="location">Popup menu origin location in parent control coordinates.</param>
|
||||
/// <param name="startBox">The currently selected box that the new node will get connected to. Can be null</param>
|
||||
public void Show(Control parent, Float2 location, Elements.Box startBox)
|
||||
/// <param name="startBoxes">The currently selected boxes that the new node will get connected to. Can be empty/ null</param>
|
||||
public void Show(Control parent, Float2 location, List<Elements.Box> startBoxes)
|
||||
{
|
||||
_selectedBox = startBox;
|
||||
_selectedBoxes = startBoxes;
|
||||
base.Show(parent, location);
|
||||
}
|
||||
|
||||
|
||||
@@ -252,10 +252,10 @@ namespace FlaxEditor.Surface
|
||||
/// </summary>
|
||||
/// <param name="activeCM">The active context menu to show.</param>
|
||||
/// <param name="location">The display location on the surface control.</param>
|
||||
/// <param name="startBox">The start box.</param>
|
||||
protected virtual void OnShowPrimaryMenu(VisjectCM activeCM, Float2 location, Box startBox)
|
||||
/// <param name="startBoxes">The start boxes.</param>
|
||||
protected virtual void OnShowPrimaryMenu(VisjectCM activeCM, Float2 location, List<Box> startBoxes)
|
||||
{
|
||||
activeCM.Show(this, location, startBox);
|
||||
activeCM.Show(this, location, startBoxes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -289,9 +289,10 @@ namespace FlaxEditor.Surface
|
||||
|
||||
_cmStartPos = location;
|
||||
|
||||
// Offset added in case the user doesn't like the box and wants to quickly get rid of it by clicking
|
||||
Box startBox = _connectionInstigators.Count > 0 ? _connectionInstigators[0] as Box : null;
|
||||
OnShowPrimaryMenu(_activeVisjectCM, _cmStartPos + ContextMenuOffset, startBox);
|
||||
List<Box> startBoxes = new List<Box>(_connectionInstigators.Cast<Box>());
|
||||
|
||||
// Position offset added so the user can quickly close the menu by clicking
|
||||
OnShowPrimaryMenu(_activeVisjectCM, _cmStartPos + ContextMenuOffset, startBoxes);
|
||||
|
||||
if (!string.IsNullOrEmpty(input))
|
||||
{
|
||||
@@ -483,8 +484,8 @@ namespace FlaxEditor.Surface
|
||||
/// Handles Visject CM item click event by spawning the selected item.
|
||||
/// </summary>
|
||||
/// <param name="visjectCmItem">The item.</param>
|
||||
/// <param name="selectedBox">The selected box.</param>
|
||||
protected virtual void OnPrimaryMenuButtonClick(VisjectCMItem visjectCmItem, Box selectedBox)
|
||||
/// <param name="selectedBoxes">The selected boxes.</param>
|
||||
protected virtual void OnPrimaryMenuButtonClick(VisjectCMItem visjectCmItem, List<Box> selectedBoxes)
|
||||
{
|
||||
if (!CanEdit)
|
||||
return;
|
||||
@@ -511,34 +512,36 @@ namespace FlaxEditor.Surface
|
||||
// Auto select new node
|
||||
Select(node);
|
||||
|
||||
if (selectedBox != null)
|
||||
for (int i = 0; i < selectedBoxes.Count; i++)
|
||||
{
|
||||
Box endBox = null;
|
||||
foreach (var box in node.GetBoxes().Where(box => box.IsOutput != selectedBox.IsOutput))
|
||||
Box currentBox = selectedBoxes[i];
|
||||
if (currentBox != null)
|
||||
{
|
||||
if (selectedBox.IsOutput)
|
||||
Box endBox = null;
|
||||
foreach (var box in node.GetBoxes().Where(box => box.IsOutput != currentBox.IsOutput))
|
||||
{
|
||||
if (box.CanUseType(selectedBox.CurrentType))
|
||||
if (currentBox.IsOutput)
|
||||
{
|
||||
endBox = box;
|
||||
break;
|
||||
if (box.CanUseType(currentBox.CurrentType))
|
||||
{
|
||||
endBox = box;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (selectedBox.CanUseType(box.CurrentType))
|
||||
else
|
||||
{
|
||||
endBox = box;
|
||||
break;
|
||||
if (currentBox.CanUseType(box.CurrentType))
|
||||
{
|
||||
endBox = box;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (endBox == null && selectedBox.CanUseType(box.CurrentType))
|
||||
{
|
||||
endBox = box;
|
||||
if (endBox == null && currentBox.CanUseType(box.CurrentType))
|
||||
endBox = box;
|
||||
}
|
||||
TryConnect(currentBox, endBox);
|
||||
}
|
||||
TryConnect(selectedBox, endBox);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -554,12 +557,8 @@ namespace FlaxEditor.Surface
|
||||
}
|
||||
|
||||
// If the user is patiently waiting for his box to get connected to the newly created one fulfill his wish!
|
||||
_connectionInstigators[0] = startBox;
|
||||
|
||||
if (!IsConnecting)
|
||||
{
|
||||
ConnectingStart(startBox);
|
||||
}
|
||||
ConnectingEnd(endBox);
|
||||
|
||||
// Smart-Select next box
|
||||
|
||||
@@ -212,7 +212,7 @@ namespace FlaxEditor.Surface
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnShowPrimaryMenu(VisjectCM activeCM, Float2 location, Box startBox)
|
||||
protected override void OnShowPrimaryMenu(VisjectCM activeCM, Float2 location, List<Box> startBoxes)
|
||||
{
|
||||
// Update nodes for method overrides
|
||||
Profiler.BeginEvent("Overrides");
|
||||
@@ -268,7 +268,7 @@ namespace FlaxEditor.Surface
|
||||
// Update nodes for invoke methods (async)
|
||||
_nodesCache.Get(activeCM);
|
||||
|
||||
base.OnShowPrimaryMenu(activeCM, location, startBox);
|
||||
base.OnShowPrimaryMenu(activeCM, location, startBoxes);
|
||||
|
||||
activeCM.VisibleChanged += OnActiveContextMenuVisibleChanged;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user