Merge pull request #27793 from guilhermefelipecgs/ux_animation_tree
[AnimationNodeBlendTreeEditor] Usability improvements
This commit is contained in:
commit
5a64c679cf
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_separator();
|
||||||
add_node->get_popup()->add_item(TTR("Load..."), MENU_LOAD_FILE);
|
add_node->get_popup()->add_item(TTR("Load..."), MENU_LOAD_FILE);
|
||||||
|
use_popup_menu_position = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Size2 AnimationNodeBlendTreeEditor::get_minimum_size() const {
|
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."));
|
EditorNode::get_singleton()->show_warning(TTR("Output node can't be added to the blend tree."));
|
||||||
return;
|
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;
|
int base = 1;
|
||||||
String name = base_name;
|
String name = base_name;
|
||||||
|
@ -412,6 +421,40 @@ void AnimationNodeBlendTreeEditor::_delete_request(const String &p_which) {
|
||||||
undo_redo->commit_action();
|
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) {
|
void AnimationNodeBlendTreeEditor::_node_selected(Object *p_node) {
|
||||||
|
|
||||||
GraphNode *gn = Object::cast_to<GraphNode>(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("_open_in_editor", &AnimationNodeBlendTreeEditor::_open_in_editor);
|
||||||
ClassDB::bind_method("_scroll_changed", &AnimationNodeBlendTreeEditor::_scroll_changed);
|
ClassDB::bind_method("_scroll_changed", &AnimationNodeBlendTreeEditor::_scroll_changed);
|
||||||
ClassDB::bind_method("_delete_request", &AnimationNodeBlendTreeEditor::_delete_request);
|
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("_edit_filters", &AnimationNodeBlendTreeEditor::_edit_filters);
|
||||||
ClassDB::bind_method("_update_filters", &AnimationNodeBlendTreeEditor::_update_filters);
|
ClassDB::bind_method("_update_filters", &AnimationNodeBlendTreeEditor::_update_filters);
|
||||||
ClassDB::bind_method("_filter_edited", &AnimationNodeBlendTreeEditor::_filter_edited);
|
ClassDB::bind_method("_filter_edited", &AnimationNodeBlendTreeEditor::_filter_edited);
|
||||||
|
@ -850,6 +895,7 @@ AnimationNodeBlendTreeEditor::AnimationNodeBlendTreeEditor() {
|
||||||
|
|
||||||
singleton = this;
|
singleton = this;
|
||||||
updating = false;
|
updating = false;
|
||||||
|
use_popup_menu_position = false;
|
||||||
|
|
||||||
graph = memnew(GraphEdit);
|
graph = memnew(GraphEdit);
|
||||||
add_child(graph);
|
add_child(graph);
|
||||||
|
@ -860,6 +906,8 @@ AnimationNodeBlendTreeEditor::AnimationNodeBlendTreeEditor() {
|
||||||
graph->connect("disconnection_request", this, "_disconnection_request", varray(), CONNECT_DEFERRED);
|
graph->connect("disconnection_request", this, "_disconnection_request", varray(), CONNECT_DEFERRED);
|
||||||
graph->connect("node_selected", this, "_node_selected");
|
graph->connect("node_selected", this, "_node_selected");
|
||||||
graph->connect("scroll_offset_changed", this, "_scroll_changed");
|
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);
|
VSeparator *vs = memnew(VSeparator);
|
||||||
graph->get_zoom_hbox()->add_child(vs);
|
graph->get_zoom_hbox()->add_child(vs);
|
||||||
|
|
|
@ -51,6 +51,8 @@ class AnimationNodeBlendTreeEditor : public AnimationTreeNodeEditorPlugin {
|
||||||
Ref<AnimationNodeBlendTree> blend_tree;
|
Ref<AnimationNodeBlendTree> blend_tree;
|
||||||
GraphEdit *graph;
|
GraphEdit *graph;
|
||||||
MenuButton *add_node;
|
MenuButton *add_node;
|
||||||
|
Vector2 popup_menu_position;
|
||||||
|
bool use_popup_menu_position;
|
||||||
|
|
||||||
PanelContainer *error_panel;
|
PanelContainer *error_panel;
|
||||||
Label *error_label;
|
Label *error_label;
|
||||||
|
@ -97,6 +99,8 @@ class AnimationNodeBlendTreeEditor : public AnimationTreeNodeEditorPlugin {
|
||||||
void _open_in_editor(const String &p_which);
|
void _open_in_editor(const String &p_which);
|
||||||
void _anim_selected(int p_index, Array p_options, const String &p_node);
|
void _anim_selected(int p_index, Array p_options, const String &p_node);
|
||||||
void _delete_request(const String &p_which);
|
void _delete_request(const String &p_which);
|
||||||
|
void _delete_nodes_request();
|
||||||
|
void _popup_request(const Vector2 &p_position);
|
||||||
|
|
||||||
bool _update_filters(const Ref<AnimationNode> &anode);
|
bool _update_filters(const Ref<AnimationNode> &anode);
|
||||||
void _edit_filters(const String &p_which);
|
void _edit_filters(const String &p_which);
|
||||||
|
|
Loading…
Reference in a new issue