Ensure array and dict editors show edited object IDs, fixes #20225

This commit is contained in:
Juan Linietsky 2018-11-21 22:10:27 -03:00
parent 9e628264b6
commit a2a606794c
5 changed files with 63 additions and 8 deletions

View file

@ -108,7 +108,7 @@ void ScriptDebuggerRemote::_put_variable(const String &p_name, const Variant &p_
}
int len = 0;
Error err = encode_variant(var, NULL, len);
Error err = encode_variant(var, NULL, len, true);
if (err != OK)
ERR_PRINT("Failed to encode variant");

View file

@ -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) {

View file

@ -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() {

View file

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

View file

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