2014-02-10 01:10:30 +00:00
|
|
|
#include "animation_tree_editor_plugin.h"
|
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
#include "animation_blend_space_1d_editor.h"
|
|
|
|
#include "animation_blend_space_2d_editor.h"
|
|
|
|
#include "animation_blend_tree_editor_plugin.h"
|
|
|
|
#include "animation_state_machine_editor.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "core/io/resource_loader.h"
|
2017-07-21 11:57:46 +00:00
|
|
|
#include "core/project_settings.h"
|
2018-08-20 16:38:18 +00:00
|
|
|
#include "math/delaunay.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "os/input.h"
|
|
|
|
#include "os/keyboard.h"
|
2018-08-20 16:38:18 +00:00
|
|
|
#include "scene/animation/animation_blend_tree.h"
|
|
|
|
#include "scene/animation/animation_player.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "scene/gui/menu_button.h"
|
|
|
|
#include "scene/gui/panel.h"
|
|
|
|
#include "scene/main/viewport.h"
|
2018-08-20 16:38:18 +00:00
|
|
|
#include "scene/scene_string_names.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
void AnimationTreeEditor::edit(AnimationTree *p_tree) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
if (tree == p_tree)
|
|
|
|
return;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
tree = p_tree;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
Vector<String> path;
|
|
|
|
if (tree->has_meta("_tree_edit_path")) {
|
|
|
|
path = tree->get_meta("_tree_edit_path");
|
|
|
|
edit_path(path);
|
|
|
|
} else {
|
|
|
|
current_root = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
void AnimationTreeEditor::_path_button_pressed(int p_path) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
Ref<AnimationNode> node = tree->get_tree_root();
|
|
|
|
if (node.is_null())
|
|
|
|
return;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
edited_path.clear();
|
|
|
|
if (p_path >= 0) {
|
|
|
|
for (int i = 0; i <= p_path; i++) {
|
|
|
|
Ref<AnimationNode> child = node->get_child_by_name(button_path[i]);
|
|
|
|
ERR_BREAK(child.is_null());
|
|
|
|
node = child;
|
|
|
|
edited_path.push_back(button_path[i]);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
for (int i = 0; i < editors.size(); i++) {
|
|
|
|
if (editors[i]->can_edit(node)) {
|
|
|
|
editors[i]->edit(node);
|
|
|
|
editors[i]->show();
|
|
|
|
} else {
|
|
|
|
editors[i]->edit(Ref<AnimationNode>());
|
|
|
|
editors[i]->hide();
|
2017-03-05 15:44:50 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
void AnimationTreeEditor::_update_path() {
|
|
|
|
while (path_hb->get_child_count()) {
|
|
|
|
memdelete(path_hb->get_child(0));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
Ref<ButtonGroup> group;
|
|
|
|
group.instance();
|
|
|
|
|
|
|
|
Button *b = memnew(Button);
|
|
|
|
b->set_text("root");
|
|
|
|
b->set_toggle_mode(true);
|
|
|
|
b->set_button_group(group);
|
|
|
|
b->set_pressed(true);
|
|
|
|
b->set_focus_mode(FOCUS_NONE);
|
|
|
|
b->connect("pressed", this, "_path_button_pressed", varray(-1));
|
|
|
|
path_hb->add_child(b);
|
|
|
|
for (int i = 0; i < button_path.size(); i++) {
|
|
|
|
b = memnew(Button);
|
|
|
|
b->set_text(button_path[i]);
|
|
|
|
b->set_toggle_mode(true);
|
|
|
|
b->set_button_group(group);
|
|
|
|
path_hb->add_child(b);
|
|
|
|
b->set_pressed(true);
|
|
|
|
b->set_focus_mode(FOCUS_NONE);
|
|
|
|
b->connect("pressed", this, "_path_button_pressed", varray(i));
|
2016-04-25 09:41:23 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
void AnimationTreeEditor::edit_path(const Vector<String> &p_path) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
button_path.clear();
|
2017-03-05 15:44:50 +00:00
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
Ref<AnimationNode> node = tree->get_tree_root();
|
2017-03-05 15:44:50 +00:00
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
if (node.is_valid()) {
|
|
|
|
current_root = node->get_instance_id();
|
2017-03-05 15:44:50 +00:00
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
for (int i = 0; i < p_path.size(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
Ref<AnimationNode> child = node->get_child_by_name(p_path[i]);
|
|
|
|
ERR_BREAK(child.is_null());
|
|
|
|
node = child;
|
|
|
|
button_path.push_back(p_path[i]);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
for (int i = 0; i < editors.size(); i++) {
|
|
|
|
if (editors[i]->can_edit(node)) {
|
|
|
|
editors[i]->edit(node);
|
|
|
|
editors[i]->show();
|
|
|
|
} else {
|
|
|
|
editors[i]->edit(Ref<AnimationNode>());
|
|
|
|
editors[i]->hide();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2018-08-20 16:38:18 +00:00
|
|
|
current_root = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
edited_path = button_path;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
_update_path();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
Vector<String> AnimationTreeEditor::get_edited_path() const {
|
|
|
|
return button_path;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
void AnimationTreeEditor::enter_editor(const String &p_path) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
Vector<String> path = edited_path;
|
|
|
|
path.push_back(p_path);
|
|
|
|
edit_path(path);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
void AnimationTreeEditor::_about_to_show_root() {
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationTreeEditor::_notification(int p_what) {
|
2018-08-20 16:38:18 +00:00
|
|
|
if (p_what == NOTIFICATION_PROCESS) {
|
|
|
|
ObjectID root = 0;
|
|
|
|
if (tree && tree->get_tree_root().is_valid()) {
|
|
|
|
root = tree->get_tree_root()->get_instance_id();
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
if (root != current_root) {
|
|
|
|
edit_path(Vector<String>());
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
void AnimationTreeEditor::_bind_methods() {
|
|
|
|
ClassDB::bind_method("_path_button_pressed", &AnimationTreeEditor::_path_button_pressed);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
AnimationTreeEditor *AnimationTreeEditor::singleton = NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
void AnimationTreeEditor::add_plugin(AnimationTreeNodeEditorPlugin *p_editor) {
|
|
|
|
ERR_FAIL_COND(p_editor->get_parent());
|
|
|
|
editor_base->add_child(p_editor);
|
|
|
|
editors.push_back(p_editor);
|
|
|
|
p_editor->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
p_editor->set_v_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
p_editor->hide();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
void AnimationTreeEditor::remove_plugin(AnimationTreeNodeEditorPlugin *p_editor) {
|
|
|
|
ERR_FAIL_COND(p_editor->get_parent() != editor_base);
|
|
|
|
editor_base->remove_child(p_editor);
|
|
|
|
editors.erase(p_editor);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
String AnimationTreeEditor::get_base_path() {
|
|
|
|
String path = SceneStringNames::get_singleton()->parameters_base_path;
|
|
|
|
for (int i = 0; i < edited_path.size(); i++) {
|
|
|
|
path += edited_path[i] + "/";
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2018-08-20 16:38:18 +00:00
|
|
|
return path;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
bool AnimationTreeEditor::can_edit(const Ref<AnimationNode> &p_node) const {
|
|
|
|
for (int i = 0; i < editors.size(); i++) {
|
|
|
|
if (editors[i]->can_edit(p_node)) {
|
|
|
|
return true;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-20 16:38:18 +00:00
|
|
|
return false;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
Vector<String> AnimationTreeEditor::get_animation_list() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
if (!singleton->is_visible()) {
|
|
|
|
return Vector<String>();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
AnimationTree *tree = singleton->tree;
|
|
|
|
if (!tree || !tree->has_node(tree->get_animation_player()))
|
|
|
|
return Vector<String>();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(tree->get_node(tree->get_animation_player()));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
if (!ap)
|
|
|
|
return Vector<String>();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
List<StringName> anims;
|
|
|
|
ap->get_animation_list(&anims);
|
|
|
|
Vector<String> ret;
|
|
|
|
for (List<StringName>::Element *E = anims.front(); E; E = E->next()) {
|
|
|
|
ret.push_back(E->get());
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
return ret;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AnimationTreeEditor::AnimationTreeEditor() {
|
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
AnimationNodeAnimation::get_editable_animation_list = get_animation_list;
|
|
|
|
path_edit = memnew(ScrollContainer);
|
|
|
|
add_child(path_edit);
|
|
|
|
path_edit->set_enable_h_scroll(true);
|
|
|
|
path_edit->set_enable_v_scroll(false);
|
|
|
|
path_hb = memnew(HBoxContainer);
|
|
|
|
path_edit->add_child(path_hb);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
current_root = 0;
|
|
|
|
singleton = this;
|
|
|
|
editor_base = memnew(PanelContainer);
|
|
|
|
editor_base->set_v_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
add_child(editor_base);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
add_plugin(memnew(AnimationNodeBlendTreeEditor));
|
|
|
|
add_plugin(memnew(AnimationNodeBlendSpace1DEditor));
|
|
|
|
add_plugin(memnew(AnimationNodeBlendSpace2DEditor));
|
|
|
|
add_plugin(memnew(AnimationNodeStateMachineEditor));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationTreeEditorPlugin::edit(Object *p_object) {
|
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
anim_tree_editor->edit(Object::cast_to<AnimationTree>(p_object));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AnimationTreeEditorPlugin::handles(Object *p_object) const {
|
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
return p_object->is_class("AnimationTree");
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationTreeEditorPlugin::make_visible(bool p_visible) {
|
|
|
|
|
|
|
|
if (p_visible) {
|
2017-01-14 11:26:56 +00:00
|
|
|
//editor->hide_animation_player_editors();
|
|
|
|
//editor->animation_panel_make_visible(true);
|
2016-01-17 23:03:57 +00:00
|
|
|
button->show();
|
|
|
|
editor->make_bottom_panel_item_visible(anim_tree_editor);
|
2018-08-20 16:38:18 +00:00
|
|
|
anim_tree_editor->set_process(true);
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
|
|
|
|
2017-01-13 13:45:50 +00:00
|
|
|
if (anim_tree_editor->is_visible_in_tree())
|
2016-01-17 23:03:57 +00:00
|
|
|
editor->hide_bottom_panel();
|
|
|
|
button->hide();
|
2018-08-20 16:38:18 +00:00
|
|
|
anim_tree_editor->set_process(false);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AnimationTreeEditorPlugin::AnimationTreeEditorPlugin(EditorNode *p_node) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
editor = p_node;
|
|
|
|
anim_tree_editor = memnew(AnimationTreeEditor);
|
|
|
|
anim_tree_editor->set_custom_minimum_size(Size2(0, 300));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-12-23 14:40:15 +00:00
|
|
|
button = editor->add_bottom_panel_item(TTR("AnimationTree"), anim_tree_editor);
|
2016-01-17 23:03:57 +00:00
|
|
|
button->hide();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
AnimationTreeEditorPlugin::~AnimationTreeEditorPlugin() {
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|