Skip to content

Commit

Permalink
- Fixed StackOverflow errors for GroupCommentNodes when they are stac…
Browse files Browse the repository at this point in the history
…ked into each other [#20](#20)

- Fixed wrong positioning of Nodes that are part of a GroupCommentNode [#21](#21)
- Nodes are now only included in a GroupCommentNode if they are fully contained and not just overlapping [#22](#22)
  • Loading branch information
Doppelkeks committed May 8, 2023
1 parent e3a148c commit d2079fa
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 22 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [0.3.6] - 2023-04-28
### Fixed
- Fixed issue with undoing changes
- Fixed port list connections not regenerating when adding a new item
- Fixed port list connections not regenerating when adding a new item

## [0.3.7] - 2023-05-08
### Fixed
- Fixed StackOverflow errors for GroupCommentNodes when they are stacked into each other [#20](https://github.com/Gentlymad-Studios/NewGraph/issues/20)
- Fixed wrong positioning of Nodes that are part of a GroupCommentNode [#21](https://github.com/Gentlymad-Studios/NewGraph/issues/21)
### Added
- Nodes are now only included in a GroupCommentNode if they are fully contained and not just overlapping [#22](https://github.com/Gentlymad-Studios/NewGraph/issues/22)
68 changes: 48 additions & 20 deletions Editor/Views/Nodes/GroupCommentNode.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using GraphViewBase;
using GraphViewBase;
using System.Collections.Generic;
using UnityEditor;
using UnityEditor.UIElements;
Expand Down Expand Up @@ -35,11 +35,12 @@ public class GroupCommentNode : INode, IUtilityNode {
private Vector2 nodeStartPosition;
private Vector2 nodeMoveDelta;
private List<NodeView> containedNodes = new List<NodeView>();
private Vector2 testPoint = new Vector2();

/// <summary>
/// Create some nice vector based dragCaret graphics
/// </summary>
private static VectorImage dragCaretGraphics = null;
/// <summary>
/// Create some nice vector based dragCaret graphics
/// </summary>
private static VectorImage dragCaretGraphics = null;
private static VectorImage DragCaretGraphics {
get {
if (dragCaretGraphics == null) {
Expand Down Expand Up @@ -95,26 +96,51 @@ private void OnColorChanged(SerializedPropertyChangeEvent evt) {
container.style.backgroundColor = evt.changedProperty.colorValue;
}

/// <summary>
/// If a left click was initiated we start listening on position changes and capture all nodes,
/// that should be moved as being part of our group node.
/// </summary>
/// <param name="evt"></param>
private void OnNodeViewMouseDown(MouseDownEvent evt) {
private bool IsPointContained(float x, float y) {
testPoint.Set(x, y);
if (!nodeView.worldBound.Contains(testPoint)) {
return false;
}
return true;
}

/// <summary>
/// If a left click was initiated we start listening on position changes and capture all nodes,
/// that should be moved as being part of our group node.
/// </summary>
/// <param name="evt"></param>
private void OnNodeViewMouseDown(MouseDownEvent evt) {
// make sure we have a left click
if (evt.button == 0) {
// clear all previously captured nodes
if (containedNodes == null) {
containedNodes = new List<NodeView>();
}
containedNodes.Clear();
// go overy all nodes and check which nodes are contained
// this is costly, so we do it only once when the movement process starts
nodeController.ForEachNode((node) => {
// check via worldbound rect if node is contained in our group
if (node != nodeView && node != null && nodeView.worldBound.Overlaps(node.worldBound)) {
containedNodes.Add(node as NodeView);
}
// go overy all nodes and check which nodes are contained
// this is costly, so we do it only once when the movement process starts

nodeController.ForEachNode((node) => {
// check via worldbound rect if node is contained in our group
if (node != nodeView && node != null) {
NodeView nodeView = node as NodeView;

if (!nodeView.controller.nodeItem.isUtilityNode && !(nodeView.controller.nodeItem.nodeData is GroupCommentNode)) {

if (!IsPointContained(node.worldBound.xMin, node.worldBound.yMin)) {
return;
} else if (!IsPointContained(node.worldBound.xMax, node.worldBound.yMin)) {
return;
} else if (!IsPointContained(node.worldBound.xMin, node.worldBound.yMax)) {
return;
} else if (!IsPointContained(node.worldBound.xMax, node.worldBound.yMax)) {
return;
}

containedNodes.Add(nodeView);
}
}

});
// capture the initial start position
nodeStartPosition = nodeView.GetPosition();
Expand All @@ -134,8 +160,10 @@ private void OnPositionChange(PositionData obj) {

// set the position of all nodes that are contained
foreach (NodeView nodeView in containedNodes) {
Vector2 nodePos = nodeView.GetPosition();
nodeView.SetPosition(new(nodePos.x+nodeMoveDelta.x, nodePos.y+nodeMoveDelta.y));
if (!nodeView.Selected) {
Vector2 nodePos = nodeView.GetPosition();
nodeView.SetPosition(new(nodePos.x + nodeMoveDelta.x, nodePos.y + nodeMoveDelta.y));
}
}
// reset move delta immediatly, since we don't want to keep track of the start position ov every node.
nodeStartPosition = nodeView.GetPosition();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.gentlymad.newgraph",
"version": "0.3.6",
"version": "0.3.7",
"displayName": "NewGraph",
"description": "A general data oriented node graph solution. This is build upon the idea to visualize complex data structures as graph networks without having to modify already established data classes, except adding [Node], [Port] and [SerializeReference] attributes to call classes that should show in the Graph View.",
"unity": "2022.2",
Expand Down

0 comments on commit d2079fa

Please sign in to comment.