diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index bb9606c94b2..f71ea5c39e0 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -532,7 +532,13 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::RID: { - r_variant = RID(); + ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA); + uint64_t id = decode_uint64(buf); + if (r_len) { + (*r_len) += 8; + } + + r_variant = RID::from_uint64(id); } break; case Variant::OBJECT: { if (type & ENCODE_FLAG_OBJECT_AS_ID) { @@ -614,9 +620,20 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int r_variant = Callable(); } break; case Variant::SIGNAL: { - r_variant = Signal(); - } break; + String name; + Error err = _decode_string(buf, len, r_len, name); + if (err) { + return err; + } + ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA); + ObjectID id = ObjectID(decode_uint64(buf)); + if (r_len) { + (*r_len) += 8; + } + + r_variant = Signal(id, StringName(name)); + } break; case Variant::DICTIONARY: { ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int32_t count = decode_uint32(buf); @@ -1352,10 +1369,12 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::RID: { - } break; - case Variant::CALLABLE: { - } break; - case Variant::SIGNAL: { + RID rid = p_variant; + + if (buf) { + encode_uint64(rid.get_id(), buf); + } + r_len += 8; } break; case Variant::OBJECT: { if (p_full_objects) { @@ -1419,6 +1438,18 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } } break; + case Variant::CALLABLE: { + } break; + case Variant::SIGNAL: { + Signal signal = p_variant; + + _encode_string(signal.get_name(), buf, r_len); + + if (buf) { + encode_uint64(signal.get_object_id(), buf); + } + r_len += 8; + } break; case Variant::DICTIONARY: { Dictionary d = p_variant; diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index aff328bba75..70622e85ff1 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -1304,7 +1304,7 @@ void EditorPropertyObjectID::update_property() { ObjectID id = get_edited_object()->get(get_edited_property()); if (id.is_valid()) { - edit->set_text(type + " ID: " + itos(id)); + edit->set_text(type + " ID: " + uitos(id)); edit->set_disabled(false); edit->set_icon(EditorNode::get_singleton()->get_class_icon(type)); } else { @@ -1328,6 +1328,54 @@ EditorPropertyObjectID::EditorPropertyObjectID() { edit->connect("pressed", callable_mp(this, &EditorPropertyObjectID::_edit_pressed)); } +///////////////////// SIGNAL ///////////////////////// + +void EditorPropertySignal::_edit_pressed() { + Signal signal = get_edited_object()->get(get_edited_property()); + emit_signal(SNAME("object_id_selected"), get_edited_property(), signal.get_object_id()); +} + +void EditorPropertySignal::update_property() { + String type = base_type; + + Signal signal = get_edited_object()->get(get_edited_property()); + + edit->set_text("Signal: " + signal.get_name()); + edit->set_disabled(false); + edit->set_icon(get_theme_icon(SNAME("Signals"), SNAME("EditorIcons"))); +} + +void EditorPropertySignal::_bind_methods() { +} + +EditorPropertySignal::EditorPropertySignal() { + edit = memnew(Button); + add_child(edit); + add_focusable(edit); + edit->connect("pressed", callable_mp(this, &EditorPropertySignal::_edit_pressed)); +} + +///////////////////// CALLABLE ///////////////////////// + +void EditorPropertyCallable::update_property() { + String type = base_type; + + Callable callable = get_edited_object()->get(get_edited_property()); + + edit->set_text("Callable"); + edit->set_disabled(true); + edit->set_icon(get_theme_icon(SNAME("Callable"), SNAME("EditorIcons"))); +} + +void EditorPropertyCallable::_bind_methods() { +} + +EditorPropertyCallable::EditorPropertyCallable() { + edit = memnew(Button); + add_child(edit); + add_focusable(edit); +} + ///////////////////// FLOAT ///////////////////////// void EditorPropertyFloat::_set_read_only(bool p_read_only) { @@ -3222,8 +3270,8 @@ EditorPropertyNodePath::EditorPropertyNodePath() { void EditorPropertyRID::update_property() { RID rid = get_edited_object()->get(get_edited_property()); if (rid.is_valid()) { - int id = rid.get_id(); - label->set_text("RID: " + itos(id)); + uint64_t id = rid.get_id(); + label->set_text("RID: " + uitos(id)); } else { label->set_text(TTR("Invalid RID")); } @@ -4002,6 +4050,14 @@ EditorProperty *EditorInspectorDefaultPlugin::get_editor_for_property(Object *p_ } } break; + case Variant::CALLABLE: { + EditorPropertyCallable *editor = memnew(EditorPropertyCallable); + return editor; + } break; + case Variant::SIGNAL: { + EditorPropertySignal *editor = memnew(EditorPropertySignal); + return editor; + } break; case Variant::DICTIONARY: { if (p_hint == PROPERTY_HINT_LOCALIZABLE_STRING) { EditorPropertyLocalizableString *editor = memnew(EditorPropertyLocalizableString); diff --git a/editor/editor_properties.h b/editor/editor_properties.h index 7cd6ea4f6b5..7bec2d0013e 100644 --- a/editor/editor_properties.h +++ b/editor/editor_properties.h @@ -389,6 +389,33 @@ public: EditorPropertyObjectID(); }; +class EditorPropertySignal : public EditorProperty { + GDCLASS(EditorPropertySignal, EditorProperty); + Button *edit = nullptr; + String base_type; + void _edit_pressed(); + +protected: + static void _bind_methods(); + +public: + virtual void update_property() override; + EditorPropertySignal(); +}; + +class EditorPropertyCallable : public EditorProperty { + GDCLASS(EditorPropertyCallable, EditorProperty); + Button *edit = nullptr; + String base_type; + +protected: + static void _bind_methods(); + +public: + virtual void update_property() override; + EditorPropertyCallable(); +}; + class EditorPropertyFloat : public EditorProperty { GDCLASS(EditorPropertyFloat, EditorProperty); EditorSpinSlider *spin = nullptr;