Skip to content

Commit 63fa4fc

Browse files
committed
Merge pull request godotengine#110131 from vaner-org/animationtree-better-deselection
Improve deselection in AnimationTree editors and inspector
2 parents 4e03f41 + f6a6aad commit 63fa4fc

File tree

5 files changed

+77
-0
lines changed

5 files changed

+77
-0
lines changed

editor/animation/animation_blend_space_1d_editor.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ void AnimationNodeBlendSpace1DEditor::_blend_space_gui_input(const Ref<InputEven
149149
return;
150150
}
151151
}
152+
153+
// If no point was selected, select host BlendSpace1D node.
154+
if (selected_point == -1) {
155+
EditorNode::get_singleton()->push_item(blend_space.ptr(), "", true);
156+
}
152157
}
153158

154159
if (mb.is_valid() && !mb->is_pressed() && dragging_selected_attempt && mb->get_button_index() == MouseButton::LEFT) {
@@ -535,7 +540,11 @@ void AnimationNodeBlendSpace1DEditor::_erase_selected() {
535540
undo_redo->add_undo_method(this, "_update_space");
536541
undo_redo->commit_action();
537542

543+
// Return selection to host BlendSpace1D node.
544+
EditorNode::get_singleton()->push_item(blend_space.ptr(), "", true);
545+
538546
updating = false;
547+
_update_tool_erase();
539548

540549
blend_space_draw->queue_redraw();
541550
}

editor/animation/animation_blend_space_2d_editor.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_gui_input(const Ref<InputEven
209209
}
210210
}
211211
}
212+
213+
// If no point or triangle was selected, select host BlendSpace2D node.
214+
if (selected_point == -1 && selected_triangle == -1) {
215+
EditorNode::get_singleton()->push_item(blend_space.ptr(), "", true);
216+
}
212217
}
213218

214219
if (mb.is_valid() && mb->is_pressed() && tool_triangle->is_pressed() && mb->get_button_index() == MouseButton::LEFT) {
@@ -733,7 +738,12 @@ void AnimationNodeBlendSpace2DEditor::_erase_selected() {
733738
undo_redo->add_do_method(this, "_update_space");
734739
undo_redo->add_undo_method(this, "_update_space");
735740
undo_redo->commit_action();
741+
742+
// Return selection to host BlendSpace2D node.
743+
EditorNode::get_singleton()->push_item(blend_space.ptr(), "", true);
744+
736745
updating = false;
746+
_update_tool_erase();
737747

738748
blend_space_draw->queue_redraw();
739749
} else if (selected_triangle != -1) {
@@ -745,7 +755,11 @@ void AnimationNodeBlendSpace2DEditor::_erase_selected() {
745755
undo_redo->add_do_method(this, "_update_space");
746756
undo_redo->add_undo_method(this, "_update_space");
747757
undo_redo->commit_action();
758+
759+
selected_triangle = -1;
760+
748761
updating = false;
762+
_update_tool_erase();
749763

750764
blend_space_draw->queue_redraw();
751765
}

editor/animation/animation_blend_tree_editor_plugin.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,15 @@ void AnimationNodeBlendTreeEditor::update_graph() {
127127

128128
visible_properties.clear();
129129

130+
// Store selected nodes before clearing the graph.
131+
List<StringName> selected_nodes;
132+
for (int i = 0; i < graph->get_child_count(); i++) {
133+
GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i));
134+
if (gn && gn->is_selected()) {
135+
selected_nodes.push_back(gn->get_name());
136+
}
137+
}
138+
130139
graph->set_scroll_offset(blend_tree->get_graph_offset() * EDSCALE);
131140

132141
graph->clear_connections();
@@ -304,6 +313,17 @@ void AnimationNodeBlendTreeEditor::update_graph() {
304313
graph->set_minimap_opacity(graph_minimap_opacity);
305314
float graph_lines_curvature = EDITOR_GET("editors/visual_editors/lines_curvature");
306315
graph->set_connection_lines_curvature(graph_lines_curvature);
316+
317+
// Restore selected nodes after graph reconstruction.
318+
for (const StringName &name : selected_nodes) {
319+
for (int i = 0; i < graph->get_child_count(); i++) {
320+
GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i));
321+
if (gn && gn->get_name() == name) {
322+
gn->set_selected(true);
323+
break;
324+
}
325+
}
326+
}
307327
}
308328

309329
void AnimationNodeBlendTreeEditor::_file_opened(const String &p_file) {
@@ -539,6 +559,9 @@ void AnimationNodeBlendTreeEditor::_delete_node_request(const String &p_which) {
539559
undo_redo->add_do_method(this, "update_graph");
540560
undo_redo->add_undo_method(this, "update_graph");
541561
undo_redo->commit_action();
562+
563+
// Return selection to host BlendTree node.
564+
EditorNode::get_singleton()->push_item(blend_tree.ptr(), "", true);
542565
}
543566

544567
void AnimationNodeBlendTreeEditor::_delete_nodes_request(const TypedArray<StringName> &p_nodes) {
@@ -597,6 +620,22 @@ void AnimationNodeBlendTreeEditor::_node_selected(Object *p_node) {
597620
EditorNode::get_singleton()->push_item(anode.ptr(), "", true);
598621
}
599622

623+
void AnimationNodeBlendTreeEditor::_node_deselected(Object *p_node) {
624+
// Check if no nodes are selected, return selection to host BlendTree node.
625+
bool any_selected = false;
626+
for (int i = 0; i < graph->get_child_count(); i++) {
627+
GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i));
628+
if (gn && gn->is_selected()) {
629+
any_selected = true;
630+
break;
631+
}
632+
}
633+
634+
if (!any_selected) {
635+
EditorNode::get_singleton()->push_item(blend_tree.ptr(), "", true);
636+
}
637+
}
638+
600639
void AnimationNodeBlendTreeEditor::_open_in_editor(const String &p_which) {
601640
Ref<AnimationNode> an = blend_tree->get_node(p_which);
602641
ERR_FAIL_COND(an.is_null());
@@ -1188,6 +1227,7 @@ AnimationNodeBlendTreeEditor::AnimationNodeBlendTreeEditor() {
11881227
graph->connect("connection_request", callable_mp(this, &AnimationNodeBlendTreeEditor::_connection_request), CONNECT_DEFERRED);
11891228
graph->connect("disconnection_request", callable_mp(this, &AnimationNodeBlendTreeEditor::_disconnection_request), CONNECT_DEFERRED);
11901229
graph->connect("node_selected", callable_mp(this, &AnimationNodeBlendTreeEditor::_node_selected));
1230+
graph->connect("node_deselected", callable_mp(this, &AnimationNodeBlendTreeEditor::_node_deselected));
11911231
graph->connect("scroll_offset_changed", callable_mp(this, &AnimationNodeBlendTreeEditor::_scroll_changed));
11921232
graph->connect("delete_nodes_request", callable_mp(this, &AnimationNodeBlendTreeEditor::_delete_nodes_request));
11931233
graph->connect("popup_request", callable_mp(this, &AnimationNodeBlendTreeEditor::_popup_request));

editor/animation/animation_blend_tree_editor_plugin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ class AnimationNodeBlendTreeEditor : public AnimationTreeNodeEditorPlugin {
111111

112112
void _scroll_changed(const Vector2 &p_scroll);
113113
void _node_selected(Object *p_node);
114+
void _node_deselected(Object *p_node);
114115
void _open_in_editor(const String &p_which);
115116
void _anim_selected(int p_index, const Array &p_options, const String &p_node);
116117
void _delete_node_request(const String &p_which);

editor/animation/animation_state_machine_editor.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,11 @@ void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Ref<InputEv
285285
}
286286
}
287287

288+
// If no state or transition was selected, select host StateMachine node.
289+
if (selected_node.is_empty() && selected_transition_index == -1) {
290+
EditorNode::get_singleton()->push_item(state_machine.ptr(), "", true);
291+
}
292+
288293
state_machine_draw->queue_redraw();
289294
_update_mode();
290295
}
@@ -1649,6 +1654,10 @@ void AnimationNodeStateMachineEditor::_erase_selected(const bool p_nested_action
16491654

16501655
connected_nodes.clear();
16511656
selected_nodes.clear();
1657+
selected_node = StringName();
1658+
1659+
// Return selection to host StateMachine node.
1660+
EditorNode::get_singleton()->push_item(state_machine.ptr(), "", true);
16521661
}
16531662

16541663
if (selected_transition_to != StringName() && selected_transition_from != StringName() && state_machine->has_transition(selected_transition_from, selected_transition_to)) {
@@ -1669,8 +1678,12 @@ void AnimationNodeStateMachineEditor::_erase_selected(const bool p_nested_action
16691678
selected_transition_from = StringName();
16701679
selected_transition_to = StringName();
16711680
selected_transition_index = -1;
1681+
1682+
// Return selection to host StateMachine node.
1683+
EditorNode::get_singleton()->push_item(state_machine.ptr(), "", true);
16721684
}
16731685

1686+
_update_mode();
16741687
state_machine_draw->queue_redraw();
16751688
}
16761689

0 commit comments

Comments
 (0)