summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2019-04-08 09:38:36 +0200
committerGitHub <noreply@github.com>2019-04-08 09:38:36 +0200
commit5a64c679cfc5463afd4a703b1c6e437d894b22b1 (patch)
tree35d77c148e11b289dc3c4d2d7912fde4fe6d791d /editor
parent3a0ab0376e4a38566eb692b5d19ca3e2544a6861 (diff)
parentccbf57611b85a5295b37a3fed6b602ef23f96b7a (diff)
Merge pull request #27793 from guilhermefelipecgs/ux_animation_tree
[AnimationNodeBlendTreeEditor] Usability improvements
Diffstat (limited to 'editor')
-rw-r--r--editor/plugins/animation_blend_tree_editor_plugin.cpp50
-rw-r--r--editor/plugins/animation_blend_tree_editor_plugin.h4
2 files changed, 53 insertions, 1 deletions
diff --git a/editor/plugins/animation_blend_tree_editor_plugin.cpp b/editor/plugins/animation_blend_tree_editor_plugin.cpp
index c5dfba6b06..f13c2170ea 100644
--- a/editor/plugins/animation_blend_tree_editor_plugin.cpp
+++ b/editor/plugins/animation_blend_tree_editor_plugin.cpp
@@ -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);
diff --git a/editor/plugins/animation_blend_tree_editor_plugin.h b/editor/plugins/animation_blend_tree_editor_plugin.h
index f2a77cecb4..cb40159a40 100644
--- a/editor/plugins/animation_blend_tree_editor_plugin.h
+++ b/editor/plugins/animation_blend_tree_editor_plugin.h
@@ -51,6 +51,8 @@ class AnimationNodeBlendTreeEditor : public AnimationTreeNodeEditorPlugin {
Ref<AnimationNodeBlendTree> blend_tree;
GraphEdit *graph;
MenuButton *add_node;
+ Vector2 popup_menu_position;
+ bool use_popup_menu_position;
PanelContainer *error_panel;
Label *error_label;
@@ -97,6 +99,8 @@ class AnimationNodeBlendTreeEditor : public AnimationTreeNodeEditorPlugin {
void _open_in_editor(const String &p_which);
void _anim_selected(int p_index, Array p_options, const String &p_node);
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);
void _edit_filters(const String &p_which);