1
0
mirror of https://github.com/Siccity/xNode.git synced 2025-12-20 01:06:01 +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. (#262)

The fix detects if there isn't a port when swapping rects.
This commit is contained in:
fdtdev 2020-05-09 13:21:35 +02:00 committed by GitHub
parent 4c6d22a152
commit 8046e6e0bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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