From 0c46089d1b55b11f3daf6b16fba96465e90ffe39 Mon Sep 17 00:00:00 2001 From: Thomas ten Cate Date: Fri, 7 Feb 2025 12:13:12 +0100 Subject: [PATCH] Allow dragging custom resources onto array property editor This duplicates some of the logic in EditorResourcePicker, but that's unavoidable: EditorResourcePicker works on a single, loaded resource, whereas we'd like this to be efficient and not need to load all (potentially many) dragged resources. Instead, we use the EditorFileSystem cache to get the information we need. Note that EditorResourcePicker also supports some automatic conversions, such as from Shader to ShaderMaterial. This change does not attempt to make that work for arrays as well. --- editor/editor_properties_array_dict.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/editor/editor_properties_array_dict.cpp b/editor/editor_properties_array_dict.cpp index 99ad820bb3a..89b1253f4c9 100644 --- a/editor/editor_properties_array_dict.cpp +++ b/editor/editor_properties_array_dict.cpp @@ -33,6 +33,7 @@ #include "core/input/input.h" #include "core/io/marshalls.h" #include "editor/editor_file_system.h" +#include "editor/editor_node.h" #include "editor/editor_properties.h" #include "editor/editor_properties_vector.h" #include "editor/editor_settings.h" @@ -570,11 +571,18 @@ bool EditorPropertyArray::_is_drop_valid(const Dictionary &p_drag_data) const { PackedStringArray files = drag_data["files"]; for (const String &file : files) { - const String ftype = EditorFileSystem::get_singleton()->get_file_type(file); + int idx_in_dir; + EditorFileSystemDirectory const *dir = EditorFileSystem::get_singleton()->find_file(file, &idx_in_dir); + if (!dir) { + return false; + } + StringName ftype = dir->get_file_type(idx_in_dir); + String script_class = dir->get_file_resource_script_class(idx_in_dir); + for (String at : allowed_type.split(",")) { at = at.strip_edges(); // Fail if one of the files is not of allowed type. - if (!ClassDB::is_parent_class(ftype, at)) { + if (!ClassDB::is_parent_class(ftype, at) && !EditorNode::get_editor_data().script_class_is_parent(script_class, at)) { return false; } }