/**************************************************************************/ /* editor_object_selector.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_object_selector.h" #include "editor/debugger/editor_debugger_inspector.h" #include "editor/editor_data.h" #include "editor/editor_node.h" #include "editor/editor_string_names.h" #include "editor/multi_node_edit.h" #include "editor/themes/editor_scale.h" #include "scene/gui/margin_container.h" Size2 EditorObjectSelector::get_minimum_size() const { Ref font = get_theme_font(SceneStringName(font)); int font_size = get_theme_font_size(SceneStringName(font_size)); return Button::get_minimum_size() + Size2(0, font->get_height(font_size)); } void EditorObjectSelector::_add_children_to_popup(Object *p_obj, int p_depth) { if (p_depth > 8) { return; } List pinfo; p_obj->get_property_list(&pinfo); for (const PropertyInfo &E : pinfo) { if (!(E.usage & PROPERTY_USAGE_EDITOR)) { continue; } if (E.hint != PROPERTY_HINT_RESOURCE_TYPE) { continue; } Variant value = p_obj->get(E.name); if (value.get_type() != Variant::OBJECT) { continue; } Object *obj = value; if (!obj) { continue; } Ref obj_icon = EditorNode::get_singleton()->get_object_icon(obj); String proper_name = ""; Vector name_parts = E.name.split("/"); for (int i = 0; i < name_parts.size(); i++) { if (i > 0) { proper_name += " > "; } proper_name += name_parts[i].capitalize(); } int index = sub_objects_menu->get_item_count(); sub_objects_menu->add_icon_item(obj_icon, proper_name, objects.size()); sub_objects_menu->set_item_indent(index, p_depth); objects.push_back(obj->get_instance_id()); _add_children_to_popup(obj, p_depth + 1); } } void EditorObjectSelector::_show_popup() { if (sub_objects_menu->is_visible()) { sub_objects_menu->hide(); return; } sub_objects_menu->clear(); Size2 size = get_size(); Point2 gp = get_screen_position(); gp.y += size.y; sub_objects_menu->set_position(gp); sub_objects_menu->set_size(Size2(size.width, 1)); sub_objects_menu->popup(); } void EditorObjectSelector::_about_to_show() { Object *obj = ObjectDB::get_instance(history->get_path_object(history->get_path_size() - 1)); if (!obj) { return; } objects.clear(); _add_children_to_popup(obj); if (sub_objects_menu->get_item_count() == 0) { sub_objects_menu->add_item(TTR("No sub-resources found.")); sub_objects_menu->set_item_disabled(0, true); } } void EditorObjectSelector::update_path() { for (int i = 0; i < history->get_path_size(); i++) { Object *obj = ObjectDB::get_instance(history->get_path_object(i)); if (!obj) { continue; } Ref obj_icon; if (Object::cast_to(obj)) { obj_icon = EditorNode::get_singleton()->get_class_icon(Object::cast_to(obj)->get_edited_class_name()); } else if (Object::cast_to(obj)) { String class_name; Ref