Skip to content

Commit

Permalink
-Added AnimationGraphPlayer (still missing features)
Browse files Browse the repository at this point in the history
-Added ability to edit resources from built-in inspector (wip, needs testing and feedback)
  • Loading branch information
reduz committed Jun 19, 2018
1 parent 5c5aafa commit 0a1c1c6
Show file tree
Hide file tree
Showing 25 changed files with 4,043 additions and 49 deletions.
1 change: 0 additions & 1 deletion core/resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ Ref<Resource> Resource::duplicate_for_local_scene(Node *p_for_scene, Map<Ref<Res

void Resource::configure_for_local_scene(Node *p_for_scene, Map<Ref<Resource>, Ref<Resource> > &remap_cache) {

print_line("configure for local: " + get_class());
List<PropertyInfo> plist;
get_property_list(&plist);

Expand Down
23 changes: 22 additions & 1 deletion editor/editor_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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())
Expand Down
6 changes: 5 additions & 1 deletion editor/editor_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class EditorHistory {
REF ref;
ObjectID object;
String property;
bool inspector_only;
};

struct History {
Expand All @@ -70,25 +71,28 @@ 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();

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);

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;
Expand Down
9 changes: 9 additions & 0 deletions editor/editor_inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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<String> p_paths, Array p_values) {

ERR_FAIL_COND(p_paths.size() == 0 || p_values.size() == 0);
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions editor/editor_inspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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);
Expand Down
97 changes: 62 additions & 35 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<EditorPlugin *> 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);
Expand All @@ -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);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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<EditorPlugin *> sub_plugins = editor_data.get_subeditors(current_obj);
Vector<EditorPlugin *> 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);
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion editor/editor_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
36 changes: 33 additions & 3 deletions editor/editor_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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()) {
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions editor/editor_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ class EditorPropertyResource : public EditorProperty {
EditorFileDialog *file;
Vector<String> inheritors_array;
EditorInspector *sub_inspector;
VBoxContainer *sub_inspector_vbox;

bool use_sub_inspector;
bool dropping;
Expand All @@ -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);
Expand Down
Loading

1 comment on commit 0a1c1c6

@mysticfall
Copy link
Contributor

@mysticfall mysticfall commented on 0a1c1c6 Jun 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know any C++ to review this, but just wanted to say I can't wait to test it out, as I really need a better alternative to current AnimationTreePlayer 👍 Thanks!

Please sign in to comment.