Marge Visual Script groups for structures (eg. double ActionConfig group)

This commit is contained in:
Wojtek Figat
2022-07-23 00:53:46 +02:00
parent d33cf5f6d9
commit 2a3316ac5e
6 changed files with 67 additions and 43 deletions

View File

@@ -113,6 +113,7 @@ namespace FlaxEditor.GUI.Timeline.Tracks
/// <summary>
/// The data for add property track buttons tag.
/// </summary>
[HideInEditor]
public struct AddMemberTag
{
/// <summary>

View File

@@ -113,9 +113,9 @@ namespace FlaxEditor.Surface
if (_cache.Count != 0)
{
// Check if context menu doesn't have the recent cached groups
if (!contextMenu.Groups.Any(g => g.Archetype.Tag is int asInt && asInt == _version))
if (!contextMenu.Groups.Any(g => g.Archetypes[0].Tag is int asInt && asInt == _version))
{
var groups = contextMenu.Groups.Where(g => g.Archetype.Tag is int).ToArray();
var groups = contextMenu.Groups.Where(g => g.Archetypes[0].Tag is int).ToArray();
foreach (var g in groups)
contextMenu.RemoveGroup(g);
foreach (var g in _cache.Values)
@@ -125,7 +125,7 @@ namespace FlaxEditor.Surface
else
{
// Remove any old groups from context menu
var groups = contextMenu.Groups.Where(g => g.Archetype.Tag is int).ToArray();
var groups = contextMenu.Groups.Where(g => g.Archetypes[0].Tag is int).ToArray();
foreach (var g in groups)
contextMenu.RemoveGroup(g);
@@ -340,7 +340,7 @@ namespace FlaxEditor.Surface
ParametersGetter = null,
CustomNodesGroup = GetCustomNodes(),
});
_cmStateMachineTransitionMenu.AddGroup(StateMachineTransitionGroupArchetype);
_cmStateMachineTransitionMenu.AddGroup(StateMachineTransitionGroupArchetype, false);
}
menu = _cmStateMachineTransitionMenu;
}

View File

@@ -171,11 +171,7 @@ namespace FlaxEditor.Surface.ContextMenu
// Check if can create group for them
if (nodes.Count > 0)
{
var group = new VisjectCMGroup(this, groupArchetype)
{
HeaderText = groupArchetype.Name
};
var group = CreateGroup(groupArchetype);
group.Close(false);
for (int i = 0; i < nodes.Count; i++)
{
@@ -205,7 +201,7 @@ namespace FlaxEditor.Surface.ContextMenu
VisjectCMGroup group = null;
for (int j = 0; j < _groups.Count; j++)
{
if (string.Equals(_groups[j].Archetype.Name, groupName, StringComparison.OrdinalIgnoreCase))
if (string.Equals(_groups[j].Name, groupName, StringComparison.OrdinalIgnoreCase))
{
group = _groups[j];
break;
@@ -215,11 +211,7 @@ namespace FlaxEditor.Surface.ContextMenu
// Create new group if name is unique
if (group == null)
{
group = new VisjectCMGroup(this, info.CustomNodesGroup)
{
HeaderText = groupName
};
group = CreateGroup(info.CustomNodesGroup, true, groupName);
group.Close(false);
group.Parent = _groupsPanel;
_groups.Add(group);
@@ -241,18 +233,15 @@ namespace FlaxEditor.Surface.ContextMenu
/// Adds the group archetype to add to the menu.
/// </summary>
/// <param name="groupArchetype">The group.</param>
public void AddGroup(GroupArchetype groupArchetype)
/// <param name="withGroupMerge">True if merge group items into any existing group of the same name.</param>
public void AddGroup(GroupArchetype groupArchetype, bool withGroupMerge = true)
{
// Check if can create group for them to be spawned via GUI
if (groupArchetype.Archetypes.Any(x => (x.Flags & NodeFlags.NoSpawnViaGUI) == 0))
{
Profiler.BeginEvent("VisjectCM.AddGroup");
var group = new VisjectCMGroup(this, groupArchetype)
{
HeaderText = groupArchetype.Name
};
var group = CreateGroup(groupArchetype, withGroupMerge);
group.Close(false);
foreach (var nodeArchetype in groupArchetype.Archetypes)
@@ -286,7 +275,8 @@ namespace FlaxEditor.Surface.ContextMenu
/// Adds the group archetypes to add to the menu.
/// </summary>
/// <param name="groupArchetypes">The groups.</param>
public void AddGroups(IEnumerable<GroupArchetype> groupArchetypes)
/// <param name="withGroupMerge">True if merge group items into any existing group of the same name.</param>
public void AddGroups(IEnumerable<GroupArchetype> groupArchetypes, bool withGroupMerge = true)
{
// Check if can create group for them to be spawned via GUI
if (groupArchetypes.Any(g => g.Archetypes.Any(x => (x.Flags & NodeFlags.NoSpawnViaGUI) == 0)))
@@ -299,11 +289,7 @@ namespace FlaxEditor.Surface.ContextMenu
var groups = new List<VisjectCMGroup>();
foreach (var groupArchetype in groupArchetypes)
{
var group = new VisjectCMGroup(this, groupArchetype)
{
HeaderText = groupArchetype.Name
};
var group = CreateGroup(groupArchetype, withGroupMerge);
group.Close(false);
foreach (var nodeArchetype in groupArchetype.Archetypes)
@@ -349,11 +335,25 @@ namespace FlaxEditor.Surface.ContextMenu
{
for (int i = 0; i < _groups.Count; i++)
{
if (_groups[i].Archetype == groupArchetype)
var group = _groups[i];
if (group.Archetypes.Remove(groupArchetype))
{
Profiler.BeginEvent("VisjectCM.RemoveGroup");
_groups[i].Dispose();
_groups.RemoveAt(i);
if (group.Archetypes.Count == 0)
{
Debug.Log("Remove");
_groups.RemoveAt(i);
group.Dispose();
}
else
{
var children = group.Children.ToArray();
foreach (var child in children)
{
if (child is VisjectCMItem item && item.GroupArchetype == groupArchetype)
item.Dispose();
}
}
Profiler.EndEvent();
break;
}
@@ -372,6 +372,24 @@ namespace FlaxEditor.Surface.ContextMenu
Profiler.EndEvent();
}
private VisjectCMGroup CreateGroup(GroupArchetype groupArchetype, bool withGroupMerge = true, string name = null)
{
if (name == null)
name = groupArchetype.Name;
if (withGroupMerge)
{
for (int i = 0; i < _groups.Count; i++)
{
if (string.Equals(_groups[i].HeaderText, name, StringComparison.Ordinal))
return _groups[i];
}
}
return new VisjectCMGroup(this, groupArchetype)
{
HeaderText = name
};
}
private void OnSearchFilterChanged()
{
// Skip events during setup or init stuff
@@ -522,11 +540,7 @@ namespace FlaxEditor.Surface.ContextMenu
Archetypes = archetypes
};
var group = new VisjectCMGroup(this, groupArchetype)
{
HeaderText = groupArchetype.Name
};
var group = CreateGroup(groupArchetype);
group.Close(false);
archetypeIndex = 0;
for (int i = 0; i < parameters.Count; i++)

View File

@@ -1,6 +1,7 @@
// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved.
using System;
using System.Collections.Generic;
using FlaxEditor.Surface.Elements;
using FlaxEditor.Utilities;
using FlaxEngine;
@@ -21,15 +22,20 @@ namespace FlaxEditor.Surface.ContextMenu
public readonly VisjectCM ContextMenu;
/// <summary>
/// The archetype.
/// The archetypes (one or more).
/// </summary>
public readonly GroupArchetype Archetype;
public readonly List<GroupArchetype> Archetypes = new List<GroupArchetype>();
/// <summary>
/// A computed score for the context menu order.
/// </summary>
public float SortScore;
/// <summary>
/// The group name.
/// </summary>
public string Name;
/// <summary>
/// Initializes a new instance of the <see cref="VisjectCMGroup"/> class.
/// </summary>
@@ -38,7 +44,8 @@ namespace FlaxEditor.Surface.ContextMenu
public VisjectCMGroup(VisjectCM cm, GroupArchetype archetype)
{
ContextMenu = cm;
Archetype = archetype;
Archetypes.Add(archetype);
Name = archetype.Name;
}
/// <summary>
@@ -148,7 +155,7 @@ namespace FlaxEditor.Surface.ContextMenu
int order = -1 * SortScore.CompareTo(otherGroup.SortScore);
if (order == 0)
{
order = string.Compare(Archetype.Name, otherGroup.Archetype.Name, StringComparison.InvariantCulture);
order = string.Compare(Name, otherGroup.Name, StringComparison.InvariantCulture);
}
return order;
}

View File

@@ -77,9 +77,9 @@ namespace FlaxEditor.Surface
if (_cache.Count != 0)
{
// Check if context menu doesn't have the recent cached groups
if (!contextMenu.Groups.Any(g => g.Archetype.Tag is int asInt && asInt == _version))
if (!contextMenu.Groups.Any(g => g.Archetypes[0].Tag is int asInt && asInt == _version))
{
var groups = contextMenu.Groups.Where(g => g.Archetype.Tag is int).ToArray();
var groups = contextMenu.Groups.Where(g => g.Archetypes[0].Tag is int).ToArray();
foreach (var g in groups)
contextMenu.RemoveGroup(g);
foreach (var g in _cache.Values)
@@ -89,7 +89,7 @@ namespace FlaxEditor.Surface
else
{
// Remove any old groups from context menu
var groups = contextMenu.Groups.Where(g => g.Archetype.Tag is int).ToArray();
var groups = contextMenu.Groups.Where(g => g.Archetypes[0].Tag is int).ToArray();
foreach (var g in groups)
contextMenu.RemoveGroup(g);
@@ -592,7 +592,7 @@ namespace FlaxEditor.Surface
}
}
activeCM.AddGroup(_methodOverridesGroupArchetype);
activeCM.AddGroup(_methodOverridesGroupArchetype, false);
}
// Update nodes for invoke methods (async)

View File

@@ -12,6 +12,7 @@ namespace FlaxEditor.Utilities
/// <summary>
/// The Shunting-Yard algorithm parsing utilities.
/// </summary>
[HideInEditor]
public static class ShuntingYard
{
/// <summary>
@@ -33,6 +34,7 @@ namespace FlaxEditor.Utilities
/// <summary>
/// Types of possible tokens used in Shunting-Yard parser.
/// </summary>
[HideInEditor]
public enum TokenType
{
/// <summary>