2018-08-29 22:38:13 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* animation_blend_tree_editor_plugin.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/*************************************************************************/
|
2020-01-01 11:16:22 +01:00
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
2018-08-29 22:38:13 +02:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2018-06-19 03:10:48 +02:00
|
|
|
#include "animation_blend_tree_editor_plugin.h"
|
|
|
|
|
2020-04-28 15:19:37 +02:00
|
|
|
#include "core/input/input.h"
|
2018-06-19 03:10:48 +02:00
|
|
|
#include "core/io/resource_loader.h"
|
2018-09-11 18:13:45 +02:00
|
|
|
#include "core/os/keyboard.h"
|
2018-06-19 03:10:48 +02:00
|
|
|
#include "core/project_settings.h"
|
2018-08-20 18:38:18 +02:00
|
|
|
#include "editor/editor_inspector.h"
|
2019-12-24 08:17:23 +01:00
|
|
|
#include "editor/editor_scale.h"
|
2018-06-19 03:10:48 +02:00
|
|
|
#include "scene/animation/animation_player.h"
|
|
|
|
#include "scene/gui/menu_button.h"
|
|
|
|
#include "scene/gui/panel.h"
|
2019-12-24 08:17:23 +01:00
|
|
|
#include "scene/gui/progress_bar.h"
|
2020-03-04 02:51:12 +01:00
|
|
|
#include "scene/main/window.h"
|
2018-06-19 03:10:48 +02:00
|
|
|
|
|
|
|
void AnimationNodeBlendTreeEditor::add_custom_type(const String &p_name, const Ref<Script> &p_script) {
|
|
|
|
for (int i = 0; i < add_options.size(); i++) {
|
|
|
|
ERR_FAIL_COND(add_options[i].script == p_script);
|
|
|
|
}
|
|
|
|
|
|
|
|
AddOption ao;
|
|
|
|
ao.name = p_name;
|
|
|
|
ao.script = p_script;
|
|
|
|
add_options.push_back(ao);
|
|
|
|
|
|
|
|
_update_options_menu();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationNodeBlendTreeEditor::remove_custom_type(const Ref<Script> &p_script) {
|
|
|
|
for (int i = 0; i < add_options.size(); i++) {
|
|
|
|
if (add_options[i].script == p_script) {
|
|
|
|
add_options.remove(i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_update_options_menu();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationNodeBlendTreeEditor::_update_options_menu() {
|
|
|
|
add_node->get_popup()->clear();
|
|
|
|
for (int i = 0; i < add_options.size(); i++) {
|
2018-08-20 18:38:18 +02:00
|
|
|
add_node->get_popup()->add_item(add_options[i].name, i);
|
2018-06-19 03:10:48 +02:00
|
|
|
}
|
2018-08-20 18:38:18 +02:00
|
|
|
|
|
|
|
Ref<AnimationNode> clipb = EditorSettings::get_singleton()->get_resource_clipboard();
|
|
|
|
if (clipb.is_valid()) {
|
|
|
|
add_node->get_popup()->add_separator();
|
|
|
|
add_node->get_popup()->add_item(TTR("Paste"), MENU_PASTE);
|
|
|
|
}
|
|
|
|
add_node->get_popup()->add_separator();
|
2019-01-07 16:57:52 +01:00
|
|
|
add_node->get_popup()->add_item(TTR("Load..."), MENU_LOAD_FILE);
|
2019-04-08 04:11:53 +02:00
|
|
|
use_popup_menu_position = false;
|
2018-06-19 03:10:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Size2 AnimationNodeBlendTreeEditor::get_minimum_size() const {
|
|
|
|
return Size2(10, 200);
|
|
|
|
}
|
|
|
|
|
2019-01-18 17:01:24 +01:00
|
|
|
void AnimationNodeBlendTreeEditor::_property_changed(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing) {
|
2018-08-20 18:38:18 +02:00
|
|
|
AnimationTree *tree = AnimationTreeEditor::get_singleton()->get_tree();
|
|
|
|
updating = true;
|
2019-02-21 20:41:01 +01:00
|
|
|
undo_redo->create_action(TTR("Parameter Changed") + ": " + String(p_property), UndoRedo::MERGE_ENDS);
|
2018-08-20 18:38:18 +02:00
|
|
|
undo_redo->add_do_property(tree, p_property, p_value);
|
|
|
|
undo_redo->add_undo_property(tree, p_property, tree->get(p_property));
|
|
|
|
undo_redo->add_do_method(this, "_update_graph");
|
|
|
|
undo_redo->add_undo_method(this, "_update_graph");
|
|
|
|
undo_redo->commit_action();
|
|
|
|
updating = false;
|
|
|
|
}
|
|
|
|
|
2018-06-19 03:10:48 +02:00
|
|
|
void AnimationNodeBlendTreeEditor::_update_graph() {
|
|
|
|
if (updating)
|
|
|
|
return;
|
|
|
|
|
2018-08-20 18:38:18 +02:00
|
|
|
visible_properties.clear();
|
|
|
|
|
2018-06-19 03:10:48 +02:00
|
|
|
graph->set_scroll_ofs(blend_tree->get_graph_offset() * EDSCALE);
|
|
|
|
|
|
|
|
graph->clear_connections();
|
|
|
|
//erase all nodes
|
|
|
|
for (int i = 0; i < graph->get_child_count(); i++) {
|
|
|
|
if (Object::cast_to<GraphNode>(graph->get_child(i))) {
|
|
|
|
memdelete(graph->get_child(i));
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
animations.clear();
|
|
|
|
|
|
|
|
List<StringName> nodes;
|
|
|
|
blend_tree->get_node_list(&nodes);
|
|
|
|
|
|
|
|
for (List<StringName>::Element *E = nodes.front(); E; E = E->next()) {
|
|
|
|
GraphNode *node = memnew(GraphNode);
|
|
|
|
graph->add_child(node);
|
|
|
|
|
|
|
|
Ref<AnimationNode> agnode = blend_tree->get_node(E->get());
|
|
|
|
|
2018-08-20 18:38:18 +02:00
|
|
|
node->set_offset(blend_tree->get_node_position(E->get()) * EDSCALE);
|
2018-06-19 03:10:48 +02:00
|
|
|
|
|
|
|
node->set_title(agnode->get_caption());
|
|
|
|
node->set_name(E->get());
|
|
|
|
|
|
|
|
int base = 0;
|
|
|
|
if (String(E->get()) != "output") {
|
|
|
|
LineEdit *name = memnew(LineEdit);
|
|
|
|
name->set_text(E->get());
|
|
|
|
name->set_expand_to_text_length(true);
|
|
|
|
node->add_child(name);
|
2020-03-12 13:37:40 +01:00
|
|
|
node->set_slot(0, false, 0, Color(), true, 0, get_theme_color("font_color", "Label"));
|
2020-02-21 18:28:45 +01:00
|
|
|
name->connect("text_entered", callable_mp(this, &AnimationNodeBlendTreeEditor::_node_renamed), varray(agnode));
|
|
|
|
name->connect("focus_exited", callable_mp(this, &AnimationNodeBlendTreeEditor::_node_renamed_focus_out), varray(name, agnode), CONNECT_DEFERRED);
|
2018-06-19 03:10:48 +02:00
|
|
|
base = 1;
|
|
|
|
node->set_show_close_button(true);
|
2020-02-21 18:28:45 +01:00
|
|
|
node->connect("close_request", callable_mp(this, &AnimationNodeBlendTreeEditor::_delete_request), varray(E->get()), CONNECT_DEFERRED);
|
2018-06-19 03:10:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < agnode->get_input_count(); i++) {
|
|
|
|
Label *in_name = memnew(Label);
|
|
|
|
node->add_child(in_name);
|
|
|
|
in_name->set_text(agnode->get_input_name(i));
|
2020-03-12 13:37:40 +01:00
|
|
|
node->set_slot(base + i, true, 0, get_theme_color("font_color", "Label"), false, 0, Color());
|
2018-06-19 03:10:48 +02:00
|
|
|
}
|
|
|
|
|
2018-08-20 18:38:18 +02:00
|
|
|
List<PropertyInfo> pinfo;
|
|
|
|
agnode->get_parameter_list(&pinfo);
|
|
|
|
for (List<PropertyInfo>::Element *F = pinfo.front(); F; F = F->next()) {
|
|
|
|
if (!(F->get().usage & PROPERTY_USAGE_EDITOR)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
String base_path = AnimationTreeEditor::get_singleton()->get_base_path() + String(E->get()) + "/" + F->get().name;
|
|
|
|
EditorProperty *prop = EditorInspector::instantiate_property_editor(AnimationTreeEditor::get_singleton()->get_tree(), F->get().type, base_path, F->get().hint, F->get().hint_string, F->get().usage);
|
|
|
|
if (prop) {
|
|
|
|
prop->set_object_and_property(AnimationTreeEditor::get_singleton()->get_tree(), base_path);
|
|
|
|
prop->update_property();
|
|
|
|
prop->set_name_split_ratio(0);
|
2020-02-21 18:28:45 +01:00
|
|
|
prop->connect("property_changed", callable_mp(this, &AnimationNodeBlendTreeEditor::_property_changed));
|
2018-08-20 18:38:18 +02:00
|
|
|
node->add_child(prop);
|
|
|
|
visible_properties.push_back(prop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-21 18:28:45 +01:00
|
|
|
node->connect("dragged", callable_mp(this, &AnimationNodeBlendTreeEditor::_node_dragged), varray(E->get()));
|
2018-06-19 03:10:48 +02:00
|
|
|
|
2018-08-20 18:38:18 +02:00
|
|
|
if (AnimationTreeEditor::get_singleton()->can_edit(agnode)) {
|
2018-06-19 03:10:48 +02:00
|
|
|
node->add_child(memnew(HSeparator));
|
|
|
|
Button *open_in_editor = memnew(Button);
|
|
|
|
open_in_editor->set_text(TTR("Open Editor"));
|
2020-03-12 13:37:40 +01:00
|
|
|
open_in_editor->set_icon(get_theme_icon("Edit", "EditorIcons"));
|
2018-06-19 03:10:48 +02:00
|
|
|
node->add_child(open_in_editor);
|
2020-02-21 18:28:45 +01:00
|
|
|
open_in_editor->connect("pressed", callable_mp(this, &AnimationNodeBlendTreeEditor::_open_in_editor), varray(E->get()), CONNECT_DEFERRED);
|
2018-06-19 03:10:48 +02:00
|
|
|
open_in_editor->set_h_size_flags(SIZE_SHRINK_CENTER);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (agnode->has_filter()) {
|
|
|
|
node->add_child(memnew(HSeparator));
|
|
|
|
Button *edit_filters = memnew(Button);
|
|
|
|
edit_filters->set_text(TTR("Edit Filters"));
|
2020-03-12 13:37:40 +01:00
|
|
|
edit_filters->set_icon(get_theme_icon("AnimationFilter", "EditorIcons"));
|
2018-06-19 03:10:48 +02:00
|
|
|
node->add_child(edit_filters);
|
2020-02-21 18:28:45 +01:00
|
|
|
edit_filters->connect("pressed", callable_mp(this, &AnimationNodeBlendTreeEditor::_edit_filters), varray(E->get()), CONNECT_DEFERRED);
|
2018-06-19 03:10:48 +02:00
|
|
|
edit_filters->set_h_size_flags(SIZE_SHRINK_CENTER);
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<AnimationNodeAnimation> anim = agnode;
|
|
|
|
if (anim.is_valid()) {
|
|
|
|
MenuButton *mb = memnew(MenuButton);
|
|
|
|
mb->set_text(anim->get_animation());
|
2020-03-12 13:37:40 +01:00
|
|
|
mb->set_icon(get_theme_icon("Animation", "EditorIcons"));
|
2018-06-19 03:10:48 +02:00
|
|
|
Array options;
|
|
|
|
|
|
|
|
node->add_child(memnew(HSeparator));
|
|
|
|
node->add_child(mb);
|
|
|
|
|
|
|
|
ProgressBar *pb = memnew(ProgressBar);
|
|
|
|
|
2018-08-20 18:38:18 +02:00
|
|
|
AnimationTree *player = AnimationTreeEditor::get_singleton()->get_tree();
|
2018-06-19 03:10:48 +02:00
|
|
|
if (player->has_node(player->get_animation_player())) {
|
|
|
|
AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(player->get_node(player->get_animation_player()));
|
|
|
|
if (ap) {
|
|
|
|
List<StringName> anims;
|
|
|
|
ap->get_animation_list(&anims);
|
|
|
|
|
|
|
|
for (List<StringName>::Element *F = anims.front(); F; F = F->next()) {
|
|
|
|
mb->get_popup()->add_item(F->get());
|
|
|
|
options.push_back(F->get());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ap->has_animation(anim->get_animation())) {
|
|
|
|
pb->set_max(ap->get_animation(anim->get_animation())->get_length());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pb->set_percent_visible(false);
|
2019-02-27 14:56:49 +01:00
|
|
|
pb->set_custom_minimum_size(Vector2(0, 14) * EDSCALE);
|
2018-06-19 03:10:48 +02:00
|
|
|
animations[E->get()] = pb;
|
|
|
|
node->add_child(pb);
|
|
|
|
|
2020-02-21 18:28:45 +01:00
|
|
|
mb->get_popup()->connect("index_pressed", callable_mp(this, &AnimationNodeBlendTreeEditor::_anim_selected), varray(options, E->get()), CONNECT_DEFERRED);
|
2018-06-19 03:10:48 +02:00
|
|
|
}
|
|
|
|
|
2018-12-17 02:18:04 +01:00
|
|
|
if (EditorSettings::get_singleton()->get("interface/theme/use_graph_node_headers")) {
|
2020-03-12 13:37:40 +01:00
|
|
|
Ref<StyleBoxFlat> sb = node->get_theme_stylebox("frame", "GraphNode");
|
2019-03-19 10:32:13 +01:00
|
|
|
Color c = sb->get_border_color();
|
2018-12-17 02:18:04 +01:00
|
|
|
Color mono_color = ((c.r + c.g + c.b) / 3) < 0.7 ? Color(1.0, 1.0, 1.0) : Color(0.0, 0.0, 0.0);
|
|
|
|
mono_color.a = 0.85;
|
|
|
|
c = mono_color;
|
|
|
|
|
2020-03-12 13:37:40 +01:00
|
|
|
node->add_theme_color_override("title_color", c);
|
2018-12-17 02:18:04 +01:00
|
|
|
c.a = 0.7;
|
2020-03-12 13:37:40 +01:00
|
|
|
node->add_theme_color_override("close_color", c);
|
|
|
|
node->add_theme_color_override("resizer_color", c);
|
2018-12-17 02:18:04 +01:00
|
|
|
}
|
2018-06-19 03:10:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
List<AnimationNodeBlendTree::NodeConnection> connections;
|
|
|
|
blend_tree->get_node_connections(&connections);
|
|
|
|
|
|
|
|
for (List<AnimationNodeBlendTree::NodeConnection>::Element *E = connections.front(); E; E = E->next()) {
|
|
|
|
StringName from = E->get().output_node;
|
|
|
|
StringName to = E->get().input_node;
|
|
|
|
int to_idx = E->get().input_index;
|
|
|
|
|
|
|
|
graph->connect_node(from, 0, to, to_idx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-20 18:38:18 +02:00
|
|
|
void AnimationNodeBlendTreeEditor::_file_opened(const String &p_file) {
|
|
|
|
file_loaded = ResourceLoader::load(p_file);
|
|
|
|
if (file_loaded.is_valid()) {
|
|
|
|
_add_node(MENU_LOAD_FILE_CONFIRM);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationNodeBlendTreeEditor::_add_node(int p_idx) {
|
2018-06-19 03:10:48 +02:00
|
|
|
Ref<AnimationNode> anode;
|
|
|
|
|
2018-08-20 18:38:18 +02:00
|
|
|
String base_name;
|
|
|
|
|
|
|
|
if (p_idx == MENU_LOAD_FILE) {
|
|
|
|
open_file->clear_filters();
|
|
|
|
List<String> filters;
|
|
|
|
ResourceLoader::get_recognized_extensions_for_type("AnimationNode", &filters);
|
|
|
|
for (List<String>::Element *E = filters.front(); E; E = E->next()) {
|
|
|
|
open_file->add_filter("*." + E->get());
|
|
|
|
}
|
|
|
|
open_file->popup_centered_ratio();
|
|
|
|
return;
|
|
|
|
} else if (p_idx == MENU_LOAD_FILE_CONFIRM) {
|
|
|
|
anode = file_loaded;
|
|
|
|
file_loaded.unref();
|
|
|
|
base_name = anode->get_class();
|
|
|
|
} else if (p_idx == MENU_PASTE) {
|
|
|
|
anode = EditorSettings::get_singleton()->get_resource_clipboard();
|
|
|
|
ERR_FAIL_COND(!anode.is_valid());
|
|
|
|
base_name = anode->get_class();
|
|
|
|
} else if (add_options[p_idx].type != String()) {
|
2018-06-19 03:10:48 +02:00
|
|
|
AnimationNode *an = Object::cast_to<AnimationNode>(ClassDB::instance(add_options[p_idx].type));
|
|
|
|
ERR_FAIL_COND(!an);
|
|
|
|
anode = Ref<AnimationNode>(an);
|
2018-08-20 18:38:18 +02:00
|
|
|
base_name = add_options[p_idx].name;
|
2018-06-19 03:10:48 +02:00
|
|
|
} else {
|
|
|
|
ERR_FAIL_COND(add_options[p_idx].script.is_null());
|
|
|
|
String base_type = add_options[p_idx].script->get_instance_base_type();
|
|
|
|
AnimationNode *an = Object::cast_to<AnimationNode>(ClassDB::instance(base_type));
|
|
|
|
ERR_FAIL_COND(!an);
|
|
|
|
anode = Ref<AnimationNode>(an);
|
2020-02-13 20:03:10 +01:00
|
|
|
anode->set_script(add_options[p_idx].script);
|
2018-08-20 18:38:18 +02:00
|
|
|
base_name = add_options[p_idx].name;
|
2018-06-19 03:10:48 +02:00
|
|
|
}
|
|
|
|
|
2018-08-20 18:38:18 +02:00
|
|
|
Ref<AnimationNodeOutput> out = anode;
|
|
|
|
if (out.is_valid()) {
|
|
|
|
EditorNode::get_singleton()->show_warning(TTR("Output node can't be added to the blend tree."));
|
|
|
|
return;
|
|
|
|
}
|
2019-04-08 04:11:53 +02:00
|
|
|
|
|
|
|
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();
|
2018-06-19 03:10:48 +02:00
|
|
|
|
|
|
|
int base = 1;
|
|
|
|
String name = base_name;
|
|
|
|
while (blend_tree->has_node(name)) {
|
|
|
|
base++;
|
|
|
|
name = base_name + " " + itos(base);
|
|
|
|
}
|
|
|
|
|
2019-02-21 20:41:01 +01:00
|
|
|
undo_redo->create_action(TTR("Add Node to BlendTree"));
|
2018-08-20 18:38:18 +02:00
|
|
|
undo_redo->add_do_method(blend_tree.ptr(), "add_node", name, anode, instance_pos / EDSCALE);
|
2018-06-21 23:08:11 +02:00
|
|
|
undo_redo->add_undo_method(blend_tree.ptr(), "remove_node", name);
|
2018-06-19 03:10:48 +02:00
|
|
|
undo_redo->add_do_method(this, "_update_graph");
|
|
|
|
undo_redo->add_undo_method(this, "_update_graph");
|
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
|
|
|
|
2018-08-20 18:38:18 +02:00
|
|
|
void AnimationNodeBlendTreeEditor::_node_dragged(const Vector2 &p_from, const Vector2 &p_to, const StringName &p_which) {
|
2018-06-19 03:10:48 +02:00
|
|
|
updating = true;
|
2019-02-21 20:41:01 +01:00
|
|
|
undo_redo->create_action(TTR("Node Moved"));
|
2018-08-20 18:38:18 +02:00
|
|
|
undo_redo->add_do_method(blend_tree.ptr(), "set_node_position", p_which, p_to / EDSCALE);
|
|
|
|
undo_redo->add_undo_method(blend_tree.ptr(), "set_node_position", p_which, p_from / EDSCALE);
|
2018-06-19 03:10:48 +02:00
|
|
|
undo_redo->add_do_method(this, "_update_graph");
|
|
|
|
undo_redo->add_undo_method(this, "_update_graph");
|
|
|
|
undo_redo->commit_action();
|
|
|
|
updating = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationNodeBlendTreeEditor::_connection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index) {
|
|
|
|
AnimationNodeBlendTree::ConnectionError err = blend_tree->can_connect_node(p_to, p_to_index, p_from);
|
|
|
|
|
|
|
|
if (err != AnimationNodeBlendTree::CONNECTION_OK) {
|
|
|
|
EditorNode::get_singleton()->show_warning(TTR("Unable to connect, port may be in use or connection may be invalid."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-02-21 20:41:01 +01:00
|
|
|
undo_redo->create_action(TTR("Nodes Connected"));
|
2018-06-21 23:08:11 +02:00
|
|
|
undo_redo->add_do_method(blend_tree.ptr(), "connect_node", p_to, p_to_index, p_from);
|
2018-12-18 18:23:39 +01:00
|
|
|
undo_redo->add_undo_method(blend_tree.ptr(), "disconnect_node", p_to, p_to_index);
|
2018-06-19 03:10:48 +02:00
|
|
|
undo_redo->add_do_method(this, "_update_graph");
|
|
|
|
undo_redo->add_undo_method(this, "_update_graph");
|
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationNodeBlendTreeEditor::_disconnection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index) {
|
|
|
|
graph->disconnect_node(p_from, p_from_index, p_to, p_to_index);
|
|
|
|
|
|
|
|
updating = true;
|
2019-02-21 20:41:01 +01:00
|
|
|
undo_redo->create_action(TTR("Nodes Disconnected"));
|
2018-06-21 23:08:11 +02:00
|
|
|
undo_redo->add_do_method(blend_tree.ptr(), "disconnect_node", p_to, p_to_index);
|
|
|
|
undo_redo->add_undo_method(blend_tree.ptr(), "connect_node", p_to, p_to_index, p_from);
|
2018-06-19 03:10:48 +02:00
|
|
|
undo_redo->add_do_method(this, "_update_graph");
|
|
|
|
undo_redo->add_undo_method(this, "_update_graph");
|
|
|
|
undo_redo->commit_action();
|
|
|
|
updating = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationNodeBlendTreeEditor::_anim_selected(int p_index, Array p_options, const String &p_node) {
|
|
|
|
String option = p_options[p_index];
|
|
|
|
|
|
|
|
Ref<AnimationNodeAnimation> anim = blend_tree->get_node(p_node);
|
|
|
|
ERR_FAIL_COND(!anim.is_valid());
|
|
|
|
|
2019-02-21 20:41:01 +01:00
|
|
|
undo_redo->create_action(TTR("Set Animation"));
|
2018-06-19 03:10:48 +02:00
|
|
|
undo_redo->add_do_method(anim.ptr(), "set_animation", option);
|
|
|
|
undo_redo->add_undo_method(anim.ptr(), "set_animation", anim->get_animation());
|
|
|
|
undo_redo->add_do_method(this, "_update_graph");
|
|
|
|
undo_redo->add_undo_method(this, "_update_graph");
|
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationNodeBlendTreeEditor::_delete_request(const String &p_which) {
|
2019-02-21 20:41:01 +01:00
|
|
|
undo_redo->create_action(TTR("Delete Node"));
|
2018-06-21 23:08:11 +02:00
|
|
|
undo_redo->add_do_method(blend_tree.ptr(), "remove_node", p_which);
|
2018-12-18 00:03:25 +01:00
|
|
|
undo_redo->add_undo_method(blend_tree.ptr(), "add_node", p_which, blend_tree->get_node(p_which), blend_tree.ptr()->get_node_position(p_which));
|
2018-06-19 03:10:48 +02:00
|
|
|
|
|
|
|
List<AnimationNodeBlendTree::NodeConnection> conns;
|
|
|
|
blend_tree->get_node_connections(&conns);
|
|
|
|
|
|
|
|
for (List<AnimationNodeBlendTree::NodeConnection>::Element *E = conns.front(); E; E = E->next()) {
|
|
|
|
if (E->get().output_node == p_which || E->get().input_node == p_which) {
|
2018-06-21 23:08:11 +02:00
|
|
|
undo_redo->add_undo_method(blend_tree.ptr(), "connect_node", E->get().input_node, E->get().input_index, E->get().output_node);
|
2018-06-19 03:10:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
undo_redo->add_do_method(this, "_update_graph");
|
|
|
|
undo_redo->add_undo_method(this, "_update_graph");
|
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
|
|
|
|
2019-04-08 04:11:53 +02:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2018-06-19 03:10:48 +02:00
|
|
|
void AnimationNodeBlendTreeEditor::_node_selected(Object *p_node) {
|
|
|
|
GraphNode *gn = Object::cast_to<GraphNode>(p_node);
|
|
|
|
ERR_FAIL_COND(!gn);
|
|
|
|
|
|
|
|
String name = gn->get_name();
|
|
|
|
|
|
|
|
Ref<AnimationNode> anode = blend_tree->get_node(name);
|
|
|
|
ERR_FAIL_COND(!anode.is_valid());
|
|
|
|
|
|
|
|
EditorNode::get_singleton()->push_item(anode.ptr(), "", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationNodeBlendTreeEditor::_open_in_editor(const String &p_which) {
|
|
|
|
Ref<AnimationNode> an = blend_tree->get_node(p_which);
|
2019-06-11 14:49:34 +02:00
|
|
|
ERR_FAIL_COND(!an.is_valid());
|
2018-08-20 18:38:18 +02:00
|
|
|
AnimationTreeEditor::get_singleton()->enter_editor(p_which);
|
2018-06-19 03:10:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationNodeBlendTreeEditor::_filter_toggled() {
|
|
|
|
updating = true;
|
2019-02-21 20:41:01 +01:00
|
|
|
undo_redo->create_action(TTR("Toggle Filter On/Off"));
|
2018-06-19 03:10:48 +02:00
|
|
|
undo_redo->add_do_method(_filter_edit.ptr(), "set_filter_enabled", filter_enabled->is_pressed());
|
|
|
|
undo_redo->add_undo_method(_filter_edit.ptr(), "set_filter_enabled", _filter_edit->is_filter_enabled());
|
|
|
|
undo_redo->add_do_method(this, "_update_filters", _filter_edit);
|
|
|
|
undo_redo->add_undo_method(this, "_update_filters", _filter_edit);
|
|
|
|
undo_redo->commit_action();
|
|
|
|
updating = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationNodeBlendTreeEditor::_filter_edited() {
|
|
|
|
TreeItem *edited = filters->get_edited();
|
|
|
|
ERR_FAIL_COND(!edited);
|
|
|
|
|
|
|
|
NodePath edited_path = edited->get_metadata(0);
|
|
|
|
bool filtered = edited->is_checked(0);
|
|
|
|
|
|
|
|
updating = true;
|
2019-02-21 20:41:01 +01:00
|
|
|
undo_redo->create_action(TTR("Change Filter"));
|
2018-06-19 03:10:48 +02:00
|
|
|
undo_redo->add_do_method(_filter_edit.ptr(), "set_filter_path", edited_path, filtered);
|
|
|
|
undo_redo->add_undo_method(_filter_edit.ptr(), "set_filter_path", edited_path, _filter_edit->is_path_filtered(edited_path));
|
|
|
|
undo_redo->add_do_method(this, "_update_filters", _filter_edit);
|
|
|
|
undo_redo->add_undo_method(this, "_update_filters", _filter_edit);
|
|
|
|
undo_redo->commit_action();
|
|
|
|
updating = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AnimationNodeBlendTreeEditor::_update_filters(const Ref<AnimationNode> &anode) {
|
|
|
|
if (updating || _filter_edit != anode)
|
|
|
|
return false;
|
|
|
|
|
2018-08-20 18:38:18 +02:00
|
|
|
NodePath player_path = AnimationTreeEditor::get_singleton()->get_tree()->get_animation_player();
|
2018-06-19 03:10:48 +02:00
|
|
|
|
2018-08-20 18:38:18 +02:00
|
|
|
if (!AnimationTreeEditor::get_singleton()->get_tree()->has_node(player_path)) {
|
2018-06-19 03:10:48 +02:00
|
|
|
EditorNode::get_singleton()->show_warning(TTR("No animation player set, so unable to retrieve track names."));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-08-20 18:38:18 +02:00
|
|
|
AnimationPlayer *player = Object::cast_to<AnimationPlayer>(AnimationTreeEditor::get_singleton()->get_tree()->get_node(player_path));
|
2018-06-19 03:10:48 +02:00
|
|
|
if (!player) {
|
|
|
|
EditorNode::get_singleton()->show_warning(TTR("Player path set is invalid, so unable to retrieve track names."));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Node *base = player->get_node(player->get_root());
|
|
|
|
|
|
|
|
if (!base) {
|
|
|
|
EditorNode::get_singleton()->show_warning(TTR("Animation player has no valid root node path, so unable to retrieve track names."));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
updating = true;
|
|
|
|
|
|
|
|
Set<String> paths;
|
2020-03-17 07:33:00 +01:00
|
|
|
HashMap<String, Set<String>> types;
|
2018-06-19 03:10:48 +02:00
|
|
|
{
|
|
|
|
List<StringName> animations;
|
|
|
|
player->get_animation_list(&animations);
|
|
|
|
|
|
|
|
for (List<StringName>::Element *E = animations.front(); E; E = E->next()) {
|
|
|
|
Ref<Animation> anim = player->get_animation(E->get());
|
|
|
|
for (int i = 0; i < anim->get_track_count(); i++) {
|
2019-11-09 21:52:22 +01:00
|
|
|
String track_path = anim->track_get_path(i);
|
|
|
|
paths.insert(track_path);
|
|
|
|
|
|
|
|
String track_type_name;
|
|
|
|
Animation::TrackType track_type = anim->track_get_type(i);
|
|
|
|
switch (track_type) {
|
|
|
|
case Animation::TrackType::TYPE_ANIMATION: {
|
|
|
|
track_type_name = TTR("Anim Clips");
|
|
|
|
} break;
|
|
|
|
case Animation::TrackType::TYPE_AUDIO: {
|
|
|
|
track_type_name = TTR("Audio Clips");
|
|
|
|
} break;
|
|
|
|
case Animation::TrackType::TYPE_METHOD: {
|
|
|
|
track_type_name = TTR("Functions");
|
|
|
|
} break;
|
|
|
|
default: {
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
if (!track_type_name.empty()) {
|
|
|
|
types[track_path].insert(track_type_name);
|
|
|
|
}
|
2018-06-19 03:10:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
filter_enabled->set_pressed(anode->is_filter_enabled());
|
|
|
|
filters->clear();
|
|
|
|
TreeItem *root = filters->create_item();
|
|
|
|
|
|
|
|
Map<String, TreeItem *> parenthood;
|
|
|
|
|
|
|
|
for (Set<String>::Element *E = paths.front(); E; E = E->next()) {
|
|
|
|
NodePath path = E->get();
|
2020-04-02 01:20:12 +02:00
|
|
|
TreeItem *ti = nullptr;
|
2018-06-19 03:10:48 +02:00
|
|
|
String accum;
|
|
|
|
for (int i = 0; i < path.get_name_count(); i++) {
|
|
|
|
String name = path.get_name(i);
|
|
|
|
if (accum != String()) {
|
|
|
|
accum += "/";
|
|
|
|
}
|
|
|
|
accum += name;
|
|
|
|
if (!parenthood.has(accum)) {
|
|
|
|
if (ti) {
|
|
|
|
ti = filters->create_item(ti);
|
|
|
|
} else {
|
|
|
|
ti = filters->create_item(root);
|
|
|
|
}
|
|
|
|
parenthood[accum] = ti;
|
|
|
|
ti->set_text(0, name);
|
|
|
|
ti->set_selectable(0, false);
|
|
|
|
ti->set_editable(0, false);
|
|
|
|
|
|
|
|
if (base->has_node(accum)) {
|
|
|
|
Node *node = base->get_node(accum);
|
2018-09-02 23:40:51 +02:00
|
|
|
ti->set_icon(0, EditorNode::get_singleton()->get_object_icon(node, "Node"));
|
2018-06-19 03:10:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
ti = parenthood[accum];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-02 01:20:12 +02:00
|
|
|
Node *node = nullptr;
|
2018-06-19 03:10:48 +02:00
|
|
|
if (base->has_node(accum)) {
|
|
|
|
node = base->get_node(accum);
|
|
|
|
}
|
|
|
|
if (!node)
|
2018-09-13 03:38:39 +02:00
|
|
|
continue; //no node, can't edit
|
2018-06-19 03:10:48 +02:00
|
|
|
|
|
|
|
if (path.get_subname_count()) {
|
|
|
|
String concat = path.get_concatenated_subnames();
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
Skeleton3D *skeleton = Object::cast_to<Skeleton3D>(node);
|
2018-06-19 03:10:48 +02:00
|
|
|
if (skeleton && skeleton->find_bone(concat) != -1) {
|
|
|
|
//path in skeleton
|
2019-06-26 15:08:25 +02:00
|
|
|
const String &bone = concat;
|
2018-06-19 03:10:48 +02:00
|
|
|
int idx = skeleton->find_bone(bone);
|
|
|
|
List<String> bone_path;
|
|
|
|
while (idx != -1) {
|
|
|
|
bone_path.push_front(skeleton->get_bone_name(idx));
|
|
|
|
idx = skeleton->get_bone_parent(idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
accum += ":";
|
|
|
|
for (List<String>::Element *F = bone_path.front(); F; F = F->next()) {
|
|
|
|
if (F != bone_path.front()) {
|
|
|
|
accum += "/";
|
|
|
|
}
|
|
|
|
|
|
|
|
accum += F->get();
|
|
|
|
if (!parenthood.has(accum)) {
|
|
|
|
ti = filters->create_item(ti);
|
|
|
|
parenthood[accum] = ti;
|
|
|
|
ti->set_text(0, F->get());
|
|
|
|
ti->set_selectable(0, false);
|
|
|
|
ti->set_editable(0, false);
|
2020-03-26 22:49:16 +01:00
|
|
|
ti->set_icon(0, get_theme_icon("BoneAttachment3D", "EditorIcons"));
|
2018-06-19 03:10:48 +02:00
|
|
|
} else {
|
|
|
|
ti = parenthood[accum];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ti->set_editable(0, true);
|
|
|
|
ti->set_selectable(0, true);
|
|
|
|
ti->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
|
|
|
|
ti->set_text(0, concat);
|
|
|
|
ti->set_checked(0, anode->is_path_filtered(path));
|
2020-03-26 22:49:16 +01:00
|
|
|
ti->set_icon(0, get_theme_icon("BoneAttachment3D", "EditorIcons"));
|
2018-06-19 03:10:48 +02:00
|
|
|
ti->set_metadata(0, path);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
//just a property
|
|
|
|
ti = filters->create_item(ti);
|
|
|
|
ti->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
|
|
|
|
ti->set_text(0, concat);
|
|
|
|
ti->set_editable(0, true);
|
|
|
|
ti->set_selectable(0, true);
|
|
|
|
ti->set_checked(0, anode->is_path_filtered(path));
|
|
|
|
ti->set_metadata(0, path);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (ti) {
|
2019-11-09 21:52:22 +01:00
|
|
|
//just a node, not a property track
|
|
|
|
String types_text = "[";
|
|
|
|
if (types.has(path)) {
|
|
|
|
Set<String>::Element *F = types[path].front();
|
|
|
|
types_text += F->get();
|
|
|
|
while (F->next()) {
|
|
|
|
F = F->next();
|
|
|
|
types_text += " / " + F->get();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
types_text += "]";
|
|
|
|
ti = filters->create_item(ti);
|
|
|
|
ti->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
|
|
|
|
ti->set_text(0, types_text);
|
2018-06-19 03:10:48 +02:00
|
|
|
ti->set_editable(0, true);
|
|
|
|
ti->set_selectable(0, true);
|
|
|
|
ti->set_checked(0, anode->is_path_filtered(path));
|
|
|
|
ti->set_metadata(0, path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
updating = false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationNodeBlendTreeEditor::_edit_filters(const String &p_which) {
|
|
|
|
Ref<AnimationNode> anode = blend_tree->get_node(p_which);
|
|
|
|
ERR_FAIL_COND(!anode.is_valid());
|
|
|
|
|
|
|
|
_filter_edit = anode;
|
|
|
|
if (!_update_filters(anode))
|
|
|
|
return;
|
|
|
|
|
2020-03-06 18:00:16 +01:00
|
|
|
filter_dialog->popup_centered(Size2(500, 500) * EDSCALE);
|
2018-06-19 03:10:48 +02:00
|
|
|
}
|
|
|
|
|
2018-06-21 23:08:11 +02:00
|
|
|
void AnimationNodeBlendTreeEditor::_removed_from_graph() {
|
|
|
|
if (is_visible()) {
|
2020-04-02 01:20:12 +02:00
|
|
|
EditorNode::get_singleton()->edit_item(nullptr);
|
2018-06-21 23:08:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-19 03:10:48 +02:00
|
|
|
void AnimationNodeBlendTreeEditor::_notification(int p_what) {
|
|
|
|
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
|
2020-03-12 13:37:40 +01:00
|
|
|
error_panel->add_theme_style_override("panel", get_theme_stylebox("bg", "Tree"));
|
|
|
|
error_label->add_theme_color_override("font_color", get_theme_color("error_color", "Editor"));
|
2018-12-17 02:18:04 +01:00
|
|
|
|
|
|
|
if (p_what == NOTIFICATION_THEME_CHANGED && is_visible_in_tree())
|
|
|
|
_update_graph();
|
2018-06-19 03:10:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (p_what == NOTIFICATION_PROCESS) {
|
|
|
|
String error;
|
|
|
|
|
2018-08-20 18:38:18 +02:00
|
|
|
if (!AnimationTreeEditor::get_singleton()->get_tree()->is_active()) {
|
2018-06-25 23:40:24 +02:00
|
|
|
error = TTR("AnimationTree is inactive.\nActivate to enable playback, check node warnings if activation fails.");
|
2018-08-20 18:38:18 +02:00
|
|
|
} else if (AnimationTreeEditor::get_singleton()->get_tree()->is_state_invalid()) {
|
|
|
|
error = AnimationTreeEditor::get_singleton()->get_tree()->get_invalid_state_reason();
|
2018-06-19 03:10:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (error != error_label->get_text()) {
|
|
|
|
error_label->set_text(error);
|
|
|
|
if (error != String()) {
|
|
|
|
error_panel->show();
|
|
|
|
} else {
|
|
|
|
error_panel->hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
List<AnimationNodeBlendTree::NodeConnection> conns;
|
|
|
|
blend_tree->get_node_connections(&conns);
|
|
|
|
for (List<AnimationNodeBlendTree::NodeConnection>::Element *E = conns.front(); E; E = E->next()) {
|
|
|
|
float activity = 0;
|
2018-08-23 21:44:10 +02:00
|
|
|
StringName path = AnimationTreeEditor::get_singleton()->get_base_path() + E->get().input_node;
|
2018-08-20 18:38:18 +02:00
|
|
|
if (AnimationTreeEditor::get_singleton()->get_tree() && !AnimationTreeEditor::get_singleton()->get_tree()->is_state_invalid()) {
|
2018-08-23 21:44:10 +02:00
|
|
|
activity = AnimationTreeEditor::get_singleton()->get_tree()->get_connection_activity(path, E->get().input_index);
|
2018-06-19 03:10:48 +02:00
|
|
|
}
|
|
|
|
graph->set_connection_activity(E->get().output_node, 0, E->get().input_node, E->get().input_index, activity);
|
|
|
|
}
|
|
|
|
|
2018-08-20 18:38:18 +02:00
|
|
|
AnimationTree *graph_player = AnimationTreeEditor::get_singleton()->get_tree();
|
2020-04-02 01:20:12 +02:00
|
|
|
AnimationPlayer *player = nullptr;
|
2018-06-19 03:10:48 +02:00
|
|
|
if (graph_player->has_node(graph_player->get_animation_player())) {
|
|
|
|
player = Object::cast_to<AnimationPlayer>(graph_player->get_node(graph_player->get_animation_player()));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (player) {
|
|
|
|
for (Map<StringName, ProgressBar *>::Element *E = animations.front(); E; E = E->next()) {
|
|
|
|
Ref<AnimationNodeAnimation> an = blend_tree->get_node(E->key());
|
|
|
|
if (an.is_valid()) {
|
|
|
|
if (player->has_animation(an->get_animation())) {
|
|
|
|
Ref<Animation> anim = player->get_animation(an->get_animation());
|
|
|
|
if (anim.is_valid()) {
|
|
|
|
E->get()->set_max(anim->get_length());
|
2018-11-08 20:51:45 +01:00
|
|
|
//StringName path = AnimationTreeEditor::get_singleton()->get_base_path() + E->get().input_node;
|
|
|
|
StringName time_path = AnimationTreeEditor::get_singleton()->get_base_path() + String(E->key()) + "/time";
|
|
|
|
E->get()->set_value(AnimationTreeEditor::get_singleton()->get_tree()->get(time_path));
|
2018-06-19 03:10:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-08-20 18:38:18 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < visible_properties.size(); i++) {
|
|
|
|
visible_properties[i]->update_property();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
|
|
|
|
set_process(is_visible_in_tree());
|
2018-06-19 03:10:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationNodeBlendTreeEditor::_scroll_changed(const Vector2 &p_scroll) {
|
|
|
|
if (updating)
|
|
|
|
return;
|
|
|
|
updating = true;
|
|
|
|
blend_tree->set_graph_offset(p_scroll / EDSCALE);
|
|
|
|
updating = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationNodeBlendTreeEditor::_bind_methods() {
|
|
|
|
ClassDB::bind_method("_update_graph", &AnimationNodeBlendTreeEditor::_update_graph);
|
|
|
|
ClassDB::bind_method("_update_filters", &AnimationNodeBlendTreeEditor::_update_filters);
|
|
|
|
}
|
|
|
|
|
2020-04-02 01:20:12 +02:00
|
|
|
AnimationNodeBlendTreeEditor *AnimationNodeBlendTreeEditor::singleton = nullptr;
|
2018-06-19 03:10:48 +02:00
|
|
|
|
|
|
|
void AnimationNodeBlendTreeEditor::_node_renamed(const String &p_text, Ref<AnimationNode> p_node) {
|
|
|
|
String prev_name = blend_tree->get_node_name(p_node);
|
|
|
|
ERR_FAIL_COND(prev_name == String());
|
|
|
|
GraphNode *gn = Object::cast_to<GraphNode>(graph->get_node(prev_name));
|
|
|
|
ERR_FAIL_COND(!gn);
|
|
|
|
|
2019-06-26 15:08:25 +02:00
|
|
|
const String &new_name = p_text;
|
2018-06-19 03:10:48 +02:00
|
|
|
|
2019-06-11 14:49:34 +02:00
|
|
|
ERR_FAIL_COND(new_name == "" || new_name.find(".") != -1 || new_name.find("/") != -1);
|
2018-06-19 03:10:48 +02:00
|
|
|
|
2018-08-20 18:38:18 +02:00
|
|
|
if (new_name == prev_name) {
|
|
|
|
return; //nothing to do
|
|
|
|
}
|
2018-06-19 03:10:48 +02:00
|
|
|
|
2019-06-26 15:08:25 +02:00
|
|
|
const String &base_name = new_name;
|
2018-06-19 03:10:48 +02:00
|
|
|
int base = 1;
|
|
|
|
String name = base_name;
|
|
|
|
while (blend_tree->has_node(name)) {
|
|
|
|
base++;
|
|
|
|
name = base_name + " " + itos(base);
|
|
|
|
}
|
|
|
|
|
2018-08-20 18:38:18 +02:00
|
|
|
String base_path = AnimationTreeEditor::get_singleton()->get_base_path();
|
|
|
|
|
2018-06-19 03:10:48 +02:00
|
|
|
updating = true;
|
2019-02-21 20:41:01 +01:00
|
|
|
undo_redo->create_action(TTR("Node Renamed"));
|
2018-06-21 23:08:11 +02:00
|
|
|
undo_redo->add_do_method(blend_tree.ptr(), "rename_node", prev_name, name);
|
|
|
|
undo_redo->add_undo_method(blend_tree.ptr(), "rename_node", name, prev_name);
|
2018-08-20 18:38:18 +02:00
|
|
|
undo_redo->add_do_method(AnimationTreeEditor::get_singleton()->get_tree(), "rename_parameter", base_path + prev_name, base_path + name);
|
|
|
|
undo_redo->add_undo_method(AnimationTreeEditor::get_singleton()->get_tree(), "rename_parameter", base_path + name, base_path + prev_name);
|
2018-06-19 03:10:48 +02:00
|
|
|
undo_redo->add_do_method(this, "_update_graph");
|
|
|
|
undo_redo->add_undo_method(this, "_update_graph");
|
|
|
|
undo_redo->commit_action();
|
|
|
|
updating = false;
|
|
|
|
gn->set_name(new_name);
|
|
|
|
gn->set_size(gn->get_minimum_size());
|
2018-08-20 18:38:18 +02:00
|
|
|
|
|
|
|
//change editors accordingly
|
|
|
|
for (int i = 0; i < visible_properties.size(); i++) {
|
|
|
|
String pname = visible_properties[i]->get_edited_property().operator String();
|
|
|
|
if (pname.begins_with(base_path + prev_name)) {
|
2019-02-12 21:10:08 +01:00
|
|
|
String new_name2 = pname.replace_first(base_path + prev_name, base_path + name);
|
|
|
|
visible_properties[i]->set_object_and_property(visible_properties[i]->get_edited_object(), new_name2);
|
2018-08-20 18:38:18 +02:00
|
|
|
}
|
|
|
|
}
|
2018-08-23 21:44:10 +02:00
|
|
|
|
|
|
|
//recreate connections
|
|
|
|
graph->clear_connections();
|
|
|
|
|
|
|
|
List<AnimationNodeBlendTree::NodeConnection> connections;
|
|
|
|
blend_tree->get_node_connections(&connections);
|
|
|
|
|
|
|
|
for (List<AnimationNodeBlendTree::NodeConnection>::Element *E = connections.front(); E; E = E->next()) {
|
|
|
|
StringName from = E->get().output_node;
|
|
|
|
StringName to = E->get().input_node;
|
|
|
|
int to_idx = E->get().input_index;
|
|
|
|
|
|
|
|
graph->connect_node(from, 0, to, to_idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
//update animations
|
|
|
|
for (Map<StringName, ProgressBar *>::Element *E = animations.front(); E; E = E->next()) {
|
|
|
|
if (E->key() == prev_name) {
|
|
|
|
animations[new_name] = animations[prev_name];
|
|
|
|
animations.erase(prev_name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-12-18 00:03:25 +01:00
|
|
|
|
|
|
|
_update_graph(); // Needed to update the signal connections with the new name.
|
2018-06-19 03:10:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationNodeBlendTreeEditor::_node_renamed_focus_out(Node *le, Ref<AnimationNode> p_node) {
|
|
|
|
_node_renamed(le->call("get_text"), p_node);
|
|
|
|
}
|
|
|
|
|
2018-08-20 18:38:18 +02:00
|
|
|
bool AnimationNodeBlendTreeEditor::can_edit(const Ref<AnimationNode> &p_node) {
|
|
|
|
Ref<AnimationNodeBlendTree> bt = p_node;
|
|
|
|
return bt.is_valid();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationNodeBlendTreeEditor::edit(const Ref<AnimationNode> &p_node) {
|
|
|
|
if (blend_tree.is_valid()) {
|
2020-02-21 18:28:45 +01:00
|
|
|
blend_tree->disconnect("removed_from_graph", callable_mp(this, &AnimationNodeBlendTreeEditor::_removed_from_graph));
|
2018-08-20 18:38:18 +02:00
|
|
|
}
|
|
|
|
|
2019-07-11 20:18:53 +02:00
|
|
|
blend_tree = p_node;
|
2018-08-20 18:38:18 +02:00
|
|
|
|
|
|
|
if (blend_tree.is_null()) {
|
|
|
|
hide();
|
|
|
|
} else {
|
2020-02-21 18:28:45 +01:00
|
|
|
blend_tree->connect("removed_from_graph", callable_mp(this, &AnimationNodeBlendTreeEditor::_removed_from_graph));
|
2018-08-20 18:38:18 +02:00
|
|
|
|
|
|
|
_update_graph();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-19 03:10:48 +02:00
|
|
|
AnimationNodeBlendTreeEditor::AnimationNodeBlendTreeEditor() {
|
|
|
|
singleton = this;
|
|
|
|
updating = false;
|
2019-04-08 04:11:53 +02:00
|
|
|
use_popup_menu_position = false;
|
2018-06-19 03:10:48 +02:00
|
|
|
|
|
|
|
graph = memnew(GraphEdit);
|
|
|
|
add_child(graph);
|
|
|
|
graph->add_valid_right_disconnect_type(0);
|
|
|
|
graph->add_valid_left_disconnect_type(0);
|
|
|
|
graph->set_v_size_flags(SIZE_EXPAND_FILL);
|
2020-02-21 18:28:45 +01:00
|
|
|
graph->connect("connection_request", callable_mp(this, &AnimationNodeBlendTreeEditor::_connection_request), varray(), CONNECT_DEFERRED);
|
|
|
|
graph->connect("disconnection_request", callable_mp(this, &AnimationNodeBlendTreeEditor::_disconnection_request), varray(), CONNECT_DEFERRED);
|
|
|
|
graph->connect("node_selected", callable_mp(this, &AnimationNodeBlendTreeEditor::_node_selected));
|
|
|
|
graph->connect("scroll_offset_changed", callable_mp(this, &AnimationNodeBlendTreeEditor::_scroll_changed));
|
|
|
|
graph->connect("delete_nodes_request", callable_mp(this, &AnimationNodeBlendTreeEditor::_delete_nodes_request));
|
|
|
|
graph->connect("popup_request", callable_mp(this, &AnimationNodeBlendTreeEditor::_popup_request));
|
2018-06-19 03:10:48 +02:00
|
|
|
|
|
|
|
VSeparator *vs = memnew(VSeparator);
|
|
|
|
graph->get_zoom_hbox()->add_child(vs);
|
|
|
|
graph->get_zoom_hbox()->move_child(vs, 0);
|
|
|
|
|
|
|
|
add_node = memnew(MenuButton);
|
|
|
|
graph->get_zoom_hbox()->add_child(add_node);
|
2019-01-07 16:57:52 +01:00
|
|
|
add_node->set_text(TTR("Add Node..."));
|
2018-06-19 03:10:48 +02:00
|
|
|
graph->get_zoom_hbox()->move_child(add_node, 0);
|
2020-02-21 18:28:45 +01:00
|
|
|
add_node->get_popup()->connect("id_pressed", callable_mp(this, &AnimationNodeBlendTreeEditor::_add_node));
|
2020-03-12 13:37:40 +01:00
|
|
|
add_node->connect("about_to_popup", callable_mp(this, &AnimationNodeBlendTreeEditor::_update_options_menu));
|
2018-06-21 20:45:44 +02:00
|
|
|
|
2018-06-19 03:10:48 +02:00
|
|
|
add_options.push_back(AddOption("Animation", "AnimationNodeAnimation"));
|
|
|
|
add_options.push_back(AddOption("OneShot", "AnimationNodeOneShot"));
|
2018-06-28 01:50:25 +02:00
|
|
|
add_options.push_back(AddOption("Add2", "AnimationNodeAdd2"));
|
|
|
|
add_options.push_back(AddOption("Add3", "AnimationNodeAdd3"));
|
2018-06-19 03:10:48 +02:00
|
|
|
add_options.push_back(AddOption("Blend2", "AnimationNodeBlend2"));
|
|
|
|
add_options.push_back(AddOption("Blend3", "AnimationNodeBlend3"));
|
|
|
|
add_options.push_back(AddOption("Seek", "AnimationNodeTimeSeek"));
|
|
|
|
add_options.push_back(AddOption("TimeScale", "AnimationNodeTimeScale"));
|
|
|
|
add_options.push_back(AddOption("Transition", "AnimationNodeTransition"));
|
|
|
|
add_options.push_back(AddOption("BlendTree", "AnimationNodeBlendTree"));
|
2018-06-22 17:13:43 +02:00
|
|
|
add_options.push_back(AddOption("BlendSpace1D", "AnimationNodeBlendSpace1D"));
|
2018-06-22 15:17:54 +02:00
|
|
|
add_options.push_back(AddOption("BlendSpace2D", "AnimationNodeBlendSpace2D"));
|
2018-06-25 21:21:57 +02:00
|
|
|
add_options.push_back(AddOption("StateMachine", "AnimationNodeStateMachine"));
|
2018-06-19 03:10:48 +02:00
|
|
|
_update_options_menu();
|
|
|
|
|
|
|
|
error_panel = memnew(PanelContainer);
|
|
|
|
add_child(error_panel);
|
|
|
|
error_label = memnew(Label);
|
|
|
|
error_panel->add_child(error_label);
|
|
|
|
error_label->set_text("eh");
|
|
|
|
|
|
|
|
filter_dialog = memnew(AcceptDialog);
|
|
|
|
add_child(filter_dialog);
|
|
|
|
filter_dialog->set_title(TTR("Edit Filtered Tracks:"));
|
|
|
|
|
|
|
|
VBoxContainer *filter_vbox = memnew(VBoxContainer);
|
|
|
|
filter_dialog->add_child(filter_vbox);
|
|
|
|
|
|
|
|
filter_enabled = memnew(CheckBox);
|
2019-03-25 01:54:29 +01:00
|
|
|
filter_enabled->set_text(TTR("Enable Filtering"));
|
2020-02-21 18:28:45 +01:00
|
|
|
filter_enabled->connect("pressed", callable_mp(this, &AnimationNodeBlendTreeEditor::_filter_toggled));
|
2018-06-19 03:10:48 +02:00
|
|
|
filter_vbox->add_child(filter_enabled);
|
|
|
|
|
|
|
|
filters = memnew(Tree);
|
|
|
|
filter_vbox->add_child(filters);
|
|
|
|
filters->set_v_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
filters->set_hide_root(true);
|
2020-02-21 18:28:45 +01:00
|
|
|
filters->connect("item_edited", callable_mp(this, &AnimationNodeBlendTreeEditor::_filter_edited));
|
2018-06-19 03:10:48 +02:00
|
|
|
|
2018-08-20 18:38:18 +02:00
|
|
|
open_file = memnew(EditorFileDialog);
|
|
|
|
add_child(open_file);
|
|
|
|
open_file->set_title(TTR("Open Animation Node"));
|
2020-03-06 18:00:16 +01:00
|
|
|
open_file->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
|
2020-02-21 18:28:45 +01:00
|
|
|
open_file->connect("file_selected", callable_mp(this, &AnimationNodeBlendTreeEditor::_file_opened));
|
2019-06-26 15:08:25 +02:00
|
|
|
undo_redo = EditorNode::get_undo_redo();
|
2018-06-19 03:10:48 +02:00
|
|
|
}
|