Added node highlight, fixed temporary load to include start node as well, fixed For-Condition
This commit is contained in:
@@ -15,6 +15,7 @@ public partial class CodingWindow : PanelContainer
|
||||
|
||||
public System.Collections.Generic.Dictionary<ProgramNode, PackedScene> DSLNodes;
|
||||
public NodeDisplay selectedNode;
|
||||
public NodeDisplay highlightedNode;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
@@ -30,7 +31,7 @@ public partial class CodingWindow : PanelContainer
|
||||
}
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (Input.IsActionJustPressed("delete_node"))
|
||||
{
|
||||
@@ -41,11 +42,63 @@ public partial class CodingWindow : PanelContainer
|
||||
editorWindow.RemoveChild(selectedNode);
|
||||
selectedNode.QueueFree();
|
||||
}
|
||||
|
||||
if (robot != null && Visible && robot.isExecuting)
|
||||
{
|
||||
UpdateCurrentNode();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateCurrentNode()
|
||||
{
|
||||
if (robot.currentNode == null)
|
||||
{
|
||||
ClearHighlightedNode();
|
||||
return;
|
||||
}
|
||||
|
||||
if (highlightedNode != null)
|
||||
{
|
||||
if (IsCurrentRuntimeNode(highlightedNode))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ClearHighlightedNode();
|
||||
}
|
||||
|
||||
foreach (Node child in editorWindow.GetChildren())
|
||||
{
|
||||
NodeDisplay nodeDisplay = child as NodeDisplay;
|
||||
if (nodeDisplay == null) continue;
|
||||
|
||||
if (IsCurrentRuntimeNode(nodeDisplay))
|
||||
{
|
||||
nodeDisplay.SetHighlighted(true);
|
||||
highlightedNode = nodeDisplay;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsCurrentRuntimeNode(NodeDisplay nodeDisplay)
|
||||
{
|
||||
return robot.currentNode.EditorNodeId != null
|
||||
&& robot.currentNode.EditorNodeId.Length > 0
|
||||
&& nodeDisplay.Name.ToString() == robot.currentNode.EditorNodeId;
|
||||
}
|
||||
|
||||
private void ClearHighlightedNode()
|
||||
{
|
||||
if (highlightedNode == null) return;
|
||||
|
||||
highlightedNode.SetHighlighted(false);
|
||||
highlightedNode = null;
|
||||
}
|
||||
|
||||
public void OnMapToggled(bool toggledOn)
|
||||
{
|
||||
if(robot == null) return;
|
||||
if (robot == null) return;
|
||||
robot.showOnMap = toggledOn;
|
||||
}
|
||||
|
||||
@@ -133,6 +186,7 @@ public partial class CodingWindow : PanelContainer
|
||||
|
||||
public void ClearWindow()
|
||||
{
|
||||
ClearHighlightedNode();
|
||||
DisconnectAllNodes();
|
||||
RemoveEditorNodes();
|
||||
scriptName.Text = "";
|
||||
@@ -210,16 +264,18 @@ public partial class CodingWindow : PanelContainer
|
||||
public void LoadTemporaryProgram()
|
||||
{
|
||||
if (robot == null) return;
|
||||
if (robot.currentNode == null) return;
|
||||
ProgramNode rootNode = robot.programStartNode ?? robot.currentNode;
|
||||
if (rootNode == null) return;
|
||||
|
||||
RunningProgramGraphBuilder builder = new RunningProgramGraphBuilder(
|
||||
DSLNodes,
|
||||
AddLoadedNode,
|
||||
ConnectNodes
|
||||
);
|
||||
builder.Load(robot.currentNode);
|
||||
builder.Load(rootNode);
|
||||
|
||||
scriptName.Text = robot.currentProgram ?? "";
|
||||
UpdateCurrentNode();
|
||||
}
|
||||
|
||||
public void DeleteProgram()
|
||||
|
||||
@@ -4,6 +4,7 @@ using Godot;
|
||||
public partial class NodeDisplay : GraphNode
|
||||
{
|
||||
public ProgramNode node;
|
||||
private bool isHighlighted = false;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
@@ -48,6 +49,14 @@ public partial class NodeDisplay : GraphNode
|
||||
|
||||
public virtual void ReadParameters() { }
|
||||
|
||||
public void SetHighlighted(bool highlighted)
|
||||
{
|
||||
if (isHighlighted == highlighted) return;
|
||||
|
||||
isHighlighted = highlighted;
|
||||
SelfModulate = highlighted ? UIStyle.GetWarningColor() : Colors.White;
|
||||
}
|
||||
|
||||
public HBoxContainer GetValueContainer()
|
||||
{
|
||||
return GetNode<HBoxContainer>("./Values");
|
||||
|
||||
@@ -40,6 +40,10 @@ public class RunningProgramGraphBuilder
|
||||
dslNodes
|
||||
);
|
||||
if (nodeDisplay == null) return null;
|
||||
if (programNode.EditorNodeId != null && programNode.EditorNodeId.Length > 0)
|
||||
{
|
||||
nodeDisplay.Name = programNode.EditorNodeId;
|
||||
}
|
||||
|
||||
addNode(nodeDisplay);
|
||||
loadedNodes.Add(programNode, nodeDisplay);
|
||||
|
||||
@@ -5,7 +5,7 @@ using System.Collections.Generic;
|
||||
public class ScriptGraphCompiler
|
||||
{
|
||||
private readonly GraphEdit editorWindow;
|
||||
private System.Collections.Generic.Dictionary<StringName, ProgramNode> availableNodes;
|
||||
private System.Collections.Generic.Dictionary<StringName, ProgramNode> runtimeNodes;
|
||||
|
||||
public ScriptGraphCompiler(GraphEdit editorWindow)
|
||||
{
|
||||
@@ -22,7 +22,7 @@ public class ScriptGraphCompiler
|
||||
return new List<ProgramNode>();
|
||||
}
|
||||
|
||||
BuildAvailableNodeLookup();
|
||||
BuildRuntimeNodeLookup();
|
||||
return BuildScriptOrder(
|
||||
startNode,
|
||||
new List<ProgramNode>(),
|
||||
@@ -30,9 +30,9 @@ public class ScriptGraphCompiler
|
||||
);
|
||||
}
|
||||
|
||||
private void BuildAvailableNodeLookup()
|
||||
private void BuildRuntimeNodeLookup()
|
||||
{
|
||||
availableNodes = new System.Collections.Generic.Dictionary<StringName, ProgramNode>();
|
||||
runtimeNodes = new System.Collections.Generic.Dictionary<StringName, ProgramNode>();
|
||||
|
||||
for (int i = 0; i < editorWindow.GetChildCount(); i++)
|
||||
{
|
||||
@@ -40,7 +40,10 @@ public class ScriptGraphCompiler
|
||||
if (nodeDisplay == null) continue;
|
||||
|
||||
nodeDisplay.ReadParameters();
|
||||
availableNodes.Add(nodeDisplay.Name, nodeDisplay.node);
|
||||
runtimeNodes.Add(
|
||||
nodeDisplay.Name,
|
||||
nodeDisplay.node.DuplicateForRuntime(nodeDisplay.Name.ToString())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,14 +55,16 @@ public class ScriptGraphCompiler
|
||||
{
|
||||
if (node == null) return program;
|
||||
if (visitedNodes.Contains(node.Name)) return program;
|
||||
if (!runtimeNodes.ContainsKey(node.Name)) return program;
|
||||
|
||||
visitedNodes.Add(node.Name);
|
||||
program.Add(node.node);
|
||||
ProgramNode runtimeNode = runtimeNodes[node.Name];
|
||||
program.Add(runtimeNode);
|
||||
|
||||
List<Dictionary> nextConnections = GetOutgoingConnections(node);
|
||||
if (nextConnections.Count <= 0) return program;
|
||||
|
||||
node.node.SetNextNode(nextConnections, availableNodes);
|
||||
runtimeNode.SetNextNode(nextConnections, runtimeNodes);
|
||||
foreach (Dictionary connection in nextConnections)
|
||||
{
|
||||
NodeDisplay nextNode = editorWindow.GetNodeOrNull<NodeDisplay>(
|
||||
|
||||
Reference in New Issue
Block a user