mirror of
				https://github.com/godotengine/godot.git
				synced 2025-11-04 07:31:16 +00:00 
			
		
		
		
	[AnimationNodeBlendTreeEditor] Usability improvements
- Add possibility to exclude multiple (selected) nodes. - Add context menu (Right click) to add nodes.
This commit is contained in:
		
							parent
							
								
									f52c294a74
								
							
						
					
					
						commit
						ccbf57611b
					
				
					 2 changed files with 53 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -80,6 +80,7 @@ void AnimationNodeBlendTreeEditor::_update_options_menu() {
 | 
			
		|||
	}
 | 
			
		||||
	add_node->get_popup()->add_separator();
 | 
			
		||||
	add_node->get_popup()->add_item(TTR("Load..."), MENU_LOAD_FILE);
 | 
			
		||||
	use_popup_menu_position = false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Size2 AnimationNodeBlendTreeEditor::get_minimum_size() const {
 | 
			
		||||
| 
						 | 
				
			
			@ -317,7 +318,15 @@ void AnimationNodeBlendTreeEditor::_add_node(int p_idx) {
 | 
			
		|||
		EditorNode::get_singleton()->show_warning(TTR("Output node can't be added to the blend tree."));
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
	Point2 instance_pos = graph->get_scroll_ofs() + graph->get_size() * 0.5;
 | 
			
		||||
 | 
			
		||||
	Point2 instance_pos = graph->get_scroll_ofs();
 | 
			
		||||
	if (use_popup_menu_position) {
 | 
			
		||||
		instance_pos += popup_menu_position;
 | 
			
		||||
	} else {
 | 
			
		||||
		instance_pos += graph->get_size() * 0.5;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	instance_pos /= graph->get_zoom();
 | 
			
		||||
 | 
			
		||||
	int base = 1;
 | 
			
		||||
	String name = base_name;
 | 
			
		||||
| 
						 | 
				
			
			@ -412,6 +421,40 @@ void AnimationNodeBlendTreeEditor::_delete_request(const String &p_which) {
 | 
			
		|||
	undo_redo->commit_action();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void AnimationNodeBlendTreeEditor::_delete_nodes_request() {
 | 
			
		||||
 | 
			
		||||
	List<StringName> to_erase;
 | 
			
		||||
 | 
			
		||||
	for (int i = 0; i < graph->get_child_count(); i++) {
 | 
			
		||||
		GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i));
 | 
			
		||||
		if (gn) {
 | 
			
		||||
			if (gn->is_selected() && gn->is_close_button_visible()) {
 | 
			
		||||
				to_erase.push_back(gn->get_name());
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (to_erase.empty())
 | 
			
		||||
		return;
 | 
			
		||||
 | 
			
		||||
	undo_redo->create_action(TTR("Delete Node(s)"));
 | 
			
		||||
 | 
			
		||||
	for (List<StringName>::Element *F = to_erase.front(); F; F = F->next()) {
 | 
			
		||||
		_delete_request(F->get());
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	undo_redo->commit_action();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void AnimationNodeBlendTreeEditor::_popup_request(const Vector2 &p_position) {
 | 
			
		||||
 | 
			
		||||
	_update_options_menu();
 | 
			
		||||
	use_popup_menu_position = true;
 | 
			
		||||
	popup_menu_position = graph->get_local_mouse_position();
 | 
			
		||||
	add_node->get_popup()->set_position(p_position);
 | 
			
		||||
	add_node->get_popup()->popup();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void AnimationNodeBlendTreeEditor::_node_selected(Object *p_node) {
 | 
			
		||||
 | 
			
		||||
	GraphNode *gn = Object::cast_to<GraphNode>(p_node);
 | 
			
		||||
| 
						 | 
				
			
			@ -730,6 +773,8 @@ void AnimationNodeBlendTreeEditor::_bind_methods() {
 | 
			
		|||
	ClassDB::bind_method("_open_in_editor", &AnimationNodeBlendTreeEditor::_open_in_editor);
 | 
			
		||||
	ClassDB::bind_method("_scroll_changed", &AnimationNodeBlendTreeEditor::_scroll_changed);
 | 
			
		||||
	ClassDB::bind_method("_delete_request", &AnimationNodeBlendTreeEditor::_delete_request);
 | 
			
		||||
	ClassDB::bind_method("_delete_nodes_request", &AnimationNodeBlendTreeEditor::_delete_nodes_request);
 | 
			
		||||
	ClassDB::bind_method("_popup_request", &AnimationNodeBlendTreeEditor::_popup_request);
 | 
			
		||||
	ClassDB::bind_method("_edit_filters", &AnimationNodeBlendTreeEditor::_edit_filters);
 | 
			
		||||
	ClassDB::bind_method("_update_filters", &AnimationNodeBlendTreeEditor::_update_filters);
 | 
			
		||||
	ClassDB::bind_method("_filter_edited", &AnimationNodeBlendTreeEditor::_filter_edited);
 | 
			
		||||
| 
						 | 
				
			
			@ -850,6 +895,7 @@ AnimationNodeBlendTreeEditor::AnimationNodeBlendTreeEditor() {
 | 
			
		|||
 | 
			
		||||
	singleton = this;
 | 
			
		||||
	updating = false;
 | 
			
		||||
	use_popup_menu_position = false;
 | 
			
		||||
 | 
			
		||||
	graph = memnew(GraphEdit);
 | 
			
		||||
	add_child(graph);
 | 
			
		||||
| 
						 | 
				
			
			@ -860,6 +906,8 @@ AnimationNodeBlendTreeEditor::AnimationNodeBlendTreeEditor() {
 | 
			
		|||
	graph->connect("disconnection_request", this, "_disconnection_request", varray(), CONNECT_DEFERRED);
 | 
			
		||||
	graph->connect("node_selected", this, "_node_selected");
 | 
			
		||||
	graph->connect("scroll_offset_changed", this, "_scroll_changed");
 | 
			
		||||
	graph->connect("delete_nodes_request", this, "_delete_nodes_request");
 | 
			
		||||
	graph->connect("popup_request", this, "_popup_request");
 | 
			
		||||
 | 
			
		||||
	VSeparator *vs = memnew(VSeparator);
 | 
			
		||||
	graph->get_zoom_hbox()->add_child(vs);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue