Path: blob/master/editor/inspector/editor_inspector.cpp
9896 views
/**************************************************************************/1/* editor_inspector.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "editor_inspector.h"31#include "editor_inspector.compat.inc"3233#include "core/os/keyboard.h"34#include "editor/debugger/editor_debugger_inspector.h"35#include "editor/doc/doc_tools.h"36#include "editor/docks/inspector_dock.h"37#include "editor/editor_main_screen.h"38#include "editor/editor_node.h"39#include "editor/editor_string_names.h"40#include "editor/editor_undo_redo_manager.h"41#include "editor/gui/editor_toaster.h"42#include "editor/gui/editor_validation_panel.h"43#include "editor/inspector/add_metadata_dialog.h"44#include "editor/inspector/editor_properties.h"45#include "editor/inspector/editor_property_name_processor.h"46#include "editor/inspector/multi_node_edit.h"47#include "editor/script/script_editor_plugin.h"48#include "editor/settings/editor_feature_profile.h"49#include "editor/settings/editor_settings.h"50#include "editor/themes/editor_scale.h"51#include "scene/gui/margin_container.h"52#include "scene/gui/separator.h"53#include "scene/gui/spin_box.h"54#include "scene/gui/texture_rect.h"55#include "scene/property_utils.h"56#include "scene/resources/packed_scene.h"57#include "scene/resources/style_box_flat.h"58#include "scene/scene_string_names.h"5960void EditorInspectorActionButton::_notification(int p_what) {61switch (p_what) {62case NOTIFICATION_THEME_CHANGED: {63set_button_icon(get_editor_theme_icon(icon_name));64} break;65}66}6768EditorInspectorActionButton::EditorInspectorActionButton(const String &p_text, const StringName &p_icon_name) {69icon_name = p_icon_name;70set_text(p_text);71set_theme_type_variation(SNAME("InspectorActionButton"));72set_h_size_flags(SIZE_SHRINK_CENTER);73}7475bool EditorInspector::_property_path_matches(const String &p_property_path, const String &p_filter, EditorPropertyNameProcessor::Style p_style) {76if (p_property_path.containsn(p_filter)) {77return true;78}7980const Vector<String> prop_sections = p_property_path.split("/");81for (int i = 0; i < prop_sections.size(); i++) {82if (p_filter.is_subsequence_ofn(EditorPropertyNameProcessor::get_singleton()->process_name(prop_sections[i], p_style, p_property_path))) {83return true;84}85}86return false;87}8889bool EditorInspector::_resource_properties_matches(const Ref<Resource> &p_resource, const String &p_filter) {90String group;91String group_base;92String subgroup;93String subgroup_base;9495List<PropertyInfo> plist;96p_resource->get_property_list(&plist, true);9798// Employ a lighter version of the update_tree() property listing to find a match.99for (PropertyInfo &p : plist) {100if (p.usage & PROPERTY_USAGE_SUBGROUP) {101subgroup = p.name;102subgroup_base = p.hint_string.get_slicec(',', 0);103104continue;105106} else if (p.usage & PROPERTY_USAGE_GROUP) {107group = p.name;108group_base = p.hint_string.get_slicec(',', 0);109subgroup = "";110subgroup_base = "";111112continue;113114} else if (p.usage & PROPERTY_USAGE_CATEGORY) {115group = "";116group_base = "";117subgroup = "";118subgroup_base = "";119120continue;121122} else if (p.name.begins_with("metadata/_") || !(p.usage & PROPERTY_USAGE_EDITOR) || _is_property_disabled_by_feature_profile(p.name) ||123(p_filter.is_empty() && restrict_to_basic && !(p.usage & PROPERTY_USAGE_EDITOR_BASIC_SETTING))) {124// Ignore properties that are not supposed to be in the inspector.125continue;126}127128if (p.usage & PROPERTY_USAGE_HIGH_END_GFX && RS::get_singleton()->is_low_end()) {129// Do not show this property in low end gfx.130continue;131}132133if (p.name == "script") {134// The script is always hidden in sub inspectors.135continue;136}137138if (p.name.begins_with("metadata/") && bool(object->call(SNAME("_hide_metadata_from_inspector")))) {139// Hide metadata from inspector if required.140continue;141}142143String path = p.name;144145// Check if we exit or not a subgroup. If there is a prefix, remove it from the property label string.146if (!subgroup.is_empty() && !subgroup_base.is_empty()) {147if (path.begins_with(subgroup_base)) {148path = path.trim_prefix(subgroup_base);149} else if (subgroup_base.begins_with(path)) {150// Keep it, this is used pretty often.151} else {152subgroup = ""; // The prefix changed, we are no longer in the subgroup.153}154}155156// Check if we exit or not a group. If there is a prefix, remove it from the property label string.157if (!group.is_empty() && !group_base.is_empty() && subgroup.is_empty()) {158if (path.begins_with(group_base)) {159path = path.trim_prefix(group_base);160} else if (group_base.begins_with(path)) {161// Keep it, this is used pretty often.162} else {163group = ""; // The prefix changed, we are no longer in the group.164subgroup = "";165}166}167168// Add the group and subgroup to the path.169if (!subgroup.is_empty()) {170path = subgroup + "/" + path;171}172if (!group.is_empty()) {173path = group + "/" + path;174}175176// Get the property label's string.177String name_override = (path.contains_char('/')) ? path.substr(path.rfind_char('/') + 1) : path;178const int dot = name_override.find_char('.');179if (dot != -1) {180name_override = name_override.substr(0, dot);181}182183// Remove the property from the path.184int idx = path.rfind_char('/');185if (idx > -1) {186path = path.left(idx);187} else {188path = "";189}190191// Check if the property matches the filter.192const String property_path = (path.is_empty() ? "" : path + "/") + name_override;193if (_property_path_matches(property_path, p_filter, property_name_style)) {194return true;195}196197// Check if the sub-resource has any properties that match the filter.198if (p.hint && p.hint == PROPERTY_HINT_RESOURCE_TYPE) {199Ref<Resource> res = p_resource->get(p.name);200if (res.is_valid() && _resource_properties_matches(res, p_filter)) {201return true;202}203}204}205206return false;207}208209String EditorProperty::get_tooltip_string(const String &p_string) const {210// Trim to 100 characters to prevent the tooltip from being too long.211constexpr int TOOLTIP_MAX_LENGTH = 100;212return p_string.left(TOOLTIP_MAX_LENGTH).strip_edges() + String((p_string.length() > TOOLTIP_MAX_LENGTH) ? "..." : "");213}214215Size2 EditorProperty::get_minimum_size() const {216Size2 ms;217Ref<Font> font = get_theme_font(SceneStringName(font), SNAME("Tree"));218int font_size = get_theme_font_size(SceneStringName(font_size), SNAME("Tree"));219ms.height = label.is_empty() ? 0 : font->get_height(font_size) + 4 * EDSCALE;220221for (int i = 0; i < get_child_count(); i++) {222Control *c = as_sortable_control(get_child(i));223if (!c) {224continue;225}226if (c == bottom_editor) {227continue;228}229230Size2 minsize = c->get_combined_minimum_size();231ms = ms.max(minsize);232}233234if (keying) {235Ref<Texture2D> key = get_editor_theme_icon(SNAME("Key"));236ms.width += key->get_width() + get_theme_constant(SNAME("h_separation"), SNAME("Tree"));237}238239if (deletable) {240Ref<Texture2D> key = get_editor_theme_icon(SNAME("Close"));241ms.width += key->get_width() + get_theme_constant(SNAME("h_separation"), SNAME("Tree"));242}243244if (checkable) {245Ref<Texture2D> check = get_theme_icon(SNAME("checked"), SNAME("CheckBox"));246ms.width += check->get_width() + get_theme_constant(SNAME("h_separation"), SNAME("Tree"));247}248249if (bottom_editor != nullptr && bottom_editor->is_visible()) {250ms.height += label.is_empty() ? 0 : get_theme_constant(SNAME("v_separation"));251Size2 bems = bottom_editor->get_combined_minimum_size();252//bems.width += get_constant("item_margin", "Tree");253ms.height += bems.height;254ms.width = MAX(ms.width, bems.width);255}256257return ms;258}259260void EditorProperty::emit_changed(const StringName &p_property, const Variant &p_value, const StringName &p_field, bool p_changing) {261Variant args[4] = { p_property, p_value, p_field, p_changing };262const Variant *argptrs[4] = { &args[0], &args[1], &args[2], &args[3] };263264cache[p_property] = p_value;265emit_signalp(SNAME("property_changed"), (const Variant **)argptrs, 4);266}267268void EditorProperty::_notification(int p_what) {269switch (p_what) {270case NOTIFICATION_ACCESSIBILITY_UPDATE: {271RID ae = get_accessibility_element();272ERR_FAIL_COND(ae.is_null());273274DisplayServer::get_singleton()->accessibility_update_set_role(ae, DisplayServer::AccessibilityRole::ROLE_BUTTON);275276DisplayServer::get_singleton()->accessibility_update_set_name(ae, vformat(TTR("Property: %s"), label));277DisplayServer::get_singleton()->accessibility_update_set_value(ae, vformat(TTR("Property: %s"), label));278279DisplayServer::get_singleton()->accessibility_update_set_popup_type(ae, DisplayServer::AccessibilityPopupType::POPUP_MENU);280DisplayServer::get_singleton()->accessibility_update_add_action(ae, DisplayServer::AccessibilityAction::ACTION_SHOW_CONTEXT_MENU, callable_mp(this, &EditorProperty::_accessibility_action_menu));281DisplayServer::get_singleton()->accessibility_update_add_action(ae, DisplayServer::AccessibilityAction::ACTION_CLICK, callable_mp(this, &EditorProperty::_accessibility_action_click));282283DisplayServer::get_singleton()->accessibility_update_set_flag(ae, DisplayServer::AccessibilityFlags::FLAG_READONLY, read_only);284if (checkable) {285DisplayServer::get_singleton()->accessibility_update_set_checked(ae, checked);286}287} break;288289case NOTIFICATION_SORT_CHILDREN: {290Size2 size = get_size();291Rect2 rect;292Rect2 bottom_rect;293294right_child_rect = Rect2();295bottom_child_rect = Rect2();296297{298int child_room = size.width * (1.0 - split_ratio);299Ref<Font> font = get_theme_font(SceneStringName(font), SNAME("Tree"));300int font_size = get_theme_font_size(SceneStringName(font_size), SNAME("Tree"));301int height = label.is_empty() ? 0 : font->get_height(font_size) + 4 * EDSCALE;302bool no_children = true;303304//compute room needed305for (int i = 0; i < get_child_count(); i++) {306Control *c = as_sortable_control(get_child(i));307if (!c) {308continue;309}310if (c == bottom_editor) {311continue;312}313314Size2 minsize = c->get_combined_minimum_size();315child_room = MAX(child_room, minsize.width);316height = MAX(height, minsize.height);317no_children = false;318}319320if (no_children) {321text_size = size.width;322rect = Rect2(size.width - 1, 0, 1, height);323} else if (!draw_label) {324text_size = 0;325rect = Rect2(1, 0, size.width - 1, height);326} else {327text_size = MAX(0, size.width - (child_room + 4 * EDSCALE));328if (is_layout_rtl()) {329rect = Rect2(1, 0, child_room, height);330} else {331rect = Rect2(size.width - child_room, 0, child_room, height);332}333}334335if (bottom_editor) {336int v_offset = label.is_empty() ? 0 : get_theme_constant(SNAME("v_separation"));337bottom_rect = Rect2(0, rect.size.height + v_offset, size.width, bottom_editor->get_combined_minimum_size().height);338}339340if (keying) {341Ref<Texture2D> key;342343if (use_keying_next()) {344key = get_editor_theme_icon(SNAME("KeyNext"));345} else {346key = get_editor_theme_icon(SNAME("Key"));347}348349rect.size.x -= key->get_width() + get_theme_constant(SNAME("h_separation"), SNAME("Tree"));350if (is_layout_rtl()) {351rect.position.x += key->get_width() + get_theme_constant(SNAME("h_separation"), SNAME("Tree"));352}353354if (no_children) {355text_size -= key->get_width() + 4 * EDSCALE;356}357}358359if (deletable) {360Ref<Texture2D> close;361362close = get_editor_theme_icon(SNAME("Close"));363364rect.size.x -= close->get_width() + get_theme_constant(SNAME("h_separation"), SNAME("Tree"));365366if (is_layout_rtl()) {367rect.position.x += close->get_width() + get_theme_constant(SNAME("h_separation"), SNAME("Tree"));368}369370if (no_children) {371text_size -= close->get_width() + 4 * EDSCALE;372}373}374375// Account for the space needed on the outer side376// when any of the icons are visible.377if (keying || deletable) {378int separation = get_theme_constant(SNAME("h_separation"), SNAME("Tree"));379rect.size.x -= separation;380381if (is_layout_rtl()) {382rect.position.x += separation;383}384}385}386387//set children388for (int i = 0; i < get_child_count(); i++) {389Control *c = as_sortable_control(get_child(i));390if (!c) {391continue;392}393if (c == bottom_editor) {394continue;395}396397fit_child_in_rect(c, rect);398right_child_rect = rect;399}400401if (bottom_editor) {402fit_child_in_rect(bottom_editor, bottom_rect);403bottom_child_rect = bottom_rect;404}405406queue_redraw(); //need to redraw text407} break;408409case NOTIFICATION_DRAW: {410Ref<Font> font = get_theme_font(SceneStringName(font), SNAME("Tree"));411int font_size = get_theme_font_size(SceneStringName(font_size), SNAME("Tree"));412bool rtl = is_layout_rtl();413414Size2 size = get_size();415if (bottom_editor) {416size.height = bottom_editor->get_offset(SIDE_TOP) - get_theme_constant(SNAME("v_separation"));417} else if (label_reference) {418size.height = label_reference->get_size().height;419}420421// Only draw the label if it's not empty.422if (label.is_empty()) {423size.height = 0;424} else {425Ref<StyleBox> sb = get_theme_stylebox(selected ? SNAME("bg_selected") : SNAME("bg"));426draw_style_box(sb, Rect2(Vector2(), size));427}428429Ref<StyleBox> bg_stylebox = get_theme_stylebox(SNAME("child_bg"));430if (draw_top_bg && right_child_rect != Rect2() && draw_background) {431draw_style_box(bg_stylebox, right_child_rect);432}433if (bottom_child_rect != Rect2() && draw_background) {434draw_style_box(bg_stylebox, bottom_child_rect);435}436437Color color;438if (draw_warning || draw_prop_warning) {439color = get_theme_color(is_read_only() ? SNAME("readonly_warning_color") : SNAME("warning_color"));440} else {441color = get_theme_color(is_read_only() ? SNAME("readonly_color") : SNAME("property_color"));442}443if (label.contains_char('.')) {444// FIXME: Move this to the project settings editor, as this is only used445// for project settings feature tag overrides.446color.a = 0.5;447}448449int ofs = get_theme_constant(SNAME("font_offset"));450int text_limit = text_size - ofs;451int base_spacing = EDITOR_GET("interface/theme/base_spacing");452int padding = base_spacing * EDSCALE;453int half_padding = padding / 2;454455if (checkable) {456Ref<Texture2D> checkbox;457if (checked) {458checkbox = get_editor_theme_icon(SNAME("GuiChecked"));459} else {460checkbox = get_editor_theme_icon(SNAME("GuiUnchecked"));461}462463check_rect = Rect2(ofs, 0, checkbox->get_width() + padding, size.height);464465Point2 rtl_pos;466if (rtl) {467rtl_pos = Point2(size.width - check_rect.position.x - (checkbox->get_width() + padding + (1 * EDSCALE)), check_rect.position.y);468}469470Color color2(1, 1, 1);471if (check_hover) {472color2.r *= 1.2;473color2.g *= 1.2;474color2.b *= 1.2;475476Ref<StyleBox> sb_hover = get_theme_stylebox(SceneStringName(hover), "Button");477if (rtl) {478draw_style_box(sb_hover, Rect2(rtl_pos, check_rect.size));479} else {480draw_style_box(sb_hover, check_rect);481}482}483if (rtl) {484draw_texture(checkbox, rtl_pos + Point2(padding, size.height - checkbox->get_height()) / 2, color2);485} else {486draw_texture(checkbox, check_rect.position + Point2(padding, size.height - checkbox->get_height()) / 2, color2);487}488int check_ofs = checkbox->get_width() + get_theme_constant(SNAME("h_separation"), SNAME("Tree"));489ofs += check_ofs;490text_limit -= check_ofs;491} else {492check_rect = Rect2();493}494495if (can_revert && !is_read_only()) {496Ref<Texture2D> reload_icon = get_editor_theme_icon(SNAME("ReloadSmall"));497text_limit -= reload_icon->get_width() + half_padding + get_theme_constant(SNAME("h_separation"), SNAME("Tree"));498revert_rect = Rect2(ofs + text_limit, 0, reload_icon->get_width() + padding + (1 * EDSCALE), size.height);499500Point2 rtl_pos;501if (rtl) {502rtl_pos = Point2(size.width - revert_rect.position.x - (reload_icon->get_width() + padding + (1 * EDSCALE)), revert_rect.position.y);503}504505Color color2(1, 1, 1);506if (revert_hover) {507color2.r *= 1.2;508color2.g *= 1.2;509color2.b *= 1.2;510511Ref<StyleBox> sb_hover = get_theme_stylebox(SceneStringName(hover), "Button");512if (rtl) {513draw_style_box(sb_hover, Rect2(rtl_pos, revert_rect.size));514} else {515draw_style_box(sb_hover, revert_rect);516}517}518if (rtl) {519draw_texture(reload_icon, rtl_pos + Point2(padding, size.height - reload_icon->get_height()) / 2, color2);520} else {521draw_texture(reload_icon, revert_rect.position + Point2(padding, size.height - reload_icon->get_height()) / 2, color2);522}523} else {524revert_rect = Rect2();525}526527if (!pin_hidden && pinned) {528Ref<Texture2D> pinned_icon = get_editor_theme_icon(SNAME("Pin"));529int margin_w = get_theme_constant(SNAME("h_separation"), SNAME("Tree"));530int total_icon_w = margin_w + pinned_icon->get_width();531int text_w = font->get_string_size(label, rtl ? HORIZONTAL_ALIGNMENT_RIGHT : HORIZONTAL_ALIGNMENT_LEFT, text_limit - total_icon_w, font_size).x;532int y = (size.height - pinned_icon->get_height()) / 2;533if (rtl) {534draw_texture(pinned_icon, Vector2(size.width - ofs - text_w - total_icon_w, y), color);535} else {536draw_texture(pinned_icon, Vector2(ofs + text_w + margin_w, y), color);537}538text_limit -= total_icon_w;539}540541int v_ofs = (size.height - font->get_height(font_size)) / 2;542if (rtl) {543draw_string(font, Point2(size.width - ofs - text_limit, v_ofs + font->get_ascent(font_size)), label, HORIZONTAL_ALIGNMENT_RIGHT, text_limit, font_size, color);544} else {545draw_string(font, Point2(ofs, v_ofs + font->get_ascent(font_size)), label, HORIZONTAL_ALIGNMENT_LEFT, text_limit, font_size, color);546}547548ofs = size.width;549550if (keying) {551Ref<Texture2D> key;552553if (use_keying_next()) {554key = get_editor_theme_icon(SNAME("KeyNext"));555} else {556key = get_editor_theme_icon(SNAME("Key"));557}558559ofs -= key->get_width() + half_padding + get_theme_constant(SNAME("h_separation"), SNAME("Tree"));560keying_rect = Rect2(ofs, 0, key->get_width() + padding, size.height);561562Point2 rtl_pos;563if (rtl) {564rtl_pos = Point2(size.width - keying_rect.position.x - (key->get_width() + padding), keying_rect.position.y);565}566567Color color2(1, 1, 1);568if (keying_hover) {569color2.r *= 1.2;570color2.g *= 1.2;571color2.b *= 1.2;572573Ref<StyleBox> sb_hover = get_theme_stylebox(SceneStringName(hover), "Button");574if (rtl) {575draw_style_box(sb_hover, Rect2(rtl_pos, keying_rect.size));576} else {577draw_style_box(sb_hover, keying_rect);578}579}580581if (rtl) {582draw_texture(key, rtl_pos + Point2(padding, size.height - key->get_height()) / 2, color2);583} else {584draw_texture(key, keying_rect.position + Point2(padding, size.height - key->get_height()) / 2, color2);585}586587} else {588keying_rect = Rect2();589}590591if (deletable) {592Ref<Texture2D> close;593594close = get_editor_theme_icon(SNAME("Close"));595596ofs -= close->get_width() + half_padding + get_theme_constant(SNAME("h_separation"), SNAME("Tree"));597delete_rect = Rect2(ofs, 0, close->get_width() + padding, size.height);598599Point2 rtl_pos;600if (rtl) {601rtl_pos = Point2(size.width - delete_rect.position.x - (close->get_width() + padding), delete_rect.position.y);602}603604Color color2(1, 1, 1);605if (delete_hover) {606color2.r *= 1.2;607color2.g *= 1.2;608color2.b *= 1.2;609610Ref<StyleBox> sb_hover = get_theme_stylebox(SceneStringName(hover), "Button");611if (rtl) {612draw_style_box(sb_hover, Rect2(rtl_pos, delete_rect.size));613} else {614draw_style_box(sb_hover, delete_rect);615}616}617618if (rtl) {619draw_texture(close, rtl_pos + Point2(padding, size.height - close->get_height()) / 2, color2);620} else {621draw_texture(close, delete_rect.position + Point2(padding, size.height - close->get_height()) / 2, color2);622}623} else {624delete_rect = Rect2();625}626} break;627case NOTIFICATION_ENTER_TREE: {628EditorInspector *inspector = get_parent_inspector();629if (inspector) {630inspector = inspector->get_root_inspector();631}632set_shortcut_context(inspector);633634if (has_borders) {635get_parent()->connect(SceneStringName(theme_changed), callable_mp(this, &EditorProperty::_update_property_bg));636_update_property_bg();637}638} break;639case NOTIFICATION_EXIT_TREE: {640if (has_borders) {641get_parent()->disconnect(SceneStringName(theme_changed), callable_mp(this, &EditorProperty::_update_property_bg));642}643} break;644case NOTIFICATION_MOUSE_EXIT: {645if (keying_hover || revert_hover || check_hover || delete_hover) {646keying_hover = false;647revert_hover = false;648check_hover = false;649delete_hover = false;650queue_redraw();651}652} break;653}654}655656void EditorProperty::set_label(const String &p_label) {657label = p_label;658queue_redraw();659}660661String EditorProperty::get_label() const {662return label;663}664665Object *EditorProperty::get_edited_object() {666return object;667}668669StringName EditorProperty::get_edited_property() const {670return property;671}672673Variant EditorProperty::get_edited_property_display_value() const {674ERR_FAIL_NULL_V(object, Variant());675Control *control = Object::cast_to<Control>(object);676if (checkable && !checked && control && String(property).begins_with("theme_override_")) {677return control->get_used_theme_item(property);678} else {679return get_edited_property_value();680}681}682683EditorInspector *EditorProperty::get_parent_inspector() const {684Node *parent = get_parent();685while (parent) {686EditorInspector *ei = Object::cast_to<EditorInspector>(parent);687if (ei) {688return ei;689}690parent = parent->get_parent();691}692return nullptr;693}694695void EditorProperty::set_doc_path(const String &p_doc_path) {696doc_path = p_doc_path;697}698699void EditorProperty::set_internal(bool p_internal) {700internal = p_internal;701}702703void EditorProperty::update_property() {704GDVIRTUAL_CALL(_update_property);705}706707void EditorProperty::_set_read_only(bool p_read_only) {708}709710void EditorProperty::set_read_only(bool p_read_only) {711read_only = p_read_only;712if (GDVIRTUAL_CALL(_set_read_only, p_read_only)) {713return;714}715_set_read_only(p_read_only);716}717718bool EditorProperty::is_read_only() const {719return read_only;720}721722Variant EditorPropertyRevert::get_property_revert_value(Object *p_object, const StringName &p_property, bool *r_is_valid) {723if (p_object->property_can_revert(p_property)) {724if (r_is_valid) {725*r_is_valid = true;726}727return p_object->property_get_revert(p_property);728}729730return PropertyUtils::get_property_default_value(p_object, p_property, r_is_valid);731}732733bool EditorPropertyRevert::can_property_revert(Object *p_object, const StringName &p_property, const Variant *p_custom_current_value) {734bool is_valid_revert = false;735Variant revert_value = EditorPropertyRevert::get_property_revert_value(p_object, p_property, &is_valid_revert);736if (!is_valid_revert) {737return false;738}739Variant current_value = p_custom_current_value ? *p_custom_current_value : p_object->get(p_property);740return PropertyUtils::is_property_value_different(p_object, current_value, revert_value);741}742743StringName EditorProperty::_get_revert_property() const {744return property;745}746747void EditorProperty::_update_property_bg() {748// This function is to be called on EditorPropertyResource, EditorPropertyArray, and EditorPropertyDictionary.749// Behavior is undetermined on any other EditorProperty.750if (!is_inside_tree()) {751return;752}753754begin_bulk_theme_override();755756if (bottom_editor) {757ColorationMode nested_color_mode = (ColorationMode)(int)EDITOR_GET("interface/inspector/nested_color_mode");758bool delimitate_all_container_and_resources = EDITOR_GET("interface/inspector/delimitate_all_container_and_resources");759int count_subinspectors = 0;760if (is_colored(nested_color_mode)) {761Node *n = this;762while (n) {763EditorProperty *ep = Object::cast_to<EditorProperty>(n);764if (ep && ep->is_colored(nested_color_mode)) {765count_subinspectors++;766}767n = n->get_parent();768}769count_subinspectors = MIN(16, count_subinspectors);770}771add_theme_style_override(SNAME("DictionaryAddItem"), get_theme_stylebox("DictionaryAddItem" + itos(count_subinspectors), EditorStringName(EditorStyles)));772add_theme_constant_override("v_separation", 0);773if (delimitate_all_container_and_resources || is_colored(nested_color_mode)) {774add_theme_style_override("bg_selected", get_theme_stylebox("sub_inspector_property_bg" + itos(count_subinspectors), EditorStringName(EditorStyles)));775add_theme_style_override("bg", get_theme_stylebox("sub_inspector_property_bg" + itos(count_subinspectors), EditorStringName(EditorStyles)));776add_theme_color_override("property_color", get_theme_color(SNAME("sub_inspector_property_color"), EditorStringName(EditorStyles)));777bottom_editor->add_theme_style_override(SceneStringName(panel), get_theme_stylebox("sub_inspector_bg" + itos(count_subinspectors), EditorStringName(EditorStyles)));778} else {779bottom_editor->add_theme_style_override(SceneStringName(panel), get_theme_stylebox("sub_inspector_bg_no_border", EditorStringName(EditorStyles)));780}781} else {782remove_theme_style_override("bg_selected");783remove_theme_style_override("bg");784remove_theme_color_override("property_color");785}786end_bulk_theme_override();787queue_redraw();788}789790void EditorProperty::update_editor_property_status() {791if (property == StringName()) {792return; //no property, so nothing to do793}794795bool new_pinned = false;796if (can_pin) {797Node *node = Object::cast_to<Node>(object);798CRASH_COND(!node);799new_pinned = node->is_property_pinned(property);800}801802bool new_warning = false;803if (object->has_method("_get_property_warning")) {804new_warning = !String(object->call("_get_property_warning", property)).is_empty();805}806807Variant current = object->get(_get_revert_property());808bool new_can_revert = EditorPropertyRevert::can_property_revert(object, property, ¤t) && !is_read_only();809810bool new_checked = checked;811if (checkable) { // for properties like theme overrides.812bool valid = false;813Variant value = object->get(property, &valid);814if (valid) {815new_checked = value.get_type() != Variant::NIL;816}817}818819if (new_can_revert != can_revert || new_pinned != pinned || new_checked != checked || new_warning != draw_prop_warning) {820if (new_can_revert != can_revert) {821emit_signal(SNAME("property_can_revert_changed"), property, new_can_revert);822}823draw_prop_warning = new_warning;824can_revert = new_can_revert;825pinned = new_pinned;826checked = new_checked;827queue_redraw();828}829}830831bool EditorProperty::use_keying_next() const {832List<PropertyInfo> plist;833object->get_property_list(&plist, true);834835for (const PropertyInfo &p : plist) {836if (p.name == property) {837return (p.usage & PROPERTY_USAGE_KEYING_INCREMENTS);838}839}840841return false;842}843844void EditorProperty::set_draw_label(bool p_draw_label) {845draw_label = p_draw_label;846queue_redraw();847queue_sort();848}849850bool EditorProperty::is_draw_label() const {851return draw_label;852}853854void EditorProperty::set_draw_background(bool p_draw_background) {855draw_background = p_draw_background;856queue_redraw();857}858859bool EditorProperty::is_draw_background() const {860return draw_background;861}862863void EditorProperty::set_checkable(bool p_checkable) {864checkable = p_checkable;865queue_redraw();866queue_sort();867}868869bool EditorProperty::is_checkable() const {870return checkable;871}872873void EditorProperty::set_checked(bool p_checked) {874checked = p_checked;875queue_redraw();876}877878bool EditorProperty::is_checked() const {879return checked;880}881882void EditorProperty::set_draw_warning(bool p_draw_warning) {883draw_warning = p_draw_warning;884queue_redraw();885}886887void EditorProperty::set_keying(bool p_keying) {888keying = p_keying;889queue_redraw();890queue_sort();891}892893void EditorProperty::set_deletable(bool p_deletable) {894deletable = p_deletable;895queue_redraw();896queue_sort();897}898899bool EditorProperty::is_deletable() const {900return deletable;901}902903bool EditorProperty::is_keying() const {904return keying;905}906907bool EditorProperty::is_draw_warning() const {908return draw_warning;909}910911void EditorProperty::_focusable_focused(int p_index) {912if (!selectable) {913return;914}915bool already_selected = selected;916selected = true;917selected_focusable = p_index;918queue_redraw();919if (!already_selected && selected) {920emit_signal(SNAME("selected"), property, selected_focusable);921}922}923924void EditorProperty::add_focusable(Control *p_control) {925p_control->connect(SceneStringName(focus_entered), callable_mp(this, &EditorProperty::_focusable_focused).bind(focusables.size()));926focusables.push_back(p_control);927}928929void EditorProperty::grab_focus(int p_focusable) {930if (focusables.is_empty()) {931return;932}933934if (p_focusable >= 0) {935ERR_FAIL_INDEX(p_focusable, focusables.size());936focusables[p_focusable]->grab_focus();937} else {938focusables[0]->grab_focus();939}940}941942void EditorProperty::select(int p_focusable) {943bool already_selected = selected;944if (!selectable) {945return;946}947948if (p_focusable >= 0) {949ERR_FAIL_INDEX(p_focusable, focusables.size());950focusables[p_focusable]->grab_focus();951} else {952selected = true;953queue_redraw();954}955956if (!already_selected && selected) {957emit_signal(SNAME("selected"), property, selected_focusable);958}959}960961void EditorProperty::deselect() {962selected = false;963selected_focusable = -1;964queue_redraw();965}966967bool EditorProperty::is_selected() const {968return selected;969}970971void EditorProperty::gui_input(const Ref<InputEvent> &p_event) {972ERR_FAIL_COND(p_event.is_null());973974if (property == StringName()) {975return;976}977978Ref<InputEventMouse> me = p_event;979980if (me.is_valid()) {981Vector2 mpos = me->get_position();982if (bottom_child_rect.has_point(mpos)) {983return; // Makes child EditorProperties behave like sibling nodes when handling mouse events.984}985if (is_layout_rtl()) {986mpos.x = get_size().x - mpos.x;987}988bool button_left = me->get_button_mask().has_flag(MouseButtonMask::LEFT);989990bool new_keying_hover = keying_rect.has_point(mpos) && !button_left;991if (new_keying_hover != keying_hover) {992keying_hover = new_keying_hover;993queue_redraw();994}995996bool new_delete_hover = delete_rect.has_point(mpos) && !button_left;997if (new_delete_hover != delete_hover) {998delete_hover = new_delete_hover;999queue_redraw();1000}10011002bool new_revert_hover = revert_rect.has_point(mpos) && !button_left;1003if (new_revert_hover != revert_hover) {1004revert_hover = new_revert_hover;1005queue_redraw();1006}10071008bool new_check_hover = check_rect.has_point(mpos) && !button_left;1009if (new_check_hover != check_hover) {1010check_hover = new_check_hover;1011queue_redraw();1012}1013}10141015Ref<InputEventMouseButton> mb = p_event;10161017if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT) {1018Vector2 mpos = mb->get_position();1019if (is_layout_rtl()) {1020mpos.x = get_size().x - mpos.x;1021}10221023select();10241025if (keying_rect.has_point(mpos)) {1026accept_event();1027emit_signal(SNAME("property_keyed"), property, use_keying_next());10281029if (use_keying_next()) {1030if (property == "frame_coords" && (object->is_class("Sprite2D") || object->is_class("Sprite3D"))) {1031Vector2i new_coords = object->get(property);1032new_coords.x++;1033if (new_coords.x >= int64_t(object->get("hframes"))) {1034new_coords.x = 0;1035new_coords.y++;1036}1037if (new_coords.x < int64_t(object->get("hframes")) && new_coords.y < int64_t(object->get("vframes"))) {1038callable_mp(this, &EditorProperty::emit_changed).call_deferred(property, new_coords, "", false);1039}1040} else {1041if (int64_t(object->get(property)) + 1 < (int64_t(object->get("hframes")) * int64_t(object->get("vframes")))) {1042callable_mp(this, &EditorProperty::emit_changed).call_deferred(property, object->get(property).operator int64_t() + 1, "", false);1043}1044}1045callable_mp(this, &EditorProperty::update_property).call_deferred();1046}1047}1048if (delete_rect.has_point(mpos)) {1049accept_event();1050emit_signal(SNAME("property_deleted"), property);1051}10521053if (revert_rect.has_point(mpos)) {1054accept_event();1055get_viewport()->gui_release_focus();1056bool is_valid_revert = false;1057Variant revert_value = EditorPropertyRevert::get_property_revert_value(object, property, &is_valid_revert);1058ERR_FAIL_COND(!is_valid_revert);1059emit_changed(_get_revert_property(), revert_value);1060update_property();1061}10621063if (check_rect.has_point(mpos)) {1064accept_event();1065if (!checked && Object::cast_to<Control>(object) && property_path.begins_with("theme_override_")) {1066List<PropertyInfo> pinfo;1067object->get_property_list(&pinfo);1068for (const PropertyInfo &E : pinfo) {1069if (E.type == Variant::OBJECT && E.name == property_path) {1070EditorToaster::get_singleton()->popup_str(TTR("Toggling the checkbox is disabled for Resource properties. Modify the property using the resource picker instead."), EditorToaster::SEVERITY_WARNING);1071return; // Disallow clicking to toggle the checkbox of type Resource to checked.1072}1073}1074}1075checked = !checked;1076queue_redraw();1077emit_signal(SNAME("property_checked"), property, checked);1078}1079} else if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MouseButton::RIGHT) {1080accept_event();1081_update_popup();1082menu->set_position(get_screen_position() + get_local_mouse_position());1083menu->reset_size();1084menu->popup();1085select();1086return;1087}1088}10891090void EditorProperty::_accessibility_action_click(const Variant &p_data) {1091select();1092if (checkable) {1093if (!checked && Object::cast_to<Control>(object) && property_path.begins_with("theme_override_")) {1094List<PropertyInfo> pinfo;1095object->get_property_list(&pinfo);1096for (const PropertyInfo &E : pinfo) {1097if (E.type == Variant::OBJECT && E.name == property_path) {1098EditorToaster::get_singleton()->popup_str(TTR("Toggling the checkbox is disabled for Resource properties. Modify the property using the resource picker instead."), EditorToaster::SEVERITY_WARNING);1099return;1100}1101}1102}11031104checked = !checked;1105queue_redraw();1106emit_signal(SNAME("property_checked"), property, checked);1107}1108}11091110void EditorProperty::_accessibility_action_menu(const Variant &p_data) {1111_update_popup();1112menu->set_position(get_screen_position());1113menu->reset_size();1114menu->popup();1115}11161117void EditorProperty::shortcut_input(const Ref<InputEvent> &p_event) {1118if (!selected || !p_event->is_pressed()) {1119return;1120}11211122const Ref<InputEventKey> k = p_event;11231124if (k.is_valid() && k->is_pressed()) {1125if (ED_IS_SHORTCUT("property_editor/copy_value", p_event)) {1126menu_option(MENU_COPY_VALUE);1127accept_event();1128} else if (!is_read_only() && ED_IS_SHORTCUT("property_editor/paste_value", p_event)) {1129menu_option(MENU_PASTE_VALUE);1130accept_event();1131} else if (!internal && ED_IS_SHORTCUT("property_editor/copy_property_path", p_event)) {1132menu_option(MENU_COPY_PROPERTY_PATH);1133accept_event();1134}1135}1136}11371138const Color *EditorProperty::_get_property_colors() {1139static Color c[4];1140c[0] = get_theme_color(SNAME("property_color_x"), EditorStringName(Editor));1141c[1] = get_theme_color(SNAME("property_color_y"), EditorStringName(Editor));1142c[2] = get_theme_color(SNAME("property_color_z"), EditorStringName(Editor));1143c[3] = get_theme_color(SNAME("property_color_w"), EditorStringName(Editor));1144return c;1145}11461147void EditorProperty::set_label_reference(Control *p_control) {1148label_reference = p_control;1149}11501151void EditorProperty::set_bottom_editor(Control *p_control) {1152bottom_editor = p_control;1153if (has_borders) {1154_update_property_bg();1155}1156}11571158Variant EditorProperty::_get_cache_value(const StringName &p_prop, bool &r_valid) const {1159return object->get(p_prop, &r_valid);1160}11611162bool EditorProperty::is_cache_valid() const {1163if (object) {1164for (const KeyValue<StringName, Variant> &E : cache) {1165bool valid;1166Variant value = _get_cache_value(E.key, valid);1167if (!valid || value != E.value) {1168return false;1169}1170}1171}1172return true;1173}1174void EditorProperty::update_cache() {1175cache.clear();1176if (object && property != StringName()) {1177bool valid;1178Variant value = _get_cache_value(property, valid);1179if (valid) {1180cache[property] = value;1181}1182}1183}1184Variant EditorProperty::get_drag_data(const Point2 &p_point) {1185if (property == StringName()) {1186return Variant();1187}11881189Dictionary dp;1190dp["type"] = "obj_property";1191dp["object"] = object;1192dp["property"] = property;1193dp["value"] = object->get(property);11941195Label *drag_label = memnew(Label);1196drag_label->set_focus_mode(FOCUS_ACCESSIBILITY);1197drag_label->set_text(property);1198drag_label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); // Don't translate raw property name.1199set_drag_preview(drag_label);1200return dp;1201}12021203void EditorProperty::set_use_folding(bool p_use_folding) {1204use_folding = p_use_folding;1205}12061207bool EditorProperty::is_using_folding() const {1208return use_folding;1209}12101211void EditorProperty::expand_all_folding() {1212}12131214void EditorProperty::collapse_all_folding() {1215}12161217void EditorProperty::expand_revertable() {1218}12191220void EditorProperty::set_selectable(bool p_selectable) {1221selectable = p_selectable;1222}12231224bool EditorProperty::is_selectable() const {1225return selectable;1226}12271228void EditorProperty::set_name_split_ratio(float p_ratio) {1229split_ratio = p_ratio;1230}12311232float EditorProperty::get_name_split_ratio() const {1233return split_ratio;1234}12351236void EditorProperty::set_favoritable(bool p_favoritable) {1237can_favorite = p_favoritable;1238}12391240bool EditorProperty::is_favoritable() const {1241return can_favorite;1242}12431244void EditorProperty::set_object_and_property(Object *p_object, const StringName &p_property) {1245object = p_object;1246property = p_property;12471248_update_flags();1249}12501251static bool _is_value_potential_override(Node *p_node, const String &p_property) {1252// Consider a value is potentially overriding another if either of the following is true:1253// a) The node is foreign (inheriting or an instance), so the original value may come from another scene.1254// b) The node belongs to the scene, but the original value comes from somewhere but the builtin class (i.e., a script).1255Node *edited_scene = EditorNode::get_singleton()->get_edited_scene();1256Vector<SceneState::PackState> states_stack = PropertyUtils::get_node_states_stack(p_node, edited_scene);1257if (states_stack.size()) {1258return true;1259} else {1260bool is_valid_default = false;1261bool is_class_default = false;1262PropertyUtils::get_property_default_value(p_node, p_property, &is_valid_default, &states_stack, false, nullptr, &is_class_default);1263return !is_class_default;1264}1265}12661267void EditorProperty::_update_flags() {1268can_pin = false;1269pin_hidden = true;12701271if (read_only) {1272return;1273}12741275if (Node *node = Object::cast_to<Node>(object)) {1276// Avoid errors down the road by ignoring nodes which are not part of a scene1277if (!node->get_owner()) {1278bool is_scene_root = false;1279for (int i = 0; i < EditorNode::get_editor_data().get_edited_scene_count(); ++i) {1280if (EditorNode::get_editor_data().get_edited_scene_root(i) == node) {1281is_scene_root = true;1282break;1283}1284}1285if (!is_scene_root) {1286return;1287}1288}1289if (!_is_value_potential_override(node, property)) {1290return;1291}1292pin_hidden = false;1293{1294HashSet<StringName> storable_properties;1295node->get_storable_properties(storable_properties);1296if (storable_properties.has(node->get_property_store_alias(property))) {1297can_pin = true;1298}1299}1300}1301}13021303Control *EditorProperty::make_custom_tooltip(const String &p_text) const {1304String symbol;1305String prologue;13061307if (object->has_method("_get_property_warning")) {1308const String custom_warning = object->call("_get_property_warning", property);1309if (!custom_warning.is_empty()) {1310prologue = "[b][color=" + get_theme_color(SNAME("warning_color")).to_html(false) + "]" + custom_warning + "[/color][/b]";1311}1312}13131314if (has_doc_tooltip) {1315symbol = p_text;13161317const EditorInspector *inspector = get_parent_inspector();1318if (inspector) {1319const String custom_description = inspector->get_custom_property_description(p_text);1320if (!custom_description.is_empty()) {1321if (!prologue.is_empty()) {1322prologue += '\n';1323}1324prologue += custom_description;1325}1326}1327}13281329if (!symbol.is_empty() || !prologue.is_empty()) {1330return EditorHelpBitTooltip::show_tooltip(const_cast<EditorProperty *>(this), symbol, prologue);1331}13321333return nullptr;1334}13351336void EditorProperty::menu_option(int p_option) {1337switch (p_option) {1338case MENU_COPY_VALUE: {1339InspectorDock::get_inspector_singleton()->set_property_clipboard(object->get(property));1340} break;1341case MENU_PASTE_VALUE: {1342emit_changed(property, InspectorDock::get_inspector_singleton()->get_property_clipboard());1343} break;1344case MENU_COPY_PROPERTY_PATH: {1345DisplayServer::get_singleton()->clipboard_set(property_path);1346} break;1347case MENU_OVERRIDE_FOR_PROJECT: {1348emit_signal(SNAME("property_overridden"));1349} break;1350case MENU_FAVORITE_PROPERTY: {1351emit_signal(SNAME("property_favorited"), property, !favorited);1352queue_redraw();1353} break;1354case MENU_PIN_VALUE: {1355emit_signal(SNAME("property_pinned"), property, !pinned);1356queue_redraw();1357} break;1358case MENU_DELETE: {1359accept_event();1360emit_signal(SNAME("property_deleted"), property);1361} break;1362case MENU_REVERT_VALUE: {1363accept_event();1364get_viewport()->gui_release_focus();1365bool is_valid_revert = false;1366Variant revert_value = EditorPropertyRevert::get_property_revert_value(object, property, &is_valid_revert);1367ERR_FAIL_COND(!is_valid_revert);1368emit_changed(_get_revert_property(), revert_value);1369update_property();1370} break;1371case MENU_OPEN_DOCUMENTATION: {1372ScriptEditor::get_singleton()->goto_help(doc_path);1373EditorNode::get_singleton()->get_editor_main_screen()->select(EditorMainScreen::EDITOR_SCRIPT);1374} break;1375}1376}13771378void EditorProperty::_bind_methods() {1379ClassDB::bind_method(D_METHOD("set_label", "text"), &EditorProperty::set_label);1380ClassDB::bind_method(D_METHOD("get_label"), &EditorProperty::get_label);13811382ClassDB::bind_method(D_METHOD("set_read_only", "read_only"), &EditorProperty::set_read_only);1383ClassDB::bind_method(D_METHOD("is_read_only"), &EditorProperty::is_read_only);13841385ClassDB::bind_method(D_METHOD("set_draw_label", "draw_label"), &EditorProperty::set_draw_label);1386ClassDB::bind_method(D_METHOD("is_draw_label"), &EditorProperty::is_draw_label);13871388ClassDB::bind_method(D_METHOD("set_draw_background", "draw_background"), &EditorProperty::set_draw_background);1389ClassDB::bind_method(D_METHOD("is_draw_background"), &EditorProperty::is_draw_background);13901391ClassDB::bind_method(D_METHOD("set_checkable", "checkable"), &EditorProperty::set_checkable);1392ClassDB::bind_method(D_METHOD("is_checkable"), &EditorProperty::is_checkable);13931394ClassDB::bind_method(D_METHOD("set_checked", "checked"), &EditorProperty::set_checked);1395ClassDB::bind_method(D_METHOD("is_checked"), &EditorProperty::is_checked);13961397ClassDB::bind_method(D_METHOD("set_draw_warning", "draw_warning"), &EditorProperty::set_draw_warning);1398ClassDB::bind_method(D_METHOD("is_draw_warning"), &EditorProperty::is_draw_warning);13991400ClassDB::bind_method(D_METHOD("set_keying", "keying"), &EditorProperty::set_keying);1401ClassDB::bind_method(D_METHOD("is_keying"), &EditorProperty::is_keying);14021403ClassDB::bind_method(D_METHOD("set_deletable", "deletable"), &EditorProperty::set_deletable);1404ClassDB::bind_method(D_METHOD("is_deletable"), &EditorProperty::is_deletable);14051406ClassDB::bind_method(D_METHOD("get_edited_property"), &EditorProperty::get_edited_property);1407ClassDB::bind_method(D_METHOD("get_edited_object"), &EditorProperty::get_edited_object);14081409ClassDB::bind_method(D_METHOD("update_property"), &EditorProperty::update_property);14101411ClassDB::bind_method(D_METHOD("add_focusable", "control"), &EditorProperty::add_focusable);1412ClassDB::bind_method(D_METHOD("set_bottom_editor", "editor"), &EditorProperty::set_bottom_editor);14131414ClassDB::bind_method(D_METHOD("set_selectable", "selectable"), &EditorProperty::set_selectable);1415ClassDB::bind_method(D_METHOD("is_selectable"), &EditorProperty::is_selectable);14161417ClassDB::bind_method(D_METHOD("set_use_folding", "use_folding"), &EditorProperty::set_use_folding);1418ClassDB::bind_method(D_METHOD("is_using_folding"), &EditorProperty::is_using_folding);14191420ClassDB::bind_method(D_METHOD("set_name_split_ratio", "ratio"), &EditorProperty::set_name_split_ratio);1421ClassDB::bind_method(D_METHOD("get_name_split_ratio"), &EditorProperty::get_name_split_ratio);14221423ClassDB::bind_method(D_METHOD("deselect"), &EditorProperty::deselect);1424ClassDB::bind_method(D_METHOD("is_selected"), &EditorProperty::is_selected);1425ClassDB::bind_method(D_METHOD("select", "focusable"), &EditorProperty::select, DEFVAL(-1));1426ClassDB::bind_method(D_METHOD("set_object_and_property", "object", "property"), &EditorProperty::set_object_and_property);1427ClassDB::bind_method(D_METHOD("set_label_reference", "control"), &EditorProperty::set_label_reference);14281429ClassDB::bind_method(D_METHOD("emit_changed", "property", "value", "field", "changing"), &EditorProperty::emit_changed, DEFVAL(StringName()), DEFVAL(false));14301431ADD_PROPERTY(PropertyInfo(Variant::STRING, "label"), "set_label", "get_label");1432ADD_PROPERTY(PropertyInfo(Variant::BOOL, "read_only"), "set_read_only", "is_read_only");1433ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_label"), "set_draw_label", "is_draw_label");1434ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_background"), "set_draw_background", "is_draw_background");1435ADD_PROPERTY(PropertyInfo(Variant::BOOL, "checkable"), "set_checkable", "is_checkable");1436ADD_PROPERTY(PropertyInfo(Variant::BOOL, "checked"), "set_checked", "is_checked");1437ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_warning"), "set_draw_warning", "is_draw_warning");1438ADD_PROPERTY(PropertyInfo(Variant::BOOL, "keying"), "set_keying", "is_keying");1439ADD_PROPERTY(PropertyInfo(Variant::BOOL, "deletable"), "set_deletable", "is_deletable");1440ADD_PROPERTY(PropertyInfo(Variant::BOOL, "selectable"), "set_selectable", "is_selectable");1441ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_folding"), "set_use_folding", "is_using_folding");1442ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "name_split_ratio"), "set_name_split_ratio", "get_name_split_ratio");14431444ADD_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")));1445ADD_SIGNAL(MethodInfo("multiple_properties_changed", PropertyInfo(Variant::PACKED_STRING_ARRAY, "properties"), PropertyInfo(Variant::ARRAY, "value")));1446ADD_SIGNAL(MethodInfo("property_keyed", PropertyInfo(Variant::STRING_NAME, "property")));1447ADD_SIGNAL(MethodInfo("property_deleted", PropertyInfo(Variant::STRING_NAME, "property")));1448ADD_SIGNAL(MethodInfo("property_keyed_with_value", PropertyInfo(Variant::STRING_NAME, "property"), PropertyInfo(Variant::NIL, "value", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT)));1449ADD_SIGNAL(MethodInfo("property_checked", PropertyInfo(Variant::STRING_NAME, "property"), PropertyInfo(Variant::BOOL, "checked")));1450ADD_SIGNAL(MethodInfo("property_overridden"));1451ADD_SIGNAL(MethodInfo("property_favorited", PropertyInfo(Variant::STRING_NAME, "property"), PropertyInfo(Variant::BOOL, "favorited")));1452ADD_SIGNAL(MethodInfo("property_pinned", PropertyInfo(Variant::STRING_NAME, "property"), PropertyInfo(Variant::BOOL, "pinned")));1453ADD_SIGNAL(MethodInfo("property_can_revert_changed", PropertyInfo(Variant::STRING_NAME, "property"), PropertyInfo(Variant::BOOL, "can_revert")));1454ADD_SIGNAL(MethodInfo("resource_selected", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::OBJECT, "resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource")));1455ADD_SIGNAL(MethodInfo("object_id_selected", PropertyInfo(Variant::STRING_NAME, "property"), PropertyInfo(Variant::INT, "id")));1456ADD_SIGNAL(MethodInfo("selected", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::INT, "focusable_idx")));14571458GDVIRTUAL_BIND(_update_property)1459GDVIRTUAL_BIND(_set_read_only, "read_only")14601461ClassDB::bind_method(D_METHOD("_update_editor_property_status"), &EditorProperty::update_editor_property_status);1462}14631464EditorProperty::EditorProperty() {1465set_focus_mode(FOCUS_ACCESSIBILITY);14661467object = nullptr;1468split_ratio = 0.5;1469text_size = 0;1470property_usage = 0;1471selected_focusable = -1;1472label_reference = nullptr;1473bottom_editor = nullptr;1474menu = nullptr;1475set_process_shortcut_input(true);1476}14771478void EditorProperty::_update_popup() {1479if (menu) {1480menu->clear();1481} else {1482menu = memnew(PopupMenu);1483add_child(menu);1484menu->connect(SceneStringName(id_pressed), callable_mp(this, &EditorProperty::menu_option));1485}1486menu->add_icon_shortcut(get_editor_theme_icon(SNAME("ActionCopy")), ED_GET_SHORTCUT("property_editor/copy_value"), MENU_COPY_VALUE);1487menu->add_icon_shortcut(get_editor_theme_icon(SNAME("ActionPaste")), ED_GET_SHORTCUT("property_editor/paste_value"), MENU_PASTE_VALUE);1488menu->add_icon_shortcut(get_editor_theme_icon(SNAME("CopyNodePath")), ED_GET_SHORTCUT("property_editor/copy_property_path"), MENU_COPY_PROPERTY_PATH);1489menu->set_item_disabled(MENU_PASTE_VALUE, is_read_only());1490menu->set_item_disabled(MENU_COPY_PROPERTY_PATH, internal);14911492if (can_favorite || !pin_hidden) {1493menu->add_separator();1494}14951496if (can_favorite) {1497if (favorited) {1498menu->add_icon_item(get_editor_theme_icon(SNAME("Unfavorite")), TTR("Unfavorite Property"), MENU_FAVORITE_PROPERTY);1499menu->set_item_tooltip(menu->get_item_index(MENU_FAVORITE_PROPERTY), TTR("Make this property be put back at its original place."));1500} else {1501// TRANSLATORS: This is a menu item to add a property to the favorites.1502menu->add_icon_item(get_editor_theme_icon(SNAME("Favorites")), TTR("Favorite Property"), MENU_FAVORITE_PROPERTY);1503menu->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."));1504}1505}15061507if (!pin_hidden) {1508if (can_pin) {1509menu->add_icon_check_item(get_editor_theme_icon(SNAME("Pin")), TTR("Pin Value"), MENU_PIN_VALUE);1510menu->set_item_checked(menu->get_item_index(MENU_PIN_VALUE), pinned);1511} else {1512menu->add_icon_check_item(get_editor_theme_icon(SNAME("Pin")), vformat(TTR("Pin Value [Disabled because '%s' is editor-only]"), property), MENU_PIN_VALUE);1513menu->set_item_disabled(menu->get_item_index(MENU_PIN_VALUE), true);1514}1515menu->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."));1516}1517if (deletable || can_revert || can_override) {1518menu->add_separator();1519if (can_override) {1520menu->add_icon_item(get_editor_theme_icon(SNAME("Override")), TTRC("Override for Project"), MENU_OVERRIDE_FOR_PROJECT);1521}1522if (deletable) {1523menu->add_icon_item(get_editor_theme_icon(SNAME("Remove")), TTR("Delete Property"), MENU_DELETE);1524}1525if (can_revert) {1526menu->add_icon_item(get_editor_theme_icon(SNAME("Reload")), TTR("Revert Value"), MENU_REVERT_VALUE);1527}1528}1529if (!doc_path.is_empty()) {1530menu->add_separator();1531menu->add_icon_item(get_editor_theme_icon(SNAME("Help")), TTR("Open Documentation"), MENU_OPEN_DOCUMENTATION);1532}1533}15341535////////////////////////////////////////////////1536////////////////////////////////////////////////15371538void EditorInspectorPlugin::add_custom_control(Control *control) {1539AddedEditor ae;1540ae.property_editor = control;1541added_editors.push_back(ae);1542}15431544void EditorInspectorPlugin::add_property_editor(const String &p_for_property, Control *p_prop, bool p_add_to_end, const String &p_label) {1545AddedEditor ae;1546ae.properties.push_back(p_for_property);1547ae.property_editor = p_prop;1548ae.add_to_end = p_add_to_end;1549ae.label = p_label;1550added_editors.push_back(ae);1551}15521553void EditorInspectorPlugin::add_property_editor_for_multiple_properties(const String &p_label, const Vector<String> &p_properties, Control *p_prop) {1554AddedEditor ae;1555ae.properties = p_properties;1556ae.property_editor = p_prop;1557ae.label = p_label;1558added_editors.push_back(ae);1559}15601561bool EditorInspectorPlugin::can_handle(Object *p_object) {1562bool success = false;1563GDVIRTUAL_CALL(_can_handle, p_object, success);1564return success;1565}15661567void EditorInspectorPlugin::parse_begin(Object *p_object) {1568GDVIRTUAL_CALL(_parse_begin, p_object);1569}15701571void EditorInspectorPlugin::parse_category(Object *p_object, const String &p_category) {1572GDVIRTUAL_CALL(_parse_category, p_object, p_category);1573}15741575void EditorInspectorPlugin::parse_group(Object *p_object, const String &p_group) {1576GDVIRTUAL_CALL(_parse_group, p_object, p_group);1577}15781579bool 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<PropertyUsageFlags> p_usage, const bool p_wide) {1580bool ret = false;1581GDVIRTUAL_CALL(_parse_property, p_object, p_type, p_path, p_hint, p_hint_text, p_usage, p_wide, ret);1582return ret;1583}15841585void EditorInspectorPlugin::parse_end(Object *p_object) {1586GDVIRTUAL_CALL(_parse_end, p_object);1587}15881589void EditorInspectorPlugin::_bind_methods() {1590ClassDB::bind_method(D_METHOD("add_custom_control", "control"), &EditorInspectorPlugin::add_custom_control);1591ClassDB::bind_method(D_METHOD("add_property_editor", "property", "editor", "add_to_end", "label"), &EditorInspectorPlugin::add_property_editor, DEFVAL(false), DEFVAL(String()));1592ClassDB::bind_method(D_METHOD("add_property_editor_for_multiple_properties", "label", "properties", "editor"), &EditorInspectorPlugin::add_property_editor_for_multiple_properties);15931594GDVIRTUAL_BIND(_can_handle, "object")1595GDVIRTUAL_BIND(_parse_begin, "object")1596GDVIRTUAL_BIND(_parse_category, "object", "category")1597GDVIRTUAL_BIND(_parse_group, "object", "group")1598GDVIRTUAL_BIND(_parse_property, "object", "type", "name", "hint_type", "hint_string", "usage_flags", "wide");1599GDVIRTUAL_BIND(_parse_end, "object")1600}16011602////////////////////////////////////////////////1603////////////////////////////////////////////////16041605static Ref<Script> _get_category_script(const PropertyInfo &p_info) {1606if (!p_info.hint_string.is_empty() && !EditorNode::get_editor_data().is_type_recognized(p_info.name) && ResourceLoader::exists(p_info.hint_string, "Script")) {1607return ResourceLoader::load(p_info.hint_string, "Script");1608}1609return Ref<Script>();1610}16111612void EditorInspectorCategory::_bind_methods() {1613ADD_SIGNAL(MethodInfo("unfavorite_all"));1614}16151616void EditorInspectorCategory::_notification(int p_what) {1617switch (p_what) {1618case NOTIFICATION_ACCESSIBILITY_UPDATE: {1619RID ae = get_accessibility_element();1620ERR_FAIL_COND(ae.is_null());16211622DisplayServer::get_singleton()->accessibility_update_set_role(ae, DisplayServer::AccessibilityRole::ROLE_BUTTON);16231624DisplayServer::get_singleton()->accessibility_update_set_name(ae, vformat(TTR("Category: %s"), label));1625DisplayServer::get_singleton()->accessibility_update_set_value(ae, vformat(TTR("Category: %s"), label));16261627DisplayServer::get_singleton()->accessibility_update_set_popup_type(ae, DisplayServer::AccessibilityPopupType::POPUP_MENU);1628DisplayServer::get_singleton()->accessibility_update_add_action(ae, DisplayServer::AccessibilityAction::ACTION_SHOW_CONTEXT_MENU, callable_mp(this, &EditorInspectorCategory::_accessibility_action_menu));1629} break;16301631case NOTIFICATION_THEME_CHANGED: {1632EditorInspector::initialize_category_theme(theme_cache, this);1633menu_icon_dirty = true;1634_update_icon();1635} break;16361637case NOTIFICATION_TRANSLATION_CHANGED: {1638if (is_favorite) {1639label = TTR("Favorites");1640}1641queue_accessibility_update();1642} break;16431644case NOTIFICATION_DRAW: {1645const Ref<StyleBox> &sb = theme_cache.background;16461647draw_style_box(sb, Rect2(Vector2(), get_size()));16481649const Ref<Font> &font = theme_cache.bold_font;1650int font_size = theme_cache.bold_font_size;16511652int hs = theme_cache.horizontal_separation;1653int icon_size = theme_cache.class_icon_size;16541655int w = font->get_string_size(label, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size).width;1656if (icon.is_valid()) {1657w += hs + icon_size;1658}1659w = MIN(w, get_size().width - sb->get_minimum_size().width);16601661int ofs = (get_size().width - w) / 2;16621663float v_margin_offset = sb->get_content_margin(SIDE_TOP) - sb->get_content_margin(SIDE_BOTTOM);16641665if (icon.is_valid()) {1666Size2 rect_size = Size2(icon_size, icon_size);1667Point2 rect_pos = Point2(ofs, (get_size().height - icon_size) / 2 + v_margin_offset).round();1668if (is_layout_rtl()) {1669rect_pos.x = get_size().width - rect_pos.x - icon_size;1670}1671draw_texture_rect(icon, Rect2(rect_pos, rect_size));16721673ofs += hs + icon_size;1674w -= hs + icon_size;1675}16761677if (is_layout_rtl()) {1678ofs = get_size().width - ofs - w;1679}1680float text_pos_y = font->get_ascent(font_size) + (get_size().height - font->get_height(font_size)) / 2 + v_margin_offset;1681Point2 text_pos = Point2(ofs, text_pos_y).round();1682draw_string(font, text_pos, label, HORIZONTAL_ALIGNMENT_LEFT, w, font_size, theme_cache.font_color);1683} break;1684}1685}16861687void EditorInspectorCategory::_accessibility_action_menu(const Variant &p_data) {1688_popup_context_menu(get_screen_position());1689}16901691Control *EditorInspectorCategory::make_custom_tooltip(const String &p_text) const {1692// If it's not a doc tooltip, fallback to the default one.1693if (doc_class_name.is_empty()) {1694return nullptr;1695}16961697return EditorHelpBitTooltip::show_tooltip(const_cast<EditorInspectorCategory *>(this), p_text);1698}16991700void EditorInspectorCategory::set_as_favorite() {1701is_favorite = true;1702_update_icon();1703}17041705void EditorInspectorCategory::set_property_info(const PropertyInfo &p_info) {1706info = p_info;17071708Ref<Script> scr = _get_category_script(info);1709if (scr.is_valid()) {1710StringName script_name = EditorNode::get_editor_data().script_class_get_name(scr->get_path());1711if (script_name != StringName()) {1712label = script_name;1713}1714}1715if (label.is_empty()) {1716label = info.name;1717}1718_update_icon();1719}17201721void EditorInspectorCategory::set_doc_class_name(const String &p_name) {1722doc_class_name = p_name;1723}17241725Size2 EditorInspectorCategory::get_minimum_size() const {1726Size2 ms;1727if (theme_cache.bold_font.is_valid()) {1728ms.height = theme_cache.bold_font->get_height(theme_cache.bold_font_size);1729}1730if (icon.is_valid()) {1731ms.height = MAX(theme_cache.class_icon_size, ms.height);1732}1733ms.height += theme_cache.vertical_separation;17341735if (theme_cache.background.is_valid()) {1736ms.height += theme_cache.background->get_content_margin(SIDE_TOP) + theme_cache.background->get_content_margin(SIDE_BOTTOM);1737}17381739return ms;1740}17411742void EditorInspectorCategory::_handle_menu_option(int p_option) {1743switch (p_option) {1744case MENU_OPEN_DOCS: {1745ScriptEditor::get_singleton()->goto_help("class:" + doc_class_name);1746EditorNode::get_singleton()->get_editor_main_screen()->select(EditorMainScreen::EDITOR_SCRIPT);1747} break;17481749case MENU_UNFAVORITE_ALL: {1750emit_signal(SNAME("unfavorite_all"));1751} break;1752}1753}17541755void EditorInspectorCategory::_popup_context_menu(const Point2i &p_position) {1756if (!is_favorite && doc_class_name.is_empty()) {1757return;1758}17591760if (menu == nullptr) {1761menu = memnew(PopupMenu);17621763if (is_favorite) {1764menu->add_item(TTRC("Unfavorite All"), MENU_UNFAVORITE_ALL);1765} else {1766menu->add_item(TTRC("Open Documentation"), MENU_OPEN_DOCS);1767menu->set_item_disabled(-1, !EditorHelp::get_doc_data()->class_list.has(doc_class_name));1768}17691770menu->connect(SceneStringName(id_pressed), callable_mp(this, &EditorInspectorCategory::_handle_menu_option));1771add_child(menu);1772}17731774if (menu_icon_dirty) {1775if (is_favorite) {1776menu->set_item_icon(menu->get_item_index(MENU_UNFAVORITE_ALL), theme_cache.icon_unfavorite);1777} else {1778menu->set_item_icon(menu->get_item_index(MENU_OPEN_DOCS), theme_cache.icon_help);1779}1780menu_icon_dirty = false;1781}17821783menu->set_position(p_position);1784menu->reset_size();1785menu->popup();1786}17871788void EditorInspectorCategory::_update_icon() {1789if (is_favorite) {1790icon = theme_cache.icon_favorites;1791return;1792}17931794icon = Ref<Texture2D>();17951796Ref<Script> scr = _get_category_script(info);1797if (scr.is_valid()) {1798StringName script_name = EditorNode::get_editor_data().script_class_get_name(scr->get_path());1799if (script_name == StringName()) {1800icon = EditorNode::get_singleton()->get_object_icon(scr.ptr(), "Object");1801} else {1802icon = EditorNode::get_singleton()->get_class_icon(script_name);1803}1804}1805if (icon.is_null() && !info.name.is_empty()) {1806icon = EditorNode::get_singleton()->get_class_icon(info.name);1807}1808}18091810void EditorInspectorCategory::gui_input(const Ref<InputEvent> &p_event) {1811const Ref<InputEventMouseButton> &mb = p_event;1812if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MouseButton::RIGHT) {1813_popup_context_menu(get_screen_position() + mb->get_position());1814}1815}18161817EditorInspectorCategory::EditorInspectorCategory() {1818set_focus_mode(FOCUS_ACCESSIBILITY);1819}18201821////////////////////////////////////////////////1822////////////////////////////////////////////////18231824void EditorInspectorSection::_test_unfold() {1825if (!vbox_added) {1826add_child(vbox);1827move_child(vbox, 0);1828vbox_added = true;1829}1830}18311832Ref<Texture2D> EditorInspectorSection::_get_arrow() {1833Ref<Texture2D> arrow;1834if (foldable) {1835if (object->editor_is_section_unfolded(section)) {1836arrow = theme_cache.arrow;1837} else {1838if (is_layout_rtl()) {1839arrow = theme_cache.arrow_collapsed_mirrored;1840} else {1841arrow = theme_cache.arrow_collapsed;1842}1843}1844}1845return arrow;1846}18471848Ref<Texture2D> EditorInspectorSection::_get_checkbox() {1849Ref<Texture2D> checkbox;18501851if (checkable) {1852if (checked) {1853checkbox = theme_cache.icon_gui_checked;1854} else {1855checkbox = theme_cache.icon_gui_unchecked;1856}1857}18581859return checkbox;1860}18611862int EditorInspectorSection::_get_header_height() {1863int header_height = theme_cache.bold_font->get_height(theme_cache.bold_font_size);1864Ref<Texture2D> arrow = _get_arrow();1865if (arrow.is_valid()) {1866header_height = MAX(header_height, arrow->get_height());1867}1868header_height += theme_cache.vertical_separation;18691870return header_height;1871}18721873void EditorInspectorSection::_notification(int p_what) {1874switch (p_what) {1875case NOTIFICATION_ACCESSIBILITY_UPDATE: {1876RID ae = get_accessibility_element();1877ERR_FAIL_COND(ae.is_null());18781879DisplayServer::get_singleton()->accessibility_update_set_role(ae, DisplayServer::AccessibilityRole::ROLE_BUTTON);18801881DisplayServer::get_singleton()->accessibility_update_set_name(ae, vformat(TTR("Section: %s"), label));1882DisplayServer::get_singleton()->accessibility_update_set_value(ae, vformat(TTR("Section: %s"), label));1883DisplayServer::get_singleton()->accessibility_update_add_action(ae, DisplayServer::AccessibilityAction::ACTION_COLLAPSE, callable_mp(this, &EditorInspectorSection::_accessibility_action_collapse));1884DisplayServer::get_singleton()->accessibility_update_add_action(ae, DisplayServer::AccessibilityAction::ACTION_EXPAND, callable_mp(this, &EditorInspectorSection::_accessibility_action_expand));1885} break;18861887case NOTIFICATION_THEME_CHANGED: {1888EditorInspector::initialize_section_theme(theme_cache, this);18891890bg_color = theme_cache.prop_subsection;1891bg_color.a /= level;1892vbox->add_theme_constant_override(SNAME("separation"), theme_cache.vertical_separation);1893} break;18941895case NOTIFICATION_SORT_CHILDREN: {1896if (!vbox_added) {1897return;1898}18991900int inspector_margin = theme_cache.inspector_margin;1901if (indent_depth > 0 && theme_cache.indent_size > 0) {1902inspector_margin += indent_depth * theme_cache.indent_size;1903}1904if (indent_depth > 0 && theme_cache.indent_box.is_valid()) {1905inspector_margin += theme_cache.indent_box->get_margin(SIDE_LEFT) + theme_cache.indent_box->get_margin(SIDE_RIGHT);1906}19071908Size2 size = get_size() - Vector2(inspector_margin, 0);1909int header_height = _get_header_height();1910Vector2 offset = Vector2(is_layout_rtl() ? 0 : inspector_margin, header_height);1911for (int i = 0; i < get_child_count(); i++) {1912Control *c = as_sortable_control(get_child(i));1913if (!c) {1914continue;1915}1916fit_child_in_rect(c, Rect2(offset, size));1917}1918} break;19191920case NOTIFICATION_DRAW: {1921int section_indent = 0;1922int section_indent_size = theme_cache.indent_size;1923if (indent_depth > 0 && section_indent_size > 0) {1924section_indent = indent_depth * section_indent_size;1925}1926Ref<StyleBoxFlat> section_indent_style = theme_cache.indent_box;1927if (indent_depth > 0 && section_indent_style.is_valid()) {1928section_indent += section_indent_style->get_margin(SIDE_LEFT) + section_indent_style->get_margin(SIDE_RIGHT);1929}19301931int header_width = get_size().width - section_indent;1932int header_offset_x = 0.0;1933bool rtl = is_layout_rtl();1934if (!rtl) {1935header_offset_x += section_indent;1936}19371938bool can_click_unfold = vbox->get_child_count(false) != 0 && !(checkable && !checked && !checkbox_only);19391940// Draw header area.1941int header_height = _get_header_height();1942Rect2 header_rect = Rect2(Vector2(header_offset_x, 0.0), Vector2(header_width, header_height));1943Color c = bg_color;1944c.a *= 0.4;1945if (header_hover) {1946c = c.lightened(Input::get_singleton()->is_mouse_button_pressed(MouseButton::LEFT) ? -0.05 : 0.2);1947}1948draw_rect(header_rect, c);19491950// Draw header title, folding arrow and count of revertable properties.1951{1952int outer_margin = Math::round(2 * EDSCALE);19531954int margin_start = section_indent + outer_margin;1955int margin_end = outer_margin;19561957// - Arrow.1958Ref<Texture2D> arrow = _get_arrow();1959if (arrow.is_valid()) {1960Point2 arrow_position;1961if (rtl) {1962arrow_position.x = get_size().width - (margin_start + arrow->get_width());1963} else {1964arrow_position.x = margin_start;1965}1966arrow_position.y = (header_height - arrow->get_height()) / 2;1967if (can_click_unfold) {1968draw_texture(arrow, arrow_position);1969}1970margin_start += arrow->get_width() + theme_cache.horizontal_separation;1971}19721973Ref<Font> font = theme_cache.bold_font;1974int font_size = theme_cache.bold_font_size;1975Color font_color = theme_cache.font_color;19761977Ref<Font> light_font = theme_cache.light_font;1978int light_font_size = theme_cache.light_font_size;19791980// - Keying1981Ref<Texture2D> key = theme_cache.icon_gui_animation_key;1982if (keying && key.is_valid()) {1983Point2 key_position;1984key_position.x = rtl ? (margin_end + 2 * EDSCALE) : (get_size().width - key->get_width() - margin_end - 2 * EDSCALE);1985keying_rect = Rect2(key_position.x - 2 * EDSCALE, 0, key->get_width() + 4 * EDSCALE, header_height);19861987Color key_color(1, 1, 1);1988if (keying_hover) {1989key_color.r *= 1.2;1990key_color.g *= 1.2;1991key_color.b *= 1.2;19921993Ref<StyleBox> sb_hover = theme_cache.key_hover;1994draw_style_box(sb_hover, keying_rect);1995}1996key_position.y = (header_height - key->get_height()) / 2;19971998draw_texture(key, key_position, key_color);1999margin_end += key->get_width() + 6 * EDSCALE;2000} else {2001keying_rect = Rect2();2002}20032004// - Checkbox.2005Ref<Texture2D> checkbox = _get_checkbox();2006if (checkbox.is_valid()) {2007const String checkbox_text = TTR("On");2008Size2 label_size = light_font->get_string_size(checkbox_text, HORIZONTAL_ALIGNMENT_LEFT, -1.0f, light_font_size);2009Point2 checkbox_position;2010Point2 label_position;2011if (rtl) {2012label_position.x = margin_end;2013checkbox_position.x = margin_end + label_size.width + 2 * EDSCALE;2014} else {2015label_position.x = get_size().width - (margin_end + label_size.width);2016checkbox_position.x = label_position.x - checkbox->get_width() - 2 * EDSCALE;2017}2018checkbox_position.y = (header_height - checkbox->get_height()) / 2;2019label_position.y = light_font->get_ascent(light_font_size) + (header_height - label_size.height) / 2.0;20202021check_rect = Rect2(checkbox_position.x, 0, checkbox->get_width() + label_size.width + 2 * EDSCALE, header_height);20222023Color check_font_color = font_color;2024Color checkbox_color(1, 1, 1);2025if (check_hover) {2026checkbox_color.r *= 1.2;2027checkbox_color.g *= 1.2;2028checkbox_color.b *= 1.2;2029check_font_color = checked ? theme_cache.font_hover_pressed_color : theme_cache.font_hover_color;2030} else if (checked) {2031check_font_color = theme_cache.font_pressed_color;2032}20332034draw_texture(checkbox, checkbox_position, checkbox_color);2035draw_string(light_font, label_position, checkbox_text, HORIZONTAL_ALIGNMENT_LEFT, -1.0f, light_font_size, check_font_color, TextServer::JUSTIFICATION_NONE);2036margin_end += label_size.width + checkbox->get_width() + 6 * EDSCALE;2037} else {2038check_rect = Rect2();2039}20402041int available = get_size().width - (margin_start + margin_end);20422043// - Count of revertable properties.2044String num_revertable_str;2045int num_revertable_width = 0;20462047bool folded = (foldable || !checkbox_only) && !object->editor_is_section_unfolded(section);20482049if (folded && revertable_properties.size()) {2050int label_width = theme_cache.bold_font->get_string_size(label, HORIZONTAL_ALIGNMENT_LEFT, available, theme_cache.bold_font_size, TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_CONSTRAIN_ELLIPSIS).x;20512052// Can we fit the long version of the revertable count text?2053num_revertable_str = vformat(TTRN("(%d change)", "(%d changes)", revertable_properties.size()), revertable_properties.size());2054num_revertable_width = light_font->get_string_size(num_revertable_str, HORIZONTAL_ALIGNMENT_LEFT, -1.0f, light_font_size, TextServer::JUSTIFICATION_NONE).x;2055if (label_width + outer_margin + num_revertable_width > available) {2056// We'll have to use the short version.2057num_revertable_str = vformat("(%d)", revertable_properties.size());2058num_revertable_width = light_font->get_string_size(num_revertable_str, HORIZONTAL_ALIGNMENT_LEFT, -1.0f, light_font_size, TextServer::JUSTIFICATION_NONE).x;2059}20602061float text_offset_y = light_font->get_ascent(light_font_size) + (header_height - light_font->get_height(light_font_size)) / 2;2062Point2 text_offset = Point2(margin_end, text_offset_y).round();2063if (!rtl) {2064text_offset.x = get_size().width - (text_offset.x + num_revertable_width);2065}2066draw_string(light_font, text_offset, num_revertable_str, HORIZONTAL_ALIGNMENT_LEFT, -1.0f, light_font_size, theme_cache.font_disabled_color, TextServer::JUSTIFICATION_NONE);2067margin_end += num_revertable_width + outer_margin;2068available -= num_revertable_width + outer_margin;2069}20702071// - Label.2072float text_offset_y = font->get_ascent(font_size) + (header_height - font->get_height(font_size)) / 2;2073Point2 text_offset = Point2(margin_start, text_offset_y).round();2074if (rtl) {2075text_offset.x = margin_end;2076}2077if (object->has_method("_get_property_warning") && !String(object->call("_get_property_warning", related_enable_property)).is_empty()) {2078font_color = theme_cache.warning_color;2079}2080HorizontalAlignment text_align = rtl ? HORIZONTAL_ALIGNMENT_RIGHT : HORIZONTAL_ALIGNMENT_LEFT;2081draw_string(font, text_offset, label, text_align, available, font_size, theme_cache.font_color, TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_CONSTRAIN_ELLIPSIS);2082}20832084// Draw section indentation.2085if (section_indent_style.is_valid() && section_indent > 0) {2086Rect2 indent_rect = Rect2(Vector2(), Vector2(indent_depth * section_indent_size, get_size().height));2087if (rtl) {2088indent_rect.position.x = get_size().width - section_indent + section_indent_style->get_margin(SIDE_RIGHT);2089} else {2090indent_rect.position.x = section_indent_style->get_margin(SIDE_LEFT);2091}2092draw_style_box(section_indent_style, indent_rect);2093}2094} break;20952096case NOTIFICATION_DRAG_BEGIN: {2097dropping_for_unfold = true;2098} break;20992100case NOTIFICATION_DRAG_END: {2101dropping_for_unfold = false;2102} break;21032104case NOTIFICATION_MOUSE_ENTER: {2105if (dropping_for_unfold) {2106dropping_unfold_timer->start();2107}2108queue_redraw();2109} break;21102111case NOTIFICATION_MOUSE_EXIT_SELF:2112case NOTIFICATION_MOUSE_EXIT: {2113if (dropping_for_unfold) {2114dropping_unfold_timer->stop();2115}21162117if (header_hover || check_hover || keying_hover) {2118header_hover = false;2119check_hover = false;2120keying_hover = false;2121queue_redraw();2122}2123} break;2124}2125}21262127Size2 EditorInspectorSection::get_minimum_size() const {2128Size2 ms;2129for (int i = 0; i < get_child_count(); i++) {2130Control *c = as_sortable_control(get_child(i));2131if (!c) {2132continue;2133}2134Size2 minsize = c->get_combined_minimum_size();2135ms = ms.max(minsize);2136}21372138if (theme_cache.font.is_valid()) {2139ms.height += theme_cache.font->get_height(theme_cache.font_size) + theme_cache.vertical_separation;2140ms.width += theme_cache.inspector_margin;2141}21422143if (indent_depth > 0 && theme_cache.indent_size > 0) {2144ms.width += indent_depth * theme_cache.indent_size;2145}2146if (indent_depth > 0 && theme_cache.indent_box.is_valid()) {2147ms.width += theme_cache.indent_box->get_margin(SIDE_LEFT) + theme_cache.indent_box->get_margin(SIDE_RIGHT);2148}21492150return ms;2151}21522153EditorInspector *EditorInspectorSection::_get_parent_inspector() const {2154Node *parent = get_parent();2155while (parent) {2156EditorInspector *ei = Object::cast_to<EditorInspector>(parent);2157if (ei) {2158return ei;2159}2160parent = parent->get_parent();2161}2162return nullptr;2163}21642165Control *EditorInspectorSection::make_custom_tooltip(const String &p_text) const {2166if (!checkable) {2167return Container::make_custom_tooltip(p_text);2168}21692170String symbol;2171String prologue;21722173if (object->has_method("_get_property_warning")) {2174const String custom_warning = object->call("_get_property_warning", related_enable_property);2175if (!custom_warning.is_empty()) {2176prologue = "[b][color=" + theme_cache.warning_color.to_html(false) + "]" + custom_warning + "[/color][/b]";2177}2178}21792180symbol = p_text;21812182const EditorInspector *inspector = _get_parent_inspector();2183if (inspector) {2184const String custom_description = inspector->get_custom_property_description(p_text);2185if (!custom_description.is_empty()) {2186if (!prologue.is_empty()) {2187prologue += '\n';2188}2189prologue += custom_description;2190}2191}21922193if (!symbol.is_empty() || !prologue.is_empty()) {2194return EditorHelpBitTooltip::show_tooltip(const_cast<EditorInspectorSection *>(this), symbol, prologue);2195}21962197return nullptr;2198}21992200void EditorInspectorSection::setup(const String &p_section, const String &p_label, Object *p_object, const Color &p_bg_color, bool p_foldable, int p_indent_depth, int p_level) {2201section = p_section;2202label = p_label;2203object = p_object;2204bg_color = p_bg_color;2205foldable = p_foldable;2206indent_depth = p_indent_depth;2207level = p_level;22082209_test_unfold();22102211if (foldable) {2212if (object->editor_is_section_unfolded(section)) {2213vbox->show();2214} else {2215vbox->hide();2216}2217}2218}22192220void EditorInspectorSection::gui_input(const Ref<InputEvent> &p_event) {2221ERR_FAIL_COND(p_event.is_null());2222bool can_click_unfold = vbox->get_child_count(false) != 0 && !(!checkbox_only && checkable && !checked);22232224Ref<InputEventMouseMotion> mm = p_event;2225if (mm.is_valid()) {2226Vector2 mpos = mm->get_position();22272228bool new_check_hover = check_rect.has_point(mpos);2229if (new_check_hover != check_hover) {2230check_hover = new_check_hover;2231queue_redraw();2232}22332234bool new_keying_hover = keying_rect.has_point(mpos);2235if (new_keying_hover != keying_hover) {2236keying_hover = new_keying_hover;2237queue_redraw();2238}22392240bool new_header_hover = foldable && can_click_unfold && (get_local_mouse_position().y < _get_header_height());2241if (new_header_hover != header_hover) {2242header_hover = new_header_hover;2243queue_redraw();2244}2245}22462247Ref<InputEventKey> k = p_event;2248if (k.is_valid() && k->is_pressed()) {2249if (foldable && can_click_unfold && k->is_action("ui_accept", true)) {2250accept_event();22512252bool should_unfold = !object->editor_is_section_unfolded(section);2253if (should_unfold) {2254unfold();2255} else {2256fold();2257}2258}2259}22602261Ref<InputEventMouseButton> mb = p_event;2262if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT) {2263Vector2 pos = mb->get_position();22642265if (object->editor_is_section_unfolded(section)) {2266int header_height = _get_header_height();22672268if (pos.y >= header_height) {2269return;2270}2271}22722273accept_event();22742275if (checkable && check_rect.has_point(pos)) {2276checked = !checked;2277emit_signal(SNAME("section_toggled_by_user"), related_enable_property, checked);2278if (checked) {2279unfold();2280} else if (!checkbox_only) {2281vbox->hide();2282}2283} else if (keying && keying_rect.has_point(pos)) {2284emit_signal(SNAME("property_keyed"), related_enable_property, false);2285} else if (foldable) {2286bool should_unfold = can_click_unfold && !object->editor_is_section_unfolded(section);2287if (should_unfold) {2288unfold();2289} else {2290fold();2291}2292}2293} else if (mb.is_valid() && !mb->is_pressed()) {2294queue_redraw();2295}2296}22972298String EditorInspectorSection::get_section() const {2299return section;2300}23012302VBoxContainer *EditorInspectorSection::get_vbox() {2303return vbox;2304}23052306void EditorInspectorSection::_accessibility_action_collapse(const Variant &p_data) {2307fold();2308}23092310void EditorInspectorSection::_accessibility_action_expand(const Variant &p_data) {2311unfold();2312}23132314void EditorInspectorSection::unfold() {2315if ((!foldable && !checkable) || (!checkbox_only && checkable && !checked)) {2316return;2317}23182319_test_unfold();23202321if (foldable) {2322object->editor_set_section_unfold(section, true);2323}23242325vbox->show();2326queue_redraw();2327}23282329void EditorInspectorSection::fold() {2330if (!foldable || !vbox_added) {2331return;2332}23332334object->editor_set_section_unfold(section, false);2335vbox->hide();2336queue_redraw();2337}23382339void EditorInspectorSection::set_bg_color(const Color &p_bg_color) {2340bg_color = p_bg_color;2341queue_redraw();2342}23432344void EditorInspectorSection::set_keying(bool p_keying) {2345if (keying == (checkable && p_keying)) {2346return;2347}23482349keying = checkable && p_keying;2350if (checkable) {2351queue_redraw();2352}2353}23542355void EditorInspectorSection::reset_timer() {2356if (dropping_for_unfold && !dropping_unfold_timer->is_stopped()) {2357dropping_unfold_timer->start();2358}2359}23602361void EditorInspectorSection::set_checkable(const String &p_related_check_property, bool p_checkbox_only, bool p_checked) {2362if (checkable == !p_related_check_property.is_empty()) {2363return;2364}23652366checkbox_only = p_checkbox_only;2367checkable = !p_related_check_property.is_empty();2368checked = p_checked;2369related_enable_property = p_related_check_property;23702371if (InspectorDock::get_singleton()) {2372if (checkable) {2373InspectorDock::get_inspector_singleton()->connect("property_edited", callable_mp(this, &EditorInspectorSection::_property_edited));2374} else {2375InspectorDock::get_inspector_singleton()->disconnect("property_edited", callable_mp(this, &EditorInspectorSection::_property_edited));2376}2377}23782379if (!checkbox_only && checkable && !checked) {2380vbox->hide();2381}23822383queue_redraw();2384}23852386void EditorInspectorSection::set_checked(bool p_checked) {2387if (checked == p_checked) {2388return;2389}23902391checked = p_checked;2392if (!checkbox_only && checkable && !checked) {2393vbox->hide();2394} else if (!checkbox_only) {2395unfold();2396}23972398queue_redraw();2399}24002401bool EditorInspectorSection::has_revertable_properties() const {2402return !revertable_properties.is_empty();2403}24042405void EditorInspectorSection::property_can_revert_changed(const String &p_path, bool p_can_revert) {2406bool had_revertable_properties = has_revertable_properties();2407if (p_can_revert) {2408revertable_properties.insert(p_path);2409} else {2410revertable_properties.erase(p_path);2411}2412if (has_revertable_properties() != had_revertable_properties) {2413queue_redraw();2414}2415}24162417void EditorInspectorSection::_property_edited(const String &p_property) {2418if (!related_enable_property.is_empty() && p_property == related_enable_property) {2419update_property();2420}2421}24222423void EditorInspectorSection::update_property() {2424if (!checkable) {2425return;2426}24272428bool valid = false;2429Variant value_checked = object->get(related_enable_property, &valid);24302431if (valid) {2432set_checked(value_checked.operator bool());2433}2434}24352436void EditorInspectorSection::_bind_methods() {2437ClassDB::bind_method(D_METHOD("setup", "section", "label", "object", "bg_color", "foldable", "indent_depth", "level"), &EditorInspectorSection::setup, DEFVAL(0), DEFVAL(1));2438ClassDB::bind_method(D_METHOD("get_vbox"), &EditorInspectorSection::get_vbox);2439ClassDB::bind_method(D_METHOD("unfold"), &EditorInspectorSection::unfold);2440ClassDB::bind_method(D_METHOD("fold"), &EditorInspectorSection::fold);24412442ADD_SIGNAL(MethodInfo("section_toggled_by_user", PropertyInfo(Variant::STRING_NAME, "property"), PropertyInfo(Variant::BOOL, "value")));2443ADD_SIGNAL(MethodInfo("property_keyed", PropertyInfo(Variant::STRING_NAME, "property")));2444}24452446EditorInspectorSection::EditorInspectorSection() {2447set_focus_mode(FOCUS_ACCESSIBILITY);24482449vbox = memnew(VBoxContainer);24502451dropping_unfold_timer = memnew(Timer);2452dropping_unfold_timer->set_wait_time(0.6);2453dropping_unfold_timer->set_one_shot(true);2454add_child(dropping_unfold_timer);2455dropping_unfold_timer->connect("timeout", callable_mp(this, &EditorInspectorSection::unfold));2456}24572458EditorInspectorSection::~EditorInspectorSection() {2459if (!vbox_added) {2460memdelete(vbox);2461}24622463if (checkable && InspectorDock::get_singleton()) {2464InspectorDock::get_inspector_singleton()->disconnect("property_edited", callable_mp(this, &EditorInspectorSection::_property_edited));2465}2466}24672468////////////////////////////////////////////////2469////////////////////////////////////////////////24702471int EditorInspectorArray::_get_array_count() {2472if (mode == MODE_USE_MOVE_ARRAY_ELEMENT_FUNCTION) {2473List<PropertyInfo> object_property_list;2474object->get_property_list(&object_property_list);2475return _extract_properties_as_array(object_property_list).size();2476} else if (mode == MODE_USE_COUNT_PROPERTY) {2477bool valid;2478int count_val = object->get(count_property, &valid);2479ERR_FAIL_COND_V_MSG(!valid, 0, vformat("%s is not a valid property to be used as array count.", count_property));2480return count_val;2481}2482return 0;2483}24842485void EditorInspectorArray::_add_button_pressed() {2486_move_element(-1, -1);2487}24882489void EditorInspectorArray::_paginator_page_changed(int p_page) {2490emit_signal("page_change_request", p_page);2491}24922493void EditorInspectorArray::_rmb_popup_id_pressed(int p_id) {2494switch (p_id) {2495case OPTION_MOVE_UP:2496if (popup_array_index_pressed > 0) {2497_move_element(popup_array_index_pressed, popup_array_index_pressed - 1);2498}2499break;2500case OPTION_MOVE_DOWN:2501if (popup_array_index_pressed < count - 1) {2502_move_element(popup_array_index_pressed, popup_array_index_pressed + 2);2503}2504break;2505case OPTION_NEW_BEFORE:2506_move_element(-1, popup_array_index_pressed);2507break;2508case OPTION_NEW_AFTER:2509_move_element(-1, popup_array_index_pressed + 1);2510break;2511case OPTION_REMOVE:2512_move_element(popup_array_index_pressed, -1);2513break;2514case OPTION_CLEAR_ARRAY:2515_clear_array();2516break;2517case OPTION_RESIZE_ARRAY:2518new_size_spin_box->set_value(count);2519resize_dialog->get_ok_button()->set_disabled(true);2520resize_dialog->popup_centered(Size2(250, 0) * EDSCALE);2521new_size_spin_box->get_line_edit()->grab_focus();2522new_size_spin_box->get_line_edit()->select_all();2523break;2524default:2525break;2526}2527}25282529void EditorInspectorArray::_control_dropping_draw() {2530int drop_position = _drop_position();25312532if (dropping && drop_position >= 0) {2533Vector2 from;2534Vector2 to;2535if (drop_position < elements_vbox->get_child_count()) {2536Transform2D xform = Object::cast_to<Control>(elements_vbox->get_child(drop_position))->get_transform();2537from = xform.xform(Vector2());2538to = xform.xform(Vector2(elements_vbox->get_size().x, 0));2539} else {2540Control *child = Object::cast_to<Control>(elements_vbox->get_child(drop_position - 1));2541Transform2D xform = child->get_transform();2542from = xform.xform(Vector2(0, child->get_size().y));2543to = xform.xform(Vector2(elements_vbox->get_size().x, child->get_size().y));2544}2545Color color = get_theme_color(SNAME("accent_color"), EditorStringName(Editor));2546control_dropping->draw_line(from, to, color, 2);2547}2548}25492550void EditorInspectorArray::_vbox_visibility_changed() {2551control_dropping->set_visible(vbox->is_visible_in_tree());2552}25532554void EditorInspectorArray::_panel_draw(int p_index) {2555ERR_FAIL_INDEX(p_index, (int)array_elements.size());25562557Ref<StyleBox> style = get_theme_stylebox(SNAME("Focus"), EditorStringName(EditorStyles));2558if (style.is_null()) {2559return;2560}2561if (array_elements[p_index].panel->has_focus()) {2562array_elements[p_index].panel->draw_style_box(style, Rect2(Vector2(), array_elements[p_index].panel->get_size()));2563}2564}25652566void EditorInspectorArray::_panel_gui_focus(int p_index) {2567array_elements[p_index].panel->queue_redraw();2568selected = p_index;2569}25702571void EditorInspectorArray::_panel_gui_unfocus(int p_index) {2572array_elements[p_index].panel->queue_redraw();2573if (selected == p_index) {2574selected = -1;2575}2576}25772578void EditorInspectorArray::_panel_gui_input(Ref<InputEvent> p_event, int p_index) {2579ERR_FAIL_INDEX(p_index, (int)array_elements.size());25802581if (read_only) {2582return;2583}25842585Ref<InputEventKey> key_ref = p_event;2586if (key_ref.is_valid()) {2587const InputEventKey &key = **key_ref;25882589if (array_elements[p_index].panel->has_focus() && key.is_pressed() && key.get_keycode() == Key::KEY_DELETE) {2590_move_element(begin_array_index + p_index, -1);2591array_elements[p_index].panel->accept_event();2592}2593}25942595Ref<InputEventMouseButton> mb = p_event;2596if (mb.is_valid()) {2597if (movable && mb->get_button_index() == MouseButton::RIGHT) {2598array_elements[p_index].panel->accept_event();2599popup_array_index_pressed = begin_array_index + p_index;2600rmb_popup->set_item_disabled(OPTION_MOVE_UP, popup_array_index_pressed == 0);2601rmb_popup->set_item_disabled(OPTION_MOVE_DOWN, popup_array_index_pressed == count - 1);2602rmb_popup->set_position(array_elements[p_index].panel->get_screen_position() + mb->get_position());2603rmb_popup->reset_size();2604rmb_popup->popup();2605}2606}2607}26082609void EditorInspectorArray::show_menu(int p_index, const Vector2 &p_offset) {2610popup_array_index_pressed = begin_array_index + p_index;2611rmb_popup->set_item_disabled(OPTION_MOVE_UP, popup_array_index_pressed == 0);2612rmb_popup->set_item_disabled(OPTION_MOVE_DOWN, popup_array_index_pressed == count - 1);2613rmb_popup->set_position(get_screen_position() + p_offset);2614rmb_popup->reset_size();2615rmb_popup->popup();2616}26172618void EditorInspectorArray::_move_element(int p_element_index, int p_to_pos) {2619String action_name;2620if (p_element_index < 0) {2621action_name = vformat(TTR("Add element to property array with prefix %s."), array_element_prefix);2622} else if (p_to_pos < 0) {2623action_name = vformat(TTR("Remove element %d from property array with prefix %s."), p_element_index, array_element_prefix);2624} else {2625action_name = vformat(TTR("Move element %d to position %d in property array with prefix %s."), p_element_index, p_to_pos, array_element_prefix);2626}2627EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();2628undo_redo->create_action(action_name);2629if (mode == MODE_USE_MOVE_ARRAY_ELEMENT_FUNCTION) {2630// Call the function.2631Callable move_function = EditorNode::get_editor_data().get_move_array_element_function(object->get_class_name());2632if (move_function.is_valid()) {2633move_function.call(undo_redo, object, array_element_prefix, p_element_index, p_to_pos);2634} else {2635WARN_PRINT(vformat("Could not find a function to move arrays elements for class %s. Register a move element function using EditorData::add_move_array_element_function", object->get_class_name()));2636}2637} else if (mode == MODE_USE_COUNT_PROPERTY) {2638ERR_FAIL_COND(p_to_pos < -1 || p_to_pos > count);26392640if (!swap_method.is_empty()) {2641ERR_FAIL_COND(!object->has_method(swap_method));26422643// Swap method was provided, use it.2644if (p_element_index < 0) {2645// Add an element at position2646undo_redo->add_do_property(object, count_property, count + 1);2647if (p_to_pos >= 0) {2648for (int i = count; i > p_to_pos; i--) {2649undo_redo->add_do_method(object, swap_method, i, i - 1);2650}2651for (int i = p_to_pos; i < count; i++) {2652undo_redo->add_undo_method(object, swap_method, i, i + 1);2653}2654}2655undo_redo->add_undo_property(object, count_property, count);26562657} else if (p_to_pos < 0) {2658if (count > 0) {2659// Remove element at position2660undo_redo->add_undo_property(object, count_property, count);26612662List<PropertyInfo> object_property_list;2663object->get_property_list(&object_property_list);26642665for (int i = p_element_index; i < count - 1; i++) {2666undo_redo->add_do_method(object, swap_method, i, i + 1);2667}26682669for (int i = count; i > p_element_index; i--) {2670undo_redo->add_undo_method(object, swap_method, i, i - 1);2671}26722673String erase_prefix = String(array_element_prefix) + itos(p_element_index);26742675for (const PropertyInfo &E : object_property_list) {2676if (E.name.begins_with(erase_prefix)) {2677undo_redo->add_undo_property(object, E.name, object->get(E.name));2678}2679}26802681undo_redo->add_do_property(object, count_property, count - 1);2682}2683} else {2684if (p_to_pos > p_element_index) {2685p_to_pos--;2686}26872688if (p_to_pos < p_element_index) {2689for (int i = p_element_index; i > p_to_pos; i--) {2690undo_redo->add_do_method(object, swap_method, i, i - 1);2691}2692for (int i = p_to_pos; i < p_element_index; i++) {2693undo_redo->add_undo_method(object, swap_method, i, i + 1);2694}2695} else if (p_to_pos > p_element_index) {2696for (int i = p_element_index; i < p_to_pos; i++) {2697undo_redo->add_do_method(object, swap_method, i, i + 1);2698}26992700for (int i = p_to_pos; i > p_element_index; i--) {2701undo_redo->add_undo_method(object, swap_method, i, i - 1);2702}2703}2704}2705} else {2706// Use standard properties.2707List<PropertyInfo> object_property_list;2708object->get_property_list(&object_property_list);27092710Array properties_as_array = _extract_properties_as_array(object_property_list);2711properties_as_array.resize(count);27122713// For undoing things2714undo_redo->add_undo_property(object, count_property, properties_as_array.size());2715for (int i = 0; i < (int)properties_as_array.size(); i++) {2716Dictionary d = Dictionary(properties_as_array[i]);2717for (const KeyValue<Variant, Variant> &kv : d) {2718undo_redo->add_undo_property(object, vformat(kv.key, i), kv.value);2719}2720}27212722if (p_element_index < 0) {2723// Add an element.2724properties_as_array.insert(p_to_pos < 0 ? properties_as_array.size() : p_to_pos, Dictionary());2725} else if (p_to_pos < 0) {2726// Delete the element.2727properties_as_array.remove_at(p_element_index);2728} else {2729// Move the element.2730properties_as_array.insert(p_to_pos, properties_as_array[p_element_index].duplicate());2731properties_as_array.remove_at(p_to_pos < p_element_index ? p_element_index + 1 : p_element_index);2732}27332734// Change the array size then set the properties.2735undo_redo->add_do_property(object, count_property, properties_as_array.size());2736for (int i = 0; i < (int)properties_as_array.size(); i++) {2737Dictionary d = properties_as_array[i];2738for (const KeyValue<Variant, Variant> &kv : d) {2739undo_redo->add_do_property(object, vformat(kv.key, i), kv.value);2740}2741}2742}2743}2744undo_redo->commit_action();27452746// Handle page change and update counts.2747if (p_element_index < 0) {2748int added_index = p_to_pos < 0 ? count : p_to_pos;2749emit_signal(SNAME("page_change_request"), added_index / page_length);2750count += 1;2751} else if (p_to_pos < 0) {2752count -= 1;2753if (page == max_page && (MAX(0, count - 1) / page_length != max_page)) {2754emit_signal(SNAME("page_change_request"), max_page - 1);2755}2756} else if (p_to_pos == begin_array_index - 1) {2757emit_signal(SNAME("page_change_request"), page - 1);2758} else if (p_to_pos > end_array_index) {2759emit_signal(SNAME("page_change_request"), page + 1);2760}2761begin_array_index = page * page_length;2762end_array_index = MIN(count, (page + 1) * page_length);2763max_page = MAX(0, count - 1) / page_length;2764}27652766void EditorInspectorArray::_clear_array() {2767EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();2768undo_redo->create_action(vformat(TTR("Clear Property Array with Prefix %s"), array_element_prefix));2769if (mode == MODE_USE_MOVE_ARRAY_ELEMENT_FUNCTION) {2770for (int i = count - 1; i >= 0; i--) {2771// Call the function.2772Callable move_function = EditorNode::get_editor_data().get_move_array_element_function(object->get_class_name());2773if (move_function.is_valid()) {2774move_function.call(undo_redo, object, array_element_prefix, i, -1);2775} else {2776WARN_PRINT(vformat("Could not find a function to move arrays elements for class %s. Register a move element function using EditorData::add_move_array_element_function", object->get_class_name()));2777}2778}2779} else if (mode == MODE_USE_COUNT_PROPERTY) {2780List<PropertyInfo> object_property_list;2781object->get_property_list(&object_property_list);27822783Array properties_as_array = _extract_properties_as_array(object_property_list);2784properties_as_array.resize(count);27852786// For undoing things2787undo_redo->add_undo_property(object, count_property, count);2788for (int i = 0; i < (int)properties_as_array.size(); i++) {2789Dictionary d = Dictionary(properties_as_array[i]);2790for (const KeyValue<Variant, Variant> &kv : d) {2791undo_redo->add_undo_property(object, vformat(kv.key, i), kv.value);2792}2793}27942795// Change the array size then set the properties.2796undo_redo->add_do_property(object, count_property, 0);2797}2798undo_redo->commit_action();27992800// Handle page change and update counts.2801emit_signal(SNAME("page_change_request"), 0);2802count = 0;2803begin_array_index = 0;2804end_array_index = 0;2805max_page = 0;2806}28072808void EditorInspectorArray::_resize_array(int p_size) {2809ERR_FAIL_COND(p_size < 0);2810if (p_size == count) {2811return;2812}28132814EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();2815undo_redo->create_action(vformat(TTR("Resize Property Array with Prefix %s"), array_element_prefix));2816if (p_size > count) {2817if (mode == MODE_USE_MOVE_ARRAY_ELEMENT_FUNCTION) {2818for (int i = count; i < p_size; i++) {2819// Call the function.2820Callable move_function = EditorNode::get_editor_data().get_move_array_element_function(object->get_class_name());2821if (move_function.is_valid()) {2822move_function.call(undo_redo, object, array_element_prefix, -1, -1);2823} else {2824WARN_PRINT(vformat("Could not find a function to move arrays elements for class %s. Register a move element function using EditorData::add_move_array_element_function", object->get_class_name()));2825}2826}2827} else if (mode == MODE_USE_COUNT_PROPERTY) {2828undo_redo->add_undo_property(object, count_property, count);2829undo_redo->add_do_property(object, count_property, p_size);2830}2831} else {2832if (mode == MODE_USE_MOVE_ARRAY_ELEMENT_FUNCTION) {2833for (int i = count - 1; i > p_size - 1; i--) {2834// Call the function.2835Callable move_function = EditorNode::get_editor_data().get_move_array_element_function(object->get_class_name());2836if (move_function.is_valid()) {2837move_function.call(undo_redo, object, array_element_prefix, i, -1);2838} else {2839WARN_PRINT(vformat("Could not find a function to move arrays elements for class %s. Register a move element function using EditorData::add_move_array_element_function", object->get_class_name()));2840}2841}2842} else if (mode == MODE_USE_COUNT_PROPERTY) {2843List<PropertyInfo> object_property_list;2844object->get_property_list(&object_property_list);28452846Array properties_as_array = _extract_properties_as_array(object_property_list);2847properties_as_array.resize(count);28482849// For undoing things2850undo_redo->add_undo_property(object, count_property, count);2851for (int i = count - 1; i > p_size - 1; i--) {2852Dictionary d = Dictionary(properties_as_array[i]);2853for (const KeyValue<Variant, Variant> &kv : d) {2854undo_redo->add_undo_property(object, vformat(kv.key, i), kv.value);2855}2856}28572858// Change the array size then set the properties.2859undo_redo->add_do_property(object, count_property, p_size);2860}2861}2862undo_redo->commit_action();28632864// Handle page change and update counts.2865emit_signal(SNAME("page_change_request"), 0);2866/*2867count = 0;2868begin_array_index = 0;2869end_array_index = 0;2870max_page = 0;2871*/2872}28732874Array EditorInspectorArray::_extract_properties_as_array(const List<PropertyInfo> &p_list) {2875Array output;28762877for (const PropertyInfo &pi : p_list) {2878if (!(pi.usage & PROPERTY_USAGE_EDITOR)) {2879continue;2880}28812882if (pi.name.begins_with(array_element_prefix)) {2883String str = pi.name.trim_prefix(array_element_prefix);28842885int to_char_index = 0;2886while (to_char_index < str.length()) {2887if (!is_digit(str[to_char_index])) {2888break;2889}2890to_char_index++;2891}2892if (to_char_index > 0) {2893int array_index = str.left(to_char_index).to_int();2894Error error = OK;2895if (array_index >= output.size()) {2896error = output.resize(array_index + 1);2897}2898if (error == OK) {2899String format_string = String(array_element_prefix) + "%d" + str.substr(to_char_index);2900Dictionary dict = output[array_index];2901dict[format_string] = object->get(pi.name);2902output[array_index] = dict;2903} else {2904WARN_PRINT(vformat("Array element %s has an index too high. Array allocation failed.", pi.name));2905}2906}2907}2908}2909return output;2910}29112912int EditorInspectorArray::_drop_position() const {2913for (int i = 0; i < (int)array_elements.size(); i++) {2914const ArrayElement &ae = array_elements[i];29152916Size2 size = ae.panel->get_size();2917Vector2 mp = ae.panel->get_local_mouse_position();29182919if (Rect2(Vector2(), size).has_point(mp)) {2920if (mp.y < size.y / 2) {2921return i;2922} else {2923return i + 1;2924}2925}2926}2927return -1;2928}29292930void EditorInspectorArray::_resize_dialog_confirmed() {2931if (int(new_size_spin_box->get_value()) == count) {2932return;2933}29342935resize_dialog->hide();2936_resize_array(int(new_size_spin_box->get_value()));2937}29382939void EditorInspectorArray::_new_size_spin_box_value_changed(float p_value) {2940resize_dialog->get_ok_button()->set_disabled(int(p_value) == count);2941}29422943void EditorInspectorArray::_new_size_spin_box_text_submitted(const String &p_text) {2944_resize_dialog_confirmed();2945}29462947void EditorInspectorArray::_setup() {2948// Setup counts.2949count = _get_array_count();2950begin_array_index = page * page_length;2951end_array_index = MIN(count, (page + 1) * page_length);2952max_page = MAX(0, count - 1) / page_length;2953array_elements.resize(MAX(0, end_array_index - begin_array_index));2954if (page < 0 || page > max_page) {2955WARN_PRINT(vformat("Invalid page number %d", page));2956page = CLAMP(page, 0, max_page);2957}29582959Ref<Font> numbers_font;2960int numbers_min_w = 0;2961bool unresizable = is_const || read_only;29622963if (numbered) {2964numbers_font = get_theme_font(SNAME("bold"), EditorStringName(EditorFonts));2965int digits_found = count;2966String test;2967while (digits_found) {2968test += "8";2969digits_found /= 10;2970}2971numbers_min_w = numbers_font->get_string_size(test).width;2972}29732974for (int i = 0; i < (int)array_elements.size(); i++) {2975ArrayElement &ae = array_elements[i];29762977// Panel and its hbox.2978ae.panel = memnew(ArrayPanelContainer);2979ae.panel->set_focus_mode(FOCUS_ALL);2980ae.panel->set_mouse_filter(MOUSE_FILTER_PASS);2981SET_DRAG_FORWARDING_GCD(ae.panel, EditorInspectorArray);29822983int element_position = begin_array_index + i;2984String ae_name = vformat(TTR("Element %d: %s%d*"), element_position, array_element_prefix, element_position);29852986ae.panel->set_meta("index", element_position);2987ae.panel->set_meta("name", ae_name);2988ae.panel->set_meta("element", this);2989ae.panel->set_tooltip_text(ae_name);2990ae.panel->connect(SceneStringName(focus_entered), callable_mp(this, &EditorInspectorArray::_panel_gui_focus).bind(i));2991ae.panel->connect(SceneStringName(focus_exited), callable_mp(this, &EditorInspectorArray::_panel_gui_unfocus).bind(i));2992ae.panel->connect(SceneStringName(draw), callable_mp(this, &EditorInspectorArray::_panel_draw).bind(i));2993ae.panel->connect(SceneStringName(gui_input), callable_mp(this, &EditorInspectorArray::_panel_gui_input).bind(i));2994ae.panel->add_theme_style_override(SceneStringName(panel), i % 2 ? odd_style : even_style);2995elements_vbox->add_child(ae.panel);29962997ae.margin = memnew(MarginContainer);2998ae.margin->set_mouse_filter(MOUSE_FILTER_PASS);2999if (is_inside_tree()) {3000Size2 min_size = get_theme_stylebox(SNAME("Focus"), EditorStringName(EditorStyles))->get_minimum_size();3001ae.margin->begin_bulk_theme_override();3002ae.margin->add_theme_constant_override("margin_left", min_size.x / 2);3003ae.margin->add_theme_constant_override("margin_top", min_size.y / 2);3004ae.margin->add_theme_constant_override("margin_right", min_size.x / 2);3005ae.margin->add_theme_constant_override("margin_bottom", min_size.y / 2);3006ae.margin->end_bulk_theme_override();3007}3008ae.panel->add_child(ae.margin);30093010ae.hbox = memnew(HBoxContainer);3011ae.hbox->set_h_size_flags(SIZE_EXPAND_FILL);3012ae.hbox->set_v_size_flags(SIZE_EXPAND_FILL);3013ae.margin->add_child(ae.hbox);30143015// Move button.3016if (movable) {3017VBoxContainer *move_vbox = memnew(VBoxContainer);3018move_vbox->set_v_size_flags(SIZE_EXPAND_FILL);3019move_vbox->set_alignment(BoxContainer::ALIGNMENT_CENTER);3020ae.hbox->add_child(move_vbox);30213022if (element_position > 0) {3023ae.move_up = memnew(Button);3024ae.move_up->set_accessibility_name(TTRC("Move Up"));3025ae.move_up->set_button_icon(get_editor_theme_icon(SNAME("MoveUp")));3026ae.move_up->connect(SceneStringName(pressed), callable_mp(this, &EditorInspectorArray::_move_element).bind(element_position, element_position - 1));3027move_vbox->add_child(ae.move_up);3028}30293030ae.move_texture_rect = memnew(TextureRect);3031ae.move_texture_rect->set_stretch_mode(TextureRect::STRETCH_KEEP_CENTERED);3032ae.move_texture_rect->set_default_cursor_shape(Control::CURSOR_MOVE);30333034if (is_inside_tree()) {3035ae.move_texture_rect->set_texture(get_editor_theme_icon(SNAME("TripleBar")));3036}3037move_vbox->add_child(ae.move_texture_rect);30383039if (element_position < count - 1) {3040ae.move_down = memnew(Button);3041ae.move_down->set_accessibility_name(TTRC("Move Down"));3042ae.move_down->set_button_icon(get_editor_theme_icon(SNAME("MoveDown")));3043ae.move_down->connect(SceneStringName(pressed), callable_mp(this, &EditorInspectorArray::_move_element).bind(element_position, element_position + 2));3044move_vbox->add_child(ae.move_down);3045}3046}30473048if (numbered) {3049ae.number = memnew(Label);3050ae.number->add_theme_font_override(SceneStringName(font), numbers_font);3051ae.number->set_custom_minimum_size(Size2(numbers_min_w, 0));3052ae.number->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_RIGHT);3053ae.number->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);3054ae.number->set_text(itos(element_position));3055ae.hbox->add_child(ae.number);3056}30573058// Right vbox.3059ae.vbox = memnew(VBoxContainer);3060ae.vbox->set_h_size_flags(SIZE_EXPAND_FILL);3061ae.vbox->set_v_size_flags(SIZE_EXPAND_FILL);3062ae.hbox->add_child(ae.vbox);30633064if (!unresizable) {3065ae.erase = memnew(Button);3066ae.erase->set_accessibility_name(TTRC("Remove"));3067ae.erase->set_button_icon(get_editor_theme_icon(SNAME("Remove")));3068ae.erase->set_v_size_flags(SIZE_SHRINK_CENTER);3069ae.erase->connect(SceneStringName(pressed), callable_mp(this, &EditorInspectorArray::_remove_item).bind(element_position));3070ae.hbox->add_child(ae.erase);3071}3072}30733074// Hide/show the add button.3075add_button->set_visible(page == max_page && !unresizable);30763077// Add paginator if there's more than 1 page.3078if (max_page > 0) {3079EditorPaginator *paginator = memnew(EditorPaginator);3080paginator->update(page, max_page);3081paginator->connect("page_changed", callable_mp(this, &EditorInspectorArray::_paginator_page_changed));3082vbox->add_child(paginator);3083}3084}30853086void EditorInspectorArray::_remove_item(int p_index) {3087_move_element(p_index, -1);3088}30893090Variant EditorInspectorArray::get_drag_data_fw(const Point2 &p_point, Control *p_from) {3091if (!movable) {3092return Variant();3093}3094int index = p_from->get_meta("index");3095Dictionary dict;3096dict["type"] = "property_array_element";3097dict["property_array_prefix"] = array_element_prefix;3098dict["index"] = index;30993100return dict;3101}31023103void EditorInspectorArray::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {3104Dictionary dict = p_data;31053106int to_drop = dict["index"];3107int drop_position = (p_point == Vector2(Math::INF, Math::INF)) ? selected : _drop_position();3108if (drop_position < 0) {3109return;3110}3111_move_element(to_drop, begin_array_index + drop_position);3112}31133114bool EditorInspectorArray::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {3115if (!movable || read_only) {3116return false;3117}3118// First, update drawing.3119control_dropping->queue_redraw();31203121if (p_data.get_type() != Variant::DICTIONARY) {3122return false;3123}3124Dictionary dict = p_data;3125int drop_position = (p_point == Vector2(Math::INF, Math::INF)) ? selected : _drop_position();3126if (!dict.has("type") || dict["type"] != "property_array_element" || String(dict["property_array_prefix"]) != array_element_prefix || drop_position < 0) {3127return false;3128}31293130// Check in dropping at the given index does indeed move the item.3131int moved_array_index = (int)dict["index"];3132int drop_array_index = begin_array_index + drop_position;31333134return drop_array_index != moved_array_index && drop_array_index - 1 != moved_array_index;3135}31363137void ArrayPanelContainer::_accessibility_action_menu(const Variant &p_data) {3138EditorInspectorArray *el = Object::cast_to<EditorInspectorArray>(get_meta("element"));3139if (el) {3140int index = get_meta("index");3141el->show_menu(index, Vector2());3142}3143}31443145void ArrayPanelContainer::_notification(int p_what) {3146switch (p_what) {3147case NOTIFICATION_ACCESSIBILITY_UPDATE: {3148RID ae = get_accessibility_element();3149ERR_FAIL_COND(ae.is_null());31503151DisplayServer::get_singleton()->accessibility_update_set_role(ae, DisplayServer::AccessibilityRole::ROLE_BUTTON);31523153DisplayServer::get_singleton()->accessibility_update_set_name(ae, get_meta("text"));3154DisplayServer::get_singleton()->accessibility_update_set_value(ae, get_meta("text"));31553156DisplayServer::get_singleton()->accessibility_update_set_popup_type(ae, DisplayServer::AccessibilityPopupType::POPUP_MENU);3157DisplayServer::get_singleton()->accessibility_update_add_action(ae, DisplayServer::AccessibilityAction::ACTION_SHOW_CONTEXT_MENU, callable_mp(this, &ArrayPanelContainer::_accessibility_action_menu));3158} break;3159}3160}31613162ArrayPanelContainer::ArrayPanelContainer() {3163set_focus_mode(FOCUS_ACCESSIBILITY);3164}31653166void EditorInspectorArray::_notification(int p_what) {3167switch (p_what) {3168case NOTIFICATION_ACCESSIBILITY_UPDATE: {3169RID ae = get_accessibility_element();3170ERR_FAIL_COND(ae.is_null());31713172DisplayServer::get_singleton()->accessibility_update_set_name(ae, vformat(TTR("Array: %s"), get_label()));3173DisplayServer::get_singleton()->accessibility_update_set_value(ae, vformat(TTR("Array: %s"), get_label()));3174} break;31753176case NOTIFICATION_THEME_CHANGED: {3177Color color = get_theme_color(SNAME("dark_color_1"), EditorStringName(Editor));3178odd_style->set_bg_color(color.darkened(-0.08));3179even_style->set_bg_color(color.darkened(0.08));31803181for (ArrayElement &ae : array_elements) {3182if (ae.move_texture_rect) {3183ae.move_texture_rect->set_texture(get_editor_theme_icon(SNAME("TripleBar")));3184}3185if (ae.move_up) {3186ae.move_up->set_button_icon(get_editor_theme_icon(SNAME("MoveUp")));3187}3188if (ae.move_down) {3189ae.move_down->set_button_icon(get_editor_theme_icon(SNAME("MoveDown")));3190}3191Size2 min_size = get_theme_stylebox(SNAME("Focus"), EditorStringName(EditorStyles))->get_minimum_size();3192ae.margin->begin_bulk_theme_override();3193ae.margin->add_theme_constant_override("margin_left", min_size.x / 2);3194ae.margin->add_theme_constant_override("margin_top", min_size.y / 2);3195ae.margin->add_theme_constant_override("margin_right", min_size.x / 2);3196ae.margin->add_theme_constant_override("margin_bottom", min_size.y / 2);3197ae.margin->end_bulk_theme_override();31983199if (ae.erase) {3200ae.erase->set_button_icon(get_editor_theme_icon(SNAME("Remove")));3201}3202}3203} break;32043205case NOTIFICATION_DRAG_BEGIN: {3206Dictionary dict = get_viewport()->gui_get_drag_data();3207if (dict.has("type") && dict["type"] == "property_array_element" && String(dict["property_array_prefix"]) == array_element_prefix) {3208dropping = true;3209control_dropping->queue_redraw();3210}3211} break;32123213case NOTIFICATION_DRAG_END: {3214if (dropping) {3215dropping = false;3216control_dropping->queue_redraw();3217}3218} break;3219}3220}32213222void EditorInspectorArray::_bind_methods() {3223ADD_SIGNAL(MethodInfo("page_change_request"));3224}32253226void EditorInspectorArray::setup_with_move_element_function(Object *p_object, const String &p_label, const StringName &p_array_element_prefix, int p_page, const Color &p_bg_color, bool p_foldable, bool p_movable, bool p_is_const, bool p_numbered, int p_page_length, const String &p_add_item_text) {3227count_property = "";3228mode = MODE_USE_MOVE_ARRAY_ELEMENT_FUNCTION;3229array_element_prefix = p_array_element_prefix;3230page = p_page;3231movable = p_movable;3232is_const = p_is_const;3233page_length = p_page_length;3234numbered = p_numbered;32353236EditorInspectorSection::setup(String(p_array_element_prefix) + "_array", p_label, p_object, p_bg_color, p_foldable, 0);32373238_setup();3239}32403241void EditorInspectorArray::setup_with_count_property(Object *p_object, const String &p_label, const StringName &p_count_property, const StringName &p_array_element_prefix, int p_page, const Color &p_bg_color, bool p_foldable, bool p_movable, bool p_is_const, bool p_numbered, int p_page_length, const String &p_add_item_text, const String &p_swap_method) {3242count_property = p_count_property;3243mode = MODE_USE_COUNT_PROPERTY;3244array_element_prefix = p_array_element_prefix;3245page = p_page;3246movable = p_movable;3247is_const = p_is_const;3248page_length = p_page_length;3249numbered = p_numbered;3250swap_method = p_swap_method;32513252add_button->set_text(p_add_item_text);3253EditorInspectorSection::setup(String(count_property) + "_array", p_label, p_object, p_bg_color, p_foldable, 0);32543255_setup();3256}32573258VBoxContainer *EditorInspectorArray::get_vbox(int p_index) {3259if (p_index >= begin_array_index && p_index < end_array_index) {3260return array_elements[p_index - begin_array_index].vbox;3261} else if (p_index < 0) {3262return vbox;3263} else {3264return nullptr;3265}3266}32673268EditorInspectorArray::EditorInspectorArray(bool p_read_only) {3269read_only = p_read_only;32703271odd_style.instantiate();3272even_style.instantiate();32733274rmb_popup = memnew(PopupMenu);3275rmb_popup->set_accessibility_name(TTRC("Move"));3276rmb_popup->add_item(TTR("Move Up"), OPTION_MOVE_UP);3277rmb_popup->add_item(TTR("Move Down"), OPTION_MOVE_DOWN);3278rmb_popup->add_separator();3279rmb_popup->add_item(TTR("Insert New Before"), OPTION_NEW_BEFORE);3280rmb_popup->add_item(TTR("Insert New After"), OPTION_NEW_AFTER);3281rmb_popup->add_separator();3282rmb_popup->add_item(TTR("Remove"), OPTION_REMOVE);3283rmb_popup->add_separator();3284rmb_popup->add_item(TTR("Clear Array"), OPTION_CLEAR_ARRAY);3285rmb_popup->add_item(TTR("Resize Array..."), OPTION_RESIZE_ARRAY);3286rmb_popup->connect(SceneStringName(id_pressed), callable_mp(this, &EditorInspectorArray::_rmb_popup_id_pressed));3287add_child(rmb_popup);32883289elements_vbox = memnew(VBoxContainer);3290elements_vbox->add_theme_constant_override("separation", 0);3291vbox->add_child(elements_vbox);32923293add_button = memnew(EditorInspectorActionButton(TTRC("Add Element"), SNAME("Add")));3294add_button->connect(SceneStringName(pressed), callable_mp(this, &EditorInspectorArray::_add_button_pressed));3295add_button->set_disabled(read_only);3296vbox->add_child(add_button);32973298control_dropping = memnew(Control);3299control_dropping->connect(SceneStringName(draw), callable_mp(this, &EditorInspectorArray::_control_dropping_draw));3300control_dropping->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);3301add_child(control_dropping);33023303resize_dialog = memnew(AcceptDialog);3304resize_dialog->set_title(TTRC("Resize Array"));3305resize_dialog->add_cancel_button();3306resize_dialog->connect(SceneStringName(confirmed), callable_mp(this, &EditorInspectorArray::_resize_dialog_confirmed));3307add_child(resize_dialog);33083309VBoxContainer *resize_dialog_vbox = memnew(VBoxContainer);3310resize_dialog->add_child(resize_dialog_vbox);33113312new_size_spin_box = memnew(SpinBox);3313new_size_spin_box->set_accessibility_name(TTRC("New Size:"));3314new_size_spin_box->set_max(16384);3315new_size_spin_box->connect(SceneStringName(value_changed), callable_mp(this, &EditorInspectorArray::_new_size_spin_box_value_changed));3316new_size_spin_box->get_line_edit()->connect(SceneStringName(text_submitted), callable_mp(this, &EditorInspectorArray::_new_size_spin_box_text_submitted));3317new_size_spin_box->set_editable(!read_only);3318resize_dialog_vbox->add_margin_child(TTRC("New Size:"), new_size_spin_box);33193320vbox->connect(SceneStringName(visibility_changed), callable_mp(this, &EditorInspectorArray::_vbox_visibility_changed));3321}33223323////////////////////////////////////////////////3324////////////////////////////////////////////////33253326void EditorPaginator::_first_page_button_pressed() {3327emit_signal("page_changed", 0);3328}33293330void EditorPaginator::_prev_page_button_pressed() {3331emit_signal("page_changed", MAX(0, page - 1));3332}33333334void EditorPaginator::_page_line_edit_text_submitted(const String &p_text) {3335if (p_text.is_valid_int()) {3336int new_page = p_text.to_int() - 1;3337new_page = MIN(MAX(0, new_page), max_page);3338page_line_edit->set_text(Variant(new_page));3339emit_signal("page_changed", new_page);3340} else {3341page_line_edit->set_text(Variant(page));3342}3343}33443345void EditorPaginator::_next_page_button_pressed() {3346emit_signal("page_changed", MIN(max_page, page + 1));3347}33483349void EditorPaginator::_last_page_button_pressed() {3350emit_signal("page_changed", max_page);3351}33523353void EditorPaginator::update(int p_page, int p_max_page) {3354page = p_page;3355max_page = p_max_page;33563357// Update buttons.3358first_page_button->set_disabled(page == 0);3359prev_page_button->set_disabled(page == 0);3360next_page_button->set_disabled(page == max_page);3361last_page_button->set_disabled(page == max_page);33623363// Update page number and page count.3364page_line_edit->set_text(vformat("%d", page + 1));3365page_count_label->set_text(vformat("/ %d", max_page + 1));3366}33673368void EditorPaginator::_notification(int p_what) {3369switch (p_what) {3370case NOTIFICATION_THEME_CHANGED: {3371first_page_button->set_button_icon(get_editor_theme_icon(SNAME("PageFirst")));3372prev_page_button->set_button_icon(get_editor_theme_icon(SNAME("PagePrevious")));3373next_page_button->set_button_icon(get_editor_theme_icon(SNAME("PageNext")));3374last_page_button->set_button_icon(get_editor_theme_icon(SNAME("PageLast")));3375} break;3376}3377}33783379void EditorPaginator::_bind_methods() {3380ADD_SIGNAL(MethodInfo("page_changed", PropertyInfo(Variant::INT, "page")));3381}33823383EditorPaginator::EditorPaginator() {3384set_h_size_flags(SIZE_EXPAND_FILL);3385set_alignment(ALIGNMENT_CENTER);33863387first_page_button = memnew(Button);3388first_page_button->set_accessibility_name(TTRC("First Page"));3389first_page_button->set_flat(true);3390first_page_button->connect(SceneStringName(pressed), callable_mp(this, &EditorPaginator::_first_page_button_pressed));3391add_child(first_page_button);33923393prev_page_button = memnew(Button);3394prev_page_button->set_accessibility_name(TTRC("Previous Page"));3395prev_page_button->set_flat(true);3396prev_page_button->connect(SceneStringName(pressed), callable_mp(this, &EditorPaginator::_prev_page_button_pressed));3397add_child(prev_page_button);33983399page_line_edit = memnew(LineEdit);3400page_line_edit->set_accessibility_name(TTRC("Page Number"));3401page_line_edit->connect(SceneStringName(text_submitted), callable_mp(this, &EditorPaginator::_page_line_edit_text_submitted));3402page_line_edit->add_theme_constant_override("minimum_character_width", 2);3403add_child(page_line_edit);34043405page_count_label = memnew(Label);3406page_count_label->set_focus_mode(FOCUS_ACCESSIBILITY);3407add_child(page_count_label);34083409next_page_button = memnew(Button);3410prev_page_button->set_accessibility_name(TTRC("Next Page"));3411next_page_button->set_flat(true);3412next_page_button->connect(SceneStringName(pressed), callable_mp(this, &EditorPaginator::_next_page_button_pressed));3413add_child(next_page_button);34143415last_page_button = memnew(Button);3416last_page_button->set_accessibility_name(TTRC("Last Page"));3417last_page_button->set_flat(true);3418last_page_button->connect(SceneStringName(pressed), callable_mp(this, &EditorPaginator::_last_page_button_pressed));3419add_child(last_page_button);3420}34213422////////////////////////////////////////////////3423////////////////////////////////////////////////34243425Ref<EditorInspectorPlugin> EditorInspector::inspector_plugins[MAX_PLUGINS];3426int EditorInspector::inspector_plugin_count = 0;34273428EditorProperty *EditorInspector::instantiate_property_editor(Object *p_object, const Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide) {3429for (int i = inspector_plugin_count - 1; i >= 0; i--) {3430if (!inspector_plugins[i]->can_handle(p_object)) {3431continue;3432}34333434inspector_plugins[i]->parse_property(p_object, p_type, p_path, p_hint, p_hint_text, p_usage, p_wide);3435if (inspector_plugins[i]->added_editors.size()) {3436for (List<EditorInspectorPlugin::AddedEditor>::Element *E = inspector_plugins[i]->added_editors.front()->next(); E; E = E->next()) { //only keep first one3437memdelete(E->get().property_editor);3438}34393440EditorProperty *prop = Object::cast_to<EditorProperty>(inspector_plugins[i]->added_editors.front()->get().property_editor);3441if (prop) {3442inspector_plugins[i]->added_editors.clear();3443return prop;3444} else {3445memdelete(inspector_plugins[i]->added_editors.front()->get().property_editor);3446inspector_plugins[i]->added_editors.clear();3447}3448}3449}3450return nullptr;3451}34523453void EditorInspector::initialize_section_theme(EditorInspectorSection::ThemeCache &p_cache, Control *p_control) {3454EditorInspector *parent_inspector = _get_control_parent_inspector(p_control);3455if (parent_inspector && parent_inspector != p_control) {3456p_cache = parent_inspector->section_theme_cache;3457return;3458}34593460p_cache.horizontal_separation = p_control->get_theme_constant(SNAME("h_separation"), SNAME("EditorInspectorSection"));3461p_cache.vertical_separation = p_control->get_theme_constant(SNAME("v_separation"), SNAME("Tree"));3462p_cache.inspector_margin = p_control->get_theme_constant(SNAME("inspector_margin"), EditorStringName(Editor));3463p_cache.indent_size = p_control->get_theme_constant(SNAME("indent_size"), SNAME("EditorInspectorSection"));34643465p_cache.warning_color = p_control->get_theme_color(SNAME("warning_color"), EditorStringName(Editor));3466p_cache.prop_subsection = p_control->get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor));3467p_cache.font_color = p_control->get_theme_color(SceneStringName(font_color), EditorStringName(Editor));3468p_cache.font_disabled_color = p_control->get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor));3469p_cache.font_hover_color = p_control->get_theme_color(SNAME("font_hover_color"), EditorStringName(Editor));3470p_cache.font_pressed_color = p_control->get_theme_color(SNAME("font_pressed_color"), EditorStringName(Editor));3471p_cache.font_hover_pressed_color = p_control->get_theme_color(SNAME("font_hover_pressed_color"), EditorStringName(Editor));34723473p_cache.font = p_control->get_theme_font(SceneStringName(font), SNAME("Tree"));3474p_cache.font_size = p_control->get_theme_font_size(SceneStringName(font_size), SNAME("Tree"));3475p_cache.bold_font = p_control->get_theme_font(SNAME("bold"), EditorStringName(EditorFonts));3476p_cache.bold_font_size = p_control->get_theme_font_size(SNAME("bold_size"), EditorStringName(EditorFonts));3477p_cache.light_font = p_control->get_theme_font(SNAME("main"), EditorStringName(EditorFonts));3478p_cache.light_font_size = p_control->get_theme_font_size(SNAME("main_size"), EditorStringName(EditorFonts));34793480p_cache.arrow = p_control->get_theme_icon(SNAME("arrow"), SNAME("Tree"));3481p_cache.arrow_collapsed = p_control->get_theme_icon(SNAME("arrow_collapsed"), SNAME("Tree"));3482p_cache.arrow_collapsed_mirrored = p_control->get_theme_icon(SNAME("arrow_collapsed_mirrored"), SNAME("Tree"));3483p_cache.icon_gui_checked = p_control->get_editor_theme_icon(SNAME("GuiChecked"));3484p_cache.icon_gui_unchecked = p_control->get_editor_theme_icon(SNAME("GuiUnchecked"));3485p_cache.icon_gui_animation_key = p_control->get_editor_theme_icon(SNAME("Key"));34863487p_cache.indent_box = p_control->get_theme_stylebox(SNAME("indent_box"), SNAME("EditorInspectorSection"));3488p_cache.key_hover = p_control->get_theme_stylebox(SceneStringName(hover), "Button");3489}34903491void EditorInspector::initialize_category_theme(EditorInspectorCategory::ThemeCache &p_cache, Control *p_control) {3492EditorInspector *parent_inspector = _get_control_parent_inspector(p_control);3493if (parent_inspector && parent_inspector != p_control) {3494p_cache = parent_inspector->category_theme_cache;3495return;3496}34973498p_cache.horizontal_separation = p_control->get_theme_constant(SNAME("h_separation"), SNAME("Tree"));3499p_cache.vertical_separation = p_control->get_theme_constant(SNAME("v_separation"), SNAME("Tree"));3500p_cache.class_icon_size = p_control->get_theme_constant(SNAME("class_icon_size"), EditorStringName(Editor));35013502p_cache.font_color = p_control->get_theme_color(SceneStringName(font_color), SNAME("Tree"));35033504p_cache.bold_font = p_control->get_theme_font(SNAME("bold"), EditorStringName(EditorFonts));3505p_cache.bold_font_size = p_control->get_theme_font_size(SNAME("bold_size"), EditorStringName(EditorFonts));35063507p_cache.icon_favorites = p_control->get_editor_theme_icon(SNAME("Favorites"));3508p_cache.icon_unfavorite = p_control->get_editor_theme_icon(SNAME("Unfavorite"));3509p_cache.icon_help = p_control->get_editor_theme_icon(SNAME("Help"));35103511p_cache.background = p_control->get_theme_stylebox(SNAME("bg"), SNAME("EditorInspectorCategory"));3512}35133514void EditorInspector::add_inspector_plugin(const Ref<EditorInspectorPlugin> &p_plugin) {3515ERR_FAIL_COND(inspector_plugin_count == MAX_PLUGINS);35163517for (int i = 0; i < inspector_plugin_count; i++) {3518if (inspector_plugins[i] == p_plugin) {3519return; //already exists3520}3521}3522inspector_plugins[inspector_plugin_count++] = p_plugin;3523}35243525void EditorInspector::remove_inspector_plugin(const Ref<EditorInspectorPlugin> &p_plugin) {3526int idx = -1;3527for (int i = 0; i < inspector_plugin_count; i++) {3528if (inspector_plugins[i] == p_plugin) {3529idx = i;3530break;3531}3532}35333534ERR_FAIL_COND_MSG(idx == -1, "Trying to remove nonexistent inspector plugin.");3535for (int i = idx; i < inspector_plugin_count - 1; i++) {3536inspector_plugins[i] = inspector_plugins[i + 1];3537}3538inspector_plugins[inspector_plugin_count - 1] = Ref<EditorInspectorPlugin>();35393540inspector_plugin_count--;3541}35423543void EditorInspector::cleanup_plugins() {3544for (int i = 0; i < inspector_plugin_count; i++) {3545inspector_plugins[i].unref();3546}3547inspector_plugin_count = 0;3548}35493550bool EditorInspector::is_main_editor_inspector() const {3551return InspectorDock::get_singleton() && InspectorDock::get_inspector_singleton() == this;3552}35533554String EditorInspector::get_selected_path() const {3555return property_selected;3556}35573558void EditorInspector::_parse_added_editors(VBoxContainer *current_vbox, EditorInspectorSection *p_section, Ref<EditorInspectorPlugin> ped) {3559for (const EditorInspectorPlugin::AddedEditor &F : ped->added_editors) {3560EditorProperty *ep = Object::cast_to<EditorProperty>(F.property_editor);35613562if (ep && !F.properties.is_empty() && current_favorites.has(F.properties[0])) {3563ep->favorited = true;3564favorites_vbox->add_child(F.property_editor);3565} else {3566current_vbox->add_child(F.property_editor);3567}35683569if (ep) {3570ep->object = object;3571ep->connect("property_changed", callable_mp(this, &EditorInspector::_property_changed).bind(false));3572ep->connect("property_keyed", callable_mp(this, &EditorInspector::_property_keyed));3573ep->connect("property_deleted", callable_mp(this, &EditorInspector::_property_deleted), CONNECT_DEFERRED);3574ep->connect("property_keyed_with_value", callable_mp(this, &EditorInspector::_property_keyed_with_value));3575ep->connect("property_checked", callable_mp(this, &EditorInspector::_property_checked));3576ep->connect("property_favorited", callable_mp(this, &EditorInspector::_set_property_favorited), CONNECT_DEFERRED);3577ep->connect("property_pinned", callable_mp(this, &EditorInspector::_property_pinned));3578ep->connect("selected", callable_mp(this, &EditorInspector::_property_selected));3579ep->connect("multiple_properties_changed", callable_mp(this, &EditorInspector::_multiple_properties_changed));3580ep->connect("resource_selected", callable_mp(get_root_inspector(), &EditorInspector::_resource_selected), CONNECT_DEFERRED);3581ep->connect("object_id_selected", callable_mp(this, &EditorInspector::_object_id_selected), CONNECT_DEFERRED);35823583if (F.properties.size()) {3584if (F.properties.size() == 1) {3585//since it's one, associate:3586ep->property = F.properties[0];3587ep->property_path = property_prefix + F.properties[0];3588ep->property_usage = 0;3589}35903591if (!F.label.is_empty()) {3592ep->set_label(F.label);3593}35943595for (int i = 0; i < F.properties.size(); i++) {3596String prop = F.properties[i];35973598if (!editor_property_map.has(prop)) {3599editor_property_map[prop] = List<EditorProperty *>();3600}3601editor_property_map[prop].push_back(ep);3602}3603}36043605Node *section_search = p_section;3606while (section_search) {3607EditorInspectorSection *section = Object::cast_to<EditorInspectorSection>(section_search);3608if (section) {3609ep->connect("property_can_revert_changed", callable_mp(section, &EditorInspectorSection::property_can_revert_changed));3610}3611section_search = section_search->get_parent();3612if (Object::cast_to<EditorInspector>(section_search)) {3613// Skip sub-resource inspectors.3614break;3615}3616}36173618ep->set_read_only(read_only);3619ep->update_property();3620ep->_update_flags();3621ep->update_editor_property_status();3622ep->set_deletable(deletable_properties);3623ep->update_cache();3624}3625}3626ped->added_editors.clear();3627}36283629bool EditorInspector::_is_property_disabled_by_feature_profile(const StringName &p_property) {3630Ref<EditorFeatureProfile> profile = EditorFeatureProfileManager::get_singleton()->get_current_profile();3631if (profile.is_null()) {3632return false;3633}36343635StringName class_name = object->get_class();36363637while (class_name != StringName()) {3638if (profile->is_class_property_disabled(class_name, p_property)) {3639return true;3640}3641if (profile->is_class_disabled(class_name)) {3642//won't see properties of a disabled class3643return true;3644}3645class_name = ClassDB::get_parent_class(class_name);3646}36473648return false;3649}36503651void EditorInspector::update_tree() {3652if (!object) {3653return;3654}36553656bool root_inspector_was_following_focus = get_root_inspector()->is_following_focus();3657if (root_inspector_was_following_focus) {3658// Temporarily disable focus following on the root inspector to avoid jumping while the inspector is updating.3659get_root_inspector()->set_follow_focus(false);3660}36613662// Store currently selected and focused elements to restore after the update.3663// TODO: Can be useful to store more context for the focusable, such as the caret position in LineEdit.3664StringName current_selected = property_selected;3665int current_focusable = -1;36663667if (property_focusable != -1) {3668// Check that focusable is actually focusable.3669bool restore_focus = false;3670Control *focused = get_viewport() ? get_viewport()->gui_get_focus_owner() : nullptr;3671if (focused) {3672Node *parent = focused->get_parent();3673while (parent) {3674EditorInspector *inspector = Object::cast_to<EditorInspector>(parent);3675if (inspector) {3676restore_focus = inspector == this; // May be owned by another inspector.3677break; // Exit after the first inspector is found, since there may be nested ones.3678}3679parent = parent->get_parent();3680}3681}36823683if (restore_focus) {3684current_focusable = property_focusable;3685}3686}36873688// The call here is for the edited object that has not changed, but the tree needs to be updated (for example, the object's property list has been modified).3689// Since the edited object has not changed, there is no need to hide the plugin at this time.3690_clear(false);36913692List<Ref<EditorInspectorPlugin>> valid_plugins;36933694for (int i = inspector_plugin_count - 1; i >= 0; i--) { //start by last, so lastly added can override newly added3695if (!inspector_plugins[i]->can_handle(object)) {3696continue;3697}3698valid_plugins.push_back(inspector_plugins[i]);3699}37003701// Decide if properties should be drawn with the warning color (yellow),3702// or if the whole object should be considered read-only.3703bool draw_warning = false;3704bool all_read_only = false;3705if (is_inside_tree()) {3706if (object->has_method("_is_read_only")) {3707all_read_only = object->call("_is_read_only");3708}37093710Node *nod = Object::cast_to<Node>(object);3711Node *es = EditorNode::get_singleton()->get_edited_scene();3712if (nod && es != nod && nod->get_owner() != es) {3713// Draw in warning color edited nodes that are not in the currently edited scene,3714// as changes may be lost in the future.3715draw_warning = true;3716} else {3717if (!all_read_only) {3718Resource *res = Object::cast_to<Resource>(object);3719if (res) {3720all_read_only = EditorNode::get_singleton()->is_resource_read_only(res);3721}3722}3723}3724}37253726String filter = search_box ? search_box->get_text() : "";3727String group;3728String group_base;3729EditorInspectorSection *group_togglable_property = nullptr;3730String subgroup;3731String subgroup_base;3732EditorInspectorSection *subgroup_togglable_property = nullptr;3733int section_depth = 0;3734bool disable_favorite = false;3735VBoxContainer *category_vbox = nullptr;37363737List<PropertyInfo> plist;3738object->get_property_list(&plist, true);37393740HashMap<VBoxContainer *, HashMap<String, VBoxContainer *>> vbox_per_path;3741HashMap<String, EditorInspectorArray *> editor_inspector_array_per_prefix;3742HashMap<String, HashMap<String, LocalVector<EditorProperty *>>> favorites_to_add;3743HashMap<String, EditorInspectorSection *> togglable_editor_inspector_sections;37443745const Color sscolor = theme_cache.prop_subsection;3746bool sub_inspectors_enabled = EDITOR_GET("interface/inspector/open_resources_in_current_inspector");37473748if (!valid_plugins.is_empty()) {3749begin_vbox->show();37503751// Get the lists of editors to add the beginning.3752for (Ref<EditorInspectorPlugin> &ped : valid_plugins) {3753ped->parse_begin(object);3754_parse_added_editors(begin_vbox, nullptr, ped);3755}3756}37573758StringName doc_name;37593760// Get the lists of editors for properties.3761for (List<PropertyInfo>::Element *E_property = plist.front(); E_property; E_property = E_property->next()) {3762PropertyInfo &p = E_property->get();37633764if (p.usage & PROPERTY_USAGE_SUBGROUP) {3765// Setup a property sub-group.3766subgroup = p.name;3767subgroup_togglable_property = nullptr;37683769Vector<String> hint_parts = p.hint_string.split(",");3770subgroup_base = hint_parts[0];3771if (hint_parts.size() > 1) {3772section_depth = hint_parts[1].to_int();3773} else {3774section_depth = 0;3775}37763777continue;37783779} else if (p.usage & PROPERTY_USAGE_GROUP) {3780// Setup a property group.3781group = p.name;3782group_togglable_property = nullptr;37833784Vector<String> hint_parts = p.hint_string.split(",");3785group_base = hint_parts[0];3786if (hint_parts.size() > 1) {3787section_depth = hint_parts[1].to_int();3788} else {3789section_depth = 0;3790}37913792subgroup = "";3793subgroup_base = "";3794subgroup_togglable_property = nullptr;37953796continue;37973798} else if (p.usage & PROPERTY_USAGE_CATEGORY) {3799// Setup a property category.3800group = "";3801group_base = "";3802group_togglable_property = nullptr;3803subgroup = "";3804subgroup_base = "";3805subgroup_togglable_property = nullptr;3806section_depth = 0;3807disable_favorite = false;38083809vbox_per_path.clear();3810editor_inspector_array_per_prefix.clear();38113812// `hint_script` should contain a native class name or a script path.3813// Otherwise the category was probably added via `@export_category` or `_get_property_list()`.3814const bool is_custom_category = p.hint_string.is_empty();38153816// Iterate over remaining properties. If no properties in category, skip the category.3817List<PropertyInfo>::Element *N = E_property->next();3818bool valid = true;3819while (N) {3820if (!N->get().name.begins_with("metadata/_") && N->get().usage & PROPERTY_USAGE_EDITOR &&3821(!filter.is_empty() || !restrict_to_basic || (N->get().usage & PROPERTY_USAGE_EDITOR_BASIC_SETTING))) {3822break;3823}3824// Treat custom categories as second-level ones. Do not skip a normal category if it is followed by a custom one.3825// Skip in the other 3 cases (normal -> normal, custom -> custom, custom -> normal).3826if ((N->get().usage & PROPERTY_USAGE_CATEGORY) && (is_custom_category || !N->get().hint_string.is_empty())) {3827valid = false;3828break;3829}3830N = N->next();3831}3832if (!valid) {3833continue; // Empty, ignore it.3834}38353836String category_tooltip;38373838// Do not add an icon, do not change the current class (`doc_name`) for custom categories.3839if (is_custom_category) {3840category_tooltip = p.name;3841} else {3842doc_name = p.name;38433844// Use category's owner script to update some of its information.3845if (!EditorNode::get_editor_data().is_type_recognized(p.name) && ResourceLoader::exists(p.hint_string, "Script")) {3846Ref<Script> scr = ResourceLoader::load(p.hint_string, "Script");3847if (scr.is_valid()) {3848doc_name = scr->get_doc_class_name();38493850// Property favorites aren't compatible with built-in scripts.3851if (scr->is_built_in()) {3852disable_favorite = true;3853}3854}3855}38563857if (use_doc_hints) {3858// `|` separators used in `EditorHelpBit`.3859category_tooltip = "class|" + doc_name + "|";3860}3861}38623863if ((is_custom_category && !show_custom_categories) || (!is_custom_category && !show_standard_categories)) {3864continue;3865}38663867// Hide the "MultiNodeEdit" category for MultiNodeEdit.3868if (Object::cast_to<MultiNodeEdit>(object) && p.name == "MultiNodeEdit") {3869continue;3870}38713872// Create an EditorInspectorCategory and add it to the inspector.3873EditorInspectorCategory *category = memnew(EditorInspectorCategory);3874category->set_property_info(p);3875main_vbox->add_child(category);3876category_vbox = nullptr; // Reset.38773878// Set the category info.3879category->set_tooltip_text(category_tooltip);3880if (!is_custom_category) {3881category->set_doc_class_name(doc_name);3882}38833884// Add editors at the start of a category.3885for (Ref<EditorInspectorPlugin> &ped : valid_plugins) {3886ped->parse_category(object, p.name);3887_parse_added_editors(main_vbox, nullptr, ped);3888}38893890continue;38913892} else if (p.name.begins_with("metadata/_") || !(p.usage & PROPERTY_USAGE_EDITOR) || _is_property_disabled_by_feature_profile(p.name) ||3893(filter.is_empty() && restrict_to_basic && !(p.usage & PROPERTY_USAGE_EDITOR_BASIC_SETTING))) {3894// Ignore properties that are not supposed to be in the inspector.3895continue;3896}38973898if (p.name == "script") {3899// Script should go into its own category.3900category_vbox = nullptr;3901}39023903if (p.usage & PROPERTY_USAGE_HIGH_END_GFX && RS::get_singleton()->is_low_end()) {3904// Do not show this property in low end gfx.3905continue;3906}39073908if (p.name == "script" && (hide_script || bool(object->call("_hide_script_from_inspector")))) {3909// Hide script variables from inspector if required.3910continue;3911}39123913if (p.name.begins_with("metadata/") && bool(object->call(SNAME("_hide_metadata_from_inspector")))) {3914// Hide metadata from inspector if required.3915continue;3916}39173918// Get the path for property.3919String path = p.name;39203921// First check if we have an array that fits the prefix.3922String array_prefix = "";3923int array_index = -1;3924for (KeyValue<String, EditorInspectorArray *> &E : editor_inspector_array_per_prefix) {3925if (p.name.begins_with(E.key) && E.key.length() > array_prefix.length()) {3926array_prefix = E.key;3927}3928}39293930if (!array_prefix.is_empty()) {3931// If we have an array element, find the according index in array.3932String str = p.name.trim_prefix(array_prefix);3933int to_char_index = 0;3934while (to_char_index < str.length()) {3935if (!is_digit(str[to_char_index])) {3936break;3937}3938to_char_index++;3939}3940if (to_char_index > 0) {3941array_index = str.left(to_char_index).to_int();3942} else {3943array_prefix = "";3944}3945}39463947// Don't allow to favorite array items.3948if (!disable_favorite) {3949disable_favorite = !array_prefix.is_empty();3950}39513952if (!array_prefix.is_empty()) {3953path = path.trim_prefix(array_prefix);3954int char_index = path.find_char('/');3955if (char_index >= 0) {3956path = path.right(-char_index - 1);3957} else {3958path = vformat(TTR("Element %s"), array_index);3959}3960} else {3961// Check if we exit or not a subgroup. If there is a prefix, remove it from the property label string.3962if (!subgroup.is_empty() && !subgroup_base.is_empty()) {3963if (path.begins_with(subgroup_base)) {3964path = path.trim_prefix(subgroup_base);3965} else if (subgroup_base.begins_with(path)) {3966// Keep it, this is used pretty often.3967} else {3968subgroup = ""; // The prefix changed, we are no longer in the subgroup.3969subgroup_togglable_property = nullptr;3970}3971}39723973// Check if we exit or not a group. If there is a prefix, remove it from the property label string.3974if (!group.is_empty() && !group_base.is_empty() && subgroup.is_empty()) {3975if (path.begins_with(group_base)) {3976path = path.trim_prefix(group_base);3977} else if (group_base.begins_with(path)) {3978// Keep it, this is used pretty often.3979} else {3980group = ""; // The prefix changed, we are no longer in the group.3981group_togglable_property = nullptr;3982subgroup = "";3983subgroup_togglable_property = nullptr;3984}3985}39863987// Add the group and subgroup to the path.3988if (!subgroup.is_empty()) {3989path = subgroup + "/" + path;3990}3991if (!group.is_empty()) {3992path = group + "/" + path;3993}3994}39953996// Get the property label's string.3997String name_override = (path.contains_char('/')) ? path.substr(path.rfind_char('/') + 1) : path;3998String feature_tag;3999{4000const int dot = name_override.find_char('.');4001if (dot != -1) {4002feature_tag = name_override.substr(dot);4003name_override = name_override.substr(0, dot);4004}4005}4006name_override = name_override.uri_decode();40074008// Don't localize script variables.4009EditorPropertyNameProcessor::Style name_style = property_name_style;4010if ((p.usage & PROPERTY_USAGE_SCRIPT_VARIABLE) && name_style == EditorPropertyNameProcessor::STYLE_LOCALIZED) {4011name_style = EditorPropertyNameProcessor::STYLE_CAPITALIZED;4012}4013const String property_label_string = EditorPropertyNameProcessor::get_singleton()->process_name(name_override, name_style, p.name, doc_name) + feature_tag;40144015// Remove the property from the path.4016int idx = path.rfind_char('/');4017if (idx > -1) {4018path = path.left(idx);4019} else {4020path = "";4021}40224023// Ignore properties that do not fit the filter.4024bool sub_inspector_use_filter = false;4025if (use_filter && !filter.is_empty()) {4026const String property_path = property_prefix + (path.is_empty() ? "" : path + "/") + name_override;4027if (!_property_path_matches(property_path, filter, property_name_style)) {4028if (!sub_inspectors_enabled || p.hint != PROPERTY_HINT_RESOURCE_TYPE) {4029continue;4030}40314032Ref<Resource> res = object->get(p.name);4033if (res.is_null()) {4034continue;4035}40364037// Check if the sub-resource has any properties that match the filter.4038if (!_resource_properties_matches(res, filter)) {4039continue;4040}40414042sub_inspector_use_filter = true;4043}4044}40454046// Recreate the category vbox if it was reset.4047if (category_vbox == nullptr) {4048category_vbox = memnew(VBoxContainer);4049category_vbox->add_theme_constant_override(SNAME("separation"), theme_cache.vertical_separation);4050category_vbox->hide();4051main_vbox->add_child(category_vbox);4052}40534054// Find the correct section/vbox to add the property editor to.4055VBoxContainer *root_vbox = array_prefix.is_empty() ? main_vbox : editor_inspector_array_per_prefix[array_prefix]->get_vbox(array_index);4056if (!root_vbox) {4057continue;4058}40594060if (!vbox_per_path.has(root_vbox)) {4061vbox_per_path[root_vbox] = HashMap<String, VBoxContainer *>();4062vbox_per_path[root_vbox][""] = root_vbox;4063}40644065VBoxContainer *current_vbox = root_vbox;4066String acc_path = "";4067int level = 1;40684069Vector<String> components = path.split("/");4070for (int i = 0; i < components.size(); i++) {4071const String &component = components[i];4072acc_path += (i > 0) ? "/" + component : component;40734074if (!vbox_per_path[root_vbox].has(acc_path)) {4075// If the section does not exists, create it.4076EditorInspectorSection *section = memnew(EditorInspectorSection);4077get_root_inspector()->get_v_scroll_bar()->connect(SceneStringName(value_changed), callable_mp(section, &EditorInspectorSection::reset_timer).unbind(1));4078current_vbox->add_child(section);4079sections.push_back(section);40804081String label;4082String tooltip;40834084// Don't localize groups for script variables.4085EditorPropertyNameProcessor::Style section_name_style = property_name_style;4086if ((p.usage & PROPERTY_USAGE_SCRIPT_VARIABLE) && section_name_style == EditorPropertyNameProcessor::STYLE_LOCALIZED) {4087section_name_style = EditorPropertyNameProcessor::STYLE_CAPITALIZED;4088}40894090// Only process group label if this is not the group or subgroup.4091if ((i == 0 && component == group) || (i == 1 && component == subgroup)) {4092if (section_name_style == EditorPropertyNameProcessor::STYLE_LOCALIZED) {4093label = EditorPropertyNameProcessor::get_singleton()->translate_group_name(component);4094tooltip = component;4095} else {4096label = component;4097tooltip = EditorPropertyNameProcessor::get_singleton()->translate_group_name(component);4098}4099} else {4100label = EditorPropertyNameProcessor::get_singleton()->process_name(component, section_name_style, p.name, doc_name);4101tooltip = EditorPropertyNameProcessor::get_singleton()->process_name(component, EditorPropertyNameProcessor::get_tooltip_style(section_name_style), p.name, doc_name);4102}41034104Color c = sscolor;4105c.a /= level;4106section->setup(acc_path, label, object, c, use_folding, section_depth, level);4107section->set_tooltip_text(tooltip);41084109section->connect("section_toggled_by_user", callable_mp(this, &EditorInspector::_section_toggled_by_user));4110section->connect("property_keyed", callable_mp(this, &EditorInspector::_property_keyed));41114112// Add editors at the start of a group.4113for (Ref<EditorInspectorPlugin> &ped : valid_plugins) {4114ped->parse_group(object, path);4115_parse_added_editors(section->get_vbox(), section, ped);4116}41174118vbox_per_path[root_vbox][acc_path] = section->get_vbox();4119}41204121current_vbox = vbox_per_path[root_vbox][acc_path];4122level = (MIN(level + 1, 4));4123}41244125// If we did not find a section to add the property to, add it to the category vbox instead (the category vbox handles margins correctly).4126if (current_vbox == main_vbox) {4127category_vbox->show();4128current_vbox = category_vbox;4129}41304131// Check if the property is an array counter, if so create a dedicated array editor for the array.4132if (p.usage & PROPERTY_USAGE_ARRAY) {4133EditorInspectorArray *editor_inspector_array = nullptr;4134StringName array_element_prefix;4135Color c = sscolor;4136c.a /= level;41374138Vector<String> class_name_components = String(p.class_name).split(",");41394140int page_size = 5;4141bool movable = true;4142bool is_const = false;4143bool numbered = false;4144bool foldable = use_folding;4145String add_button_text = TTRC("Add Element");4146String swap_method;4147for (int i = (p.type == Variant::NIL ? 1 : 2); i < class_name_components.size(); i++) {4148if (class_name_components[i].begins_with("page_size") && class_name_components[i].get_slice_count("=") == 2) {4149page_size = class_name_components[i].get_slicec('=', 1).to_int();4150} else if (class_name_components[i].begins_with("add_button_text") && class_name_components[i].get_slice_count("=") == 2) {4151add_button_text = class_name_components[i].get_slicec('=', 1).strip_edges();4152} else if (class_name_components[i] == "static") {4153movable = false;4154} else if (class_name_components[i] == "const") {4155is_const = true;4156} else if (class_name_components[i] == "numbered") {4157numbered = true;4158} else if (class_name_components[i] == "unfoldable") {4159foldable = false;4160} else if (class_name_components[i].begins_with("swap_method") && class_name_components[i].get_slice_count("=") == 2) {4161swap_method = class_name_components[i].get_slicec('=', 1).strip_edges();4162}4163}41644165if (p.type == Variant::NIL) {4166// Setup the array to use a method to create/move/delete elements.4167array_element_prefix = class_name_components[0];4168editor_inspector_array = memnew(EditorInspectorArray(all_read_only));41694170String array_label = path.contains_char('/') ? path.substr(path.rfind_char('/') + 1) : path;4171array_label = EditorPropertyNameProcessor::get_singleton()->process_name(property_label_string, property_name_style, p.name, doc_name);4172int page = per_array_page.has(array_element_prefix) ? per_array_page[array_element_prefix] : 0;4173editor_inspector_array->setup_with_move_element_function(object, array_label, array_element_prefix, page, c, use_folding);4174editor_inspector_array->connect("page_change_request", callable_mp(this, &EditorInspector::_page_change_request).bind(array_element_prefix));4175} else if (p.type == Variant::INT) {4176// Setup the array to use the count property and built-in functions to create/move/delete elements.4177if (class_name_components.size() >= 2) {4178array_element_prefix = class_name_components[1];4179editor_inspector_array = memnew(EditorInspectorArray(all_read_only));4180int page = per_array_page.has(array_element_prefix) ? per_array_page[array_element_prefix] : 0;41814182editor_inspector_array->setup_with_count_property(object, class_name_components[0], p.name, array_element_prefix, page, c, foldable, movable, is_const, numbered, page_size, add_button_text, swap_method);4183editor_inspector_array->connect("page_change_request", callable_mp(this, &EditorInspector::_page_change_request).bind(array_element_prefix));4184}4185}41864187if (editor_inspector_array) {4188current_vbox->add_child(editor_inspector_array);4189editor_inspector_array_per_prefix[array_element_prefix] = editor_inspector_array;4190}41914192continue;4193}41944195// Checkable and checked properties.4196bool checkable = false;4197bool checked = false;4198if (p.usage & PROPERTY_USAGE_CHECKABLE) {4199checkable = true;4200checked = p.usage & PROPERTY_USAGE_CHECKED;4201}42024203bool property_read_only = (p.usage & PROPERTY_USAGE_READ_ONLY) || read_only;42044205// Mark properties that would require an editor restart (mostly when editing editor settings).4206if (p.usage & PROPERTY_USAGE_RESTART_IF_CHANGED) {4207restart_request_props.insert(p.name);4208}42094210String doc_path;4211String theme_item_name;4212String doc_tooltip_text;4213StringName classname = doc_name;42144215// Build the doc hint, to use as tooltip.4216if (use_doc_hints) {4217if (!object_class.is_empty()) {4218classname = object_class;4219} else if (Object::cast_to<MultiNodeEdit>(object)) {4220classname = Object::cast_to<MultiNodeEdit>(object)->get_edited_class_name();4221} else if (classname == "") {4222classname = object->get_class_name();4223Resource *res = Object::cast_to<Resource>(object);4224if (res && !res->get_script().is_null()) {4225// Grab the script of this resource to get the evaluated script class.4226Ref<Script> scr = res->get_script();4227if (scr.is_valid()) {4228Vector<DocData::ClassDoc> docs = scr->get_documentation();4229if (!docs.is_empty()) {4230// The documentation of a GDScript's main class is at the end of the array.4231// Hacky because this isn't necessarily always guaranteed.4232classname = docs[docs.size() - 1].name;4233}4234}4235}4236}42374238StringName propname = property_prefix + p.name;4239bool found = false;42404241// Small hack for theme_overrides. They are listed under Control, but come from another class.4242if (classname == "Control" && p.name.begins_with("theme_override_")) {4243classname = get_edited_object()->get_class();4244}42454246// Search for the doc path in the cache.4247HashMap<StringName, HashMap<StringName, DocCacheInfo>>::Iterator E = doc_cache.find(classname);4248if (E) {4249HashMap<StringName, DocCacheInfo>::Iterator F = E->value.find(propname);4250if (F) {4251found = true;4252doc_path = F->value.doc_path;4253theme_item_name = F->value.theme_item_name;4254}4255}42564257if (!found) {4258DocTools *dd = EditorHelp::get_doc_data();4259// Do not cache the doc path information of scripts.4260bool is_native_class = ClassDB::class_exists(classname);42614262HashMap<String, DocData::ClassDoc>::ConstIterator F = dd->class_list.find(classname);4263while (F) {4264Vector<String> slices = propname.operator String().split("/");4265// Check if it's a theme item first.4266if (slices.size() == 2 && slices[0].begins_with("theme_override_")) {4267for (int i = 0; i < F->value.theme_properties.size(); i++) {4268String doc_path_current = "class_theme_item:" + F->value.name + ":" + F->value.theme_properties[i].name;4269if (F->value.theme_properties[i].name == slices[1]) {4270doc_path = doc_path_current;4271theme_item_name = F->value.theme_properties[i].name;4272}4273}4274} else {4275for (int i = 0; i < F->value.properties.size(); i++) {4276String doc_path_current = "class_property:" + F->value.name + ":" + F->value.properties[i].name;4277if (F->value.properties[i].name == propname.operator String()) {4278doc_path = doc_path_current;4279}4280}4281}42824283if (is_native_class) {4284DocCacheInfo cache_info;4285cache_info.doc_path = doc_path;4286cache_info.theme_item_name = theme_item_name;4287doc_cache[classname][propname] = cache_info;4288}42894290if (!doc_path.is_empty() || F->value.inherits.is_empty()) {4291break;4292}4293// Couldn't find the doc path in the class itself, try its super class.4294F = dd->class_list.find(F->value.inherits);4295}4296}42974298// `|` separators used in `EditorHelpBit`.4299if (theme_item_name.is_empty()) {4300if (p.name.contains("shader_parameter/")) {4301ShaderMaterial *shader_material = Object::cast_to<ShaderMaterial>(object);4302if (shader_material) {4303doc_tooltip_text = "property|" + shader_material->get_shader()->get_path() + "|" + property_prefix + p.name;4304}4305} else if (p.usage & PROPERTY_USAGE_INTERNAL) {4306doc_tooltip_text = "internal_property|" + classname + "|" + property_prefix + p.name;4307} else {4308doc_tooltip_text = "property|" + classname + "|" + property_prefix + p.name;4309}4310} else {4311doc_tooltip_text = "theme_item|" + classname + "|" + theme_item_name;4312}4313}43144315// Only used for boolean types. Makes the section header a checkable group and adds tooltips.4316if (p.hint == PROPERTY_HINT_GROUP_ENABLE) {4317if (p.type == Variant::BOOL && (p.name.begins_with(group_base) || p.name.begins_with(subgroup_base))) {4318EditorInspectorSection *last_created_section = Object::cast_to<EditorInspectorSection>(current_vbox->get_parent());4319if (last_created_section) {4320bool valid = false;4321Variant value_checked = object->get(p.name, &valid);43224323if (valid) {4324last_created_section->set_checkable(p.name, p.hint_string == "checkbox_only", value_checked.operator bool());4325last_created_section->set_keying(keying);43264327if (p.name.begins_with(group_base)) {4328group_togglable_property = last_created_section;4329} else {4330subgroup_togglable_property = last_created_section;4331}43324333if (use_doc_hints) {4334last_created_section->set_tooltip_text(doc_tooltip_text);4335}4336continue;4337}4338}4339} else {4340ERR_PRINT("PROPERTY_HINT_GROUP_ENABLE can only be used on boolean types and must have the same prefix as the group.");4341}4342}43434344Vector<EditorInspectorPlugin::AddedEditor> editors;4345Vector<EditorInspectorPlugin::AddedEditor> late_editors;43464347// Search for the inspector plugin that will handle the properties. Then add the correct property editor to it.4348for (Ref<EditorInspectorPlugin> &ped : valid_plugins) {4349bool exclusive = ped->parse_property(object, p.type, p.name, p.hint, p.hint_string, p.usage, wide_editors);43504351for (const EditorInspectorPlugin::AddedEditor &F : ped->added_editors) {4352if (F.add_to_end) {4353late_editors.push_back(F);4354} else {4355editors.push_back(F);4356}4357}43584359ped->added_editors.clear();43604361if (exclusive) {4362break;4363}4364}43654366editors.append_array(late_editors);43674368const Node *node = Object::cast_to<Node>(object);43694370Vector<SceneState::PackState> sstack;4371if (node != nullptr) {4372const Node *es = EditorNode::get_singleton()->get_edited_scene();4373sstack = PropertyUtils::get_node_states_stack(node, es);4374}43754376for (int i = 0; i < editors.size(); i++) {4377EditorProperty *ep = Object::cast_to<EditorProperty>(editors[i].property_editor);4378const Vector<String> &properties = editors[i].properties;43794380if (ep) {4381// Set all this before the control gets the ENTER_TREE notification.4382ep->object = object;43834384if (properties.size()) {4385if (properties.size() == 1) {4386// Since it's one, associate:4387ep->property = properties[0];4388ep->property_path = property_prefix + properties[0];4389ep->property_usage = p.usage;4390// And set label?4391}4392if (!editors[i].label.is_empty()) {4393ep->set_label(editors[i].label);4394} else {4395// Use the existing one.4396ep->set_label(property_label_string);4397}43984399for (int j = 0; j < properties.size(); j++) {4400String prop = properties[j];44014402if (!editor_property_map.has(prop)) {4403editor_property_map[prop] = List<EditorProperty *>();4404}4405editor_property_map[prop].push_back(ep);4406}4407}44084409if (sub_inspector_use_filter) {4410EditorPropertyResource *epr = Object::cast_to<EditorPropertyResource>(ep);4411if (epr) {4412epr->set_use_filter(true);4413}4414}44154416if (p.name.begins_with("metadata/")) {4417Variant _default = Variant();4418if (node != nullptr) {4419_default = PropertyUtils::get_property_default_value(node, p.name, nullptr, &sstack, false, nullptr, nullptr);4420}4421ep->set_deletable(_default == Variant());4422} else {4423ep->set_deletable(deletable_properties);4424}44254426ep->set_draw_warning(draw_warning);4427ep->set_use_folding(use_folding);4428ep->set_favoritable(can_favorite && !disable_favorite && !ep->is_deletable());4429ep->set_checkable(checkable);4430ep->set_checked(checked);4431ep->set_keying(keying);4432ep->set_read_only(property_read_only || all_read_only);4433}44344435if (ep && ep->is_favoritable() && current_favorites.has(p.name)) {4436ep->favorited = true;4437favorites_to_add[group][subgroup].push_back(ep);44384439if (group_togglable_property) {4440togglable_editor_inspector_sections[group] = group_togglable_property;4441}4442if (subgroup_togglable_property) {4443togglable_editor_inspector_sections[group + "/" + subgroup] = subgroup_togglable_property;4444}4445} else {4446current_vbox->add_child(editors[i].property_editor);44474448if (ep) {4449Node *section_search = current_vbox->get_parent();4450while (section_search) {4451EditorInspectorSection *section = Object::cast_to<EditorInspectorSection>(section_search);4452if (section) {4453ep->connect("property_can_revert_changed", callable_mp(section, &EditorInspectorSection::property_can_revert_changed));4454}4455section_search = section_search->get_parent();4456if (Object::cast_to<EditorInspector>(section_search)) {4457// Skip sub-resource inspectors.4458break;4459}4460}4461}4462}44634464if (ep) {4465// Eventually, set other properties/signals after the property editor got added to the tree.4466bool update_all = (p.usage & PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED);4467ep->connect("property_changed", callable_mp(this, &EditorInspector::_property_changed).bind(update_all));4468ep->connect("property_keyed", callable_mp(this, &EditorInspector::_property_keyed));4469ep->connect("property_deleted", callable_mp(this, &EditorInspector::_property_deleted), CONNECT_DEFERRED);4470ep->connect("property_keyed_with_value", callable_mp(this, &EditorInspector::_property_keyed_with_value));4471ep->connect("property_favorited", callable_mp(this, &EditorInspector::_set_property_favorited), CONNECT_DEFERRED);4472ep->connect("property_checked", callable_mp(this, &EditorInspector::_property_checked));4473ep->connect("property_pinned", callable_mp(this, &EditorInspector::_property_pinned));4474ep->connect("selected", callable_mp(this, &EditorInspector::_property_selected));4475ep->connect("multiple_properties_changed", callable_mp(this, &EditorInspector::_multiple_properties_changed));4476ep->connect("resource_selected", callable_mp(get_root_inspector(), &EditorInspector::_resource_selected), CONNECT_DEFERRED);4477ep->connect("object_id_selected", callable_mp(this, &EditorInspector::_object_id_selected), CONNECT_DEFERRED);44784479ep->set_tooltip_text(doc_tooltip_text);4480ep->has_doc_tooltip = use_doc_hints;4481ep->set_doc_path(doc_path);4482ep->set_internal(p.usage & PROPERTY_USAGE_INTERNAL);44834484// If this property is favorited, it won't be in the tree yet. So don't do this setup right now.4485if (ep->is_inside_tree()) {4486ep->update_property();4487ep->_update_flags();4488ep->update_editor_property_status();4489ep->update_cache();44904491if (current_selected && ep->property == current_selected) {4492ep->select(current_focusable);4493}4494}4495}4496}4497}44984499if (!current_favorites.is_empty()) {4500favorites_section->show();45014502// Organize the favorited properties in their sections, to keep context and differentiate from others with the same name.4503bool is_localized = property_name_style == EditorPropertyNameProcessor::STYLE_LOCALIZED;4504for (const KeyValue<String, HashMap<String, LocalVector<EditorProperty *>>> &KV : favorites_to_add) {4505String section_name = KV.key;4506String label;4507String tooltip;4508VBoxContainer *parent_vbox = favorites_vbox;4509if (!section_name.is_empty()) {4510if (is_localized) {4511label = EditorPropertyNameProcessor::get_singleton()->translate_group_name(section_name);4512tooltip = section_name;4513} else {4514label = section_name;4515tooltip = EditorPropertyNameProcessor::get_singleton()->translate_group_name(section_name);4516}45174518EditorInspectorSection *section = memnew(EditorInspectorSection);4519get_root_inspector()->get_v_scroll_bar()->connect(SceneStringName(value_changed), callable_mp(section, &EditorInspectorSection::reset_timer).unbind(1));4520favorites_groups_vbox->add_child(section);4521parent_vbox = section->get_vbox();4522section->setup("", section_name, object, sscolor, false);4523section->set_tooltip_text(tooltip);45244525if (togglable_editor_inspector_sections.has(section_name)) {4526EditorInspectorSection *corresponding_section = togglable_editor_inspector_sections.get(section_name);45274528bool valid = false;4529Variant value_checked = object->get(corresponding_section->related_enable_property, &valid);4530if (valid) {4531section->section = corresponding_section->section;4532section->set_checkable(corresponding_section->related_enable_property, corresponding_section->checkbox_only, value_checked.operator bool());4533section->set_keying(keying);4534if (use_doc_hints) {4535section->set_tooltip_text(corresponding_section->get_tooltip_text());4536}45374538section->connect("section_toggled_by_user", callable_mp(this, &EditorInspector::_section_toggled_by_user));4539section->connect("property_keyed", callable_mp(this, &EditorInspector::_property_keyed));4540sections.push_back(section);4541}4542}4543}45444545for (const KeyValue<String, LocalVector<EditorProperty *>> &KV2 : KV.value) {4546section_name = KV2.key;4547VBoxContainer *vbox = parent_vbox;4548if (!section_name.is_empty()) {4549if (is_localized) {4550label = EditorPropertyNameProcessor::get_singleton()->translate_group_name(section_name);4551tooltip = section_name;4552} else {4553label = section_name;4554tooltip = EditorPropertyNameProcessor::get_singleton()->translate_group_name(section_name);4555}45564557EditorInspectorSection *section = memnew(EditorInspectorSection);4558get_root_inspector()->get_v_scroll_bar()->connect(SceneStringName(value_changed), callable_mp(section, &EditorInspectorSection::reset_timer).unbind(1));4559vbox->add_child(section);4560vbox = section->get_vbox();4561section->setup("", section_name, object, sscolor, false);4562section->set_tooltip_text(tooltip);45634564if (togglable_editor_inspector_sections.has(KV.key + "/" + section_name)) {4565EditorInspectorSection *corresponding_section = togglable_editor_inspector_sections.get(KV.key + "/" + section_name);45664567bool valid = false;4568Variant value_checked = object->get(corresponding_section->related_enable_property, &valid);4569if (valid) {4570section->section = corresponding_section->section;4571section->set_checkable(corresponding_section->related_enable_property, corresponding_section->checkbox_only, value_checked.operator bool());4572section->set_keying(keying);4573if (use_doc_hints) {4574section->set_tooltip_text(corresponding_section->get_tooltip_text());4575}45764577section->connect("section_toggled_by_user", callable_mp(this, &EditorInspector::_section_toggled_by_user));4578section->connect("property_keyed", callable_mp(this, &EditorInspector::_property_keyed));4579sections.push_back(section);4580}4581}4582}45834584for (EditorProperty *ep : KV2.value) {4585vbox->add_child(ep);45864587Node *section_search = vbox->get_parent();4588while (section_search) {4589EditorInspectorSection *section = Object::cast_to<EditorInspectorSection>(section_search);4590if (section) {4591ep->connect("property_can_revert_changed", callable_mp(section, &EditorInspectorSection::property_can_revert_changed));4592}4593section_search = section_search->get_parent();4594if (Object::cast_to<EditorInspector>(section_search)) {4595// Skip sub-resource inspectors.4596break;4597}4598}45994600// Now that it's inside the tree, do the setup.4601ep->update_property();4602ep->_update_flags();4603ep->update_editor_property_status();4604ep->update_cache();46054606if (current_selected && ep->property == current_selected) {4607ep->select(current_focusable);4608}4609}4610}4611}46124613// Show a separator if there's no category to clearly divide the properties.4614favorites_separator->hide();4615if (main_vbox->get_child_count() > 0) {4616EditorInspectorCategory *category = Object::cast_to<EditorInspectorCategory>(main_vbox->get_child(0));4617if (!category) {4618favorites_separator->show();4619}4620}46214622// Clean up empty sections.4623for (List<EditorInspectorSection *>::Element *I = sections.back(); I;) {4624EditorInspectorSection *section = I->get();4625I = I->prev(); // Note: Advance before erasing element.4626if (section->get_vbox()->get_child_count() == 0) {4627sections.erase(section);4628vbox_per_path[main_vbox].erase(section->get_section());4629memdelete(section);4630}4631}4632}46334634if (!hide_metadata && !object->call("_hide_metadata_from_inspector")) {4635// Add 4px of spacing between the "Add Metadata" button and the content above it.4636Control *spacer = memnew(Control);4637spacer->set_custom_minimum_size(Size2(0, 4) * EDSCALE);4638main_vbox->add_child(spacer);46394640Button *add_md = memnew(EditorInspectorActionButton(TTRC("Add Metadata"), SNAME("Add")));4641add_md->connect(SceneStringName(pressed), callable_mp(this, &EditorInspector::_show_add_meta_dialog));4642main_vbox->add_child(add_md);4643if (all_read_only) {4644add_md->set_disabled(true);4645}4646}46474648// Get the lists of to add at the end.4649for (Ref<EditorInspectorPlugin> &ped : valid_plugins) {4650ped->parse_end(object);4651_parse_added_editors(main_vbox, nullptr, ped);4652}46534654if (is_main_editor_inspector()) {4655// Updating inspector might invalidate some editing owners.4656EditorNode::get_singleton()->hide_unused_editors();4657}46584659if (root_inspector_was_following_focus) {4660get_root_inspector()->set_follow_focus(true);4661}4662}46634664void EditorInspector::update_property(const String &p_prop) {4665if (!editor_property_map.has(p_prop)) {4666return;4667}46684669for (EditorProperty *E : editor_property_map[p_prop]) {4670E->update_property();4671E->update_editor_property_status();4672E->update_cache();4673}46744675for (EditorInspectorSection *S : sections) {4676if (S->is_checkable()) {4677S->_property_edited(p_prop);4678}4679}4680}46814682void EditorInspector::_clear(bool p_hide_plugins) {4683begin_vbox->hide();4684while (begin_vbox->get_child_count()) {4685memdelete(begin_vbox->get_child(0));4686}46874688favorites_section->hide();4689while (favorites_vbox->get_child_count()) {4690memdelete(favorites_vbox->get_child(0));4691}4692while (favorites_groups_vbox->get_child_count()) {4693memdelete(favorites_groups_vbox->get_child(0));4694}46954696while (main_vbox->get_child_count()) {4697memdelete(main_vbox->get_child(0));4698}46994700property_selected = StringName();4701property_focusable = -1;4702editor_property_map.clear();4703sections.clear();4704pending.clear();4705restart_request_props.clear();47064707if (p_hide_plugins && is_main_editor_inspector()) {4708EditorNode::get_singleton()->hide_unused_editors(this);4709}4710}47114712Object *EditorInspector::get_edited_object() {4713return object;4714}47154716Object *EditorInspector::get_next_edited_object() {4717return next_object;4718}47194720void EditorInspector::edit(Object *p_object) {4721if (object == p_object) {4722return;4723}47244725next_object = p_object; // Some plugins need to know the next edited object when clearing the inspector.4726if (object) {4727if (likely(Variant(object).get_validated_object())) {4728object->disconnect(CoreStringName(property_list_changed), callable_mp(this, &EditorInspector::_changed_callback));4729}4730_clear();4731}4732per_array_page.clear();47334734object = p_object;47354736if (object) {4737update_scroll_request = 0; //reset4738if (scroll_cache.has(object->get_instance_id())) { //if exists, set something else4739update_scroll_request = scroll_cache[object->get_instance_id()]; //done this way because wait until full size is accommodated4740}4741object->connect(CoreStringName(property_list_changed), callable_mp(this, &EditorInspector::_changed_callback));47424743can_favorite = Object::cast_to<Node>(object) || Object::cast_to<Resource>(object);4744_update_current_favorites();47454746update_tree();4747}47484749// Keep it available until the end so it works with both main and sub inspectors.4750next_object = nullptr;47514752emit_signal(SNAME("edited_object_changed"));4753}47544755void EditorInspector::set_keying(bool p_active) {4756if (keying == p_active) {4757return;4758}4759keying = p_active;4760_keying_changed();4761}47624763void EditorInspector::_keying_changed() {4764for (const KeyValue<StringName, List<EditorProperty *>> &F : editor_property_map) {4765for (EditorProperty *E : F.value) {4766if (E) {4767E->set_keying(keying);4768}4769}4770}47714772for (EditorInspectorSection *S : sections) {4773S->set_keying(keying);4774}4775}47764777void EditorInspector::set_read_only(bool p_read_only) {4778if (p_read_only == read_only) {4779return;4780}4781read_only = p_read_only;4782update_tree();4783}47844785EditorPropertyNameProcessor::Style EditorInspector::get_property_name_style() const {4786return property_name_style;4787}47884789void EditorInspector::set_property_name_style(EditorPropertyNameProcessor::Style p_style) {4790if (property_name_style == p_style) {4791return;4792}4793property_name_style = p_style;4794update_tree();4795}47964797void EditorInspector::set_use_settings_name_style(bool p_enable) {4798if (use_settings_name_style == p_enable) {4799return;4800}4801use_settings_name_style = p_enable;4802if (use_settings_name_style) {4803set_property_name_style(EditorPropertyNameProcessor::get_singleton()->get_settings_style());4804}4805}48064807void EditorInspector::set_autoclear(bool p_enable) {4808autoclear = p_enable;4809}48104811void EditorInspector::set_show_categories(bool p_show_standard, bool p_show_custom) {4812show_standard_categories = p_show_standard;4813show_custom_categories = p_show_custom;4814update_tree();4815}48164817void EditorInspector::set_use_doc_hints(bool p_enable) {4818use_doc_hints = p_enable;4819update_tree();4820}48214822void EditorInspector::set_hide_script(bool p_hide) {4823hide_script = p_hide;4824update_tree();4825}48264827void EditorInspector::set_hide_metadata(bool p_hide) {4828hide_metadata = p_hide;4829update_tree();4830}48314832void EditorInspector::set_use_filter(bool p_use) {4833use_filter = p_use;4834update_tree();4835}48364837void EditorInspector::register_text_enter(Node *p_line_edit) {4838search_box = Object::cast_to<LineEdit>(p_line_edit);4839if (search_box) {4840search_box->connect(SceneStringName(text_changed), callable_mp(this, &EditorInspector::update_tree).unbind(1));4841}4842}48434844void EditorInspector::set_use_folding(bool p_use_folding, bool p_update_tree) {4845use_folding = p_use_folding;48464847if (p_update_tree) {4848update_tree();4849}4850}48514852bool EditorInspector::is_using_folding() {4853return use_folding;4854}48554856void EditorInspector::collapse_all_folding() {4857for (EditorInspectorSection *E : sections) {4858E->fold();4859}48604861for (const KeyValue<StringName, List<EditorProperty *>> &F : editor_property_map) {4862for (EditorProperty *E : F.value) {4863E->collapse_all_folding();4864}4865}4866}48674868void EditorInspector::expand_all_folding() {4869for (EditorInspectorSection *E : sections) {4870E->unfold();4871}4872for (const KeyValue<StringName, List<EditorProperty *>> &F : editor_property_map) {4873for (EditorProperty *E : F.value) {4874E->expand_all_folding();4875}4876}4877}48784879void EditorInspector::expand_revertable() {4880HashSet<EditorInspectorSection *> sections_to_unfold[2];4881for (EditorInspectorSection *E : sections) {4882if (E->has_revertable_properties()) {4883sections_to_unfold[0].insert(E);4884}4885}48864887// Climb up the hierarchy doing double buffering with the sets.4888int a = 0;4889int b = 1;4890while (sections_to_unfold[a].size()) {4891for (EditorInspectorSection *E : sections_to_unfold[a]) {4892E->unfold();48934894Node *n = E->get_parent();4895while (n) {4896if (Object::cast_to<EditorInspector>(n)) {4897break;4898}4899if (Object::cast_to<EditorInspectorSection>(n) && !sections_to_unfold[a].has((EditorInspectorSection *)n)) {4900sections_to_unfold[b].insert((EditorInspectorSection *)n);4901}4902n = n->get_parent();4903}4904}49054906sections_to_unfold[a].clear();4907SWAP(a, b);4908}49094910for (const KeyValue<StringName, List<EditorProperty *>> &F : editor_property_map) {4911for (EditorProperty *E : F.value) {4912E->expand_revertable();4913}4914}4915}49164917void EditorInspector::set_scroll_offset(int p_offset) {4918// This can be called before the container finishes sorting its children, so defer it.4919callable_mp((ScrollContainer *)this, &ScrollContainer::set_v_scroll).call_deferred(p_offset);4920}49214922int EditorInspector::get_scroll_offset() const {4923return get_v_scroll();4924}49254926void EditorInspector::set_use_wide_editors(bool p_enable) {4927wide_editors = p_enable;4928}49294930void EditorInspector::set_root_inspector(EditorInspector *p_root_inspector) {4931root_inspector = p_root_inspector;4932// Only the root inspector should follow focus.4933set_follow_focus(false);4934}49354936void EditorInspector::_section_toggled_by_user(const String &p_path, bool p_value) {4937_property_changed(p_path, p_value);4938}49394940void EditorInspector::set_use_deletable_properties(bool p_enabled) {4941deletable_properties = p_enabled;4942}49434944void EditorInspector::_page_change_request(int p_new_page, const StringName &p_array_prefix) {4945int prev_page = per_array_page.has(p_array_prefix) ? per_array_page[p_array_prefix] : 0;4946int new_page = MAX(0, p_new_page);4947if (new_page != prev_page) {4948per_array_page[p_array_prefix] = new_page;4949update_tree_pending = true;4950}4951}49524953void EditorInspector::_edit_request_change(Object *p_object, const String &p_property) {4954if (object != p_object) { //may be undoing/redoing for a non edited object, so ignore4955return;4956}49574958if (changing) {4959return;4960}49614962if (p_property.is_empty()) {4963update_tree_pending = true;4964} else {4965pending.insert(p_property);4966}4967}49684969void EditorInspector::_edit_set(const String &p_name, const Variant &p_value, bool p_refresh_all, const String &p_changed_field) {4970if (autoclear && editor_property_map.has(p_name)) {4971for (EditorProperty *E : editor_property_map[p_name]) {4972if (E->is_checkable()) {4973E->set_checked(true);4974}4975}4976}49774978EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();4979if (bool(object->call("_dont_undo_redo"))) {4980object->set(p_name, p_value);4981if (p_refresh_all) {4982_edit_request_change(object, "");4983} else {4984_edit_request_change(object, p_name);4985}49864987emit_signal(_prop_edited, p_name);4988} else if (Object::cast_to<MultiNodeEdit>(object)) {4989Object::cast_to<MultiNodeEdit>(object)->set_property_field(p_name, p_value, p_changed_field);4990_edit_request_change(object, p_name);4991emit_signal(_prop_edited, p_name);4992} else if (Object::cast_to<EditorDebuggerRemoteObjects>(object)) {4993Object::cast_to<EditorDebuggerRemoteObjects>(object)->set_property_field(p_name, p_value, p_changed_field);4994_edit_request_change(object, p_name);4995emit_signal(_prop_edited, p_name);4996} else {4997undo_redo->create_action(vformat(TTR("Set %s"), p_name), UndoRedo::MERGE_ENDS, nullptr, false, mark_unsaved);4998undo_redo->add_do_property(object, p_name, p_value);4999bool valid = false;5000Variant value = object->get(p_name, &valid);5001if (valid) {5002if (Object::cast_to<Control>(object) && (p_name == "anchors_preset" || p_name == "layout_mode")) {5003undo_redo->add_undo_method(object, "_edit_set_state", Object::cast_to<Control>(object)->_edit_get_state());5004} else {5005undo_redo->add_undo_property(object, p_name, value);5006}5007}50085009List<StringName> linked_properties;5010ClassDB::get_linked_properties_info(object->get_class_name(), p_name, &linked_properties);50115012for (const StringName &linked_prop : linked_properties) {5013valid = false;5014Variant undo_value = object->get(linked_prop, &valid);5015if (valid) {5016undo_redo->add_undo_property(object, linked_prop, undo_value);5017}5018}50195020PackedStringArray linked_properties_dynamic = object->call("_get_linked_undo_properties", p_name, p_value);5021for (int i = 0; i < linked_properties_dynamic.size(); i++) {5022valid = false;5023Variant undo_value = object->get(linked_properties_dynamic[i], &valid);5024if (valid) {5025undo_redo->add_undo_property(object, linked_properties_dynamic[i], undo_value);5026}5027}50285029Variant v_undo_redo = undo_redo;5030Variant v_object = object;5031Variant v_name = p_name;5032const Vector<Callable> &callbacks = EditorNode::get_editor_data().get_undo_redo_inspector_hook_callback();5033for (int i = 0; i < callbacks.size(); i++) {5034const Callable &callback = callbacks[i];50355036const Variant *p_arguments[] = { &v_undo_redo, &v_object, &v_name, &p_value };5037Variant return_value;5038Callable::CallError call_error;50395040callback.callp(p_arguments, 4, return_value, call_error);5041if (call_error.error != Callable::CallError::CALL_OK) {5042ERR_PRINT("Invalid UndoRedo callback.");5043}5044}50455046if (p_refresh_all) {5047undo_redo->add_do_method(this, "_edit_request_change", object, "");5048undo_redo->add_undo_method(this, "_edit_request_change", object, "");5049} else {5050undo_redo->add_do_method(this, "_edit_request_change", object, p_name);5051undo_redo->add_undo_method(this, "_edit_request_change", object, p_name);5052}50535054Resource *r = Object::cast_to<Resource>(object);5055if (r) {5056if (String(p_name) == "resource_local_to_scene") {5057bool prev = object->get(p_name);5058bool next = p_value;5059if (next) {5060undo_redo->add_do_method(r, "setup_local_to_scene");5061}5062if (prev) {5063undo_redo->add_undo_method(r, "setup_local_to_scene");5064}5065}5066}5067undo_redo->add_do_method(this, "emit_signal", _prop_edited, p_name);5068undo_redo->add_undo_method(this, "emit_signal", _prop_edited, p_name);5069undo_redo->commit_action();5070}50715072if (editor_property_map.has(p_name)) {5073for (EditorProperty *E : editor_property_map[p_name]) {5074E->update_editor_property_status();5075}5076}5077}50785079void EditorInspector::_property_changed(const String &p_path, const Variant &p_value, const String &p_name, bool p_changing, bool p_update_all) {5080// The "changing" variable must be true for properties that trigger events as typing occurs,5081// like "text_changed" signal. E.g. text property of Label, Button, RichTextLabel, etc.5082if (p_changing) {5083changing++;5084}50855086_edit_set(p_path, p_value, p_update_all, p_name);50875088if (p_changing) {5089changing--;5090}50915092if (restart_request_props.has(p_path)) {5093emit_signal(SNAME("restart_requested"));5094}5095}50965097void EditorInspector::_multiple_properties_changed(const Vector<String> &p_paths, const Array &p_values, bool p_changing) {5098ERR_FAIL_COND(p_paths.is_empty() || p_values.is_empty());5099ERR_FAIL_COND(p_paths.size() != p_values.size());5100String names;5101for (int i = 0; i < p_paths.size(); i++) {5102if (i > 0) {5103names += ",";5104}5105names += p_paths[i];5106}5107EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();5108// TRANSLATORS: This is describing a change to multiple properties at once. The parameter is a list of property names.5109undo_redo->create_action(vformat(TTR("Set Multiple: %s"), names), UndoRedo::MERGE_ENDS);5110for (int i = 0; i < p_paths.size(); i++) {5111_edit_set(p_paths[i], p_values[i], false, "");5112if (restart_request_props.has(p_paths[i])) {5113emit_signal(SNAME("restart_requested"));5114}5115}5116if (p_changing) {5117changing++;5118}5119undo_redo->commit_action();5120if (p_changing) {5121changing--;5122}5123}51245125void EditorInspector::_property_keyed(const String &p_path, bool p_advance) {5126if (!object) {5127return;5128}51295130// The second parameter could be null, causing the event to fire with less arguments, so use the pointer call which preserves it.5131const Variant args[3] = { p_path, object->get(p_path), p_advance };5132const Variant *argp[3] = { &args[0], &args[1], &args[2] };5133emit_signalp(SNAME("property_keyed"), argp, 3);5134}51355136void EditorInspector::_property_deleted(const String &p_path) {5137if (!object) {5138return;5139}51405141if (p_path.begins_with("metadata/")) {5142String name = p_path.replace_first("metadata/", "");5143EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();5144undo_redo->create_action(vformat(TTR("Remove metadata %s"), name));5145undo_redo->add_do_method(object, "remove_meta", name);5146undo_redo->add_undo_method(object, "set_meta", name, object->get_meta(name));5147undo_redo->commit_action();5148}51495150if (restart_request_props.has(p_path)) {5151emit_signal(SNAME("restart_requested"));5152}5153emit_signal(SNAME("property_deleted"), p_path);5154}51555156void EditorInspector::_property_keyed_with_value(const String &p_path, const Variant &p_value, bool p_advance) {5157if (!object) {5158return;5159}51605161// The second parameter could be null, causing the event to fire with less arguments, so use the pointer call which preserves it.5162const Variant args[3] = { p_path, p_value, p_advance };5163const Variant *argp[3] = { &args[0], &args[1], &args[2] };5164emit_signalp(SNAME("property_keyed"), argp, 3);5165}51665167void EditorInspector::_property_checked(const String &p_path, bool p_checked) {5168if (!object) {5169return;5170}51715172//property checked5173if (autoclear) {5174if (!p_checked) {5175_edit_set(p_path, Variant(), false, "");5176} else {5177Variant to_create;5178Control *control = Object::cast_to<Control>(object);5179if (control && p_path.begins_with("theme_override_")) {5180to_create = control->get_used_theme_item(p_path);5181} else {5182List<PropertyInfo> pinfo;5183object->get_property_list(&pinfo);5184for (const PropertyInfo &E : pinfo) {5185if (E.name == p_path) {5186Callable::CallError ce;5187Variant::construct(E.type, to_create, nullptr, 0, ce);5188break;5189}5190}5191}5192_edit_set(p_path, to_create, false, "");5193}51945195if (editor_property_map.has(p_path)) {5196for (EditorProperty *E : editor_property_map[p_path]) {5197E->set_checked(p_checked);5198E->update_property();5199E->update_editor_property_status();5200E->update_cache();5201}5202}5203} else {5204emit_signal(SNAME("property_toggled"), p_path, p_checked);5205}5206}52075208void EditorInspector::_property_pinned(const String &p_path, bool p_pinned) {5209if (!object) {5210return;5211}52125213Node *node = Object::cast_to<Node>(object);5214ERR_FAIL_NULL(node);52155216EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();5217undo_redo->create_action(vformat(p_pinned ? TTR("Pinned %s") : TTR("Unpinned %s"), p_path));5218undo_redo->add_do_method(node, "_set_property_pinned", p_path, p_pinned);5219undo_redo->add_undo_method(node, "_set_property_pinned", p_path, !p_pinned);5220if (editor_property_map.has(p_path)) {5221for (List<EditorProperty *>::Element *E = editor_property_map[p_path].front(); E; E = E->next()) {5222undo_redo->add_do_method(E->get(), "_update_editor_property_status");5223undo_redo->add_undo_method(E->get(), "_update_editor_property_status");5224}5225}5226undo_redo->commit_action();5227}52285229void EditorInspector::_property_selected(const String &p_path, int p_focusable) {5230property_selected = p_path;5231property_focusable = p_focusable;5232// Deselect the others.5233for (const KeyValue<StringName, List<EditorProperty *>> &F : editor_property_map) {5234if (F.key == property_selected) {5235continue;5236}5237for (EditorProperty *E : F.value) {5238if (E->is_selected()) {5239E->deselect();5240}5241}5242}52435244emit_signal(SNAME("property_selected"), p_path);5245}52465247void EditorInspector::_object_id_selected(const String &p_path, ObjectID p_id) {5248emit_signal(SNAME("object_id_selected"), p_id);5249}52505251void EditorInspector::_resource_selected(const String &p_path, Ref<Resource> p_resource) {5252emit_signal(SNAME("resource_selected"), p_resource, p_path);5253}52545255void EditorInspector::_node_removed(Node *p_node) {5256if (p_node == object) {5257edit(nullptr);5258}5259}52605261void EditorInspector::_update_current_favorites() {5262current_favorites.clear();5263if (!can_favorite) {5264return;5265}52665267HashMap<String, PackedStringArray> favorites = EditorSettings::get_singleton()->get_favorite_properties();52685269// Fetch script properties.5270Ref<Script> scr = object->get_script();5271if (scr.is_valid()) {5272List<PropertyInfo> plist;5273// FIXME: Only properties from a saved script will be available, unsaved ones will be ignored.5274// Can cause a little wonkiness, while nothing serious, would be nice to find a way to get5275// unsaved ones without needing to get the entire property list of an object.5276scr->get_script_property_list(&plist);52775278String path;5279HashMap<String, LocalVector<String>> props;52805281for (PropertyInfo &p : plist) {5282if (p.usage & PROPERTY_USAGE_CATEGORY) {5283path = favorites.has(p.hint_string) ? p.hint_string : String();5284} else if (p.usage & PROPERTY_USAGE_SCRIPT_VARIABLE && !path.is_empty()) {5285props[path].push_back(p.name);5286}5287}52885289// Add favorited properties while removing invalid ones.5290bool invalid_props = false;5291for (const KeyValue<String, LocalVector<String>> &KV : props) {5292path = KV.key;5293for (int i = 0; i < favorites[path].size(); i++) {5294String prop = favorites[path][i];5295if (KV.value.has(prop)) {5296current_favorites.append(prop);5297} else {5298invalid_props = true;5299favorites[path].erase(prop);5300i--;5301}5302}53035304if (favorites[path].is_empty()) {5305favorites.erase(path);5306}5307}53085309if (invalid_props) {5310EditorSettings::get_singleton()->set_favorite_properties(favorites);5311}5312}53135314// Fetch built-in properties.5315StringName class_name = object->get_class_name();5316for (const KeyValue<String, PackedStringArray> &KV : favorites) {5317if (ClassDB::is_parent_class(class_name, KV.key)) {5318current_favorites.append_array(KV.value);5319}5320}5321}53225323void EditorInspector::_set_property_favorited(const String &p_path, bool p_favorited) {5324if (!object) {5325return;5326}53275328StringName validate_name = object->get_class_name();5329StringName class_name;53305331String theme_property;5332if (p_path.begins_with("theme_override_")) {5333theme_property = p_path.get_slicec('/', 1);5334}53355336while (!validate_name.is_empty()) {5337class_name = validate_name;53385339if (!theme_property.is_empty()) { // Deal with theme properties.5340bool found = false;5341HashMap<String, DocData::ClassDoc>::ConstIterator F = EditorHelp::get_doc_data()->class_list.find(class_name);5342if (F) {5343for (const DocData::ThemeItemDoc &prop : F->value.theme_properties) {5344if (prop.name == theme_property) {5345found = true;5346break;5347}5348}5349}53505351if (found) {5352break;5353}5354} else if (ClassDB::has_property(class_name, p_path, true)) { // Check if the property is built-in.5355break;5356}53575358validate_name = ClassDB::get_parent_class_nocheck(class_name);5359}53605361// "script" isn't a real property, so a hack is necessary.5362if (validate_name.is_empty() && p_path != "script") {5363class_name = "";5364}53655366if (class_name.is_empty()) {5367// Check if it's part of a script.5368Ref<Script> scr = object->get_script();5369if (scr.is_valid()) {5370List<PropertyInfo> plist;5371scr->get_script_property_list(&plist);53725373String path;5374for (PropertyInfo &p : plist) {5375if (p.usage & PROPERTY_USAGE_CATEGORY) {5376path = p.hint_string;5377} else if (p.usage & PROPERTY_USAGE_SCRIPT_VARIABLE && p.name == p_path) {5378class_name = path;5379break;5380}5381}5382}53835384ERR_FAIL_COND_MSG(class_name.is_empty(), "Can't favorite invalid property. If said property was from a script and recently renamed, try saving it first.");5385}53865387HashMap<String, PackedStringArray> favorites = EditorSettings::get_singleton()->get_favorite_properties();5388if (p_favorited) {5389current_favorites.append(p_path);5390favorites[class_name].append(p_path);5391} else {5392current_favorites.erase(p_path);53935394if (favorites.has(class_name) && favorites[class_name].has(p_path)) {5395if (favorites[class_name].size() > 1) {5396favorites[class_name].erase(p_path);5397} else {5398favorites.erase(class_name);5399}5400}5401}5402EditorSettings::get_singleton()->set_favorite_properties(favorites);54035404update_tree();5405}54065407void EditorInspector::_clear_current_favorites() {5408current_favorites.clear();54095410HashMap<String, PackedStringArray> favorites = EditorSettings::get_singleton()->get_favorite_properties();54115412Ref<Script> scr = object->get_script();5413if (scr.is_valid()) {5414List<PropertyInfo> plist;5415scr->get_script_property_list(&plist);54165417for (PropertyInfo &p : plist) {5418if (p.usage & PROPERTY_USAGE_CATEGORY && favorites.has(p.hint_string)) {5419favorites.erase(p.hint_string);5420}5421}5422}54235424StringName class_name = object->get_class_name();5425while (class_name) {5426if (favorites.has(class_name)) {5427favorites.erase(class_name);5428}54295430class_name = ClassDB::get_parent_class(class_name);5431}54325433EditorSettings::get_singleton()->set_favorite_properties(favorites);5434update_tree();5435}54365437void EditorInspector::_notification(int p_what) {5438switch (p_what) {5439case NOTIFICATION_TRANSLATION_CHANGED: {5440if (property_name_style == EditorPropertyNameProcessor::STYLE_LOCALIZED) {5441update_tree_pending = true;5442}5443} break;54445445case NOTIFICATION_THEME_CHANGED: {5446if (updating_theme) {5447break;5448}54495450theme_cache.vertical_separation = get_theme_constant(SNAME("v_separation"), SNAME("EditorInspector"));5451theme_cache.prop_subsection = get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor));5452theme_cache.icon_add = get_editor_theme_icon(SNAME("Add"));54535454initialize_section_theme(section_theme_cache, this);5455initialize_category_theme(category_theme_cache, this);54565457base_vbox->add_theme_constant_override("separation", theme_cache.vertical_separation);5458begin_vbox->add_theme_constant_override("separation", theme_cache.vertical_separation);5459favorites_section->add_theme_constant_override("separation", theme_cache.vertical_separation);5460favorites_groups_vbox->add_theme_constant_override("separation", theme_cache.vertical_separation);5461main_vbox->add_theme_constant_override("separation", theme_cache.vertical_separation);5462} break;54635464case NOTIFICATION_READY: {5465ERR_FAIL_NULL(EditorFeatureProfileManager::get_singleton());5466EditorFeatureProfileManager::get_singleton()->connect("current_feature_profile_changed", callable_mp(this, &EditorInspector::_feature_profile_changed));5467set_process(is_visible_in_tree());5468if (!is_sub_inspector()) {5469get_tree()->connect("node_removed", callable_mp(this, &EditorInspector::_node_removed));5470}5471} break;54725473case NOTIFICATION_PREDELETE: {5474if (!is_sub_inspector() && is_inside_tree()) {5475get_tree()->disconnect("node_removed", callable_mp(this, &EditorInspector::_node_removed));5476}5477edit(nullptr);5478} break;54795480case NOTIFICATION_VISIBILITY_CHANGED: {5481set_process(is_visible_in_tree());5482} break;54835484case NOTIFICATION_PROCESS: {5485if (update_scroll_request >= 0) {5486callable_mp((Range *)get_v_scroll_bar(), &Range::set_value).call_deferred(update_scroll_request);5487update_scroll_request = -1;5488}5489if (update_tree_pending) {5490refresh_countdown = float(EDITOR_GET("docks/property_editor/auto_refresh_interval"));5491} else if (refresh_countdown > 0) {5492refresh_countdown -= get_process_delta_time();5493if (refresh_countdown <= 0) {5494for (const KeyValue<StringName, List<EditorProperty *>> &F : editor_property_map) {5495for (EditorProperty *E : F.value) {5496if (E && !E->is_cache_valid()) {5497E->update_property();5498E->update_editor_property_status();5499E->update_cache();5500}5501}5502}55035504for (EditorInspectorSection *S : sections) {5505S->update_property();5506}55075508refresh_countdown = float(EDITOR_GET("docks/property_editor/auto_refresh_interval"));5509}5510}55115512changing++;55135514if (update_tree_pending) {5515update_tree();5516update_tree_pending = false;5517pending.clear();55185519} else {5520while (pending.size()) {5521StringName prop = *pending.begin();5522if (editor_property_map.has(prop)) {5523for (EditorProperty *E : editor_property_map[prop]) {5524E->update_property();5525E->update_editor_property_status();5526E->update_cache();5527}5528}5529pending.remove(pending.begin());5530}55315532for (EditorInspectorSection *S : sections) {5533S->update_property();5534}5535}55365537changing--;5538} break;55395540case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {5541if (use_settings_name_style && EditorSettings::get_singleton()->check_changed_settings_in_group("interface/editor/localize_settings")) {5542EditorPropertyNameProcessor::Style style = EditorPropertyNameProcessor::get_settings_style();5543if (property_name_style != style) {5544property_name_style = style;5545update_tree_pending = true;5546}5547}55485549if (EditorSettings::get_singleton()->check_changed_settings_in_group("interface/inspector")) {5550update_tree_pending = true;5551}5552} break;5553}5554}55555556void EditorInspector::_changed_callback() {5557//this is called when property change is notified via notify_property_list_changed()5558if (object != nullptr) {5559_update_current_favorites();5560_edit_request_change(object, String());5561}5562}55635564void EditorInspector::_vscroll_changed(double p_offset) {5565if (update_scroll_request >= 0) { //waiting, do nothing5566return;5567}55685569if (object) {5570scroll_cache[object->get_instance_id()] = p_offset;5571}5572}55735574void EditorInspector::set_property_prefix(const String &p_prefix) {5575property_prefix = p_prefix;5576}55775578String EditorInspector::get_property_prefix() const {5579return property_prefix;5580}55815582void EditorInspector::add_custom_property_description(const String &p_class, const String &p_property, const String &p_description) {5583const String key = vformat("property|%s|%s", p_class, p_property);5584custom_property_descriptions[key] = p_description;5585}55865587String EditorInspector::get_custom_property_description(const String &p_property) const {5588HashMap<String, String>::ConstIterator E = custom_property_descriptions.find(p_property);5589if (E) {5590return E->value;5591}5592return "";5593}55945595void EditorInspector::set_object_class(const String &p_class) {5596object_class = p_class;5597}55985599String EditorInspector::get_object_class() const {5600return object_class;5601}56025603void EditorInspector::_feature_profile_changed() {5604update_tree();5605}56065607void EditorInspector::set_restrict_to_basic_settings(bool p_restrict) {5608restrict_to_basic = p_restrict;5609update_tree();5610}56115612void EditorInspector::set_property_clipboard(const Variant &p_value) {5613property_clipboard = p_value;5614}56155616Variant EditorInspector::get_property_clipboard() const {5617return property_clipboard;5618}56195620void EditorInspector::_show_add_meta_dialog() {5621if (!add_meta_dialog) {5622add_meta_dialog = memnew(AddMetadataDialog());5623add_meta_dialog->connect(SceneStringName(confirmed), callable_mp(this, &EditorInspector::_add_meta_confirm));5624add_child(add_meta_dialog);5625}56265627StringName dialog_title;5628Node *node = Object::cast_to<Node>(object);5629// If object is derived from Node use node name, if derived from Resource use classname.5630dialog_title = node ? node->get_name() : StringName(object->get_class());56315632List<StringName> existing_meta_keys;5633object->get_meta_list(&existing_meta_keys);5634add_meta_dialog->open(dialog_title, existing_meta_keys);5635}56365637void EditorInspector::_add_meta_confirm() {5638// Ensure metadata is unfolded when adding a new metadata.5639object->editor_set_section_unfold("metadata", true);56405641String name = add_meta_dialog->get_meta_name();5642EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();5643undo_redo->create_action(vformat(TTR("Add metadata %s"), name));5644undo_redo->add_do_method(object, "set_meta", name, add_meta_dialog->get_meta_defval());5645undo_redo->add_undo_method(object, "remove_meta", name);5646undo_redo->commit_action();5647}56485649EditorInspector *EditorInspector::_get_control_parent_inspector(Control *p_control) {5650{5651EditorInspector *inspector = Object::cast_to<EditorInspector>(p_control);5652if (inspector) {5653return inspector;5654}5655}56565657Control *parent = p_control->get_parent_control();5658while (parent) {5659EditorInspector *inspector = Object::cast_to<EditorInspector>(parent);5660if (inspector) {5661return inspector;5662}5663parent = parent->get_parent_control();5664}5665return nullptr;5666}56675668void EditorInspector::_bind_methods() {5669ClassDB::bind_method(D_METHOD("edit", "object"), &EditorInspector::edit);5670ClassDB::bind_method("_edit_request_change", &EditorInspector::_edit_request_change);5671ClassDB::bind_method("get_selected_path", &EditorInspector::get_selected_path);5672ClassDB::bind_method("get_edited_object", &EditorInspector::get_edited_object);56735674ClassDB::bind_static_method("EditorInspector", D_METHOD("instantiate_property_editor", "object", "type", "path", "hint", "hint_text", "usage", "wide"), &EditorInspector::instantiate_property_editor, DEFVAL(false));56755676ADD_SIGNAL(MethodInfo("property_selected", PropertyInfo(Variant::STRING, "property")));5677ADD_SIGNAL(MethodInfo("property_keyed", PropertyInfo(Variant::STRING, "property"), PropertyInfo(Variant::NIL, "value", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT), PropertyInfo(Variant::BOOL, "advance")));5678ADD_SIGNAL(MethodInfo("property_deleted", PropertyInfo(Variant::STRING, "property")));5679ADD_SIGNAL(MethodInfo("resource_selected", PropertyInfo(Variant::OBJECT, "resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource"), PropertyInfo(Variant::STRING, "path")));5680ADD_SIGNAL(MethodInfo("object_id_selected", PropertyInfo(Variant::INT, "id")));5681ADD_SIGNAL(MethodInfo("property_edited", PropertyInfo(Variant::STRING, "property")));5682ADD_SIGNAL(MethodInfo("property_toggled", PropertyInfo(Variant::STRING, "property"), PropertyInfo(Variant::BOOL, "checked")));5683ADD_SIGNAL(MethodInfo("edited_object_changed"));5684ADD_SIGNAL(MethodInfo("restart_requested"));5685}56865687EditorInspector::EditorInspector() {5688object = nullptr;56895690base_vbox = memnew(VBoxContainer);5691base_vbox->set_h_size_flags(SIZE_EXPAND_FILL);5692add_child(base_vbox);56935694begin_vbox = memnew(VBoxContainer);5695base_vbox->add_child(begin_vbox);5696begin_vbox->hide();56975698favorites_section = memnew(VBoxContainer);5699base_vbox->add_child(favorites_section);5700favorites_section->hide();57015702EditorInspectorCategory *favorites_category = memnew(EditorInspectorCategory);5703favorites_category->set_as_favorite();5704favorites_category->connect("unfavorite_all", callable_mp(this, &EditorInspector::_clear_current_favorites));5705favorites_section->add_child(favorites_category);57065707favorites_vbox = memnew(VBoxContainer);5708favorites_section->add_child(favorites_vbox);5709favorites_groups_vbox = memnew(VBoxContainer);5710favorites_section->add_child(favorites_groups_vbox);57115712favorites_separator = memnew(HSeparator);5713favorites_section->add_child(favorites_separator);5714favorites_separator->hide();57155716main_vbox = memnew(VBoxContainer);5717base_vbox->add_child(main_vbox);57185719set_horizontal_scroll_mode(SCROLL_MODE_DISABLED);5720set_follow_focus(true);57215722changing = 0;5723search_box = nullptr;5724_prop_edited = "property_edited";5725set_process(false);5726set_focus_mode(FocusMode::FOCUS_ALL);5727property_focusable = -1;5728property_clipboard = Variant();57295730get_v_scroll_bar()->connect(SceneStringName(value_changed), callable_mp(this, &EditorInspector::_vscroll_changed));5731update_scroll_request = -1;5732if (EditorSettings::get_singleton()) {5733refresh_countdown = float(EDITOR_GET("docks/property_editor/auto_refresh_interval"));5734} else {5735//used when class is created by the docgen to dump default values of everything bindable, editorsettings may not be created5736refresh_countdown = 0.33;5737}57385739ED_SHORTCUT("property_editor/copy_value", TTRC("Copy Value"), KeyModifierMask::CMD_OR_CTRL | Key::C);5740ED_SHORTCUT("property_editor/paste_value", TTRC("Paste Value"), KeyModifierMask::CMD_OR_CTRL | Key::V);5741ED_SHORTCUT("property_editor/copy_property_path", TTRC("Copy Property Path"), KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT | Key::C);57425743// `use_settings_name_style` is true by default, set the name style accordingly.5744set_property_name_style(EditorPropertyNameProcessor::get_singleton()->get_settings_style());57455746set_draw_focus_border(true);5747set_scroll_on_drag_hover(true);5748}574957505751