1
0
mirror of https://github.com/Siccity/xNode.git synced 2025-12-22 02:06:05 +08:00

Add Disconnect(Node) Menu And Node Header Tooltip (#288)

This commit is contained in:
MYTNB 2020-08-11 14:31:53 +08:00 committed by GitHub
parent 60a8e89cdb
commit 85341bf4cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 11 deletions

View File

@ -104,6 +104,11 @@ namespace XNodeEditor {
return NodeEditorResources.styles.nodeHighlight; return NodeEditorResources.styles.nodeHighlight;
} }
/// <summary> Override to display custom node header tooltips </summary>
public virtual string GetHeaderTooltip() {
return null;
}
/// <summary> Add items for the context menu when right-clicking this node. Override to add custom menu items. </summary> /// <summary> Add items for the context menu when right-clicking this node. Override to add custom menu items. </summary>
public virtual void AddContextMenuItems(GenericMenu menu) { public virtual void AddContextMenuItems(GenericMenu menu) {
bool canRemove = true; bool canRemove = true;

View File

@ -112,6 +112,11 @@ namespace XNodeEditor {
/// <summary> Show right-click context menu for hovered port </summary> /// <summary> Show right-click context menu for hovered port </summary>
void ShowPortContextMenu(XNode.NodePort hoveredPort) { void ShowPortContextMenu(XNode.NodePort hoveredPort) {
GenericMenu contextMenu = new GenericMenu(); GenericMenu contextMenu = new GenericMenu();
foreach (var port in hoveredPort.GetConnections()) {
var name = port.node.name;
var index = hoveredPort.GetConnectionIndex(port);
contextMenu.AddItem(new GUIContent($"Disconnect({name})"), false, () => hoveredPort.Disconnect(index));
}
contextMenu.AddItem(new GUIContent("Clear Connections"), false, () => hoveredPort.ClearConnections()); contextMenu.AddItem(new GUIContent("Clear Connections"), false, () => hoveredPort.ClearConnections());
contextMenu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero)); contextMenu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero));
if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets(); if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
@ -551,16 +556,22 @@ namespace XNodeEditor {
} }
private void DrawTooltip() { private void DrawTooltip() {
if (hoveredPort != null && NodeEditorPreferences.GetSettings().portTooltips && graphEditor != null) { if (!NodeEditorPreferences.GetSettings().portTooltips || graphEditor is null)
string tooltip = graphEditor.GetPortTooltip(hoveredPort); return;
if (string.IsNullOrEmpty(tooltip)) return; string tooltip = null;
GUIContent content = new GUIContent(tooltip); if (hoveredPort != null) {
Vector2 size = NodeEditorResources.styles.tooltip.CalcSize(content); tooltip = graphEditor.GetPortTooltip(hoveredPort);
size.x += 8;
Rect rect = new Rect(Event.current.mousePosition - (size), size);
EditorGUI.LabelField(rect, content, NodeEditorResources.styles.tooltip);
Repaint();
} }
else if (hoveredNode != null && IsHoveringNode && IsHoveringTitle(hoveredNode)) {
tooltip = NodeEditor.GetEditor(hoveredNode, this).GetHeaderTooltip();
}
if (string.IsNullOrEmpty(tooltip)) return;
GUIContent content = new GUIContent(tooltip);
Vector2 size = NodeEditorResources.styles.tooltip.CalcSize(content);
size.x += 8;
Rect rect = new Rect(Event.current.mousePosition - (size), size);
EditorGUI.LabelField(rect, content, NodeEditorResources.styles.tooltip);
Repaint();
} }
} }
} }