Added Run order button and fixed a node connection issue

This commit is contained in:
Chromium 2025-04-27 01:36:14 +01:00
parent 4985cf5748
commit 0c53ac8d18
4 changed files with 114 additions and 39 deletions

View File

@ -14,7 +14,7 @@ namespace ImageProcessingGraph.Editor
public static IPTPort Create(IEdgeConnectorListener connectorListener, bool isInput, Type type) public static IPTPort Create(IEdgeConnectorListener connectorListener, bool isInput, Type type)
{ {
var port = new IPTPort(Orientation.Horizontal, isInput ? Direction.Input : Direction.Output, var port = new IPTPort(Orientation.Horizontal, isInput ? Direction.Input : Direction.Output,
Capacity.Multi, type) isInput ? Capacity.Single : Capacity.Multi, type)
{ {
m_EdgeConnector = new EdgeConnector<Edge>(connectorListener), m_EdgeConnector = new EdgeConnector<Edge>(connectorListener),
}; };

View File

@ -3,16 +3,9 @@ using UnityEngine;
namespace ImageProcessingGraph.Editor namespace ImageProcessingGraph.Editor
{ {
#if true
[CreateAssetMenu(menuName = "PreferenceCreate")]
#endif
public class IPT_Preferences : ScriptableObject public class IPT_Preferences : ScriptableObject
{ {
[Header("Grid Settings")] public bool debugMode = false;
public float thickLines;
public float spacing;
public Color gridBackgroundColour;
public Color lineColour;
} }
} }

View File

@ -16,7 +16,7 @@ namespace ImageProcessingGraph.Editor
{ {
[SerializeReference] private List<BaseImageNode> nodes; [SerializeReference] private List<BaseImageNode> nodes;
[SerializeField] private List<GraphConnection> connections; [SerializeField] private List<GraphConnection> connections;
[SerializeField] public List<BaseImageNode> runOrder; [SerializeReference] public List<BaseImageNode> runOrder;
[SerializeField] public List<StickyNote> stickyNotes; [SerializeField] public List<StickyNote> stickyNotes;
public List<BaseImageNode> Nodes => nodes; public List<BaseImageNode> Nodes => nodes;

View File

@ -14,7 +14,6 @@ namespace ImageProcessingGraph.Editor
internal ImageProcessingGraphAsset asset; internal ImageProcessingGraphAsset asset;
private SerializedObject serializedObject; private SerializedObject serializedObject;
private ImageProcessingGraphEditorWindow window; private ImageProcessingGraphEditorWindow window;
public ImageProcessingGraphEditorWindow Window => window; public ImageProcessingGraphEditorWindow Window => window;
public List<ImageProcessingGraphNodeVisual> graphNodes; public List<ImageProcessingGraphNodeVisual> graphNodes;
@ -23,6 +22,11 @@ namespace ImageProcessingGraph.Editor
internal ImageProcessingGraphSearchProvider searchProvider; internal ImageProcessingGraphSearchProvider searchProvider;
internal ImageProcessingGraphEdgeConnectorListener edgeConnectorListener; internal ImageProcessingGraphEdgeConnectorListener edgeConnectorListener;
private bool isDropdownEnabled = false;
private Button debugModeButton;
private Button outputRunOrder;
public ImageProcessingGraphViewWindow(SerializedObject obeject, ImageProcessingGraphEditorWindow window) public ImageProcessingGraphViewWindow(SerializedObject obeject, ImageProcessingGraphEditorWindow window)
{ {
@ -50,36 +54,13 @@ namespace ImageProcessingGraph.Editor
styleSheets.Add(styleSheet); styleSheets.Add(styleSheet);
GridBackground background = new GridBackground(); GridBackground background = new GridBackground();
background.name = "Grid"; background.name = "Grid";
Button runButton = new Button();
runButton.text = "Run";
// Set the size of the button (width and height)
runButton.style.width = 100; // Width in pixels
runButton.style.height = 40; // Height in pixels
// Position the button at the top-left corner
runButton.style.position = Position.Absolute; // Make sure it's positioned absolutely
runButton.style.top = 10; // Top 10 pixels from the top
runButton.style.left = 10; // Left 10 pixels from the left edge
// On click, execute the function
runButton.clicked += () =>
{
asset.RunGraph();
};
// Add the button to the UI
Add(runButton);
Add(background); Add(background);
background.SendToBack(); background.SendToBack();
CreateButtons();
this.AddManipulator(new ContentDragger()); this.AddManipulator(new ContentDragger());
this.AddManipulator(new SelectionDragger()); this.AddManipulator(new SelectionDragger());
this.AddManipulator(new RectangleSelector()); this.AddManipulator(new RectangleSelector());
@ -92,7 +73,108 @@ namespace ImageProcessingGraph.Editor
graphViewChanged += OnGraphViewChanged; graphViewChanged += OnGraphViewChanged;
Undo.undoRedoEvent += UndoEvent; Undo.undoRedoEvent += UndoEvent;
} }
private void CreateButtons()
{
#region Run Button
Button runButton = new Button
{
text = "Run",
style =
{
width = 100,
height = 40,
position = Position.Absolute,
top = 10,
left = 10
}
};
runButton.clicked += () =>
{
asset.RunGraph();
};
Add(runButton);
#endregion
#if false
debugModeButton = new Button
{
text = "Debug Mode",
style =
{
width = 120,
height = 40,
position = Position.Absolute,
top = 55,
right = 10
}
};
debugModeButton.clicked += () =>
{
};
#endif
outputRunOrder = new Button
{
text = "Recalculate Run Order",
style =
{
width = 120,
height = 40,
position = Position.Absolute,
top = 55,
right = 10,
fontSize = 9
}
};
outputRunOrder.clicked += () =>
{
asset.runOrder = asset.GetExecutionOrder(asset.Nodes, asset.Connections);
};
Button dropdownButton = new Button
{
text = "Options",
style =
{
width = 120,
height = 40,
position = Position.Absolute,
top = 10,
right = 10
}
};
dropdownButton.clicked+= () =>
{
if (!isDropdownEnabled)
{
#if false
Add(debugModeButton);
#endif
Add(outputRunOrder);
}
else
{
#if false
Remove(debugModeButton);
#endif
Remove(outputRunOrder);
}
isDropdownEnabled = !isDropdownEnabled;
};
Add(dropdownButton);
}
private ImageProcessingGraphNodeVisual GetNode(string NodeID) private ImageProcessingGraphNodeVisual GetNode(string NodeID)
{ {
ImageProcessingGraphNodeVisual node = null; ImageProcessingGraphNodeVisual node = null;