Make Resource properties accept SE plugin scripts

This commit is contained in:
Riley Lyman 2020-07-02 11:00:13 -07:00
parent 3fb5faaceb
commit ab0fe13efb

View file

@ -2983,8 +2983,16 @@ bool EditorPropertyResource::_is_drop_valid(const Dictionary &p_drag_data) const
String allowed_type = base_type; String allowed_type = base_type;
Dictionary drag_data = p_drag_data; Dictionary drag_data = p_drag_data;
if (drag_data.has("type") && String(drag_data["type"]) == "resource") {
Ref<Resource> res = drag_data["resource"]; Ref<Resource> res;
if (drag_data.has("type") && String(drag_data["type"]) == "script_list_element") {
ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(drag_data["script_list_element"]);
res = se->get_edited_resource();
} else if (drag_data.has("type") && String(drag_data["type"]) == "resource") {
res = drag_data["resource"];
}
if (res.is_valid()) {
for (int i = 0; i < allowed_type.get_slice_count(","); i++) { for (int i = 0; i < allowed_type.get_slice_count(","); i++) {
String at = allowed_type.get_slice(",", i).strip_edges(); String at = allowed_type.get_slice(",", i).strip_edges();
if (res.is_valid() && ClassDB::is_parent_class(res->get_class(), at)) { if (res.is_valid() && ClassDB::is_parent_class(res->get_class(), at)) {
@ -3022,13 +3030,19 @@ void EditorPropertyResource::drop_data_fw(const Point2 &p_point, const Variant &
ERR_FAIL_COND(!_is_drop_valid(p_data)); ERR_FAIL_COND(!_is_drop_valid(p_data));
Dictionary drag_data = p_data; Dictionary drag_data = p_data;
if (drag_data.has("type") && String(drag_data["type"]) == "resource") {
Ref<Resource> res = drag_data["resource"]; Ref<Resource> res;
if (res.is_valid()) { if (drag_data.has("type") && String(drag_data["type"]) == "script_list_element") {
emit_changed(get_edited_property(), res); ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(drag_data["script_list_element"]);
update_property(); res = se->get_edited_resource();
return; } else if (drag_data.has("type") && String(drag_data["type"]) == "resource") {
} res = drag_data["resource"];
}
if (res.is_valid()) {
emit_changed(get_edited_property(), res);
update_property();
return;
} }
if (drag_data.has("type") && String(drag_data["type"]) == "files") { if (drag_data.has("type") && String(drag_data["type"]) == "files") {
@ -3036,9 +3050,9 @@ void EditorPropertyResource::drop_data_fw(const Point2 &p_point, const Variant &
if (files.size() == 1) { if (files.size() == 1) {
String file = files[0]; String file = files[0];
RES res = ResourceLoader::load(file); RES file_res = ResourceLoader::load(file);
if (res.is_valid()) { if (file_res.is_valid()) {
emit_changed(get_edited_property(), res); emit_changed(get_edited_property(), file_res);
update_property(); update_property();
return; return;
} }