/*************************************************************************/ /* editor_resource_picker.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* 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 "core/containers/pair.h" #include "core/containers/rb_map.h" #include "core/error/error_macros.h" #include "core/input/input_event.h" #include "core/io/resource_loader.h" #include "core/math/color.h" #include "core/math/math_defs.h" #include "core/math/rect2.h" #include "core/object/class_db.h" #include "core/object/ref_ptr.h" #include "core/object/script_language.h" #include "core/os/memory.h" #include "core/string/string_name.h" #include "core/typedefs.h" #include "core/variant/dictionary.h" #include "editor/editor_data.h" #include "editor/editor_file_dialog.h" #include "editor/editor_file_system.h" #include "editor/editor_resource_preview.h" #include "editor/property_editor.h" #include "editor/quick_open.h" #include "editor/scene_tree_dock.h" #include "editor_node.h" #include "editor_scale.h" #include "editor_settings.h" #include "filesystem_dock.h" #include "scene/2d/canvas_item.h" #include "scene/gui/button.h" #include "scene/gui/control.h" #include "scene/gui/popup_menu.h" #include "scene/gui/tab_container.h" #include "scene/gui/texture_rect.h" #include "scene/main/node.h" #include "scene/main/viewport.h" #include "scene/resources/material/material.h" #include "scene/resources/shader.h" #include "scene/resources/style_box.h" #include "scene/resources/texture.h" #include "modules/modules_enabled.gen.h" #ifdef MODULE_EDITOR_CODE_EDITOR_ENABLED #include "editor_code_editor/editor_script_editor.h" #include "editor_code_editor/editor_script_editor_base.h" #endif HashMap> EditorResourcePicker::allowed_types_cache; void EditorResourcePicker::clear_caches() { allowed_types_cache.clear(); } void EditorResourcePicker::_update_resource() { preview_rect->set_texture(Ref()); assign_button->set_custom_minimum_size(Size2(1, 1)); if (edited_resource == RES()) { assign_button->set_icon(Ref()); assign_button->set_text(TTR("[empty]")); assign_button->set_tooltip(""); } else { assign_button->set_icon(EditorNode::get_singleton()->get_object_icon(edited_resource.operator->(), "Object")); if (edited_resource->get_name() != String()) { assign_button->set_text(edited_resource->get_name()); } else if (edited_resource->get_path().is_resource_file()) { assign_button->set_text(edited_resource->get_path().get_file()); } else { String class_name = edited_resource->get_class(); Ref