diff options
author | Juan Linietsky <reduzio@gmail.com> | 2018-11-21 22:10:27 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2018-11-21 22:10:58 -0300 |
commit | a2a606794c7d29452a59eee1eab07213827654a0 (patch) | |
tree | 2008a901b6e52756dc91dbf2d4b62a39df7480a3 /editor | |
parent | 9e628264b68205f8d003223a5abff574389354ee (diff) |
Ensure array and dict editors show edited object IDs, fixes #20225
Diffstat (limited to 'editor')
-rw-r--r-- | editor/array_property_edit.cpp | 11 | ||||
-rw-r--r-- | editor/editor_properties_array_dict.cpp | 54 | ||||
-rw-r--r-- | editor/editor_properties_array_dict.h | 3 | ||||
-rw-r--r-- | editor/script_editor_debugger.cpp | 1 |
4 files changed, 62 insertions, 7 deletions
diff --git a/editor/array_property_edit.cpp b/editor/array_property_edit.cpp index a32a71262f..245c9273ff 100644 --- a/editor/array_property_edit.cpp +++ b/editor/array_property_edit.cpp @@ -30,6 +30,7 @@ #include "array_property_edit.h" +#include "core/io/marshalls.h" #include "editor_node.h" #define ITEMS_PER_PAGE 100 @@ -202,6 +203,11 @@ bool ArrayPropertyEdit::_get(const StringName &p_name, Variant &r_ret) const { int idx = pn.get_slicec('/', 1).to_int(); bool valid; r_ret = arr.get(idx, &valid); + + if (r_ret.get_type() == Variant::OBJECT && Object::cast_to<EncodedObjectAsID>(r_ret)) { + r_ret = Object::cast_to<EncodedObjectAsID>(r_ret)->get_object_id(); + } + return valid; } } @@ -232,6 +238,11 @@ void ArrayPropertyEdit::_get_property_list(List<PropertyInfo> *p_list) const { p_list->push_back(PropertyInfo(Variant::INT, "indices/" + itos(i + offset) + "_type", PROPERTY_HINT_ENUM, vtypes)); } + if (v.get_type() == Variant::OBJECT && Object::cast_to<EncodedObjectAsID>(v)) { + p_list->push_back(PropertyInfo(Variant::INT, "indices/" + itos(i + offset), PROPERTY_HINT_OBJECT_ID, "Object")); + continue; + } + if (is_typed || v.get_type() != Variant::NIL) { PropertyInfo pi(v.get_type(), "indices/" + itos(i + offset)); if (subtype != Variant::NIL) { diff --git a/editor/editor_properties_array_dict.cpp b/editor/editor_properties_array_dict.cpp index 24360813a2..431f608f46 100644 --- a/editor/editor_properties_array_dict.cpp +++ b/editor/editor_properties_array_dict.cpp @@ -29,9 +29,9 @@ /*************************************************************************/ #include "editor_properties_array_dict.h" +#include "core/io/marshalls.h" #include "editor/editor_scale.h" #include "editor_properties.h" - bool EditorPropertyArrayObject::_set(const StringName &p_name, const Variant &p_value) { String pn = p_name; @@ -54,6 +54,10 @@ bool EditorPropertyArrayObject::_get(const StringName &p_name, Variant &r_ret) c int idx = pn.get_slicec('/', 1).to_int(); bool valid; r_ret = array.get(idx, &valid); + if (r_ret.get_type() == Variant::OBJECT && Object::cast_to<EncodedObjectAsID>(r_ret)) { + r_ret = Object::cast_to<EncodedObjectAsID>(r_ret)->get_object_id(); + } + return valid; } @@ -120,6 +124,10 @@ bool EditorPropertyDictionaryObject::_get(const StringName &p_name, Variant &r_r int idx = pn.get_slicec('/', 1).to_int(); Variant key = dict.get_key_at_index(idx); r_ret = dict[key]; + if (r_ret.get_type() == Variant::OBJECT && Object::cast_to<EncodedObjectAsID>(r_ret)) { + r_ret = Object::cast_to<EncodedObjectAsID>(r_ret)->get_object_id(); + } + return true; } @@ -198,6 +206,10 @@ void EditorPropertyArray::_change_type_menu(int p_index) { update_property(); } +void EditorPropertyArray::_object_id_selected(const String &p_property, ObjectID p_id) { + emit_signal("object_id_selected", p_property, p_id); +} + void EditorPropertyArray::update_property() { Variant array = get_edited_object()->get(get_edited_property()); @@ -431,9 +443,19 @@ void EditorPropertyArray::update_property() { } break; case Variant::OBJECT: { - EditorPropertyResource *editor = memnew(EditorPropertyResource); - editor->setup("Resource"); - prop = editor; + + if (Object::cast_to<EncodedObjectAsID>(value)) { + + EditorPropertyObjectID *editor = memnew(EditorPropertyObjectID); + editor->setup("Object"); + prop = editor; + + } else { + + EditorPropertyResource *editor = memnew(EditorPropertyResource); + editor->setup("Resource"); + prop = editor; + } } break; case Variant::DICTIONARY: { @@ -497,6 +519,7 @@ void EditorPropertyArray::update_property() { prop->set_label(itos(i + offset)); prop->set_selectable(false); prop->connect("property_changed", this, "_property_changed"); + prop->connect("object_id_selected", this, "_object_id_selected"); if (array.get_type() == Variant::ARRAY) { HBoxContainer *hb = memnew(HBoxContainer); vbox->add_child(hb); @@ -578,6 +601,7 @@ void EditorPropertyArray::_bind_methods() { ClassDB::bind_method("_property_changed", &EditorPropertyArray::_property_changed, DEFVAL(false)); ClassDB::bind_method("_change_type", &EditorPropertyArray::_change_type); ClassDB::bind_method("_change_type_menu", &EditorPropertyArray::_change_type_menu); + ClassDB::bind_method("_object_id_selected", &EditorPropertyArray::_object_id_selected); } EditorPropertyArray::EditorPropertyArray() { @@ -893,9 +917,19 @@ void EditorPropertyDictionary::update_property() { } break; case Variant::OBJECT: { - EditorPropertyResource *editor = memnew(EditorPropertyResource); - editor->setup("Resource"); - prop = editor; + + if (Object::cast_to<EncodedObjectAsID>(value)) { + + EditorPropertyObjectID *editor = memnew(EditorPropertyObjectID); + editor->setup("Object"); + prop = editor; + + } else { + + EditorPropertyResource *editor = memnew(EditorPropertyResource); + editor->setup("Resource"); + prop = editor; + } } break; case Variant::DICTIONARY: { @@ -986,6 +1020,7 @@ void EditorPropertyDictionary::update_property() { prop->set_selectable(false); prop->connect("property_changed", this, "_property_changed"); + prop->connect("object_id_selected", this, "_object_id_selected"); HBoxContainer *hb = memnew(HBoxContainer); if (add_vbox) { @@ -1022,6 +1057,10 @@ void EditorPropertyDictionary::update_property() { #endif } +void EditorPropertyDictionary::_object_id_selected(const String &p_property, ObjectID p_id) { + emit_signal("object_id_selected", p_property, p_id); +} + void EditorPropertyDictionary::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { @@ -1055,6 +1094,7 @@ void EditorPropertyDictionary::_bind_methods() { ClassDB::bind_method("_change_type", &EditorPropertyDictionary::_change_type); ClassDB::bind_method("_change_type_menu", &EditorPropertyDictionary::_change_type_menu); ClassDB::bind_method("_add_key_value", &EditorPropertyDictionary::_add_key_value); + ClassDB::bind_method("_object_id_selected", &EditorPropertyDictionary::_object_id_selected); } EditorPropertyDictionary::EditorPropertyDictionary() { diff --git a/editor/editor_properties_array_dict.h b/editor/editor_properties_array_dict.h index d2bd849f30..d5eecd9106 100644 --- a/editor/editor_properties_array_dict.h +++ b/editor/editor_properties_array_dict.h @@ -101,6 +101,8 @@ class EditorPropertyArray : public EditorProperty { void _change_type(Object *p_button, int p_index); void _change_type_menu(int p_index); + void _object_id_selected(const String &p_property, ObjectID p_id); + protected: static void _bind_methods(); void _notification(int p_what); @@ -134,6 +136,7 @@ class EditorPropertyDictionary : public EditorProperty { void _change_type_menu(int p_index); void _add_key_value(); + void _object_id_selected(const String &p_property, ObjectID p_id); protected: static void _bind_methods(); diff --git a/editor/script_editor_debugger.cpp b/editor/script_editor_debugger.cpp index faa561ad54..559ab32505 100644 --- a/editor/script_editor_debugger.cpp +++ b/editor/script_editor_debugger.cpp @@ -602,6 +602,7 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da String n = p_data[ofs + i * 2 + 0]; Variant v = p_data[ofs + i * 2 + 1]; + PropertyHint h = PROPERTY_HINT_NONE; String hs = String(); |