diff --git a/Editor/Scripts/Editor/Data Types/IPT_StickyNote.cs b/Editor/Scripts/Editor/Data Types/IPT_StickyNote.cs new file mode 100644 index 0000000..ad03e90 --- /dev/null +++ b/Editor/Scripts/Editor/Data Types/IPT_StickyNote.cs @@ -0,0 +1,68 @@ +using System; +using UnityEditor.Experimental.GraphView; +using UnityEngine; +using UnityEngine.UIElements; + +namespace ImageProcessingGraph.Editor +{ + [System.Serializable] + public class IPT_StickyNoteData + { + [SerializeField] private string guid; + [SerializeField] private string title; + [SerializeField] private string content; + [SerializeField] private Rect position; + [SerializeField] private Vector2 size; + + + public string GUID { get => guid; } + + public string Title { get => title; set => title = value; } + + public string Content { get => content; set => content = value; } + public Rect Position { get => position; set => position = value; } + public Vector2 Size { get => size; set => size = value; } + + public IPT_StickyNoteData(string title) + { + this.guid = Guid.NewGuid().ToString(); + } + + } + + + public class IPT_StickyNote : StickyNote + { + private IPT_StickyNoteData data; + public IPT_StickyNoteData Data => data; + + private ImageProcessingGraphViewWindow window; + + public IPT_StickyNote(IPT_StickyNoteData data, ImageProcessingGraphViewWindow window) + { + this.theme = StickyNoteTheme.Black; + this.window = window; + this.data = data; + + this.title = data.Title; + this.contents = data.Content; + this.SetPosition(data.Position); + + var le = this.Q("contents-field"); + + le.RegisterValueChangedCallback(evt => + { + this.data.Content = evt.newValue; + }); + } + + public override void OnResized() + { + base.OnResized(); + data.Size = new Vector2(this.resolvedStyle.width, this.resolvedStyle.height); + } + + public void SavePosition() => data.Position = GetPosition(); + } + +} \ No newline at end of file diff --git a/Editor/Scripts/Editor/Data Types/IPT_StickyNote.cs.meta b/Editor/Scripts/Editor/Data Types/IPT_StickyNote.cs.meta new file mode 100644 index 0000000..ac78f14 --- /dev/null +++ b/Editor/Scripts/Editor/Data Types/IPT_StickyNote.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 119eef6b9f4b410da217f8a12be9973d +timeCreated: 1746345401 \ No newline at end of file diff --git a/Editor/Scripts/Editor/ImageProcessingGraphAsset.cs b/Editor/Scripts/Editor/ImageProcessingGraphAsset.cs index 1a48d78..2eb24fb 100644 --- a/Editor/Scripts/Editor/ImageProcessingGraphAsset.cs +++ b/Editor/Scripts/Editor/ImageProcessingGraphAsset.cs @@ -18,7 +18,7 @@ namespace ImageProcessingGraph.Editor [SerializeReference] private List nodes; [SerializeField] private List connections; [SerializeReference] public List runOrder; - [SerializeField] public List stickyNotes; + [SerializeField] public List stickyNotes; public List Nodes => nodes; public List Connections => connections; diff --git a/Editor/Scripts/Editor/Nodes/Base/BaseImageNode.cs b/Editor/Scripts/Editor/Nodes/Base/BaseImageNode.cs index a0e2d49..1b42602 100644 --- a/Editor/Scripts/Editor/Nodes/Base/BaseImageNode.cs +++ b/Editor/Scripts/Editor/Nodes/Base/BaseImageNode.cs @@ -32,9 +32,6 @@ namespace ImageProcessingGraph.Editor public BaseImageNode() { guid = Guid.NewGuid().ToString(); - - /*Type t = this.GetType(); - Debug.Log(t.Name);*/ } public void SetNodeInputs() diff --git a/Editor/Scripts/Editor/Windows/ImageProcessingGraphViewWindow.cs b/Editor/Scripts/Editor/Windows/ImageProcessingGraphViewWindow.cs index c730860..56499c1 100644 --- a/Editor/Scripts/Editor/Windows/ImageProcessingGraphViewWindow.cs +++ b/Editor/Scripts/Editor/Windows/ImageProcessingGraphViewWindow.cs @@ -22,6 +22,7 @@ namespace ImageProcessingGraph.Editor public List graphNodes; public Dictionary nodeDictionary; public Dictionary connectionDictionary; + public Dictionary stickyNoteDictionary; internal ImageProcessingGraphSearchProvider searchProvider; internal ImageProcessingGraphEdgeConnectorListener edgeConnectorListener; @@ -32,6 +33,7 @@ namespace ImageProcessingGraph.Editor private Button debugModeButton; private Button outputRunOrder; + private Button makeStickyNode; public ImageProcessingGraphViewWindow(SerializedObject obeject, ImageProcessingGraphEditorWindow window) { @@ -40,6 +42,7 @@ namespace ImageProcessingGraph.Editor this.graphNodes = new List(); nodeDictionary = new Dictionary(); + stickyNoteDictionary = new Dictionary(); connectionDictionary = new Dictionary(); searchProvider = ScriptableObject.CreateInstance(); @@ -74,6 +77,7 @@ namespace ImageProcessingGraph.Editor DrawNodes(); DrawConnections(); + DrawStickyNotes(); graphViewChanged += OnGraphViewChanged; @@ -91,6 +95,7 @@ namespace ImageProcessingGraph.Editor { DrawNodes(); DrawConnections(); + DrawStickyNotes(); } private void CreateButtons() @@ -155,6 +160,27 @@ namespace ImageProcessingGraph.Editor { asset.runOrder = asset.GetExecutionOrder(asset.Nodes, asset.Connections); }; + + makeStickyNode = new Button + { + text = "Make Sticky Node", + style = + { + width = 120, + height = 40, + position = Position.Absolute, + top = 55+45, + right = 10, + fontSize = 9 + } + }; + + makeStickyNode.clicked += () => + { + var noteData = new IPT_StickyNoteData(""); + asset.stickyNotes.Add(noteData); + this.DrawStickyNote(noteData); + }; Button dropdownButton = new Button @@ -178,6 +204,7 @@ namespace ImageProcessingGraph.Editor Add(debugModeButton); #endif Add(outputRunOrder); + Add(makeStickyNode); } else { @@ -185,6 +212,7 @@ namespace ImageProcessingGraph.Editor Remove(debugModeButton); #endif Remove(outputRunOrder); + Remove(makeStickyNode); } isDropdownEnabled = !isDropdownEnabled; @@ -252,6 +280,11 @@ namespace ImageProcessingGraph.Editor { VARIABLE.SavePosition(); } + + foreach (var VARIABLE in graphviewchange.movedElements.OfType()) + { + VARIABLE.SavePosition(); + } } if (graphviewchange.elementsToRemove != null) @@ -511,5 +544,30 @@ namespace ImageProcessingGraph.Editor #endregion + #region Sticky Note + + public void DrawStickyNotes() + { + foreach (var stick in asset.stickyNotes) + { + this.stickyNoteDictionary.Add(stick.GUID, DrawStickyNote(stick)); + } + } + + public IPT_StickyNote DrawStickyNote(IPT_StickyNoteData stickyNote) + { + IPT_StickyNote stickyNoteVisual = new IPT_StickyNote(stickyNote, this); + + stickyNoteVisual.SetPosition(stickyNote.Position); + stickyNoteVisual.style.width = stickyNote.Size.x; + stickyNoteVisual.style.height = stickyNote.Size.y; + + this.Add(stickyNoteVisual); + return stickyNoteVisual; + } + + #endregion + + } }