Merge branch 'Visject-AutomaticCasting' of https://github.com/Chikinsupu/FlaxEngine into Chikinsupu-Visject-AutomaticCasting
This commit is contained in:
@@ -787,7 +787,7 @@ namespace FlaxEditor.Surface.Archetypes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class AsNode : SurfaceNode
|
internal class AsNode : SurfaceNode
|
||||||
{
|
{
|
||||||
private TypePickerControl _picker;
|
private TypePickerControl _picker;
|
||||||
|
|
||||||
@@ -838,6 +838,15 @@ namespace FlaxEditor.Surface.Archetypes
|
|||||||
box.CurrentType = type ? type : ScriptType.FlaxObject;
|
box.CurrentType = type ? type : ScriptType.FlaxObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the type of the picker and the type of the output box
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="type">Target Type</param>
|
||||||
|
public void SetPickerValue(ScriptType type)
|
||||||
|
{
|
||||||
|
_picker.Value = type;
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void OnDestroy()
|
public override void OnDestroy()
|
||||||
{
|
{
|
||||||
@@ -999,6 +1008,15 @@ namespace FlaxEditor.Surface.Archetypes
|
|||||||
GetBox(4).CurrentType = type ? type : _picker.Type;
|
GetBox(4).CurrentType = type ? type : _picker.Type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the type of the picker and the type of the output box
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="type">Target Type</param>
|
||||||
|
public void SetPickerValue(ScriptType type)
|
||||||
|
{
|
||||||
|
_picker.Value = type;
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void OnDestroy()
|
public override void OnDestroy()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -820,8 +820,70 @@ namespace FlaxEditor.Surface.Elements
|
|||||||
if (useCaster)
|
if (useCaster)
|
||||||
{
|
{
|
||||||
// Connect via Caster
|
// Connect via Caster
|
||||||
//AddCaster(oB, iB);
|
const float casterXOffset = 250;
|
||||||
throw new NotImplementedException("AddCaster(..) function");
|
if (Surface.Undo != null && Surface.Undo.Enabled)
|
||||||
|
{
|
||||||
|
bool undoEnabled = Surface.Undo.Enabled;
|
||||||
|
Surface.Undo.Enabled = false;
|
||||||
|
SurfaceNode node = Surface.Context.SpawnNode(7, 22, Float2.Zero); // 22 AsNode, 25 CastNode
|
||||||
|
Surface.Undo.Enabled = undoEnabled;
|
||||||
|
|
||||||
|
if(node is not Archetypes.Tools.AsNode castNode)
|
||||||
|
throw new Exception("Node is not a casting node!");
|
||||||
|
|
||||||
|
// Set the type of the casting node
|
||||||
|
undoEnabled = castNode.Surface.Undo.Enabled;
|
||||||
|
castNode.Surface.Undo.Enabled = false;
|
||||||
|
castNode.SetPickerValue(iB.CurrentType);
|
||||||
|
castNode.Surface.Undo.Enabled = undoEnabled;
|
||||||
|
|
||||||
|
if (node.GetBox(0) is not OutputBox castOutputBox || node.GetBox(1) is not InputBox castInputBox)
|
||||||
|
{
|
||||||
|
throw new NullReferenceException("Casting failed. Cast node is invalid!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// We set the position of the cast node here to set it relative to the target nodes input box
|
||||||
|
undoEnabled = castNode.Surface.Undo.Enabled;
|
||||||
|
castNode.Surface.Undo.Enabled = false;
|
||||||
|
var wantedOffset = iB.ParentNode.Location - new Float2(casterXOffset, -(iB.LocalY - castOutputBox.LocalY));
|
||||||
|
castNode.Location = Surface.Root.PointFromParent(ref wantedOffset);
|
||||||
|
castNode.Surface.Undo.Enabled = undoEnabled;
|
||||||
|
|
||||||
|
var spawnNodeAction = new AddRemoveNodeAction(castNode, true);
|
||||||
|
|
||||||
|
var connectToCastNodeAction = new ConnectBoxesAction(castInputBox, oB, true);
|
||||||
|
castInputBox.CreateConnection(oB);
|
||||||
|
connectToCastNodeAction.End();
|
||||||
|
|
||||||
|
var connectCastToTargetNodeAction = new ConnectBoxesAction(iB, castOutputBox, true);
|
||||||
|
iB.CreateConnection(castOutputBox);
|
||||||
|
connectCastToTargetNodeAction.End();
|
||||||
|
|
||||||
|
Surface.AddBatchedUndoAction(new MultiUndoAction(spawnNodeAction, connectToCastNodeAction, connectCastToTargetNodeAction));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SurfaceNode node = Surface.Context.SpawnNode(7, 22, Float2.Zero); // 22 AsNode, 25 CastNode
|
||||||
|
|
||||||
|
if(node is not Archetypes.Tools.AsNode castNode)
|
||||||
|
throw new Exception("Node is not a casting node!");
|
||||||
|
|
||||||
|
// Set the type of the casting node
|
||||||
|
castNode.SetPickerValue(iB.CurrentType);
|
||||||
|
|
||||||
|
if (node.GetBox(0) is not OutputBox castOutputBox || node.GetBox(1) is not InputBox castInputBox)
|
||||||
|
{
|
||||||
|
throw new NullReferenceException("Casting failed. Cast node is invalid!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// We set the position of the cast node here to set it relative to the target nodes input box
|
||||||
|
var wantedOffset = iB.ParentNode.Location - new Float2(casterXOffset, -(iB.LocalY - castOutputBox.LocalY));
|
||||||
|
castNode.Location = Surface.Root.PointFromParent(ref wantedOffset);
|
||||||
|
|
||||||
|
castInputBox.CreateConnection(oB);
|
||||||
|
iB.CreateConnection(castOutputBox);
|
||||||
|
}
|
||||||
|
Surface.MarkAsEdited();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user