1
0
mirror of https://github.com/Siccity/xNode.git synced 2025-12-21 17:56:06 +08:00

Merge pull request #300 from neoneper/Improvments - customization

Internal changes that allow for greater customization options
This commit is contained in:
Thor Brigsted 2020-10-12 09:47:29 +02:00 committed by GitHub
commit e3127a9135
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 59 additions and 34 deletions

View File

@ -14,16 +14,25 @@ namespace XNodeEditor {
public static XNode.Node[] copyBuffer = null; public static XNode.Node[] copyBuffer = null;
private bool IsDraggingPort { get { return draggedOutput != null; } } public bool IsDraggingPort { get { return draggedOutput != null; } }
private bool IsHoveringPort { get { return hoveredPort != null; } } public bool IsHoveringPort { get { return hoveredPort != null; } }
private bool IsHoveringNode { get { return hoveredNode != null; } } public bool IsHoveringNode { get { return hoveredNode != null; } }
private bool IsHoveringReroute { get { return hoveredReroute.port != null; } } public bool IsHoveringReroute { get { return hoveredReroute.port != null; } }
/// <summary> Return the dragged port or null if not exist </summary>
public XNode.NodePort DraggedOutputPort { get { XNode.NodePort result = draggedOutput; return result; } }
/// <summary> Return the Hovered port or null if not exist </summary>
public XNode.NodePort HoveredPort { get { XNode.NodePort result = hoveredPort; return result; } }
/// <summary> Return the Hovered node or null if not exist </summary>
public XNode.Node HoveredNode { get { XNode.Node result = hoveredNode; return result; } }
private XNode.Node hoveredNode = null; private XNode.Node hoveredNode = null;
[NonSerialized] public XNode.NodePort hoveredPort = null; [NonSerialized] public XNode.NodePort hoveredPort = null;
[NonSerialized] private XNode.NodePort draggedOutput = null; [NonSerialized] private XNode.NodePort draggedOutput = null;
[NonSerialized] private XNode.NodePort draggedOutputTarget = null; [NonSerialized] private XNode.NodePort draggedOutputTarget = null;
[NonSerialized] private XNode.NodePort autoConnectOutput = null; [NonSerialized] private XNode.NodePort autoConnectOutput = null;
[NonSerialized] private List<Vector2> draggedOutputReroutes = new List<Vector2>(); [NonSerialized] private List<Vector2> draggedOutputReroutes = new List<Vector2>();
private RerouteReference hoveredReroute = new RerouteReference(); private RerouteReference hoveredReroute = new RerouteReference();
public List<RerouteReference> selectedReroutes = new List<RerouteReference>(); public List<RerouteReference> selectedReroutes = new List<RerouteReference>();
private Vector2 dragBoxStart; private Vector2 dragBoxStart;

View File

@ -556,7 +556,7 @@ namespace XNodeEditor {
} }
private void DrawTooltip() { private void DrawTooltip() {
if (!NodeEditorPreferences.GetSettings().portTooltips || graphEditor is null) if (!NodeEditorPreferences.GetSettings().portTooltips || graphEditor == null)
return; return;
string tooltip = null; string tooltip = null;
if (hoveredPort != null) { if (hoveredPort != null) {

View File

@ -101,7 +101,8 @@ namespace XNodeEditor {
} }
rect = GUILayoutUtility.GetLastRect(); rect = GUILayoutUtility.GetLastRect();
rect.position = rect.position - new Vector2(16, -spacePadding); float paddingLeft = NodeEditorResources.styles.inputPort.padding.left;
rect.position = rect.position - new Vector2(16 + paddingLeft, -spacePadding);
// If property is an output, display a text label and put a port handle on the right side // If property is an output, display a text label and put a port handle on the right side
} else if (port.direction == XNode.NodePort.IO.Output) { } else if (port.direction == XNode.NodePort.IO.Output) {
// Get data from [Output] attribute // Get data from [Output] attribute
@ -160,13 +161,13 @@ namespace XNodeEditor {
} }
rect = GUILayoutUtility.GetLastRect(); rect = GUILayoutUtility.GetLastRect();
rect.width += NodeEditorResources.styles.outputPort.padding.right;
rect.position = rect.position + new Vector2(rect.width, spacePadding); rect.position = rect.position + new Vector2(rect.width, spacePadding);
} }
rect.size = new Vector2(16, 16); rect.size = new Vector2(16, 16);
NodeEditor editor = NodeEditor.GetEditor(port.node, NodeEditorWindow.current); Color backgroundColor = NodeEditorWindow.current.graphEditor.GetPortBackgroundColor(port);
Color backgroundColor = editor.GetTint();
Color col = NodeEditorWindow.current.graphEditor.GetPortColor(port); Color col = NodeEditorWindow.current.graphEditor.GetPortColor(port);
DrawPortHandle(rect, backgroundColor, col); DrawPortHandle(rect, backgroundColor, col);
@ -200,7 +201,8 @@ namespace XNodeEditor {
EditorGUILayout.LabelField(content, options); EditorGUILayout.LabelField(content, options);
Rect rect = GUILayoutUtility.GetLastRect(); Rect rect = GUILayoutUtility.GetLastRect();
position = rect.position - new Vector2(16, 0); float paddingLeft = NodeEditorResources.styles.inputPort.padding.left;
position = rect.position - new Vector2(16 + paddingLeft, 0);
} }
// If property is an output, display a text label and put a port handle on the right side // If property is an output, display a text label and put a port handle on the right side
else if (port.direction == XNode.NodePort.IO.Output) { else if (port.direction == XNode.NodePort.IO.Output) {
@ -208,6 +210,7 @@ namespace XNodeEditor {
EditorGUILayout.LabelField(content, NodeEditorResources.OutputPort, options); EditorGUILayout.LabelField(content, NodeEditorResources.OutputPort, options);
Rect rect = GUILayoutUtility.GetLastRect(); Rect rect = GUILayoutUtility.GetLastRect();
rect.width += NodeEditorResources.styles.outputPort.padding.right;
position = rect.position + new Vector2(rect.width, 0); position = rect.position + new Vector2(rect.width, 0);
} }
PortField(position, port); PortField(position, port);
@ -219,8 +222,7 @@ namespace XNodeEditor {
Rect rect = new Rect(position, new Vector2(16, 16)); Rect rect = new Rect(position, new Vector2(16, 16));
NodeEditor editor = NodeEditor.GetEditor(port.node, NodeEditorWindow.current); Color backgroundColor = NodeEditorWindow.current.graphEditor.GetPortBackgroundColor(port);
Color backgroundColor = editor.GetTint();
Color col = NodeEditorWindow.current.graphEditor.GetPortColor(port); Color col = NodeEditorWindow.current.graphEditor.GetPortColor(port);
DrawPortHandle(rect, backgroundColor, col); DrawPortHandle(rect, backgroundColor, col);
@ -237,17 +239,18 @@ namespace XNodeEditor {
// If property is an input, display a regular property field and put a port handle on the left side // If property is an input, display a regular property field and put a port handle on the left side
if (port.direction == XNode.NodePort.IO.Input) { if (port.direction == XNode.NodePort.IO.Input) {
rect = GUILayoutUtility.GetLastRect(); rect = GUILayoutUtility.GetLastRect();
rect.position = rect.position - new Vector2(16, 0); float paddingLeft = NodeEditorResources.styles.inputPort.padding.left;
rect.position = rect.position - new Vector2(16 + paddingLeft, 0);
// If property is an output, display a text label and put a port handle on the right side // If property is an output, display a text label and put a port handle on the right side
} else if (port.direction == XNode.NodePort.IO.Output) { } else if (port.direction == XNode.NodePort.IO.Output) {
rect = GUILayoutUtility.GetLastRect(); rect = GUILayoutUtility.GetLastRect();
rect.width += NodeEditorResources.styles.outputPort.padding.right;
rect.position = rect.position + new Vector2(rect.width, 0); rect.position = rect.position + new Vector2(rect.width, 0);
} }
rect.size = new Vector2(16, 16); rect.size = new Vector2(16, 16);
NodeEditor editor = NodeEditor.GetEditor(port.node, NodeEditorWindow.current); Color backgroundColor = NodeEditorWindow.current.graphEditor.GetPortBackgroundColor(port);
Color backgroundColor = editor.GetTint();
Color col = NodeEditorWindow.current.graphEditor.GetPortColor(port); Color col = NodeEditorWindow.current.graphEditor.GetPortColor(port);
DrawPortHandle(rect, backgroundColor, col); DrawPortHandle(rect, backgroundColor, col);

View File

@ -20,10 +20,10 @@ namespace XNodeEditor {
[System.Serializable] [System.Serializable]
public class Settings : ISerializationCallbackReceiver { public class Settings : ISerializationCallbackReceiver {
[SerializeField] private Color32 _gridLineColor = new Color(0.45f, 0.45f, 0.45f); [SerializeField] private Color32 _gridLineColor = new Color(.23f, .23f, .23f);
public Color32 gridLineColor { get { return _gridLineColor; } set { _gridLineColor = value; _gridTexture = null; _crossTexture = null; } } public Color32 gridLineColor { get { return _gridLineColor; } set { _gridLineColor = value; _gridTexture = null; _crossTexture = null; } }
[SerializeField] private Color32 _gridBgColor = new Color(0.18f, 0.18f, 0.18f); [SerializeField] private Color32 _gridBgColor = new Color(.19f, .19f, .19f);
public Color32 gridBgColor { get { return _gridBgColor; } set { _gridBgColor = value; _gridTexture = null; } } public Color32 gridBgColor { get { return _gridBgColor; } set { _gridBgColor = value; _gridTexture = null; } }
[Obsolete("Use maxZoom instead")] [Obsolete("Use maxZoom instead")]
@ -42,6 +42,8 @@ namespace XNodeEditor {
[SerializeField] private string typeColorsData = ""; [SerializeField] private string typeColorsData = "";
[NonSerialized] public Dictionary<string, Color> typeColors = new Dictionary<string, Color>(); [NonSerialized] public Dictionary<string, Color> typeColors = new Dictionary<string, Color>();
[FormerlySerializedAs("noodleType")] public NoodlePath noodlePath = NoodlePath.Curvy; [FormerlySerializedAs("noodleType")] public NoodlePath noodlePath = NoodlePath.Curvy;
public float noodleThickness = 2f;
public NoodleStroke noodleStroke = NoodleStroke.Full; public NoodleStroke noodleStroke = NoodleStroke.Full;
private Texture2D _gridTexture; private Texture2D _gridTexture;
@ -160,6 +162,7 @@ namespace XNodeEditor {
EditorGUILayout.LabelField("Node", EditorStyles.boldLabel); EditorGUILayout.LabelField("Node", EditorStyles.boldLabel);
settings.highlightColor = EditorGUILayout.ColorField("Selection", settings.highlightColor); settings.highlightColor = EditorGUILayout.ColorField("Selection", settings.highlightColor);
settings.noodlePath = (NoodlePath) EditorGUILayout.EnumPopup("Noodle path", (Enum) settings.noodlePath); settings.noodlePath = (NoodlePath) EditorGUILayout.EnumPopup("Noodle path", (Enum) settings.noodlePath);
settings.noodleThickness = EditorGUILayout.FloatField(new GUIContent("Noodle thickness", "Noodle Thickness of the node connections"), settings.noodleThickness);
settings.noodleStroke = (NoodleStroke) EditorGUILayout.EnumPopup("Noodle stroke", (Enum) settings.noodleStroke); settings.noodleStroke = (NoodleStroke) EditorGUILayout.EnumPopup("Noodle stroke", (Enum) settings.noodleStroke);
settings.portTooltips = EditorGUILayout.Toggle("Port Tooltips", settings.portTooltips); settings.portTooltips = EditorGUILayout.Toggle("Port Tooltips", settings.portTooltips);
settings.dragToCreate = EditorGUILayout.Toggle(new GUIContent("Drag to Create", "Drag a port connection anywhere on the grid to create and connect a node"), settings.dragToCreate); settings.dragToCreate = EditorGUILayout.Toggle(new GUIContent("Drag to Create", "Drag a port connection anywhere on the grid to create and connect a node"), settings.dragToCreate);

View File

@ -18,7 +18,7 @@ namespace XNodeEditor {
public static Styles _styles = null; public static Styles _styles = null;
public static GUIStyle OutputPort { get { return new GUIStyle(EditorStyles.label) { alignment = TextAnchor.UpperRight }; } } public static GUIStyle OutputPort { get { return new GUIStyle(EditorStyles.label) { alignment = TextAnchor.UpperRight }; } }
public class Styles { public class Styles {
public GUIStyle inputPort, nodeHeader, nodeBody, tooltip, nodeHighlight; public GUIStyle inputPort, outputPort, nodeHeader, nodeBody, tooltip, nodeHighlight;
public Styles() { public Styles() {
GUIStyle baseStyle = new GUIStyle("Label"); GUIStyle baseStyle = new GUIStyle("Label");
@ -26,7 +26,11 @@ namespace XNodeEditor {
inputPort = new GUIStyle(baseStyle); inputPort = new GUIStyle(baseStyle);
inputPort.alignment = TextAnchor.UpperLeft; inputPort.alignment = TextAnchor.UpperLeft;
inputPort.padding.left = 10; inputPort.padding.left = 0;
outputPort = new GUIStyle(baseStyle);
outputPort.alignment = TextAnchor.UpperRight;
outputPort.padding.right = 0;
nodeHeader = new GUIStyle(); nodeHeader = new GUIStyle();
nodeHeader.alignment = TextAnchor.MiddleCenter; nodeHeader.alignment = TextAnchor.MiddleCenter;

View File

@ -125,7 +125,7 @@ namespace XNodeEditor {
/// <param name="output"> The output this noodle comes from. Never null. </param> /// <param name="output"> The output this noodle comes from. Never null. </param>
/// <param name="input"> The output this noodle comes from. Can be null if we are dragging the noodle. </param> /// <param name="input"> The output this noodle comes from. Can be null if we are dragging the noodle. </param>
public virtual float GetNoodleThickness(XNode.NodePort output, XNode.NodePort input) { public virtual float GetNoodleThickness(XNode.NodePort output, XNode.NodePort input) {
return 5f; return NodeEditorPreferences.GetSettings().noodleThickness;
} }
public virtual NoodlePath GetNoodlePath(XNode.NodePort output, XNode.NodePort input) { public virtual NoodlePath GetNoodlePath(XNode.NodePort output, XNode.NodePort input) {
@ -141,6 +141,12 @@ namespace XNodeEditor {
return GetTypeColor(port.ValueType); return GetTypeColor(port.ValueType);
} }
/// <summary> The returned color is used to color the background of the door.
/// Usually used for outer edge effect </summary>
public virtual Color GetPortBackgroundColor(XNode.NodePort port) {
return Color.gray;
}
/// <summary> Returns generated color for a type. This color is editable in preferences </summary> /// <summary> Returns generated color for a type. This color is editable in preferences </summary>
public virtual Color GetTypeColor(Type type) { public virtual Color GetTypeColor(Type type) {
return NodeEditorPreferences.GetTypeColor(type); return NodeEditorPreferences.GetTypeColor(type);