2018-08-29 20:38:13 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
/* animation_tree_editor_plugin.cpp */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/**************************************************************************/
|
|
|
|
|
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"
|
2024-02-07 23:08:07 +00:00
|
|
|
#include "editor/editor_command_palette.h"
|
2022-02-12 01:46:22 +00:00
|
|
|
#include "editor/editor_node.h"
|
2024-01-30 22:22:22 +00:00
|
|
|
#include "editor/gui/editor_bottom_panel.h"
|
2024-01-15 12:14:55 +00:00
|
|
|
#include "editor/themes/editor_scale.h"
|
2018-08-20 16:38:18 +00:00
|
|
|
#include "scene/animation/animation_blend_tree.h"
|
2023-10-02 11:43:08 +00:00
|
|
|
#include "scene/gui/button.h"
|
2024-02-23 13:51:47 +00:00
|
|
|
#include "scene/gui/margin_container.h"
|
2023-10-02 11:43:08 +00:00
|
|
|
#include "scene/gui/scroll_container.h"
|
|
|
|
#include "scene/gui/separator.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
void AnimationTreeEditor::edit(AnimationTree *p_tree) {
|
2023-07-20 15:34:06 +00:00
|
|
|
if (p_tree && !p_tree->is_connected("animation_list_changed", callable_mp(this, &AnimationTreeEditor::_animation_list_changed))) {
|
|
|
|
p_tree->connect("animation_list_changed", callable_mp(this, &AnimationTreeEditor::_animation_list_changed), CONNECT_DEFERRED);
|
2022-09-01 14:00:55 +00:00
|
|
|
}
|
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (tree == p_tree) {
|
2018-08-20 16:38:18 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2023-07-20 15:34:06 +00:00
|
|
|
if (tree && tree->is_connected("animation_list_changed", callable_mp(this, &AnimationTreeEditor::_animation_list_changed))) {
|
|
|
|
tree->disconnect("animation_list_changed", callable_mp(this, &AnimationTreeEditor::_animation_list_changed));
|
2022-09-01 14:00:55 +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;
|
2023-01-25 14:27:16 +00:00
|
|
|
if (tree) {
|
|
|
|
edit_path(path);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-20 14:53:17 +00:00
|
|
|
void AnimationTreeEditor::_node_removed(Node *p_node) {
|
|
|
|
if (p_node == tree) {
|
|
|
|
tree = nullptr;
|
2022-12-12 18:00:11 +00:00
|
|
|
_clear_editors();
|
2022-11-20 14:53:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
void AnimationTreeEditor::_path_button_pressed(int p_path) {
|
|
|
|
edited_path.clear();
|
2018-12-17 19:08:41 +00:00
|
|
|
for (int i = 0; i <= p_path; i++) {
|
|
|
|
edited_path.push_back(button_path[i]);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-01 14:00:55 +00:00
|
|
|
void AnimationTreeEditor::_animation_list_changed() {
|
|
|
|
AnimationNodeBlendTreeEditor *bte = AnimationNodeBlendTreeEditor::get_singleton();
|
|
|
|
if (bte) {
|
|
|
|
bte->update_graph();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
void AnimationTreeEditor::_update_path() {
|
2018-12-18 01:52:14 +00:00
|
|
|
while (path_hb->get_child_count() > 1) {
|
|
|
|
memdelete(path_hb->get_child(1));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
Ref<ButtonGroup> group;
|
2021-06-17 22:03:09 +00:00
|
|
|
group.instantiate();
|
2018-08-20 16:38:18 +00:00
|
|
|
|
|
|
|
Button *b = memnew(Button);
|
2021-07-19 19:10:05 +00:00
|
|
|
b->set_text(TTR("Root"));
|
2018-08-20 16:38:18 +00:00
|
|
|
b->set_toggle_mode(true);
|
|
|
|
b->set_button_group(group);
|
|
|
|
b->set_pressed(true);
|
|
|
|
b->set_focus_mode(FOCUS_NONE);
|
2024-05-14 07:40:21 +00:00
|
|
|
b->connect(SceneStringName(pressed), callable_mp(this, &AnimationTreeEditor::_path_button_pressed).bind(-1));
|
2018-08-20 16:38:18 +00:00
|
|
|
path_hb->add_child(b);
|
|
|
|
for (int i = 0; i < button_path.size(); i++) {
|
|
|
|
b = memnew(Button);
|
2024-03-28 01:16:56 +00:00
|
|
|
b->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
|
2018-08-20 16:38:18 +00:00
|
|
|
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);
|
2024-05-14 07:40:21 +00:00
|
|
|
b->connect(SceneStringName(pressed), callable_mp(this, &AnimationTreeEditor::_path_button_pressed).bind(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) {
|
|
|
|
button_path.clear();
|
2017-03-05 15:44:50 +00:00
|
|
|
|
2023-07-20 15:34:06 +00:00
|
|
|
Ref<AnimationNode> node = tree->get_root_animation_node();
|
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++) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-07-11 18:18:53 +00:00
|
|
|
edited_path = button_path;
|
|
|
|
|
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 {
|
2020-02-12 17:24:06 +00:00
|
|
|
current_root = ObjectID();
|
2019-07-11 18:18:53 +00:00
|
|
|
edited_path = button_path;
|
2021-02-06 13:32:21 +00:00
|
|
|
for (int i = 0; i < editors.size(); i++) {
|
|
|
|
editors[i]->edit(Ref<AnimationNode>());
|
|
|
|
editors[i]->hide();
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2022-12-12 18:00:11 +00:00
|
|
|
void AnimationTreeEditor::_clear_editors() {
|
|
|
|
button_path.clear();
|
|
|
|
current_root = ObjectID();
|
|
|
|
edited_path = button_path;
|
|
|
|
for (int i = 0; i < editors.size(); i++) {
|
|
|
|
editors[i]->edit(Ref<AnimationNode>());
|
|
|
|
editors[i]->hide();
|
|
|
|
}
|
|
|
|
_update_path();
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
Vector<String> path = edited_path;
|
|
|
|
path.push_back(p_path);
|
|
|
|
edit_path(path);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationTreeEditor::_notification(int p_what) {
|
2022-02-16 02:44:22 +00:00
|
|
|
switch (p_what) {
|
2022-11-20 14:53:17 +00:00
|
|
|
case NOTIFICATION_ENTER_TREE: {
|
|
|
|
get_tree()->connect("node_removed", callable_mp(this, &AnimationTreeEditor::_node_removed));
|
|
|
|
} break;
|
2022-02-16 02:44:22 +00:00
|
|
|
case NOTIFICATION_PROCESS: {
|
|
|
|
ObjectID root;
|
2023-07-20 15:34:06 +00:00
|
|
|
if (tree && tree->get_root_animation_node().is_valid()) {
|
|
|
|
root = tree->get_root_animation_node()->get_instance_id();
|
2022-02-16 02:44:22 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2022-02-16 02:44:22 +00:00
|
|
|
if (root != current_root) {
|
|
|
|
edit_path(Vector<String>());
|
|
|
|
}
|
2018-12-17 19:08:41 +00:00
|
|
|
|
2022-02-16 02:44:22 +00:00
|
|
|
if (button_path.size() != edited_path.size()) {
|
|
|
|
edit_path(edited_path);
|
|
|
|
}
|
|
|
|
} break;
|
2022-11-20 14:53:17 +00:00
|
|
|
case NOTIFICATION_EXIT_TREE: {
|
|
|
|
get_tree()->disconnect("node_removed", callable_mp(this, &AnimationTreeEditor::_node_removed));
|
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-01 23:20:12 +00:00
|
|
|
AnimationTreeEditor *AnimationTreeEditor::singleton = nullptr;
|
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() {
|
2024-05-14 11:28:56 +00:00
|
|
|
String path = Animation::PARAMETERS_BASE_PATH;
|
2018-08-20 16:38:18 +00:00
|
|
|
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() {
|
2023-08-02 14:45:09 +00:00
|
|
|
if (!singleton->tree || !singleton->is_visible()) {
|
|
|
|
// When tree is empty, singleton not in the main thread.
|
2018-08-20 16:38:18 +00:00
|
|
|
return Vector<String>();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
AnimationTree *tree = singleton->tree;
|
2023-07-20 15:34:06 +00:00
|
|
|
if (!tree) {
|
2018-08-20 16:38:18 +00:00
|
|
|
return Vector<String>();
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
List<StringName> anims;
|
2023-07-20 15:34:06 +00:00
|
|
|
tree->get_animation_list(&anims);
|
2018-08-20 16:38:18 +00:00
|
|
|
Vector<String> ret;
|
2021-07-24 13:46:25 +00:00
|
|
|
for (const StringName &E : anims) {
|
2021-07-16 03:45:57 +00:00
|
|
|
ret.push_back(E);
|
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);
|
2021-12-08 23:25:17 +00:00
|
|
|
path_edit->set_vertical_scroll_mode(ScrollContainer::SCROLL_MODE_DISABLED);
|
2018-08-20 16:38:18 +00:00
|
|
|
path_hb = memnew(HBoxContainer);
|
|
|
|
path_edit->add_child(path_hb);
|
2018-12-18 01:52:14 +00:00
|
|
|
path_hb->add_child(memnew(Label(TTR("Path:"))));
|
|
|
|
|
|
|
|
add_child(memnew(HSeparator));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-08-20 16:38:18 +00:00
|
|
|
singleton = this;
|
2020-07-02 05:53:42 +00:00
|
|
|
editor_base = memnew(MarginContainer);
|
2018-08-20 16:38:18 +00:00
|
|
|
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();
|
2024-01-30 22:22:22 +00:00
|
|
|
EditorNode::get_bottom_panel()->make_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 {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (anim_tree_editor->is_visible_in_tree()) {
|
2024-01-30 22:22:22 +00:00
|
|
|
EditorNode::get_bottom_panel()->hide_bottom_panel();
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2016-01-17 23:03:57 +00:00
|
|
|
button->hide();
|
2018-08-20 16:38:18 +00:00
|
|
|
anim_tree_editor->set_process(false);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-27 09:36:51 +00:00
|
|
|
AnimationTreeEditorPlugin::AnimationTreeEditorPlugin() {
|
2014-02-10 01:10:30 +00:00
|
|
|
anim_tree_editor = memnew(AnimationTreeEditor);
|
2020-01-12 07:24:15 +00:00
|
|
|
anim_tree_editor->set_custom_minimum_size(Size2(0, 300) * EDSCALE);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2024-02-07 23:08:07 +00:00
|
|
|
button = EditorNode::get_bottom_panel()->add_item(TTR("AnimationTree"), anim_tree_editor, ED_SHORTCUT_AND_COMMAND("bottom_panels/toggle_animation_tree_bottom_panel", TTR("Toggle AnimationTree Bottom Panel")));
|
2016-01-17 23:03:57 +00:00
|
|
|
button->hide();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AnimationTreeEditorPlugin::~AnimationTreeEditorPlugin() {
|
|
|
|
}
|