/**************************************************************************/ /* editor_resource_picker.cpp */ /**************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* https://godotengine.org */ /**************************************************************************/ /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ /* "Software"), to deal in the Software without restriction, including */ /* without limitation the rights to use, copy, modify, merge, publish, */ /* distribute, sublicense, and/or sell copies of the Software, and to */ /* permit persons to whom the Software is furnished to do so, subject to */ /* the following conditions: */ /* */ /* The above copyright notice and this permission notice shall be */ /* included in all copies or substantial portions of the Software. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /**************************************************************************/ #include "editor_resource_picker.h" #include "editor/audio/audio_stream_preview.h" #include "editor/doc/editor_help.h" #include "editor/docks/filesystem_dock.h" #include "editor/docks/scene_tree_dock.h" #include "editor/editor_node.h" #include "editor/editor_string_names.h" #include "editor/gui/editor_file_dialog.h" #include "editor/gui/editor_quick_open_dialog.h" #include "editor/inspector/editor_inspector.h" #include "editor/inspector/editor_resource_preview.h" #include "editor/plugins/editor_resource_conversion_plugin.h" #include "editor/script/script_editor_plugin.h" #include "editor/settings/editor_settings.h" #include "editor/themes/editor_scale.h" #include "scene/gui/button.h" #include "scene/gui/texture_rect.h" #include "scene/resources/gradient_texture.h" #include "scene/resources/image_texture.h" static bool _has_sub_resources(const Ref &p_res) { List property_list; p_res->get_property_list(&property_list); for (const PropertyInfo &p : property_list) { Variant value = p_res->get(p.name); if (p.type == Variant::OBJECT && p.hint == PROPERTY_HINT_RESOURCE_TYPE && !(p.usage & PROPERTY_USAGE_NEVER_DUPLICATE) && p_res->get(p.name).get_validated_object()) { return true; } else if (p.type == Variant::ARRAY) { Array arr = value; for (Variant &var : arr) { Ref res = var; if (res.is_valid()) { return true; } } } else if (p.type == Variant::DICTIONARY) { Dictionary dict = value; for (const KeyValue &kv : dict) { Ref resk = kv.key; Ref resv = kv.value; if (resk.is_valid() || resv.is_valid()) { return true; } } } } return false; } void EditorResourcePicker::_update_resource() { String resource_path; if (edited_resource.is_valid() && edited_resource->get_path().is_resource_file()) { resource_path = edited_resource->get_path() + "\n"; } String class_name = _get_resource_type(edited_resource); if (preview_rect) { preview_rect->set_texture(Ref()); assign_button->set_custom_minimum_size(assign_button_min_size); if (edited_resource == Ref()) { assign_button->set_button_icon(Ref()); assign_button->set_text(TTR("")); assign_button->set_tooltip_text(""); make_unique_button->set_disabled(true); make_unique_button->set_visible(false); } else { Ref parent_res = _has_parent_resource(); bool unique_enable = _is_uniqueness_enabled(); bool unique_recursive_enabled = _is_uniqueness_enabled(true); bool is_internal = EditorNode::get_singleton()->is_resource_internal_to_scene(edited_resource); int num_of_copies = EditorNode::get_singleton()->get_resource_count(edited_resource); make_unique_button->set_button_icon(get_editor_theme_icon(SNAME("Instance"))); make_unique_button->set_visible((num_of_copies > 1 || !is_internal) && !Object::cast_to