From 0a1c1c660fc6aa0689816e85f2b6791c225c6d63 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Mon, 18 Jun 2018 22:10:48 -0300 Subject: [PATCH] -Added AnimationGraphPlayer (still missing features) -Added ability to edit resources from built-in inspector (wip, needs testing and feedback) --- core/resource.cpp | 1 - editor/editor_data.cpp | 23 +- editor/editor_data.h | 6 +- editor/editor_inspector.cpp | 9 + editor/editor_inspector.h | 1 + editor/editor_node.cpp | 97 +- editor/editor_node.h | 4 +- editor/editor_properties.cpp | 36 +- editor/editor_properties.h | 3 + editor/editor_themes.cpp | 1 + .../animation_blend_tree_editor_plugin.cpp | 829 ++++++++++++ .../animation_blend_tree_editor_plugin.h | 115 ++ scene/animation/animation_blend_tree.cpp | 1105 +++++++++++++++ scene/animation/animation_blend_tree.h | 328 +++++ scene/animation/animation_graph_player.cpp | 1194 +++++++++++++++++ scene/animation/animation_graph_player.h | 261 ++++ scene/animation/animation_player.cpp | 2 + scene/gui/graph_edit.cpp | 33 +- scene/gui/graph_edit.h | 8 + scene/gui/line_edit.cpp | 10 +- scene/gui/progress_bar.cpp | 6 +- scene/register_scene_types.cpp | 15 + .../resources/default_theme/default_theme.cpp | 1 + scene/scene_string_names.cpp | 2 + scene/scene_string_names.h | 2 + 25 files changed, 4043 insertions(+), 49 deletions(-) create mode 100644 editor/plugins/animation_blend_tree_editor_plugin.cpp create mode 100644 editor/plugins/animation_blend_tree_editor_plugin.h create mode 100644 scene/animation/animation_blend_tree.cpp create mode 100644 scene/animation/animation_blend_tree.h create mode 100644 scene/animation/animation_graph_player.cpp create mode 100644 scene/animation/animation_graph_player.h diff --git a/core/resource.cpp b/core/resource.cpp index 179333aa14cd..f100f4447b03 100644 --- a/core/resource.cpp +++ b/core/resource.cpp @@ -187,7 +187,6 @@ Ref Resource::duplicate_for_local_scene(Node *p_for_scene, Map, Ref > &remap_cache) { - print_line("configure for local: " + get_class()); List plist; get_property_list(&plist); diff --git a/editor/editor_data.cpp b/editor/editor_data.cpp index d41d5c929a17..4dde893c6df7 100644 --- a/editor/editor_data.cpp +++ b/editor/editor_data.cpp @@ -78,7 +78,7 @@ void EditorHistory::cleanup_history() { current = history.size() - 1; } -void EditorHistory::_add_object(ObjectID p_object, const String &p_property, int p_level_change) { +void EditorHistory::_add_object(ObjectID p_object, const String &p_property, int p_level_change, bool p_inspector_only) { Object *obj = ObjectDB::get_instance(p_object); ERR_FAIL_COND(!obj); @@ -88,6 +88,7 @@ void EditorHistory::_add_object(ObjectID p_object, const String &p_property, int o.ref = REF(r); o.object = p_object; o.property = p_property; + o.inspector_only = p_inspector_only; History h; @@ -120,6 +121,11 @@ void EditorHistory::_add_object(ObjectID p_object, const String &p_property, int current++; } +void EditorHistory::add_object_inspector_only(ObjectID p_object) { + + _add_object(p_object, "", -1, true); +} + void EditorHistory::add_object(ObjectID p_object) { _add_object(p_object, "", -1); @@ -142,6 +148,13 @@ int EditorHistory::get_history_pos() { return current; } +bool EditorHistory::is_history_obj_inspector_only(int p_obj) const { + + ERR_FAIL_INDEX_V(p_obj, history.size(), false); + ERR_FAIL_INDEX_V(history[p_obj].level, history[p_obj].path.size(), false); + return history[p_obj].path[history[p_obj].level].inspector_only; +} + ObjectID EditorHistory::get_history_obj(int p_obj) const { ERR_FAIL_INDEX_V(p_obj, history.size(), 0); ERR_FAIL_INDEX_V(history[p_obj].level, history[p_obj].path.size(), 0); @@ -180,6 +193,14 @@ bool EditorHistory::previous() { return true; } +bool EditorHistory::is_current_inspector_only() const { + + if (current < 0 || current >= history.size()) + return false; + + const History &h = history[current]; + return h.path[h.level].inspector_only; +} ObjectID EditorHistory::get_current() { if (current < 0 || current >= history.size()) diff --git a/editor/editor_data.h b/editor/editor_data.h index 0452867bf4f0..0ecef8ae31c5 100644 --- a/editor/editor_data.h +++ b/editor/editor_data.h @@ -50,6 +50,7 @@ class EditorHistory { REF ref; ObjectID object; String property; + bool inspector_only; }; struct History { @@ -70,7 +71,7 @@ class EditorHistory { Variant value; }; - void _add_object(ObjectID p_object, const String &p_property, int p_level_change); + void _add_object(ObjectID p_object, const String &p_property, int p_level_change, bool p_inspector_only = false); public: void cleanup_history(); @@ -78,6 +79,7 @@ class EditorHistory { bool is_at_beginning() const; bool is_at_end() const; + void add_object_inspector_only(ObjectID p_object); void add_object(ObjectID p_object); void add_object(ObjectID p_object, const String &p_subprop); void add_object(ObjectID p_object, int p_relevel); @@ -85,10 +87,12 @@ class EditorHistory { int get_history_len(); int get_history_pos(); ObjectID get_history_obj(int p_obj) const; + bool is_history_obj_inspector_only(int p_obj) const; bool next(); bool previous(); ObjectID get_current(); + bool is_current_inspector_only() const; int get_path_size() const; ObjectID get_path_object(int p_index) const; diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 848e0b30daf3..9a3174fb1a83 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -1477,6 +1477,9 @@ void EditorInspector::update_tree() { ep->object = object; ep->connect("property_changed", this, "_property_changed"); + if (p.usage & PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED) { + ep->connect("property_changed", this, "_property_changed_update_all", varray(), CONNECT_DEFERRED); + } ep->connect("property_keyed", this, "_property_keyed"); ep->connect("property_keyed_with_value", this, "_property_keyed_with_value"); ep->connect("property_checked", this, "_property_checked"); @@ -1782,6 +1785,10 @@ void EditorInspector::_property_changed(const String &p_path, const Variant &p_v _edit_set(p_path, p_value, false, ""); } +void EditorInspector::_property_changed_update_all(const String &p_path, const Variant &p_value) { + update_tree(); +} + void EditorInspector::_multiple_properties_changed(Vector p_paths, Array p_values) { ERR_FAIL_COND(p_paths.size() == 0 || p_values.size() == 0); @@ -1951,6 +1958,8 @@ void EditorInspector::_bind_methods() { ClassDB::bind_method("_multiple_properties_changed", &EditorInspector::_multiple_properties_changed); ClassDB::bind_method("_property_changed", &EditorInspector::_property_changed); + ClassDB::bind_method("_property_changed_update_all", &EditorInspector::_property_changed_update_all); + ClassDB::bind_method("_edit_request_change", &EditorInspector::_edit_request_change); ClassDB::bind_method("_node_removed", &EditorInspector::_node_removed); ClassDB::bind_method("_filter_changed", &EditorInspector::_filter_changed); diff --git a/editor/editor_inspector.h b/editor/editor_inspector.h index 06426a30e6ba..2a88be656a10 100644 --- a/editor/editor_inspector.h +++ b/editor/editor_inspector.h @@ -257,6 +257,7 @@ class EditorInspector : public ScrollContainer { void _edit_set(const String &p_name, const Variant &p_value, bool p_refresh_all, const String &p_changed_field); void _property_changed(const String &p_path, const Variant &p_value); + void _property_changed_update_all(const String &p_path, const Variant &p_value); void _multiple_properties_changed(Vector p_paths, Array p_values); void _property_keyed(const String &p_path); void _property_keyed_with_value(const String &p_path, const Variant &p_value); diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 72a7ce353413..a34aebc63a4b 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -66,6 +66,7 @@ #include "editor/import/resource_importer_scene.h" #include "editor/import/resource_importer_texture.h" #include "editor/import/resource_importer_wav.h" +#include "editor/plugins/animation_blend_tree_editor_plugin.h" #include "editor/plugins/animation_player_editor_plugin.h" #include "editor/plugins/animation_tree_editor_plugin.h" #include "editor/plugins/asset_library_editor_plugin.h" @@ -1300,7 +1301,25 @@ void EditorNode::_dialog_action(String p_file) { } } -void EditorNode::push_item(Object *p_object, const String &p_property) { +bool EditorNode::item_has_editor(Object *p_object) { + + return editor_data.get_subeditors(p_object).size() > 0; +} + +void EditorNode::edit_item(Object *p_object) { + + Vector sub_plugins = editor_data.get_subeditors(p_object); + + if (!sub_plugins.empty()) { + _display_top_editors(false); + + _set_top_editors(sub_plugins); + _set_editing_top_editors(p_object); + _display_top_editors(true); + } +} + +void EditorNode::push_item(Object *p_object, const String &p_property, bool p_inspector_only) { if (!p_object) { get_inspector()->edit(NULL); @@ -1312,7 +1331,9 @@ void EditorNode::push_item(Object *p_object, const String &p_property) { uint32_t id = p_object->get_instance_id(); if (id != editor_history.get_current()) { - if (p_property == "") + if (p_inspector_only) { + editor_history.add_object_inspector_only(id); + } else if (p_property == "") editor_history.add_object(id); else editor_history.add_object(id, p_property); @@ -1366,6 +1387,7 @@ void EditorNode::_edit_current() { uint32_t current = editor_history.get_current(); Object *current_obj = current > 0 ? ObjectDB::get_instance(current) : NULL; + bool inspector_only = editor_history.is_current_inspector_only(); this->current = current_obj; @@ -1457,57 +1479,60 @@ void EditorNode::_edit_current() { /* Take care of PLUGIN EDITOR */ - EditorPlugin *main_plugin = editor_data.get_editor(current_obj); + if (!inspector_only) { - if (main_plugin) { + EditorPlugin *main_plugin = editor_data.get_editor(current_obj); - // special case if use of external editor is true - if (main_plugin->get_name() == "Script" && (bool(EditorSettings::get_singleton()->get("text_editor/external/use_external_editor")) || overrides_external_editor(current_obj))) { - if (!changing_scene) - main_plugin->edit(current_obj); - } + if (main_plugin) { - else if (main_plugin != editor_plugin_screen && (!ScriptEditor::get_singleton() || !ScriptEditor::get_singleton()->is_visible_in_tree() || ScriptEditor::get_singleton()->can_take_away_focus())) { - // update screen main_plugin + // special case if use of external editor is true + if (main_plugin->get_name() == "Script" && (bool(EditorSettings::get_singleton()->get("text_editor/external/use_external_editor")) || overrides_external_editor(current_obj))) { + if (!changing_scene) + main_plugin->edit(current_obj); + } - if (!changing_scene) { + else if (main_plugin != editor_plugin_screen && (!ScriptEditor::get_singleton() || !ScriptEditor::get_singleton()->is_visible_in_tree() || ScriptEditor::get_singleton()->can_take_away_focus())) { + // update screen main_plugin - if (editor_plugin_screen) - editor_plugin_screen->make_visible(false); - editor_plugin_screen = main_plugin; - editor_plugin_screen->edit(current_obj); + if (!changing_scene) { - editor_plugin_screen->make_visible(true); + if (editor_plugin_screen) + editor_plugin_screen->make_visible(false); + editor_plugin_screen = main_plugin; + editor_plugin_screen->edit(current_obj); - int plugin_count = editor_data.get_editor_plugin_count(); - for (int i = 0; i < plugin_count; i++) { - editor_data.get_editor_plugin(i)->notify_main_screen_changed(editor_plugin_screen->get_name()); - } + editor_plugin_screen->make_visible(true); + + int plugin_count = editor_data.get_editor_plugin_count(); + for (int i = 0; i < plugin_count; i++) { + editor_data.get_editor_plugin(i)->notify_main_screen_changed(editor_plugin_screen->get_name()); + } - for (int i = 0; i < editor_table.size(); i++) { + for (int i = 0; i < editor_table.size(); i++) { - main_editor_buttons[i]->set_pressed(editor_table[i] == main_plugin); + main_editor_buttons[i]->set_pressed(editor_table[i] == main_plugin); + } } - } - } else { + } else { - editor_plugin_screen->edit(current_obj); + editor_plugin_screen->edit(current_obj); + } } - } - Vector sub_plugins = editor_data.get_subeditors(current_obj); + Vector sub_plugins = editor_data.get_subeditors(current_obj); - if (!sub_plugins.empty()) { - _display_top_editors(false); + if (!sub_plugins.empty()) { + _display_top_editors(false); - _set_top_editors(sub_plugins); - _set_editing_top_editors(current_obj); - _display_top_editors(true); + _set_top_editors(sub_plugins); + _set_editing_top_editors(current_obj); + _display_top_editors(true); - } else if (!editor_plugins_over->get_plugins_list().empty()) { + } else if (!editor_plugins_over->get_plugins_list().empty()) { - _hide_top_editors(); + _hide_top_editors(); + } } inspector_dock->update(current_obj); @@ -5346,6 +5371,8 @@ EditorNode::EditorNode() { add_editor_plugin(memnew(SpatialEditorPlugin(this))); add_editor_plugin(memnew(ScriptEditorPlugin(this))); + add_editor_plugin(memnew(AnimationNodeBlendTreeEditorPlugin(this))); + EditorAudioBuses *audio_bus_editor = EditorAudioBuses::register_editor(); ScriptTextEditor::register_editor(); //register one for text scripts diff --git a/editor/editor_node.h b/editor/editor_node.h index a441440dccac..dedd947633d7 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -634,7 +634,9 @@ class EditorNode : public Node { static HBoxContainer *get_menu_hb() { return singleton->menu_hb; } - void push_item(Object *p_object, const String &p_property = ""); + void push_item(Object *p_object, const String &p_property = "", bool p_inspector_only = false); + void edit_item(Object *p_object); + bool item_has_editor(Object *p_object); void open_request(const String &p_path); diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index c50187aa02df..5abcae80e08b 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -1986,6 +1986,13 @@ void EditorPropertyResource::_sub_inspector_object_id_selected(int p_id) { emit_signal("object_id_selected", get_edited_property(), p_id); } +void EditorPropertyResource::_open_editor_pressed() { + RES res = get_edited_object()->get(get_edited_property()); + if (res.is_valid()) { + EditorNode::get_singleton()->edit_item(res.ptr()); + } +} + void EditorPropertyResource::update_property() { RES res = get_edited_object()->get(get_edited_property()); @@ -2009,9 +2016,29 @@ void EditorPropertyResource::update_property() { sub_inspector->set_read_only(is_read_only()); sub_inspector->set_use_folding(is_using_folding()); - add_child(sub_inspector); - set_bottom_editor(sub_inspector); + sub_inspector_vbox = memnew(VBoxContainer); + add_child(sub_inspector_vbox); + set_bottom_editor(sub_inspector_vbox); + + sub_inspector_vbox->add_child(sub_inspector); assign->set_pressed(true); + + bool use_editor = false; + for (int i = 0; i < EditorNode::get_singleton()->get_editor_data().get_editor_plugin_count(); i++) { + EditorPlugin *ep = EditorNode::get_singleton()->get_editor_data().get_editor_plugin(i); + if (ep->handles(res.ptr())) { + use_editor = true; + } + } + + if (use_editor) { + Button *open_in_editor = memnew(Button); + open_in_editor->set_text(TTR("Open Editor")); + open_in_editor->set_icon(get_icon("Edit", "EditorIcons")); + sub_inspector_vbox->add_child(open_in_editor); + open_in_editor->connect("pressed", this, "_open_editor_pressed"); + open_in_editor->set_h_size_flags(SIZE_SHRINK_CENTER); + } } if (res.ptr() != sub_inspector->get_edited_object()) { @@ -2021,8 +2048,9 @@ void EditorPropertyResource::update_property() { } else { if (sub_inspector) { set_bottom_editor(NULL); - memdelete(sub_inspector); + memdelete(sub_inspector_vbox); sub_inspector = NULL; + sub_inspector_vbox = NULL; } } #endif @@ -2242,11 +2270,13 @@ void EditorPropertyResource::_bind_methods() { ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &EditorPropertyResource::can_drop_data_fw); ClassDB::bind_method(D_METHOD("drop_data_fw"), &EditorPropertyResource::drop_data_fw); ClassDB::bind_method(D_METHOD("_button_draw"), &EditorPropertyResource::_button_draw); + ClassDB::bind_method(D_METHOD("_open_editor_pressed"), &EditorPropertyResource::_open_editor_pressed); } EditorPropertyResource::EditorPropertyResource() { sub_inspector = NULL; + sub_inspector_vbox = NULL; use_sub_inspector = !bool(EDITOR_GET("interface/inspector/open_resources_in_new_inspector")); HBoxContainer *hbc = memnew(HBoxContainer); add_child(hbc); diff --git a/editor/editor_properties.h b/editor/editor_properties.h index 03e72b4ec21f..734ca2de8200 100644 --- a/editor/editor_properties.h +++ b/editor/editor_properties.h @@ -491,6 +491,7 @@ class EditorPropertyResource : public EditorProperty { EditorFileDialog *file; Vector inheritors_array; EditorInspector *sub_inspector; + VBoxContainer *sub_inspector_vbox; bool use_sub_inspector; bool dropping; @@ -516,6 +517,8 @@ class EditorPropertyResource : public EditorProperty { bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const; void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from); + void _open_editor_pressed(); + protected: static void _bind_methods(); void _notification(int p_what); diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp index 30d439b1c1e4..78aa3da54630 100644 --- a/editor/editor_themes.cpp +++ b/editor/editor_themes.cpp @@ -948,6 +948,7 @@ Ref create_editor_theme(const Ref p_theme) { theme->set_stylebox("bg", "GraphEdit", style_tree_bg); theme->set_color("grid_major", "GraphEdit", grid_major_color); theme->set_color("grid_minor", "GraphEdit", grid_minor_color); + theme->set_color("activity", "GraphEdit", accent_color); theme->set_icon("minus", "GraphEdit", theme->get_icon("ZoomLess", "EditorIcons")); theme->set_icon("more", "GraphEdit", theme->get_icon("ZoomMore", "EditorIcons")); theme->set_icon("reset", "GraphEdit", theme->get_icon("ZoomReset", "EditorIcons")); diff --git a/editor/plugins/animation_blend_tree_editor_plugin.cpp b/editor/plugins/animation_blend_tree_editor_plugin.cpp new file mode 100644 index 000000000000..f466758917df --- /dev/null +++ b/editor/plugins/animation_blend_tree_editor_plugin.cpp @@ -0,0 +1,829 @@ +#include "animation_blend_tree_editor_plugin.h" + +#include "core/io/resource_loader.h" +#include "core/project_settings.h" +#include "os/input.h" +#include "os/keyboard.h" +#include "scene/animation/animation_player.h" +#include "scene/gui/menu_button.h" +#include "scene/gui/panel.h" +#include "scene/main/viewport.h" + +void AnimationNodeBlendTreeEditor::edit(AnimationNodeBlendTree *p_blend_tree) { + + blend_tree = p_blend_tree; + + if (!blend_tree) { + hide(); + } else { + _update_graph(); + } +} + +void AnimationNodeBlendTreeEditor::add_custom_type(const String &p_name, const Ref