mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 17:26:02 +08:00
Add Disconnect(Node) Menu And Node Header Tooltip (#288)
This commit is contained in:
parent
60a8e89cdb
commit
85341bf4cc
@ -104,6 +104,11 @@ namespace XNodeEditor {
|
||||
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>
|
||||
public virtual void AddContextMenuItems(GenericMenu menu) {
|
||||
bool canRemove = true;
|
||||
|
||||
@ -112,6 +112,11 @@ namespace XNodeEditor {
|
||||
/// <summary> Show right-click context menu for hovered port </summary>
|
||||
void ShowPortContextMenu(XNode.NodePort hoveredPort) {
|
||||
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.DropDown(new Rect(Event.current.mousePosition, Vector2.zero));
|
||||
if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
|
||||
@ -551,16 +556,22 @@ namespace XNodeEditor {
|
||||
}
|
||||
|
||||
private void DrawTooltip() {
|
||||
if (hoveredPort != null && NodeEditorPreferences.GetSettings().portTooltips && graphEditor != null) {
|
||||
string tooltip = graphEditor.GetPortTooltip(hoveredPort);
|
||||
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();
|
||||
if (!NodeEditorPreferences.GetSettings().portTooltips || graphEditor is null)
|
||||
return;
|
||||
string tooltip = null;
|
||||
if (hoveredPort != null) {
|
||||
tooltip = graphEditor.GetPortTooltip(hoveredPort);
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user