Browse Source

Allow dragging resources (not just files) onto array property editor

The most common scenario is dragging a file from the filesystem dock,
which drags it as type "file", not "resource". This already worked. This
change also makes it possible to drag a resource from another property
editor.
Thomas ten Cate 6 months ago
parent
commit
b557840af5
1 changed files with 32 additions and 0 deletions
  1. 32 0
      editor/editor_properties_array_dict.cpp

+ 32 - 0
editor/editor_properties_array_dict.cpp

@@ -592,6 +592,28 @@ bool EditorPropertyArray::_is_drop_valid(const Dictionary &p_drag_data) const {
 		return true;
 	}
 
+	if (drop_type == "resource") {
+		Ref<Resource> res = drag_data["resource"];
+		if (res.is_null()) {
+			return false;
+		}
+
+		String res_type = res->get_class();
+		StringName script_class;
+		if (res->get_script()) {
+			script_class = EditorNode::get_singleton()->get_object_custom_type_name(res->get_script());
+		}
+
+		for (String at : allowed_type.split(",")) {
+			at = at.strip_edges();
+			if (ClassDB::is_parent_class(res_type, at) || EditorNode::get_editor_data().script_class_is_parent(script_class, at)) {
+				return true;
+			}
+		}
+
+		return false;
+	}
+
 	if (drop_type == "nodes") {
 		Array node_paths = drag_data["nodes"];
 
@@ -679,6 +701,16 @@ void EditorPropertyArray::drop_data_fw(const Point2 &p_point, const Variant &p_d
 		emit_changed(get_edited_property(), array);
 	}
 
+	if (drop_type == "resource") {
+		Ref<Resource> res = drag_data["resource"];
+
+		if (res.is_valid()) {
+			array.call("push_back", res);
+
+			emit_changed(get_edited_property(), array);
+		}
+	}
+
 	if (drop_type == "nodes") {
 		Array node_paths = drag_data["nodes"];
 		Node *base_node = get_base_node();