From 106e0e5c3afdf669e0a92a69172714097500271e Mon Sep 17 00:00:00 2001 From: Chris Cranford Date: Thu, 15 Aug 2024 12:07:54 -0400 Subject: [PATCH] GH-738 Fix `Select Group` to include Knots and Nodes --- src/editor/graph/graph_edit.cpp | 17 +++++++++++++++++ src/editor/graph/graph_edit.h | 6 ++++++ src/editor/graph/graph_node.cpp | 6 +++--- src/editor/graph/graph_node.h | 4 ++-- src/editor/graph/nodes/graph_node_comment.cpp | 16 ++++++++-------- 5 files changed, 36 insertions(+), 13 deletions(-) diff --git a/src/editor/graph/graph_edit.cpp b/src/editor/graph/graph_edit.cpp index 2e9baa68..3bc848ec 100644 --- a/src/editor/graph/graph_edit.cpp +++ b/src/editor/graph/graph_edit.cpp @@ -372,6 +372,23 @@ void OrchestratorGraphEdit::for_each_graph_node(std::function& p_func, bool p_nodes, bool p_knots) +{ + const int child_count = get_child_count(); + for (int index = 0; index < child_count; index++) + { + GraphElement* element = Object::cast_to(get_child(index)); + if (!element) + continue; + + const OrchestratorGraphNode* node = Object::cast_to(element); + const OrchestratorGraphKnot* knot = Object::cast_to(element); + + if ((p_nodes && node) || (p_knots && knot)) + p_func(element); + } +} + void OrchestratorGraphEdit::execute_action(const String& p_action_name) { Ref action = memnew(InputEventAction); diff --git a/src/editor/graph/graph_edit.h b/src/editor/graph/graph_edit.h index c9ff3e22..22ff97db 100644 --- a/src/editor/graph/graph_edit.h +++ b/src/editor/graph/graph_edit.h @@ -209,6 +209,12 @@ class OrchestratorGraphEdit : public GraphEdit /// @param p_func the lambda to be applied void for_each_graph_node(std::function p_func); + /// Perform an action for each GraphNode object type + /// @param p_func the function to call for each graph element + /// @param p_nodes whether OrchestratorGraphNode objects are included, defaults to true + /// @param p_knots whether OrchestratorGraphKnot objects are included, defaults to true + void for_each_graph_element(const std::function& p_func, bool p_nodes = true, bool p_knots = true); + /// Execute the specified action /// @param p_action_name the action to execute void execute_action(const String& p_action_name); diff --git a/src/editor/graph/graph_node.cpp b/src/editor/graph/graph_node.cpp index 22767517..4d5670e9 100644 --- a/src/editor/graph/graph_node.cpp +++ b/src/editor/graph/graph_node.cpp @@ -618,12 +618,12 @@ void OrchestratorGraphNode::_add_option_pin() function_call_node->add_dynamic_pin(); } -List OrchestratorGraphNode::get_nodes_within_global_rect() +List OrchestratorGraphNode::get_elements_within_global_rect() { Rect2 rect = get_global_rect(); - List results; - _graph->for_each_graph_node([&](OrchestratorGraphNode* other) { + List results; + _graph->for_each_graph_element([&](GraphElement* other) { if (other && other != this) { Rect2 other_rect = other->get_global_rect(); diff --git a/src/editor/graph/graph_node.h b/src/editor/graph/graph_node.h index b7a13330..66069044 100644 --- a/src/editor/graph/graph_node.h +++ b/src/editor/graph/graph_node.h @@ -159,8 +159,8 @@ class OrchestratorGraphNode : public GraphNode /// Set whether node icons are shown virtual void show_icons(bool p_show_icons) { } - /// Get a list of nodes within this node's global rect. - List get_nodes_within_global_rect(); + /// Get a list of elements within this node's global rect. + List get_elements_within_global_rect(); /// Get the specified point index at the given position and direction /// @param p_position the position diff --git a/src/editor/graph/nodes/graph_node_comment.cpp b/src/editor/graph/nodes/graph_node_comment.cpp index 1d63d182..f36f184e 100644 --- a/src/editor/graph/nodes/graph_node_comment.cpp +++ b/src/editor/graph/nodes/graph_node_comment.cpp @@ -121,8 +121,8 @@ void OrchestratorGraphNodeComment::_on_raise_request() bool OrchestratorGraphNodeComment::is_group_selected() { - List intersections = get_nodes_within_global_rect(); - for (OrchestratorGraphNode* child : intersections) + List intersections = get_elements_within_global_rect(); + for (GraphElement* child : intersections) if (!child->is_selected()) return false; return true; @@ -131,16 +131,16 @@ bool OrchestratorGraphNodeComment::is_group_selected() void OrchestratorGraphNodeComment::select_group() { // Select all child nodes - List intersections = get_nodes_within_global_rect(); - for (OrchestratorGraphNode* child : intersections) + List intersections = get_elements_within_global_rect(); + for (GraphElement* child : intersections) child->set_selected(true); } void OrchestratorGraphNodeComment::deselect_group() { // Deselects all child nodes - List intersections = get_nodes_within_global_rect(); - for (OrchestratorGraphNode* child : intersections) + List intersections = get_elements_within_global_rect(); + for (GraphElement* child : intersections) child->set_selected(false); } @@ -148,7 +148,7 @@ void OrchestratorGraphNodeComment::raise_request_node_reorder() { // This guarantees that any node that intersects with a comment node will be repositioned // in the scene after the comment, so that the rendering order appears correct. - List intersections = get_nodes_within_global_rect(); - for (OrchestratorGraphNode* node : intersections) + List intersections = get_elements_within_global_rect(); + for (GraphElement* node : intersections) get_parent()->move_child(node, -1); } \ No newline at end of file