1
0
mirror of https://github.com/Siccity/xNode.git synced 2026-03-26 22:49:02 +08:00

[FIX] fix a problem when a complex class with optional port drawing is used with NodeEditorGUILayout.DynamicPortList. By having an item that wasn't drawing the port, the method was throwing a KeyNotFoundException when reordering.

The fix detects if there isn't a port when swapping rects.
This commit is contained in:
FDT 2020-05-09 12:51:56 +02:00
parent 4c6d22a152
commit 25f1f13bb5

View File

@ -371,7 +371,10 @@ namespace XNodeEditor {
}; };
list.onReorderCallback = list.onReorderCallback =
(ReorderableList rl) => { (ReorderableList rl) => {
bool hasRect = false;
bool hasNewRect = false;
Rect rect = Rect.zero;
Rect newRect = Rect.zero;
// Move up // Move up
if (rl.index > reorderableListIndex) { if (rl.index > reorderableListIndex) {
for (int i = reorderableListIndex; i < rl.index; ++i) { for (int i = reorderableListIndex; i < rl.index; ++i) {
@ -380,9 +383,10 @@ namespace XNodeEditor {
port.SwapConnections(nextPort); port.SwapConnections(nextPort);
// Swap cached positions to mitigate twitching // Swap cached positions to mitigate twitching
Rect rect = NodeEditorWindow.current.portConnectionPoints[port]; hasRect = NodeEditorWindow.current.portConnectionPoints.TryGetValue(port, out rect);
NodeEditorWindow.current.portConnectionPoints[port] = NodeEditorWindow.current.portConnectionPoints[nextPort]; hasNewRect = NodeEditorWindow.current.portConnectionPoints.TryGetValue(nextPort, out newRect);
NodeEditorWindow.current.portConnectionPoints[nextPort] = rect; NodeEditorWindow.current.portConnectionPoints[port] = hasNewRect?newRect:rect;
NodeEditorWindow.current.portConnectionPoints[nextPort] = hasRect?rect:newRect;
} }
} }
// Move down // Move down
@ -393,9 +397,10 @@ namespace XNodeEditor {
port.SwapConnections(nextPort); port.SwapConnections(nextPort);
// Swap cached positions to mitigate twitching // Swap cached positions to mitigate twitching
Rect rect = NodeEditorWindow.current.portConnectionPoints[port]; hasRect = NodeEditorWindow.current.portConnectionPoints.TryGetValue(port, out rect);
NodeEditorWindow.current.portConnectionPoints[port] = NodeEditorWindow.current.portConnectionPoints[nextPort]; hasNewRect = NodeEditorWindow.current.portConnectionPoints.TryGetValue(nextPort, out newRect);
NodeEditorWindow.current.portConnectionPoints[nextPort] = rect; NodeEditorWindow.current.portConnectionPoints[port] = hasNewRect?newRect:rect;
NodeEditorWindow.current.portConnectionPoints[nextPort] = hasRect?rect:newRect;
} }
} }
// Apply changes // Apply changes