sticky notes kinda work!

This commit is contained in:
Chromium 2025-05-04 10:12:39 +01:00
parent e3e851e9db
commit 020d29a6fe
5 changed files with 130 additions and 4 deletions

View File

@ -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<TextField>("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();
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 119eef6b9f4b410da217f8a12be9973d
timeCreated: 1746345401

View File

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

View File

@ -32,9 +32,6 @@ namespace ImageProcessingGraph.Editor
public BaseImageNode()
{
guid = Guid.NewGuid().ToString();
/*Type t = this.GetType();
Debug.Log(t.Name);*/
}
public void SetNodeInputs()

View File

@ -22,6 +22,7 @@ namespace ImageProcessingGraph.Editor
public List<ImageProcessingGraphNodeVisual> graphNodes;
public Dictionary<string, ImageProcessingGraphNodeVisual> nodeDictionary;
public Dictionary<Edge, GraphConnection> connectionDictionary;
public Dictionary<string, IPT_StickyNote> 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<ImageProcessingGraphNodeVisual>();
nodeDictionary = new Dictionary<string, ImageProcessingGraphNodeVisual>();
stickyNoteDictionary = new Dictionary<string, IPT_StickyNote>();
connectionDictionary = new Dictionary<Edge, GraphConnection>();
searchProvider = ScriptableObject.CreateInstance<ImageProcessingGraphSearchProvider>();
@ -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()
@ -156,6 +161,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<IPT_StickyNote>())
{
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
}
}