Fix Visject Surface search to check nested surfaces (such as State Machine graphs)

This commit is contained in:
Wojtek Figat
2024-10-28 20:32:17 +01:00
parent f88eeeb313
commit 41a0ccb218
4 changed files with 71 additions and 27 deletions

View File

@@ -225,8 +225,7 @@ namespace FlaxEditor.Surface.Archetypes
/// <inheritdoc />
public override void OnDestroy()
{
if (Surface != null)
Surface.RemoveContext(this);
Surface?.RemoveContext(this);
_maxTransitionsPerUpdate = null;
_reinitializeOnBecomingRelevant = null;
@@ -717,9 +716,12 @@ namespace FlaxEditor.Surface.Archetypes
LoadTransitions();
// Register for surface mouse events to handle transition arrows interactions
Surface.CustomMouseUp += OnSurfaceMouseUp;
Surface.CustomMouseDoubleClick += OnSurfaceMouseDoubleClick;
if (Surface != null)
{
// Register for surface mouse events to handle transition arrows interactions
Surface.CustomMouseUp += OnSurfaceMouseUp;
Surface.CustomMouseDoubleClick += OnSurfaceMouseDoubleClick;
}
}
private void OnSurfaceMouseUp(ref Float2 mouse, MouseButton buttons, ref bool handled)
@@ -1398,7 +1400,8 @@ namespace FlaxEditor.Surface.Archetypes
if (context.FindNode(9, 21) == null)
{
var wasEnabled = true;
if (Surface.Undo != null)
var undo = Surface?.Undo;
if (undo != null)
{
wasEnabled = Surface.Undo.Enabled;
Surface.Undo.Enabled = false;
@@ -1406,7 +1409,7 @@ namespace FlaxEditor.Surface.Archetypes
context.SpawnNode(9, 21, new Float2(100.0f));
if (Surface.Undo != null)
if (undo != null)
{
Surface.Undo.Enabled = wasEnabled;
}
@@ -1492,7 +1495,7 @@ namespace FlaxEditor.Surface.Archetypes
/// <inheritdoc />
public override void OnDestroy()
{
Surface.RemoveContext(this);
Surface?.RemoveContext(this);
base.OnDestroy();
}
@@ -1886,7 +1889,7 @@ namespace FlaxEditor.Surface.Archetypes
if (context.FindNode(9, 22) == null)
{
var wasEnabled = true;
var undo = SourceState.Surface.Undo;
var undo = SourceState.Surface?.Undo;
if (undo != null)
{
wasEnabled = undo.Enabled;

View File

@@ -87,7 +87,7 @@ namespace FlaxEditor.Surface
Title = TitleValue;
Color = ColorValue;
var size = SizeValue;
if (Surface.GridSnappingEnabled)
if (Surface != null && Surface.GridSnappingEnabled)
size = Surface.SnapToGrid(size, true);
Size = size;

View File

@@ -2,8 +2,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FlaxEditor.Surface.Undo;
using FlaxEngine;
namespace FlaxEditor.Surface
{
@@ -57,6 +57,28 @@ namespace FlaxEditor.Surface
return null;
}
/// <summary>
/// Opens the surface context with the given owning nodes IDs path.
/// </summary>
/// <param name="nodePath">The node ids path.</param>
/// <returns>Found context or null if cannot.</returns>
public VisjectSurfaceContext OpenContext(Span<uint> nodePath)
{
OpenContext(RootContext.Context);
if (nodePath != null && nodePath.Length != 0)
{
for (int i = 0; i < nodePath.Length; i++)
{
var node = Context.FindNode(nodePath[i]);
if (node is ISurfaceContext context)
OpenContext(context);
else
return null;
}
}
return Context;
}
/// <summary>
/// Creates the Visject surface context for the given surface data source context.
/// </summary>
@@ -101,7 +123,12 @@ namespace FlaxEditor.Surface
if (_root == null)
_root = surfaceContext;
else if (ContextStack.Contains(surfaceContext))
throw new ArgumentException("Context has been already added to the stack.");
{
// Go up until the given context
while (ContextStack.First() != surfaceContext)
CloseContext();
return;
}
// Change stack
ContextStack.Push(surfaceContext);