You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-24 15:26:15 +00:00
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.
This commit is contained in:
@@ -33,6 +33,7 @@
|
|||||||
#include "core/input/input.h"
|
#include "core/input/input.h"
|
||||||
#include "core/io/marshalls.h"
|
#include "core/io/marshalls.h"
|
||||||
#include "editor/editor_file_system.h"
|
#include "editor/editor_file_system.h"
|
||||||
|
#include "editor/editor_node.h"
|
||||||
#include "editor/editor_properties.h"
|
#include "editor/editor_properties.h"
|
||||||
#include "editor/editor_properties_vector.h"
|
#include "editor/editor_properties_vector.h"
|
||||||
#include "editor/editor_settings.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"];
|
PackedStringArray files = drag_data["files"];
|
||||||
|
|
||||||
for (const String &file : 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(",")) {
|
for (String at : allowed_type.split(",")) {
|
||||||
at = at.strip_edges();
|
at = at.strip_edges();
|
||||||
// Fail if one of the files is not of allowed type.
|
// 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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user