/**************************************************************************/ /* editor_inspector.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_inspector.h" #include "editor_inspector.compat.inc" #include "core/os/keyboard.h" #include "editor/debugger/editor_debugger_inspector.h" #include "editor/doc/doc_tools.h" #include "editor/docks/inspector_dock.h" #include "editor/editor_main_screen.h" #include "editor/editor_node.h" #include "editor/editor_string_names.h" #include "editor/editor_undo_redo_manager.h" #include "editor/gui/editor_toaster.h" #include "editor/gui/editor_validation_panel.h" #include "editor/inspector/add_metadata_dialog.h" #include "editor/inspector/editor_properties.h" #include "editor/inspector/editor_property_name_processor.h" #include "editor/inspector/multi_node_edit.h" #include "editor/script/script_editor_plugin.h" #include "editor/settings/editor_feature_profile.h" #include "editor/settings/editor_settings.h" #include "editor/themes/editor_scale.h" #include "scene/gui/margin_container.h" #include "scene/gui/separator.h" #include "scene/gui/spin_box.h" #include "scene/gui/texture_rect.h" #include "scene/property_utils.h" #include "scene/resources/packed_scene.h" #include "scene/resources/style_box_flat.h" #include "scene/scene_string_names.h" void EditorInspectorActionButton::_notification(int p_what) { switch (p_what) { case NOTIFICATION_THEME_CHANGED: { set_button_icon(get_editor_theme_icon(icon_name)); } break; } } EditorInspectorActionButton::EditorInspectorActionButton(const String &p_text, const StringName &p_icon_name) { icon_name = p_icon_name; set_text(p_text); set_theme_type_variation(SNAME("InspectorActionButton")); set_h_size_flags(SIZE_SHRINK_CENTER); } bool EditorInspector::_property_path_matches(const String &p_property_path, const String &p_filter, EditorPropertyNameProcessor::Style p_style) { if (p_property_path.containsn(p_filter)) { return true; } const Vector prop_sections = p_property_path.split("/"); for (int i = 0; i < prop_sections.size(); i++) { if (p_filter.is_subsequence_ofn(EditorPropertyNameProcessor::get_singleton()->process_name(prop_sections[i], p_style, p_property_path))) { return true; } } return false; } bool EditorInspector::_resource_properties_matches(const Ref &p_resource, const String &p_filter) { String group; String group_base; String subgroup; String subgroup_base; List plist; p_resource->get_property_list(&plist, true); // Employ a lighter version of the update_tree() property listing to find a match. for (PropertyInfo &p : plist) { if (p.usage & PROPERTY_USAGE_SUBGROUP) { subgroup = p.name; subgroup_base = p.hint_string.get_slicec(',', 0); continue; } else if (p.usage & PROPERTY_USAGE_GROUP) { group = p.name; group_base = p.hint_string.get_slicec(',', 0); subgroup = ""; subgroup_base = ""; continue; } else if (p.usage & PROPERTY_USAGE_CATEGORY) { group = ""; group_base = ""; subgroup = ""; subgroup_base = ""; continue; } else if (p.name.begins_with("metadata/_") || !(p.usage & PROPERTY_USAGE_EDITOR) || _is_property_disabled_by_feature_profile(p.name) || (p_filter.is_empty() && restrict_to_basic && !(p.usage & PROPERTY_USAGE_EDITOR_BASIC_SETTING))) { // Ignore properties that are not supposed to be in the inspector. continue; } if (p.usage & PROPERTY_USAGE_HIGH_END_GFX && RS::get_singleton()->is_low_end()) { // Do not show this property in low end gfx. continue; } if (p.name == "script") { // The script is always hidden in sub inspectors. continue; } if (p.name.begins_with("metadata/") && bool(object->call(SNAME("_hide_metadata_from_inspector")))) { // Hide metadata from inspector if required. continue; } String path = p.name; // Check if we exit or not a subgroup. If there is a prefix, remove it from the property label string. if (!subgroup.is_empty() && !subgroup_base.is_empty()) { if (path.begins_with(subgroup_base)) { path = path.trim_prefix(subgroup_base); } else if (subgroup_base.begins_with(path)) { // Keep it, this is used pretty often. } else { subgroup = ""; // The prefix changed, we are no longer in the subgroup. } } // Check if we exit or not a group. If there is a prefix, remove it from the property label string. if (!group.is_empty() && !group_base.is_empty() && subgroup.is_empty()) { if (path.begins_with(group_base)) { path = path.trim_prefix(group_base); } else if (group_base.begins_with(path)) { // Keep it, this is used pretty often. } else { group = ""; // The prefix changed, we are no longer in the group. subgroup = ""; } } // Add the group and subgroup to the path. if (!subgroup.is_empty()) { path = subgroup + "/" + path; } if (!group.is_empty()) { path = group + "/" + path; } // Get the property label's string. String name_override = (path.contains_char('/')) ? path.substr(path.rfind_char('/') + 1) : path; const int dot = name_override.find_char('.'); if (dot != -1) { name_override = name_override.substr(0, dot); } // Remove the property from the path. int idx = path.rfind_char('/'); if (idx > -1) { path = path.left(idx); } else { path = ""; } // Check if the property matches the filter. const String property_path = (path.is_empty() ? "" : path + "/") + name_override; if (_property_path_matches(property_path, p_filter, property_name_style)) { return true; } // Check if the sub-resource has any properties that match the filter. if (p.hint && p.hint == PROPERTY_HINT_RESOURCE_TYPE) { Ref res = p_resource->get(p.name); if (res.is_valid() && _resource_properties_matches(res, p_filter)) { return true; } } } return false; } String EditorProperty::get_tooltip_string(const String &p_string) const { // Trim to 100 characters to prevent the tooltip from being too long. constexpr int TOOLTIP_MAX_LENGTH = 100; return p_string.left(TOOLTIP_MAX_LENGTH).strip_edges() + String((p_string.length() > TOOLTIP_MAX_LENGTH) ? "..." : ""); } Size2 EditorProperty::get_minimum_size() const { Size2 ms; Ref font = get_theme_font(SceneStringName(font), SNAME("Tree")); int font_size = get_theme_font_size(SceneStringName(font_size), SNAME("Tree")); ms.height = label.is_empty() ? 0 : font->get_height(font_size) + 4 * EDSCALE; for (int i = 0; i < get_child_count(); i++) { Control *c = as_sortable_control(get_child(i)); if (!c) { continue; } if (c == bottom_editor) { continue; } Size2 minsize = c->get_combined_minimum_size(); ms = ms.max(minsize); } if (keying) { Ref key = get_editor_theme_icon(SNAME("Key")); ms.width += key->get_width() + get_theme_constant(SNAME("h_separation"), SNAME("Tree")); } if (deletable) { Ref key = get_editor_theme_icon(SNAME("Close")); ms.width += key->get_width() + get_theme_constant(SNAME("h_separation"), SNAME("Tree")); } if (checkable) { Ref check = get_theme_icon(SNAME("checked"), SNAME("CheckBox")); ms.width += check->get_width() + get_theme_constant(SNAME("h_separation"), SNAME("Tree")); } if (bottom_editor != nullptr && bottom_editor->is_visible()) { ms.height += label.is_empty() ? 0 : get_theme_constant(SNAME("v_separation")); Size2 bems = bottom_editor->get_combined_minimum_size(); //bems.width += get_constant("item_margin", "Tree"); ms.height += bems.height; ms.width = MAX(ms.width, bems.width); } return ms; } void EditorProperty::emit_changed(const StringName &p_property, const Variant &p_value, const StringName &p_field, bool p_changing) { Variant args[4] = { p_property, p_value, p_field, p_changing }; const Variant *argptrs[4] = { &args[0], &args[1], &args[2], &args[3] }; cache[p_property] = p_value; emit_signalp(SNAME("property_changed"), (const Variant **)argptrs, 4); } void EditorProperty::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ACCESSIBILITY_UPDATE: { RID ae = get_accessibility_element(); ERR_FAIL_COND(ae.is_null()); DisplayServer::get_singleton()->accessibility_update_set_role(ae, DisplayServer::AccessibilityRole::ROLE_BUTTON); DisplayServer::get_singleton()->accessibility_update_set_name(ae, vformat(TTR("Property: %s"), label)); DisplayServer::get_singleton()->accessibility_update_set_value(ae, vformat(TTR("Property: %s"), label)); DisplayServer::get_singleton()->accessibility_update_set_popup_type(ae, DisplayServer::AccessibilityPopupType::POPUP_MENU); DisplayServer::get_singleton()->accessibility_update_add_action(ae, DisplayServer::AccessibilityAction::ACTION_SHOW_CONTEXT_MENU, callable_mp(this, &EditorProperty::_accessibility_action_menu)); DisplayServer::get_singleton()->accessibility_update_add_action(ae, DisplayServer::AccessibilityAction::ACTION_CLICK, callable_mp(this, &EditorProperty::_accessibility_action_click)); DisplayServer::get_singleton()->accessibility_update_set_flag(ae, DisplayServer::AccessibilityFlags::FLAG_READONLY, read_only); if (checkable) { DisplayServer::get_singleton()->accessibility_update_set_checked(ae, checked); } } break; case NOTIFICATION_SORT_CHILDREN: { Size2 size = get_size(); Rect2 rect; Rect2 bottom_rect; right_child_rect = Rect2(); bottom_child_rect = Rect2(); { int child_room = size.width * (1.0 - split_ratio); Ref font = get_theme_font(SceneStringName(font), SNAME("Tree")); int font_size = get_theme_font_size(SceneStringName(font_size), SNAME("Tree")); int height = label.is_empty() ? 0 : font->get_height(font_size) + 4 * EDSCALE; bool no_children = true; //compute room needed for (int i = 0; i < get_child_count(); i++) { Control *c = as_sortable_control(get_child(i)); if (!c) { continue; } if (c == bottom_editor) { continue; } Size2 minsize = c->get_combined_minimum_size(); child_room = MAX(child_room, minsize.width); height = MAX(height, minsize.height); no_children = false; } if (no_children) { text_size = size.width; rect = Rect2(size.width - 1, 0, 1, height); } else if (!draw_label) { text_size = 0; rect = Rect2(1, 0, size.width - 1, height); } else { text_size = MAX(0, size.width - (child_room + 4 * EDSCALE)); if (is_layout_rtl()) { rect = Rect2(1, 0, child_room, height); } else { rect = Rect2(size.width - child_room, 0, child_room, height); } } if (bottom_editor) { int v_offset = label.is_empty() ? 0 : get_theme_constant(SNAME("v_separation")); bottom_rect = Rect2(0, rect.size.height + v_offset, size.width, bottom_editor->get_combined_minimum_size().height); } if (keying) { Ref key; if (use_keying_next()) { key = get_editor_theme_icon(SNAME("KeyNext")); } else { key = get_editor_theme_icon(SNAME("Key")); } rect.size.x -= key->get_width() + get_theme_constant(SNAME("h_separation"), SNAME("Tree")); if (is_layout_rtl()) { rect.position.x += key->get_width() + get_theme_constant(SNAME("h_separation"), SNAME("Tree")); } if (no_children) { text_size -= key->get_width() + 4 * EDSCALE; } } if (deletable) { Ref close; close = get_editor_theme_icon(SNAME("Close")); rect.size.x -= close->get_width() + get_theme_constant(SNAME("h_separation"), SNAME("Tree")); if (is_layout_rtl()) { rect.position.x += close->get_width() + get_theme_constant(SNAME("h_separation"), SNAME("Tree")); } if (no_children) { text_size -= close->get_width() + 4 * EDSCALE; } } // Account for the space needed on the outer side // when any of the icons are visible. if (keying || deletable) { int separation = get_theme_constant(SNAME("h_separation"), SNAME("Tree")); rect.size.x -= separation; if (is_layout_rtl()) { rect.position.x += separation; } } } //set children for (int i = 0; i < get_child_count(); i++) { Control *c = as_sortable_control(get_child(i)); if (!c) { continue; } if (c == bottom_editor) { continue; } fit_child_in_rect(c, rect); right_child_rect = rect; } if (bottom_editor) { fit_child_in_rect(bottom_editor, bottom_rect); bottom_child_rect = bottom_rect; } queue_redraw(); //need to redraw text } break; case NOTIFICATION_DRAW: { Ref font = get_theme_font(SceneStringName(font), SNAME("Tree")); int font_size = get_theme_font_size(SceneStringName(font_size), SNAME("Tree")); bool rtl = is_layout_rtl(); Size2 size = get_size(); if (bottom_editor) { size.height = bottom_editor->get_offset(SIDE_TOP) - get_theme_constant(SNAME("v_separation")); } else if (label_reference) { size.height = label_reference->get_size().height; } // Only draw the label if it's not empty. if (label.is_empty()) { size.height = 0; } else { Ref sb = get_theme_stylebox(selected ? SNAME("bg_selected") : SNAME("bg")); draw_style_box(sb, Rect2(Vector2(), size)); } Ref bg_stylebox = get_theme_stylebox(SNAME("child_bg")); if (draw_top_bg && right_child_rect != Rect2() && draw_background) { draw_style_box(bg_stylebox, right_child_rect); } if (bottom_child_rect != Rect2() && draw_background) { draw_style_box(bg_stylebox, bottom_child_rect); } Color color; if (draw_warning || draw_prop_warning) { color = get_theme_color(is_read_only() ? SNAME("readonly_warning_color") : SNAME("warning_color")); } else { color = get_theme_color(is_read_only() ? SNAME("readonly_color") : SNAME("property_color")); } if (label.contains_char('.')) { // FIXME: Move this to the project settings editor, as this is only used // for project settings feature tag overrides. color.a = 0.5; } int ofs = get_theme_constant(SNAME("font_offset")); int text_limit = text_size - ofs; int base_spacing = EDITOR_GET("interface/theme/base_spacing"); int padding = base_spacing * EDSCALE; int half_padding = padding / 2; if (checkable) { Ref checkbox; if (checked) { checkbox = get_editor_theme_icon(SNAME("GuiChecked")); } else { checkbox = get_editor_theme_icon(SNAME("GuiUnchecked")); } check_rect = Rect2(ofs, 0, checkbox->get_width() + padding, size.height); Point2 rtl_pos; if (rtl) { rtl_pos = Point2(size.width - check_rect.position.x - (checkbox->get_width() + padding + (1 * EDSCALE)), check_rect.position.y); } Color color2(1, 1, 1); if (check_hover) { color2.r *= 1.2; color2.g *= 1.2; color2.b *= 1.2; Ref sb_hover = get_theme_stylebox(SceneStringName(hover), "Button"); if (rtl) { draw_style_box(sb_hover, Rect2(rtl_pos, check_rect.size)); } else { draw_style_box(sb_hover, check_rect); } } if (rtl) { draw_texture(checkbox, rtl_pos + Point2(padding, size.height - checkbox->get_height()) / 2, color2); } else { draw_texture(checkbox, check_rect.position + Point2(padding, size.height - checkbox->get_height()) / 2, color2); } int check_ofs = checkbox->get_width() + get_theme_constant(SNAME("h_separation"), SNAME("Tree")); ofs += check_ofs; text_limit -= check_ofs; } else { check_rect = Rect2(); } if (can_revert && !is_read_only()) { Ref reload_icon = get_editor_theme_icon(SNAME("ReloadSmall")); text_limit -= reload_icon->get_width() + half_padding + get_theme_constant(SNAME("h_separation"), SNAME("Tree")); revert_rect = Rect2(ofs + text_limit, 0, reload_icon->get_width() + padding + (1 * EDSCALE), size.height); Point2 rtl_pos; if (rtl) { rtl_pos = Point2(size.width - revert_rect.position.x - (reload_icon->get_width() + padding + (1 * EDSCALE)), revert_rect.position.y); } Color color2(1, 1, 1); if (revert_hover) { color2.r *= 1.2; color2.g *= 1.2; color2.b *= 1.2; Ref sb_hover = get_theme_stylebox(SceneStringName(hover), "Button"); if (rtl) { draw_style_box(sb_hover, Rect2(rtl_pos, revert_rect.size)); } else { draw_style_box(sb_hover, revert_rect); } } if (rtl) { draw_texture(reload_icon, rtl_pos + Point2(padding, size.height - reload_icon->get_height()) / 2, color2); } else { draw_texture(reload_icon, revert_rect.position + Point2(padding, size.height - reload_icon->get_height()) / 2, color2); } } else { revert_rect = Rect2(); } if (!pin_hidden && pinned) { Ref pinned_icon = get_editor_theme_icon(SNAME("Pin")); int margin_w = get_theme_constant(SNAME("h_separation"), SNAME("Tree")); int total_icon_w = margin_w + pinned_icon->get_width(); int text_w = font->get_string_size(label, rtl ? HORIZONTAL_ALIGNMENT_RIGHT : HORIZONTAL_ALIGNMENT_LEFT, text_limit - total_icon_w, font_size).x; int y = (size.height - pinned_icon->get_height()) / 2; if (rtl) { draw_texture(pinned_icon, Vector2(size.width - ofs - text_w - total_icon_w, y), color); } else { draw_texture(pinned_icon, Vector2(ofs + text_w + margin_w, y), color); } text_limit -= total_icon_w; } int v_ofs = (size.height - font->get_height(font_size)) / 2; if (rtl) { draw_string(font, Point2(size.width - ofs - text_limit, v_ofs + font->get_ascent(font_size)), label, HORIZONTAL_ALIGNMENT_RIGHT, text_limit, font_size, color); } else { draw_string(font, Point2(ofs, v_ofs + font->get_ascent(font_size)), label, HORIZONTAL_ALIGNMENT_LEFT, text_limit, font_size, color); } ofs = size.width; if (keying) { Ref key; if (use_keying_next()) { key = get_editor_theme_icon(SNAME("KeyNext")); } else { key = get_editor_theme_icon(SNAME("Key")); } ofs -= key->get_width() + half_padding + get_theme_constant(SNAME("h_separation"), SNAME("Tree")); keying_rect = Rect2(ofs, 0, key->get_width() + padding, size.height); Point2 rtl_pos; if (rtl) { rtl_pos = Point2(size.width - keying_rect.position.x - (key->get_width() + padding), keying_rect.position.y); } Color color2(1, 1, 1); if (keying_hover) { color2.r *= 1.2; color2.g *= 1.2; color2.b *= 1.2; Ref sb_hover = get_theme_stylebox(SceneStringName(hover), "Button"); if (rtl) { draw_style_box(sb_hover, Rect2(rtl_pos, keying_rect.size)); } else { draw_style_box(sb_hover, keying_rect); } } if (rtl) { draw_texture(key, rtl_pos + Point2(padding, size.height - key->get_height()) / 2, color2); } else { draw_texture(key, keying_rect.position + Point2(padding, size.height - key->get_height()) / 2, color2); } } else { keying_rect = Rect2(); } if (deletable) { Ref close; close = get_editor_theme_icon(SNAME("Close")); ofs -= close->get_width() + half_padding + get_theme_constant(SNAME("h_separation"), SNAME("Tree")); delete_rect = Rect2(ofs, 0, close->get_width() + padding, size.height); Point2 rtl_pos; if (rtl) { rtl_pos = Point2(size.width - delete_rect.position.x - (close->get_width() + padding), delete_rect.position.y); } Color color2(1, 1, 1); if (delete_hover) { color2.r *= 1.2; color2.g *= 1.2; color2.b *= 1.2; Ref sb_hover = get_theme_stylebox(SceneStringName(hover), "Button"); if (rtl) { draw_style_box(sb_hover, Rect2(rtl_pos, delete_rect.size)); } else { draw_style_box(sb_hover, delete_rect); } } if (rtl) { draw_texture(close, rtl_pos + Point2(padding, size.height - close->get_height()) / 2, color2); } else { draw_texture(close, delete_rect.position + Point2(padding, size.height - close->get_height()) / 2, color2); } } else { delete_rect = Rect2(); } } break; case NOTIFICATION_ENTER_TREE: { EditorInspector *inspector = get_parent_inspector(); if (inspector) { inspector = inspector->get_root_inspector(); } set_shortcut_context(inspector); if (has_borders) { get_parent()->connect(SceneStringName(theme_changed), callable_mp(this, &EditorProperty::_update_property_bg)); _update_property_bg(); } } break; case NOTIFICATION_EXIT_TREE: { if (has_borders) { get_parent()->disconnect(SceneStringName(theme_changed), callable_mp(this, &EditorProperty::_update_property_bg)); } } break; case NOTIFICATION_MOUSE_EXIT: { if (keying_hover || revert_hover || check_hover || delete_hover) { keying_hover = false; revert_hover = false; check_hover = false; delete_hover = false; queue_redraw(); } } break; } } void EditorProperty::set_label(const String &p_label) { label = p_label; queue_redraw(); } String EditorProperty::get_label() const { return label; } Object *EditorProperty::get_edited_object() { return object; } StringName EditorProperty::get_edited_property() const { return property; } Variant EditorProperty::get_edited_property_display_value() const { ERR_FAIL_NULL_V(object, Variant()); Control *control = Object::cast_to(object); if (checkable && !checked && control && String(property).begins_with("theme_override_")) { return control->get_used_theme_item(property); } else { return get_edited_property_value(); } } EditorInspector *EditorProperty::get_parent_inspector() const { Node *parent = get_parent(); while (parent) { EditorInspector *ei = Object::cast_to(parent); if (ei) { return ei; } parent = parent->get_parent(); } return nullptr; } void EditorProperty::set_doc_path(const String &p_doc_path) { doc_path = p_doc_path; } void EditorProperty::set_internal(bool p_internal) { internal = p_internal; } void EditorProperty::update_property() { GDVIRTUAL_CALL(_update_property); } void EditorProperty::_set_read_only(bool p_read_only) { } void EditorProperty::set_read_only(bool p_read_only) { read_only = p_read_only; if (GDVIRTUAL_CALL(_set_read_only, p_read_only)) { return; } _set_read_only(p_read_only); } bool EditorProperty::is_read_only() const { return read_only; } Variant EditorPropertyRevert::get_property_revert_value(Object *p_object, const StringName &p_property, bool *r_is_valid) { if (p_object->property_can_revert(p_property)) { if (r_is_valid) { *r_is_valid = true; } return p_object->property_get_revert(p_property); } return PropertyUtils::get_property_default_value(p_object, p_property, r_is_valid); } bool EditorPropertyRevert::can_property_revert(Object *p_object, const StringName &p_property, const Variant *p_custom_current_value) { bool is_valid_revert = false; Variant revert_value = EditorPropertyRevert::get_property_revert_value(p_object, p_property, &is_valid_revert); if (!is_valid_revert) { return false; } Variant current_value = p_custom_current_value ? *p_custom_current_value : p_object->get(p_property); return PropertyUtils::is_property_value_different(p_object, current_value, revert_value); } StringName EditorProperty::_get_revert_property() const { return property; } void EditorProperty::_update_property_bg() { // This function is to be called on EditorPropertyResource, EditorPropertyArray, and EditorPropertyDictionary. // Behavior is undetermined on any other EditorProperty. if (!is_inside_tree()) { return; } begin_bulk_theme_override(); if (bottom_editor) { ColorationMode nested_color_mode = (ColorationMode)(int)EDITOR_GET("interface/inspector/nested_color_mode"); bool delimitate_all_container_and_resources = EDITOR_GET("interface/inspector/delimitate_all_container_and_resources"); int count_subinspectors = 0; if (is_colored(nested_color_mode)) { Node *n = this; while (n) { EditorProperty *ep = Object::cast_to(n); if (ep && ep->is_colored(nested_color_mode)) { count_subinspectors++; } n = n->get_parent(); } count_subinspectors = MIN(16, count_subinspectors); } add_theme_style_override(SNAME("DictionaryAddItem"), get_theme_stylebox("DictionaryAddItem" + itos(count_subinspectors), EditorStringName(EditorStyles))); add_theme_constant_override("v_separation", 0); if (delimitate_all_container_and_resources || is_colored(nested_color_mode)) { add_theme_style_override("bg_selected", get_theme_stylebox("sub_inspector_property_bg" + itos(count_subinspectors), EditorStringName(EditorStyles))); add_theme_style_override("bg", get_theme_stylebox("sub_inspector_property_bg" + itos(count_subinspectors), EditorStringName(EditorStyles))); add_theme_color_override("property_color", get_theme_color(SNAME("sub_inspector_property_color"), EditorStringName(EditorStyles))); bottom_editor->add_theme_style_override(SceneStringName(panel), get_theme_stylebox("sub_inspector_bg" + itos(count_subinspectors), EditorStringName(EditorStyles))); } else { bottom_editor->add_theme_style_override(SceneStringName(panel), get_theme_stylebox("sub_inspector_bg_no_border", EditorStringName(EditorStyles))); } } else { remove_theme_style_override("bg_selected"); remove_theme_style_override("bg"); remove_theme_color_override("property_color"); } end_bulk_theme_override(); queue_redraw(); } void EditorProperty::update_editor_property_status() { if (property == StringName()) { return; //no property, so nothing to do } bool new_pinned = false; if (can_pin) { Node *node = Object::cast_to(object); CRASH_COND(!node); new_pinned = node->is_property_pinned(property); } bool new_warning = false; if (object->has_method("_get_property_warning")) { new_warning = !String(object->call("_get_property_warning", property)).is_empty(); } Variant current = object->get(_get_revert_property()); bool new_can_revert = EditorPropertyRevert::can_property_revert(object, property, ¤t) && !is_read_only(); bool new_checked = checked; if (checkable) { // for properties like theme overrides. bool valid = false; Variant value = object->get(property, &valid); if (valid) { new_checked = value.get_type() != Variant::NIL; } } if (new_can_revert != can_revert || new_pinned != pinned || new_checked != checked || new_warning != draw_prop_warning) { if (new_can_revert != can_revert) { emit_signal(SNAME("property_can_revert_changed"), property, new_can_revert); } draw_prop_warning = new_warning; can_revert = new_can_revert; pinned = new_pinned; checked = new_checked; queue_redraw(); } } bool EditorProperty::use_keying_next() const { List plist; object->get_property_list(&plist, true); for (const PropertyInfo &p : plist) { if (p.name == property) { return (p.usage & PROPERTY_USAGE_KEYING_INCREMENTS); } } return false; } void EditorProperty::set_draw_label(bool p_draw_label) { draw_label = p_draw_label; queue_redraw(); queue_sort(); } bool EditorProperty::is_draw_label() const { return draw_label; } void EditorProperty::set_draw_background(bool p_draw_background) { draw_background = p_draw_background; queue_redraw(); } bool EditorProperty::is_draw_background() const { return draw_background; } void EditorProperty::set_checkable(bool p_checkable) { checkable = p_checkable; queue_redraw(); queue_sort(); } bool EditorProperty::is_checkable() const { return checkable; } void EditorProperty::set_checked(bool p_checked) { checked = p_checked; queue_redraw(); } bool EditorProperty::is_checked() const { return checked; } void EditorProperty::set_draw_warning(bool p_draw_warning) { draw_warning = p_draw_warning; queue_redraw(); } void EditorProperty::set_keying(bool p_keying) { keying = p_keying; queue_redraw(); queue_sort(); } void EditorProperty::set_deletable(bool p_deletable) { deletable = p_deletable; queue_redraw(); queue_sort(); } bool EditorProperty::is_deletable() const { return deletable; } bool EditorProperty::is_keying() const { return keying; } bool EditorProperty::is_draw_warning() const { return draw_warning; } void EditorProperty::_focusable_focused(int p_index) { if (!selectable) { return; } bool already_selected = selected; selected = true; selected_focusable = p_index; queue_redraw(); if (!already_selected && selected) { emit_signal(SNAME("selected"), property, selected_focusable); } } void EditorProperty::add_focusable(Control *p_control) { p_control->connect(SceneStringName(focus_entered), callable_mp(this, &EditorProperty::_focusable_focused).bind(focusables.size())); focusables.push_back(p_control); } void EditorProperty::grab_focus(int p_focusable) { if (focusables.is_empty()) { return; } if (p_focusable >= 0) { ERR_FAIL_INDEX(p_focusable, focusables.size()); focusables[p_focusable]->grab_focus(); } else { focusables[0]->grab_focus(); } } void EditorProperty::select(int p_focusable) { bool already_selected = selected; if (!selectable) { return; } if (p_focusable >= 0) { ERR_FAIL_INDEX(p_focusable, focusables.size()); focusables[p_focusable]->grab_focus(); } else { selected = true; queue_redraw(); } if (!already_selected && selected) { emit_signal(SNAME("selected"), property, selected_focusable); } } void EditorProperty::deselect() { selected = false; selected_focusable = -1; queue_redraw(); } bool EditorProperty::is_selected() const { return selected; } void EditorProperty::gui_input(const Ref &p_event) { ERR_FAIL_COND(p_event.is_null()); if (property == StringName()) { return; } Ref me = p_event; if (me.is_valid()) { Vector2 mpos = me->get_position(); if (bottom_child_rect.has_point(mpos)) { return; // Makes child EditorProperties behave like sibling nodes when handling mouse events. } if (is_layout_rtl()) { mpos.x = get_size().x - mpos.x; } bool button_left = me->get_button_mask().has_flag(MouseButtonMask::LEFT); bool new_keying_hover = keying_rect.has_point(mpos) && !button_left; if (new_keying_hover != keying_hover) { keying_hover = new_keying_hover; queue_redraw(); } bool new_delete_hover = delete_rect.has_point(mpos) && !button_left; if (new_delete_hover != delete_hover) { delete_hover = new_delete_hover; queue_redraw(); } bool new_revert_hover = revert_rect.has_point(mpos) && !button_left; if (new_revert_hover != revert_hover) { revert_hover = new_revert_hover; queue_redraw(); } bool new_check_hover = check_rect.has_point(mpos) && !button_left; if (new_check_hover != check_hover) { check_hover = new_check_hover; queue_redraw(); } } Ref mb = p_event; if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT) { Vector2 mpos = mb->get_position(); if (is_layout_rtl()) { mpos.x = get_size().x - mpos.x; } select(); if (keying_rect.has_point(mpos)) { accept_event(); emit_signal(SNAME("property_keyed"), property, use_keying_next()); if (use_keying_next()) { if (property == "frame_coords" && (object->is_class("Sprite2D") || object->is_class("Sprite3D"))) { Vector2i new_coords = object->get(property); new_coords.x++; if (new_coords.x >= int64_t(object->get("hframes"))) { new_coords.x = 0; new_coords.y++; } if (new_coords.x < int64_t(object->get("hframes")) && new_coords.y < int64_t(object->get("vframes"))) { callable_mp(this, &EditorProperty::emit_changed).call_deferred(property, new_coords, "", false); } } else { if (int64_t(object->get(property)) + 1 < (int64_t(object->get("hframes")) * int64_t(object->get("vframes")))) { callable_mp(this, &EditorProperty::emit_changed).call_deferred(property, object->get(property).operator int64_t() + 1, "", false); } } callable_mp(this, &EditorProperty::update_property).call_deferred(); } } if (delete_rect.has_point(mpos)) { accept_event(); emit_signal(SNAME("property_deleted"), property); } if (revert_rect.has_point(mpos)) { accept_event(); get_viewport()->gui_release_focus(); bool is_valid_revert = false; Variant revert_value = EditorPropertyRevert::get_property_revert_value(object, property, &is_valid_revert); ERR_FAIL_COND(!is_valid_revert); emit_changed(_get_revert_property(), revert_value); update_property(); } if (check_rect.has_point(mpos)) { accept_event(); if (!checked && Object::cast_to(object) && property_path.begins_with("theme_override_")) { List pinfo; object->get_property_list(&pinfo); for (const PropertyInfo &E : pinfo) { if (E.type == Variant::OBJECT && E.name == property_path) { EditorToaster::get_singleton()->popup_str(TTR("Toggling the checkbox is disabled for Resource properties. Modify the property using the resource picker instead."), EditorToaster::SEVERITY_WARNING); return; // Disallow clicking to toggle the checkbox of type Resource to checked. } } } checked = !checked; queue_redraw(); emit_signal(SNAME("property_checked"), property, checked); } } else if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MouseButton::RIGHT) { accept_event(); _update_popup(); menu->set_position(get_screen_position() + get_local_mouse_position()); menu->reset_size(); menu->popup(); select(); return; } } void EditorProperty::_accessibility_action_click(const Variant &p_data) { select(); if (checkable) { if (!checked && Object::cast_to(object) && property_path.begins_with("theme_override_")) { List pinfo; object->get_property_list(&pinfo); for (const PropertyInfo &E : pinfo) { if (E.type == Variant::OBJECT && E.name == property_path) { EditorToaster::get_singleton()->popup_str(TTR("Toggling the checkbox is disabled for Resource properties. Modify the property using the resource picker instead."), EditorToaster::SEVERITY_WARNING); return; } } } checked = !checked; queue_redraw(); emit_signal(SNAME("property_checked"), property, checked); } } void EditorProperty::_accessibility_action_menu(const Variant &p_data) { _update_popup(); menu->set_position(get_screen_position()); menu->reset_size(); menu->popup(); } void EditorProperty::shortcut_input(const Ref &p_event) { if (!selected || !p_event->is_pressed()) { return; } const Ref k = p_event; if (k.is_valid() && k->is_pressed()) { if (ED_IS_SHORTCUT("property_editor/copy_value", p_event)) { menu_option(MENU_COPY_VALUE); accept_event(); } else if (!is_read_only() && ED_IS_SHORTCUT("property_editor/paste_value", p_event)) { menu_option(MENU_PASTE_VALUE); accept_event(); } else if (!internal && ED_IS_SHORTCUT("property_editor/copy_property_path", p_event)) { menu_option(MENU_COPY_PROPERTY_PATH); accept_event(); } } } const Color *EditorProperty::_get_property_colors() { static Color c[4]; c[0] = get_theme_color(SNAME("property_color_x"), EditorStringName(Editor)); c[1] = get_theme_color(SNAME("property_color_y"), EditorStringName(Editor)); c[2] = get_theme_color(SNAME("property_color_z"), EditorStringName(Editor)); c[3] = get_theme_color(SNAME("property_color_w"), EditorStringName(Editor)); return c; } void EditorProperty::set_label_reference(Control *p_control) { label_reference = p_control; } void EditorProperty::set_bottom_editor(Control *p_control) { bottom_editor = p_control; if (has_borders) { _update_property_bg(); } } Variant EditorProperty::_get_cache_value(const StringName &p_prop, bool &r_valid) const { return object->get(p_prop, &r_valid); } bool EditorProperty::is_cache_valid() const { if (object) { for (const KeyValue &E : cache) { bool valid; Variant value = _get_cache_value(E.key, valid); if (!valid || value != E.value) { return false; } } } return true; } void EditorProperty::update_cache() { cache.clear(); if (object && property != StringName()) { bool valid; Variant value = _get_cache_value(property, valid); if (valid) { cache[property] = value; } } } Variant EditorProperty::get_drag_data(const Point2 &p_point) { if (property == StringName()) { return Variant(); } Dictionary dp; dp["type"] = "obj_property"; dp["object"] = object; dp["property"] = property; dp["value"] = object->get(property); Label *drag_label = memnew(Label); drag_label->set_focus_mode(FOCUS_ACCESSIBILITY); drag_label->set_text(property); drag_label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); // Don't translate raw property name. set_drag_preview(drag_label); return dp; } void EditorProperty::set_use_folding(bool p_use_folding) { use_folding = p_use_folding; } bool EditorProperty::is_using_folding() const { return use_folding; } void EditorProperty::expand_all_folding() { } void EditorProperty::collapse_all_folding() { } void EditorProperty::expand_revertable() { } void EditorProperty::set_selectable(bool p_selectable) { selectable = p_selectable; } bool EditorProperty::is_selectable() const { return selectable; } void EditorProperty::set_name_split_ratio(float p_ratio) { split_ratio = p_ratio; } float EditorProperty::get_name_split_ratio() const { return split_ratio; } void EditorProperty::set_favoritable(bool p_favoritable) { can_favorite = p_favoritable; } bool EditorProperty::is_favoritable() const { return can_favorite; } void EditorProperty::set_object_and_property(Object *p_object, const StringName &p_property) { object = p_object; property = p_property; _update_flags(); } static bool _is_value_potential_override(Node *p_node, const String &p_property) { // Consider a value is potentially overriding another if either of the following is true: // a) The node is foreign (inheriting or an instance), so the original value may come from another scene. // b) The node belongs to the scene, but the original value comes from somewhere but the builtin class (i.e., a script). Node *edited_scene = EditorNode::get_singleton()->get_edited_scene(); Vector states_stack = PropertyUtils::get_node_states_stack(p_node, edited_scene); if (states_stack.size()) { return true; } else { bool is_valid_default = false; bool is_class_default = false; PropertyUtils::get_property_default_value(p_node, p_property, &is_valid_default, &states_stack, false, nullptr, &is_class_default); return !is_class_default; } } void EditorProperty::_update_flags() { can_pin = false; pin_hidden = true; if (read_only) { return; } if (Node *node = Object::cast_to(object)) { // Avoid errors down the road by ignoring nodes which are not part of a scene if (!node->get_owner()) { bool is_scene_root = false; for (int i = 0; i < EditorNode::get_editor_data().get_edited_scene_count(); ++i) { if (EditorNode::get_editor_data().get_edited_scene_root(i) == node) { is_scene_root = true; break; } } if (!is_scene_root) { return; } } if (!_is_value_potential_override(node, property)) { return; } pin_hidden = false; { HashSet storable_properties; node->get_storable_properties(storable_properties); if (storable_properties.has(node->get_property_store_alias(property))) { can_pin = true; } } } } Control *EditorProperty::make_custom_tooltip(const String &p_text) const { String symbol; String prologue; if (object->has_method("_get_property_warning")) { const String custom_warning = object->call("_get_property_warning", property); if (!custom_warning.is_empty()) { prologue = "[b][color=" + get_theme_color(SNAME("warning_color")).to_html(false) + "]" + custom_warning + "[/color][/b]"; } } if (has_doc_tooltip) { symbol = p_text; const EditorInspector *inspector = get_parent_inspector(); if (inspector) { const String custom_description = inspector->get_custom_property_description(p_text); if (!custom_description.is_empty()) { if (!prologue.is_empty()) { prologue += '\n'; } prologue += custom_description; } } } if (!symbol.is_empty() || !prologue.is_empty()) { return EditorHelpBitTooltip::show_tooltip(const_cast(this), symbol, prologue); } return nullptr; } void EditorProperty::menu_option(int p_option) { switch (p_option) { case MENU_COPY_VALUE: { InspectorDock::get_inspector_singleton()->set_property_clipboard(object->get(property)); } break; case MENU_PASTE_VALUE: { emit_changed(property, InspectorDock::get_inspector_singleton()->get_property_clipboard()); } break; case MENU_COPY_PROPERTY_PATH: { DisplayServer::get_singleton()->clipboard_set(property_path); } break; case MENU_OVERRIDE_FOR_PROJECT: { emit_signal(SNAME("property_overridden")); } break; case MENU_FAVORITE_PROPERTY: { emit_signal(SNAME("property_favorited"), property, !favorited); queue_redraw(); } break; case MENU_PIN_VALUE: { emit_signal(SNAME("property_pinned"), property, !pinned); queue_redraw(); } break; case MENU_DELETE: { accept_event(); emit_signal(SNAME("property_deleted"), property); } break; case MENU_REVERT_VALUE: { accept_event(); get_viewport()->gui_release_focus(); bool is_valid_revert = false; Variant revert_value = EditorPropertyRevert::get_property_revert_value(object, property, &is_valid_revert); ERR_FAIL_COND(!is_valid_revert); emit_changed(_get_revert_property(), revert_value); update_property(); } break; case MENU_OPEN_DOCUMENTATION: { ScriptEditor::get_singleton()->goto_help(doc_path); EditorNode::get_singleton()->get_editor_main_screen()->select(EditorMainScreen::EDITOR_SCRIPT); } break; } } void EditorProperty::_bind_methods() { ClassDB::bind_method(D_METHOD("set_label", "text"), &EditorProperty::set_label); ClassDB::bind_method(D_METHOD("get_label"), &EditorProperty::get_label); ClassDB::bind_method(D_METHOD("set_read_only", "read_only"), &EditorProperty::set_read_only); ClassDB::bind_method(D_METHOD("is_read_only"), &EditorProperty::is_read_only); ClassDB::bind_method(D_METHOD("set_draw_label", "draw_label"), &EditorProperty::set_draw_label); ClassDB::bind_method(D_METHOD("is_draw_label"), &EditorProperty::is_draw_label); ClassDB::bind_method(D_METHOD("set_draw_background", "draw_background"), &EditorProperty::set_draw_background); ClassDB::bind_method(D_METHOD("is_draw_background"), &EditorProperty::is_draw_background); ClassDB::bind_method(D_METHOD("set_checkable", "checkable"), &EditorProperty::set_checkable); ClassDB::bind_method(D_METHOD("is_checkable"), &EditorProperty::is_checkable); ClassDB::bind_method(D_METHOD("set_checked", "checked"), &EditorProperty::set_checked); ClassDB::bind_method(D_METHOD("is_checked"), &EditorProperty::is_checked); ClassDB::bind_method(D_METHOD("set_draw_warning", "draw_warning"), &EditorProperty::set_draw_warning); ClassDB::bind_method(D_METHOD("is_draw_warning"), &EditorProperty::is_draw_warning); ClassDB::bind_method(D_METHOD("set_keying", "keying"), &EditorProperty::set_keying); ClassDB::bind_method(D_METHOD("is_keying"), &EditorProperty::is_keying); ClassDB::bind_method(D_METHOD("set_deletable", "deletable"), &EditorProperty::set_deletable); ClassDB::bind_method(D_METHOD("is_deletable"), &EditorProperty::is_deletable); ClassDB::bind_method(D_METHOD("get_edited_property"), &EditorProperty::get_edited_property); ClassDB::bind_method(D_METHOD("get_edited_object"), &EditorProperty::get_edited_object); ClassDB::bind_method(D_METHOD("update_property"), &EditorProperty::update_property); ClassDB::bind_method(D_METHOD("add_focusable", "control"), &EditorProperty::add_focusable); ClassDB::bind_method(D_METHOD("set_bottom_editor", "editor"), &EditorProperty::set_bottom_editor); ClassDB::bind_method(D_METHOD("set_selectable", "selectable"), &EditorProperty::set_selectable); ClassDB::bind_method(D_METHOD("is_selectable"), &EditorProperty::is_selectable); ClassDB::bind_method(D_METHOD("set_use_folding", "use_folding"), &EditorProperty::set_use_folding); ClassDB::bind_method(D_METHOD("is_using_folding"), &EditorProperty::is_using_folding); ClassDB::bind_method(D_METHOD("set_name_split_ratio", "ratio"), &EditorProperty::set_name_split_ratio); ClassDB::bind_method(D_METHOD("get_name_split_ratio"), &EditorProperty::get_name_split_ratio); ClassDB::bind_method(D_METHOD("deselect"), &EditorProperty::deselect); ClassDB::bind_method(D_METHOD("is_selected"), &EditorProperty::is_selected); ClassDB::bind_method(D_METHOD("select", "focusable"), &EditorProperty::select, DEFVAL(-1)); ClassDB::bind_method(D_METHOD("set_object_and_property", "object", "property"), &EditorProperty::set_object_and_property); ClassDB::bind_method(D_METHOD("set_label_reference", "control"), &EditorProperty::set_label_reference); ClassDB::bind_method(D_METHOD("emit_changed", "property", "value", "field", "changing"), &EditorProperty::emit_changed, DEFVAL(StringName()), DEFVAL(false)); ADD_PROPERTY(PropertyInfo(Variant::STRING, "label"), "set_label", "get_label"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "read_only"), "set_read_only", "is_read_only"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_label"), "set_draw_label", "is_draw_label"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_background"), "set_draw_background", "is_draw_background"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "checkable"), "set_checkable", "is_checkable"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "checked"), "set_checked", "is_checked"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_warning"), "set_draw_warning", "is_draw_warning"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "keying"), "set_keying", "is_keying"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "deletable"), "set_deletable", "is_deletable"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "selectable"), "set_selectable", "is_selectable"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_folding"), "set_use_folding", "is_using_folding"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "name_split_ratio"), "set_name_split_ratio", "get_name_split_ratio"); ADD_SIGNAL(MethodInfo("property_changed", PropertyInfo(Variant::STRING_NAME, "property"), PropertyInfo(Variant::NIL, "value", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT), PropertyInfo(Variant::STRING_NAME, "field"), PropertyInfo(Variant::BOOL, "changing"))); ADD_SIGNAL(MethodInfo("multiple_properties_changed", PropertyInfo(Variant::PACKED_STRING_ARRAY, "properties"), PropertyInfo(Variant::ARRAY, "value"))); ADD_SIGNAL(MethodInfo("property_keyed", PropertyInfo(Variant::STRING_NAME, "property"))); ADD_SIGNAL(MethodInfo("property_deleted", PropertyInfo(Variant::STRING_NAME, "property"))); ADD_SIGNAL(MethodInfo("property_keyed_with_value", PropertyInfo(Variant::STRING_NAME, "property"), PropertyInfo(Variant::NIL, "value", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT))); ADD_SIGNAL(MethodInfo("property_checked", PropertyInfo(Variant::STRING_NAME, "property"), PropertyInfo(Variant::BOOL, "checked"))); ADD_SIGNAL(MethodInfo("property_overridden")); ADD_SIGNAL(MethodInfo("property_favorited", PropertyInfo(Variant::STRING_NAME, "property"), PropertyInfo(Variant::BOOL, "favorited"))); ADD_SIGNAL(MethodInfo("property_pinned", PropertyInfo(Variant::STRING_NAME, "property"), PropertyInfo(Variant::BOOL, "pinned"))); ADD_SIGNAL(MethodInfo("property_can_revert_changed", PropertyInfo(Variant::STRING_NAME, "property"), PropertyInfo(Variant::BOOL, "can_revert"))); ADD_SIGNAL(MethodInfo("resource_selected", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::OBJECT, "resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource"))); ADD_SIGNAL(MethodInfo("object_id_selected", PropertyInfo(Variant::STRING_NAME, "property"), PropertyInfo(Variant::INT, "id"))); ADD_SIGNAL(MethodInfo("selected", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::INT, "focusable_idx"))); GDVIRTUAL_BIND(_update_property) GDVIRTUAL_BIND(_set_read_only, "read_only") ClassDB::bind_method(D_METHOD("_update_editor_property_status"), &EditorProperty::update_editor_property_status); } EditorProperty::EditorProperty() { set_focus_mode(FOCUS_ACCESSIBILITY); object = nullptr; split_ratio = 0.5; text_size = 0; property_usage = 0; selected_focusable = -1; label_reference = nullptr; bottom_editor = nullptr; menu = nullptr; set_process_shortcut_input(true); } void EditorProperty::_update_popup() { if (menu) { menu->clear(); } else { menu = memnew(PopupMenu); add_child(menu); menu->connect(SceneStringName(id_pressed), callable_mp(this, &EditorProperty::menu_option)); } menu->add_icon_shortcut(get_editor_theme_icon(SNAME("ActionCopy")), ED_GET_SHORTCUT("property_editor/copy_value"), MENU_COPY_VALUE); menu->add_icon_shortcut(get_editor_theme_icon(SNAME("ActionPaste")), ED_GET_SHORTCUT("property_editor/paste_value"), MENU_PASTE_VALUE); menu->add_icon_shortcut(get_editor_theme_icon(SNAME("CopyNodePath")), ED_GET_SHORTCUT("property_editor/copy_property_path"), MENU_COPY_PROPERTY_PATH); menu->set_item_disabled(MENU_PASTE_VALUE, is_read_only()); menu->set_item_disabled(MENU_COPY_PROPERTY_PATH, internal); if (can_favorite || !pin_hidden) { menu->add_separator(); } if (can_favorite) { if (favorited) { menu->add_icon_item(get_editor_theme_icon(SNAME("Unfavorite")), TTR("Unfavorite Property"), MENU_FAVORITE_PROPERTY); menu->set_item_tooltip(menu->get_item_index(MENU_FAVORITE_PROPERTY), TTR("Make this property be put back at its original place.")); } else { // TRANSLATORS: This is a menu item to add a property to the favorites. menu->add_icon_item(get_editor_theme_icon(SNAME("Favorites")), TTR("Favorite Property"), MENU_FAVORITE_PROPERTY); menu->set_item_tooltip(menu->get_item_index(MENU_FAVORITE_PROPERTY), TTR("Make this property be placed at the top for all objects of this class.")); } } if (!pin_hidden) { if (can_pin) { menu->add_icon_check_item(get_editor_theme_icon(SNAME("Pin")), TTR("Pin Value"), MENU_PIN_VALUE); menu->set_item_checked(menu->get_item_index(MENU_PIN_VALUE), pinned); } else { menu->add_icon_check_item(get_editor_theme_icon(SNAME("Pin")), vformat(TTR("Pin Value [Disabled because '%s' is editor-only]"), property), MENU_PIN_VALUE); menu->set_item_disabled(menu->get_item_index(MENU_PIN_VALUE), true); } menu->set_item_tooltip(menu->get_item_index(MENU_PIN_VALUE), TTR("Pinning a value forces it to be saved even if it's equal to the default.")); } if (deletable || can_revert || can_override) { menu->add_separator(); if (can_override) { menu->add_icon_item(get_editor_theme_icon(SNAME("Override")), TTRC("Override for Project"), MENU_OVERRIDE_FOR_PROJECT); } if (deletable) { menu->add_icon_item(get_editor_theme_icon(SNAME("Remove")), TTR("Delete Property"), MENU_DELETE); } if (can_revert) { menu->add_icon_item(get_editor_theme_icon(SNAME("Reload")), TTR("Revert Value"), MENU_REVERT_VALUE); } } if (!doc_path.is_empty()) { menu->add_separator(); menu->add_icon_item(get_editor_theme_icon(SNAME("Help")), TTR("Open Documentation"), MENU_OPEN_DOCUMENTATION); } } //////////////////////////////////////////////// //////////////////////////////////////////////// void EditorInspectorPlugin::add_custom_control(Control *control) { AddedEditor ae; ae.property_editor = control; added_editors.push_back(ae); } void EditorInspectorPlugin::add_property_editor(const String &p_for_property, Control *p_prop, bool p_add_to_end, const String &p_label) { AddedEditor ae; ae.properties.push_back(p_for_property); ae.property_editor = p_prop; ae.add_to_end = p_add_to_end; ae.label = p_label; added_editors.push_back(ae); } void EditorInspectorPlugin::add_property_editor_for_multiple_properties(const String &p_label, const Vector &p_properties, Control *p_prop) { AddedEditor ae; ae.properties = p_properties; ae.property_editor = p_prop; ae.label = p_label; added_editors.push_back(ae); } bool EditorInspectorPlugin::can_handle(Object *p_object) { bool success = false; GDVIRTUAL_CALL(_can_handle, p_object, success); return success; } void EditorInspectorPlugin::parse_begin(Object *p_object) { GDVIRTUAL_CALL(_parse_begin, p_object); } void EditorInspectorPlugin::parse_category(Object *p_object, const String &p_category) { GDVIRTUAL_CALL(_parse_category, p_object, p_category); } void EditorInspectorPlugin::parse_group(Object *p_object, const String &p_group) { GDVIRTUAL_CALL(_parse_group, p_object, p_group); } bool EditorInspectorPlugin::parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const BitField p_usage, const bool p_wide) { bool ret = false; GDVIRTUAL_CALL(_parse_property, p_object, p_type, p_path, p_hint, p_hint_text, p_usage, p_wide, ret); return ret; } void EditorInspectorPlugin::parse_end(Object *p_object) { GDVIRTUAL_CALL(_parse_end, p_object); } void EditorInspectorPlugin::_bind_methods() { ClassDB::bind_method(D_METHOD("add_custom_control", "control"), &EditorInspectorPlugin::add_custom_control); ClassDB::bind_method(D_METHOD("add_property_editor", "property", "editor", "add_to_end", "label"), &EditorInspectorPlugin::add_property_editor, DEFVAL(false), DEFVAL(String())); ClassDB::bind_method(D_METHOD("add_property_editor_for_multiple_properties", "label", "properties", "editor"), &EditorInspectorPlugin::add_property_editor_for_multiple_properties); GDVIRTUAL_BIND(_can_handle, "object") GDVIRTUAL_BIND(_parse_begin, "object") GDVIRTUAL_BIND(_parse_category, "object", "category") GDVIRTUAL_BIND(_parse_group, "object", "group") GDVIRTUAL_BIND(_parse_property, "object", "type", "name", "hint_type", "hint_string", "usage_flags", "wide"); GDVIRTUAL_BIND(_parse_end, "object") } //////////////////////////////////////////////// //////////////////////////////////////////////// static Ref