changed how actor context menus are created.

This commit is contained in:
Chandler Cox
2022-10-31 19:18:43 -05:00
parent 38d65d38d1
commit 1af0188a3c
44 changed files with 197 additions and 192 deletions

View File

@@ -246,24 +246,51 @@ namespace FlaxEditor.Windows.Assets
// Spawning actors options
contextMenu.AddSeparator();
var spawnMenu = contextMenu.AddChildMenu("New");
var newActorCm = spawnMenu.ContextMenu;
for (int i = 0; i < SceneTreeWindow.SpawnActorsGroups.Length; i++)
// go through each actor and add it to the context menu if it has the ActorContextMenu attribute
foreach (var actorType in Editor.CodeEditing.Actors.Get())
{
var group = SceneTreeWindow.SpawnActorsGroups[i];
if (group.Types.Length == 1)
if (actorType.IsAbstract || !actorType.HasAttribute(typeof(ActorContextMenuAttribute), true))
continue;
ActorContextMenuAttribute attribute = null;
foreach (var actorAttribute in actorType.GetAttributes(true))
{
var type = group.Types[0].Value;
newActorCm.AddButton(group.Types[0].Key, () => Spawn(type));
}
else
{
var groupCm = newActorCm.AddChildMenu(group.Name).ContextMenu;
for (int j = 0; j < group.Types.Length; j++)
if (actorAttribute is ActorContextMenuAttribute actorContextMenuAttribute)
{
var type = group.Types[j].Value;
groupCm.AddButton(group.Types[j].Key, () => Spawn(type));
attribute = actorContextMenuAttribute;
}
}
var splitPath = attribute?.Path.Split('/');
ContextMenuChildMenu childCM = null;
bool mainCM = true;
for (int i = 0; i < splitPath?.Length; i++)
{
if (i == splitPath.Length - 1)
{
if (mainCM)
{
contextMenu.AddButton(splitPath[i].Trim(), () => Spawn(actorType.Type));
mainCM = false;
}
else
{
childCM?.ContextMenu.AddButton(splitPath[i].Trim(), () => Spawn(actorType.Type));
childCM.ContextMenu.AutoSort = true;
}
}
else
{
if (mainCM)
{
childCM = contextMenu.GetOrAddChildMenu(splitPath[i].Trim());
mainCM = false;
}
else
{
childCM = childCM?.ContextMenu.GetOrAddChildMenu(splitPath[i].Trim());
}
childCM.ContextMenu.AutoSort = true;
}
}
}