Added tooltip to nodes to better explain their functionality.
Readded node deletion.
This commit is contained in:
@@ -11,8 +11,10 @@ public partial class CodingWindow : PanelContainer
|
||||
[Export] OptionButton availableScripts;
|
||||
[Export] LineEdit scriptName;
|
||||
[Export] LineEdit nameInput;
|
||||
[Export] NodeTooltip nodeTooltip;
|
||||
|
||||
public System.Collections.Generic.Dictionary<ProgramNode, PackedScene> DSLNodes;
|
||||
public NodeDisplay selectedNode;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
@@ -28,6 +30,29 @@ public partial class CodingWindow : PanelContainer
|
||||
}
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (Input.IsActionJustPressed("delete_node"))
|
||||
{
|
||||
Control focused = GetViewport().GuiGetFocusOwner();
|
||||
|
||||
if (focused is LineEdit || focused is TextEdit) return;
|
||||
if (selectedNode == null) return;
|
||||
editorWindow.RemoveChild(selectedNode);
|
||||
selectedNode.QueueFree();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnNodeSelect(NodeDisplay node)
|
||||
{
|
||||
selectedNode = node;
|
||||
}
|
||||
|
||||
public void OnNodeDeselect(NodeDisplay node)
|
||||
{
|
||||
selectedNode = null;
|
||||
}
|
||||
|
||||
private void LoadWindow()
|
||||
{
|
||||
if (robot == null) return;
|
||||
@@ -76,6 +101,14 @@ public partial class CodingWindow : PanelContainer
|
||||
{
|
||||
AddEditorNode(nodeTemplate);
|
||||
};
|
||||
nodeListButton.MouseEntered += () =>
|
||||
{
|
||||
nodeTooltip.ShowTooltip(nodeTemplate.DisplayText, nodeTemplate.DisplayText, nodeListButton);
|
||||
};
|
||||
nodeListButton.MouseExited += () =>
|
||||
{
|
||||
nodeTooltip.HideTooltip();
|
||||
};
|
||||
codeBlocks.AddChild(nodeListButton);
|
||||
}
|
||||
}
|
||||
@@ -85,7 +118,6 @@ public partial class CodingWindow : PanelContainer
|
||||
NodeDisplay editorDisplay = DSLNodes[node].Instantiate<NodeDisplay>();
|
||||
editorDisplay.PositionOffset = GetVisibleGraphCenter() - editorDisplay.Size / 2f;
|
||||
editorWindow.AddChild(editorDisplay);
|
||||
RegisterEditorNode(editorDisplay);
|
||||
}
|
||||
|
||||
private Vector2 GetVisibleGraphCenter()
|
||||
@@ -93,15 +125,6 @@ public partial class CodingWindow : PanelContainer
|
||||
return (editorWindow.ScrollOffset + editorWindow.Size / 2f) / editorWindow.Zoom;
|
||||
}
|
||||
|
||||
private void RegisterEditorNode(NodeDisplay editorDisplay)
|
||||
{
|
||||
editorDisplay.OnDeleteNode += () =>
|
||||
{
|
||||
editorWindow.RemoveChild(editorDisplay);
|
||||
editorDisplay.QueueFree();
|
||||
};
|
||||
}
|
||||
|
||||
public void ClearWindow()
|
||||
{
|
||||
DisconnectAllNodes();
|
||||
@@ -176,7 +199,6 @@ public partial class CodingWindow : PanelContainer
|
||||
private void AddLoadedNode(NodeDisplay nodeDisplay)
|
||||
{
|
||||
editorWindow.AddChild(nodeDisplay);
|
||||
RegisterEditorNode(nodeDisplay);
|
||||
}
|
||||
|
||||
public void LoadTemporaryProgram()
|
||||
|
||||
@@ -5,9 +5,6 @@ public partial class NodeDisplay : GraphNode
|
||||
{
|
||||
public ProgramNode node;
|
||||
|
||||
[Signal]
|
||||
public delegate void OnDeleteNodeEventHandler();
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
if (node == null)
|
||||
@@ -20,11 +17,6 @@ public partial class NodeDisplay : GraphNode
|
||||
SetupDisplay();
|
||||
}
|
||||
|
||||
public void DeleteNodePressed()
|
||||
{
|
||||
EmitSignal(SignalName.OnDeleteNode);
|
||||
}
|
||||
|
||||
public static NodeDisplay Load(
|
||||
string nodeName,
|
||||
string content,
|
||||
|
||||
@@ -41,6 +41,7 @@ public partial class IfNodeDisplay : NodeDisplay
|
||||
ifNode.amount = (int)valueContainer.GetNode<SpinBox>("./Amount").Value;
|
||||
|
||||
OptionButton comparators = valueContainer.GetNode<OptionButton>("./Comparator");
|
||||
if(comparators.GetSelectedId() == -1) return;
|
||||
ifNode.comparator = comparators.GetItemText(comparators.GetSelectedId());
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ public partial class WhileNodeDisplay : NodeDisplay
|
||||
whileNode.amount = (int)valueContainer.GetNode<SpinBox>("./Amount").Value;
|
||||
|
||||
OptionButton comparators = valueContainer.GetNode<OptionButton>("./Comparator");
|
||||
if(comparators.GetSelectedId() == -1) return;
|
||||
whileNode.comparator = comparators.GetItemText(comparators.GetSelectedId());
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
using Godot;
|
||||
|
||||
public partial class NodeTooltip : PanelContainer
|
||||
{
|
||||
[Export] RichTextLabel title;
|
||||
[Export] TextureRect image;
|
||||
[Export] RichTextLabel description;
|
||||
|
||||
private static Vector2 spacing = new Vector2(5, 0);
|
||||
|
||||
public void ShowTooltip(string titleText, string descriptionText, Button button)
|
||||
{
|
||||
title.Text = titleText;
|
||||
image.Texture = ResourceLoader.LoadDSLTooltip(titleText);
|
||||
description.Text = descriptionText;
|
||||
Show();
|
||||
Position = button.GlobalPosition - spacing - new Vector2(Size.X, Size.Y/2);
|
||||
}
|
||||
|
||||
public void HideTooltip()
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://dx5oy38ochrw2
|
||||
Reference in New Issue
Block a user