diff --git a/editor/editor_resource_picker.cpp b/editor/editor_resource_picker.cpp index d850773a6dc..e5c18362050 100644 --- a/editor/editor_resource_picker.cpp +++ b/editor/editor_resource_picker.cpp @@ -184,6 +184,21 @@ void EditorResourcePicker::_update_menu_items() { edit_menu->add_icon_item(get_theme_icon(SNAME("Edit"), SNAME("EditorIcons")), TTR("Edit"), OBJ_MENU_EDIT); edit_menu->add_icon_item(get_theme_icon(SNAME("Clear"), SNAME("EditorIcons")), TTR("Clear"), OBJ_MENU_CLEAR); edit_menu->add_icon_item(get_theme_icon(SNAME("Duplicate"), SNAME("EditorIcons")), TTR("Make Unique"), OBJ_MENU_MAKE_UNIQUE); + + // Check whether the resource has subresources. + List property_list; + edited_resource->get_property_list(&property_list); + bool has_subresources = false; + for (PropertyInfo &p : property_list) { + if ((p.type == Variant::OBJECT) && (p.hint == PROPERTY_HINT_RESOURCE_TYPE) && (p.name != "script")) { + has_subresources = true; + break; + } + } + if (has_subresources) { + edit_menu->add_icon_item(get_theme_icon(SNAME("Duplicate"), SNAME("EditorIcons")), TTR("Make Unique (Recursive)"), OBJ_MENU_MAKE_UNIQUE_RECURSIVE); + } + edit_menu->add_icon_item(get_theme_icon(SNAME("Save"), SNAME("EditorIcons")), TTR("Save"), OBJ_MENU_SAVE); if (edited_resource->get_path().is_resource_file()) { @@ -297,28 +312,22 @@ void EditorResourcePicker::_edit_menu_cbk(int p_which) { return; } - List property_list; - edited_resource->get_property_list(&property_list); - List> propvalues; - for (const PropertyInfo &pi : property_list) { - Pair p; - if (pi.usage & PROPERTY_USAGE_STORAGE) { - p.first = pi.name; - p.second = edited_resource->get(pi.name); - } - - propvalues.push_back(p); - } - - String orig_type = edited_resource->get_class(); - Object *inst = ClassDB::instantiate(orig_type); - Ref unique_resource = Ref(Object::cast_to(inst)); + Ref unique_resource = edited_resource->duplicate(); ERR_FAIL_COND(unique_resource.is_null()); - for (const Pair &p : propvalues) { - unique_resource->set(p.first, p.second); + edited_resource = unique_resource; + emit_signal(SNAME("resource_changed"), edited_resource); + _update_resource(); + } break; + + case OBJ_MENU_MAKE_UNIQUE_RECURSIVE: { + if (edited_resource.is_null()) { + return; } + Ref unique_resource = edited_resource->duplicate(true); + ERR_FAIL_COND(unique_resource.is_null()); + edited_resource = unique_resource; emit_signal(SNAME("resource_changed"), edited_resource); _update_resource(); diff --git a/editor/editor_resource_picker.h b/editor/editor_resource_picker.h index d36e742bcdd..3a4d5985bd5 100644 --- a/editor/editor_resource_picker.h +++ b/editor/editor_resource_picker.h @@ -66,6 +66,7 @@ class EditorResourcePicker : public HBoxContainer { OBJ_MENU_EDIT, OBJ_MENU_CLEAR, OBJ_MENU_MAKE_UNIQUE, + OBJ_MENU_MAKE_UNIQUE_RECURSIVE, OBJ_MENU_SAVE, OBJ_MENU_COPY, OBJ_MENU_PASTE,