Jelajahi Sumber

Merge pull request #24981 from akien-mga/property-editor-rid

Add EditorPropertyRID as read-only label showing RID
Rémi Verschelde 6 tahun lalu
induk
melakukan
577659cb1b

+ 20 - 0
editor/editor_properties.cpp

@@ -795,6 +795,7 @@ EditorPropertyLayers::EditorPropertyLayers() {
 	layers->set_hide_on_checkable_item_selection(false);
 	layers->connect("id_pressed", this, "_menu_pressed");
 }
+
 ///////////////////// INT /////////////////////////
 
 void EditorPropertyInteger::_value_changed(double val) {
@@ -1951,6 +1952,23 @@ EditorPropertyNodePath::EditorPropertyNodePath() {
 	scene_tree = NULL; //do not allocate unnecessarily
 }
 
+///////////////////// RID /////////////////////////
+
+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));
+	} else {
+		label->set_text(TTR("Invalid RID"));
+	}
+}
+
+EditorPropertyRID::EditorPropertyRID() {
+	label = memnew(Label);
+	add_child(label);
+}
+
 ////////////// RESOURCE //////////////////////
 
 void EditorPropertyResource::_file_selected(const String &p_path) {
@@ -3117,6 +3135,8 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
 
 		} break; // 15
 		case Variant::_RID: {
+			EditorPropertyRID *editor = memnew(EditorPropertyRID);
+			add_property_editor(p_path, editor);
 		} break;
 		case Variant::OBJECT: {
 			EditorPropertyResource *editor = memnew(EditorPropertyResource);

+ 9 - 0
editor/editor_properties.h

@@ -515,6 +515,15 @@ public:
 	EditorPropertyNodePath();
 };
 
+class EditorPropertyRID : public EditorProperty {
+	GDCLASS(EditorPropertyRID, EditorProperty)
+	Label *label;
+
+public:
+	virtual void update_property();
+	EditorPropertyRID();
+};
+
 class EditorPropertyResource : public EditorProperty {
 	GDCLASS(EditorPropertyResource, EditorProperty)
 

+ 2 - 0
editor/editor_properties_array_dict.cpp

@@ -29,9 +29,11 @@
 /*************************************************************************/
 
 #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;