From 157e810b2ead3475557fa76a680903a4e649205c Mon Sep 17 00:00:00 2001 From: Riley Lyman Date: Thu, 2 Jul 2020 11:00:13 -0700 Subject: [PATCH] Make Resource properties accept SE plugin scripts (cherry picked from commit ab0fe13efb9b29cac9cbd46f768979baf177af38) --- editor/editor_properties.cpp | 38 ++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index c3ccaf22a4c..36d602284ae 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -2812,8 +2812,16 @@ bool EditorPropertyResource::_is_drop_valid(const Dictionary &p_drag_data) const String allowed_type = base_type; Dictionary drag_data = p_drag_data; - if (drag_data.has("type") && String(drag_data["type"]) == "resource") { - Ref res = drag_data["resource"]; + + Ref res; + if (drag_data.has("type") && String(drag_data["type"]) == "script_list_element") { + ScriptEditorBase *se = Object::cast_to(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++) { String at = allowed_type.get_slice(",", i).strip_edges(); if (res.is_valid() && ClassDB::is_parent_class(res->get_class(), at)) { @@ -2854,13 +2862,19 @@ void EditorPropertyResource::drop_data_fw(const Point2 &p_point, const Variant & ERR_FAIL_COND(!_is_drop_valid(p_data)); Dictionary drag_data = p_data; - if (drag_data.has("type") && String(drag_data["type"]) == "resource") { - Ref res = drag_data["resource"]; - if (res.is_valid()) { - emit_changed(get_edited_property(), res); - update_property(); - return; - } + + Ref res; + if (drag_data.has("type") && String(drag_data["type"]) == "script_list_element") { + ScriptEditorBase *se = Object::cast_to(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()) { + emit_changed(get_edited_property(), res); + update_property(); + return; } if (drag_data.has("type") && String(drag_data["type"]) == "files") { @@ -2869,9 +2883,9 @@ void EditorPropertyResource::drop_data_fw(const Point2 &p_point, const Variant & if (files.size() == 1) { String file = files[0]; - RES res = ResourceLoader::load(file); - if (res.is_valid()) { - emit_changed(get_edited_property(), res); + RES file_res = ResourceLoader::load(file); + if (file_res.is_valid()) { + emit_changed(get_edited_property(), file_res); update_property(); return; }