diff options
Diffstat (limited to 'editor/editor_inspector.cpp')
-rw-r--r-- | editor/editor_inspector.cpp | 327 |
1 files changed, 136 insertions, 191 deletions
diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 6adc640651..1b423f69b7 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -39,22 +39,24 @@ #include "scene/resources/packed_scene.h" Size2 EditorProperty::get_minimum_size() const { - Size2 ms; Ref<Font> font = get_theme_font("font", "Tree"); ms.height = font->get_height(); for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to<Control>(get_child(i)); - if (!c) + if (!c) { continue; - if (c->is_set_as_toplevel()) + } + if (c->is_set_as_toplevel()) { continue; - if (!c->is_visible()) + } + if (!c->is_visible()) { continue; - if (c == bottom_editor) + } + if (c == bottom_editor) { continue; + } Size2 minsize = c->get_combined_minimum_size(); ms.width = MAX(ms.width, minsize.width); @@ -88,7 +90,6 @@ Size2 EditorProperty::get_minimum_size() const { } void EditorProperty::emit_changed(const StringName &p_property, const Variant &p_value, const StringName &p_field, bool p_changing) { - Variant args[4] = { p_property, p_value, p_field, p_changing }; const Variant *argptrs[4] = { &args[0], &args[1], &args[2], &args[3] }; @@ -96,9 +97,7 @@ void EditorProperty::emit_changed(const StringName &p_property, const Variant &p } void EditorProperty::_notification(int p_what) { - if (p_what == NOTIFICATION_SORT_CHILDREN) { - Size2 size = get_size(); Rect2 rect; Rect2 bottom_rect; @@ -114,14 +113,16 @@ void EditorProperty::_notification(int p_what) { //compute room needed for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to<Control>(get_child(i)); - if (!c) + if (!c) { continue; - if (c->is_set_as_toplevel()) + } + if (c->is_set_as_toplevel()) { continue; - if (c == bottom_editor) + } + if (c == bottom_editor) { continue; + } Size2 minsize = c->get_combined_minimum_size(); child_room = MAX(child_room, minsize.width); @@ -138,7 +139,6 @@ void EditorProperty::_notification(int p_what) { } if (bottom_editor) { - int m = 0; //get_constant("item_margin", "Tree"); bottom_rect = Rect2(m, rect.size.height + get_theme_constant("vseparation", "Tree"), size.width - m, bottom_editor->get_combined_minimum_size().height); @@ -175,14 +175,16 @@ void EditorProperty::_notification(int p_what) { //set children for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to<Control>(get_child(i)); - if (!c) + if (!c) { continue; - if (c->is_set_as_toplevel()) + } + if (c->is_set_as_toplevel()) { continue; - if (c == bottom_editor) + } + if (c == bottom_editor) { continue; + } fit_child_in_rect(c, rect); right_child_rect = rect; @@ -234,10 +236,11 @@ void EditorProperty::_notification(int p_what) { if (checkable) { Ref<Texture2D> checkbox; - if (checked) + if (checked) { checkbox = get_theme_icon("GuiChecked", "EditorIcons"); - else + } else { checkbox = get_theme_icon("GuiUnchecked", "EditorIcons"); + } Color color2(1, 1, 1); if (check_hover) { @@ -335,8 +338,9 @@ StringName EditorProperty::get_edited_property() { } void EditorProperty::update_property() { - if (get_script_instance()) + if (get_script_instance()) { get_script_instance()->call("update_property"); + } } void EditorProperty::set_read_only(bool p_read_only) { @@ -348,14 +352,12 @@ bool EditorProperty::is_read_only() const { } bool EditorPropertyRevert::may_node_be_in_instance(Node *p_node) { - Node *edited_scene = EditorNode::get_singleton()->get_edited_scene(); bool might_be = false; Node *node = p_node; while (node) { - if (node->get_scene_instance_state().is_valid()) { might_be = true; break; @@ -375,7 +377,6 @@ bool EditorPropertyRevert::may_node_be_in_instance(Node *p_node) { } bool EditorPropertyRevert::get_instanced_node_original_property(Node *p_node, const StringName &p_prop, Variant &value) { - Node *node = p_node; Node *orig = node; @@ -384,7 +385,6 @@ bool EditorPropertyRevert::get_instanced_node_original_property(Node *p_node, co bool found = false; while (node) { - Ref<SceneState> ss; if (node == edited_scene) { @@ -395,7 +395,6 @@ bool EditorPropertyRevert::get_instanced_node_original_property(Node *p_node, co } if (ss.is_valid()) { - NodePath np = node->get_path_to(orig); int node_idx = ss->find_node_by_path(np); if (node_idx >= 0) { @@ -403,7 +402,6 @@ bool EditorPropertyRevert::get_instanced_node_original_property(Node *p_node, co Variant lvar; lvar = ss->get_property_value(node_idx, p_prop, lfound); if (lfound) { - found = true; value = lvar; } @@ -429,21 +427,20 @@ bool EditorPropertyRevert::get_instanced_node_original_property(Node *p_node, co } bool EditorPropertyRevert::is_node_property_different(Node *p_node, const Variant &p_current, const Variant &p_orig) { - // this is a pretty difficult function, because a property may not be saved but may have // the flag to not save if one or if zero //make sure there is an actual state { Node *node = p_node; - if (!node) + if (!node) { return false; + } Node *edited_scene = EditorNode::get_singleton()->get_edited_scene(); bool found_state = false; while (node) { - Ref<SceneState> ss; if (node == edited_scene) { @@ -463,8 +460,9 @@ bool EditorPropertyRevert::is_node_property_different(Node *p_node, const Varian node = node->get_owner(); } - if (!found_state) + if (!found_state) { return false; //pointless to check if we are not comparing against anything. + } } if (p_current.get_type() == Variant::FLOAT && p_orig.get_type() == Variant::FLOAT) { @@ -478,7 +476,6 @@ bool EditorPropertyRevert::is_node_property_different(Node *p_node, const Varian } bool EditorPropertyRevert::can_property_revert(Object *p_object, const StringName &p_property) { - bool has_revert = false; Node *node = Object::cast_to<Node>(p_object); @@ -524,9 +521,9 @@ bool EditorPropertyRevert::can_property_revert(Object *p_object, const StringNam } void EditorProperty::update_reload_status() { - - if (property == StringName()) + if (property == StringName()) { return; //no property, so nothing to do + } bool has_reload = EditorPropertyRevert::can_property_revert(object, property); @@ -550,31 +547,27 @@ bool EditorProperty::use_keying_next() const { return false; } -void EditorProperty::set_checkable(bool p_checkable) { +void EditorProperty::set_checkable(bool p_checkable) { checkable = p_checkable; update(); queue_sort(); } bool EditorProperty::is_checkable() const { - return checkable; } void EditorProperty::set_checked(bool p_checked) { - checked = p_checked; update(); } bool EditorProperty::is_checked() const { - return checked; } void EditorProperty::set_draw_red(bool p_draw_red) { - draw_red = p_draw_red; update(); } @@ -600,14 +593,13 @@ bool EditorProperty::is_keying() const { } bool EditorProperty::is_draw_red() const { - return draw_red; } void EditorProperty::_focusable_focused(int p_index) { - - if (!selectable) + if (!selectable) { return; + } bool already_selected = selected; selected = true; selected_focusable = p_index; @@ -618,13 +610,11 @@ void EditorProperty::_focusable_focused(int p_index) { } void EditorProperty::add_focusable(Control *p_control) { - p_control->connect("focus_entered", callable_mp(this, &EditorProperty::_focusable_focused), varray(focusables.size())); focusables.push_back(p_control); } void EditorProperty::select(int p_focusable) { - bool already_selected = selected; if (p_focusable >= 0) { @@ -651,14 +641,13 @@ bool EditorProperty::is_selected() const { } void EditorProperty::_gui_input(const Ref<InputEvent> &p_event) { - - if (property == StringName()) + if (property == StringName()) { return; + } Ref<InputEventMouse> me = p_event; if (me.is_valid()) { - bool button_left = me->get_button_mask() & BUTTON_MASK_LEFT; bool new_keying_hover = keying_rect.has_point(me->get_position()) && !button_left; @@ -689,7 +678,6 @@ void EditorProperty::_gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventMouseButton> mb = p_event; if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { - if (!selected && selectable) { selected = true; emit_signal("selected", property, -1); @@ -721,12 +709,10 @@ void EditorProperty::_gui_input(const Ref<InputEvent> &p_event) { } if (revert_rect.has_point(mb->get_position())) { - Variant vorig; Node *node = Object::cast_to<Node>(object); if (node && EditorPropertyRevert::may_node_be_in_instance(node) && EditorPropertyRevert::get_instanced_node_original_property(node, property, vorig)) { - emit_changed(property, vorig.duplicate(true)); update_property(); return; @@ -767,17 +753,17 @@ void EditorProperty::_gui_input(const Ref<InputEvent> &p_event) { } void EditorProperty::set_label_reference(Control *p_control) { - label_reference = p_control; } -void EditorProperty::set_bottom_editor(Control *p_control) { +void EditorProperty::set_bottom_editor(Control *p_control) { bottom_editor = p_control; } -Variant EditorProperty::get_drag_data(const Point2 &p_point) { - if (property == StringName()) +Variant EditorProperty::get_drag_data(const Point2 &p_point) { + if (property == StringName()) { return Variant(); + } Dictionary dp; dp["type"] = "obj_property"; @@ -792,12 +778,10 @@ Variant EditorProperty::get_drag_data(const Point2 &p_point) { } void EditorProperty::set_use_folding(bool p_use_folding) { - use_folding = p_use_folding; } bool EditorProperty::is_using_folding() const { - return use_folding; } @@ -820,7 +804,6 @@ void EditorProperty::set_name_split_ratio(float p_ratio) { } float EditorProperty::get_name_split_ratio() const { - return split_ratio; } @@ -830,7 +813,6 @@ void EditorProperty::set_object_and_property(Object *p_object, const StringName } Control *EditorProperty::make_custom_tooltip(const String &p_text) const { - tooltip_text = p_text; EditorHelpBit *help_bit = memnew(EditorHelpBit); //help_bit->add_theme_style_override("panel", get_theme_stylebox("panel", "TooltipPanel")); @@ -859,7 +841,6 @@ String EditorProperty::get_tooltip_text() const { } void EditorProperty::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_label", "text"), &EditorProperty::set_label); ClassDB::bind_method(D_METHOD("get_label"), &EditorProperty::get_label); @@ -916,7 +897,6 @@ void EditorProperty::_bind_methods() { } EditorProperty::EditorProperty() { - draw_top_bg = true; object = nullptr; split_ratio = 0.5; @@ -939,18 +919,17 @@ EditorProperty::EditorProperty() { label_reference = nullptr; bottom_editor = nullptr; } + //////////////////////////////////////////////// //////////////////////////////////////////////// void EditorInspectorPlugin::add_custom_control(Control *control) { - AddedEditor ae; ae.property_editor = control; added_editors.push_back(ae); } void EditorInspectorPlugin::add_property_editor(const String &p_for_property, Control *p_prop) { - ERR_FAIL_COND(Object::cast_to<EditorProperty>(p_prop) == nullptr); AddedEditor ae; @@ -960,7 +939,6 @@ void EditorInspectorPlugin::add_property_editor(const String &p_for_property, Co } void EditorInspectorPlugin::add_property_editor_for_multiple_properties(const String &p_label, const Vector<String> &p_properties, Control *p_prop) { - AddedEditor ae; ae.properties = p_properties; ae.property_editor = p_prop; @@ -969,28 +947,25 @@ void EditorInspectorPlugin::add_property_editor_for_multiple_properties(const St } bool EditorInspectorPlugin::can_handle(Object *p_object) { - if (get_script_instance()) { return get_script_instance()->call("can_handle", p_object); } return false; } -void EditorInspectorPlugin::parse_begin(Object *p_object) { +void EditorInspectorPlugin::parse_begin(Object *p_object) { if (get_script_instance()) { get_script_instance()->call("parse_begin", p_object); } } void EditorInspectorPlugin::parse_category(Object *p_object, const String &p_parse_category) { - if (get_script_instance()) { get_script_instance()->call("parse_category", p_object, p_parse_category); } } bool EditorInspectorPlugin::parse_property(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage, bool p_wide) { - if (get_script_instance()) { Variant arg[6] = { p_object, p_type, p_path, p_hint, p_hint_text, p_usage @@ -1004,15 +979,14 @@ bool EditorInspectorPlugin::parse_property(Object *p_object, Variant::Type p_typ } return false; } -void EditorInspectorPlugin::parse_end() { +void EditorInspectorPlugin::parse_end() { if (get_script_instance()) { get_script_instance()->call("parse_end"); } } void EditorInspectorPlugin::_bind_methods() { - ClassDB::bind_method(D_METHOD("add_custom_control", "control"), &EditorInspectorPlugin::add_custom_control); ClassDB::bind_method(D_METHOD("add_property_editor", "property", "editor"), &EditorInspectorPlugin::add_property_editor); ClassDB::bind_method(D_METHOD("add_property_editor_for_multiple_properties", "label", "properties", "editor"), &EditorInspectorPlugin::add_property_editor_for_multiple_properties); @@ -1047,9 +1021,7 @@ void EditorInspectorPlugin::_bind_methods() { //////////////////////////////////////////////// void EditorInspectorCategory::_notification(int p_what) { - if (p_what == NOTIFICATION_DRAW) { - draw_rect(Rect2(Vector2(), get_size()), bg_color); Ref<Font> font = get_theme_font("font", "Tree"); @@ -1073,7 +1045,6 @@ void EditorInspectorCategory::_notification(int p_what) { } Control *EditorInspectorCategory::make_custom_tooltip(const String &p_text) const { - tooltip_text = p_text; EditorHelpBit *help_bit = memnew(EditorHelpBit); help_bit->add_theme_style_override("panel", get_theme_stylebox("panel", "TooltipPanel")); @@ -1097,7 +1068,6 @@ Control *EditorInspectorCategory::make_custom_tooltip(const String &p_text) cons } Size2 EditorInspectorCategory::get_minimum_size() const { - Ref<Font> font = get_theme_font("font", "Tree"); Size2 ms; @@ -1116,7 +1086,6 @@ void EditorInspectorCategory::_bind_methods() { } String EditorInspectorCategory::get_tooltip_text() const { - return tooltip_text; } @@ -1127,7 +1096,6 @@ EditorInspectorCategory::EditorInspectorCategory() { //////////////////////////////////////////////// void EditorInspectorSection::_test_unfold() { - if (!vbox_added) { add_child(vbox); vbox_added = true; @@ -1135,9 +1103,7 @@ void EditorInspectorSection::_test_unfold() { } void EditorInspectorSection::_notification(int p_what) { - if (p_what == NOTIFICATION_SORT_CHILDREN) { - Ref<Font> font = get_theme_font("font", "Tree"); Ref<Texture2D> arrow; @@ -1163,14 +1129,16 @@ void EditorInspectorSection::_notification(int p_what) { //set children for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to<Control>(get_child(i)); - if (!c) + if (!c) { continue; - if (c->is_set_as_toplevel()) + } + if (c->is_set_as_toplevel()) { continue; - if (!c->is_visible_in_tree()) + } + if (!c->is_visible_in_tree()) { continue; + } fit_child_in_rect(c, rect); } @@ -1179,7 +1147,6 @@ void EditorInspectorSection::_notification(int p_what) { } if (p_what == NOTIFICATION_DRAW) { - Ref<Texture2D> arrow; if (foldable) { @@ -1211,17 +1178,18 @@ void EditorInspectorSection::_notification(int p_what) { } Size2 EditorInspectorSection::get_minimum_size() const { - Size2 ms; for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to<Control>(get_child(i)); - if (!c) + if (!c) { continue; - if (c->is_set_as_toplevel()) + } + if (c->is_set_as_toplevel()) { continue; - if (!c->is_visible()) + } + if (!c->is_visible()) { continue; + } Size2 minsize = c->get_combined_minimum_size(); ms.width = MAX(ms.width, minsize.width); ms.height = MAX(ms.height, minsize.height); @@ -1235,7 +1203,6 @@ Size2 EditorInspectorSection::get_minimum_size() const { } void EditorInspectorSection::setup(const String &p_section, const String &p_label, Object *p_object, const Color &p_bg_color, bool p_foldable) { - section = p_section; label = p_label; object = p_object; @@ -1258,13 +1225,12 @@ void EditorInspectorSection::setup(const String &p_section, const String &p_labe } void EditorInspectorSection::_gui_input(const Ref<InputEvent> &p_event) { - - if (!foldable) + if (!foldable) { return; + } Ref<InputEventMouseButton> mb = p_event; if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { - Ref<Font> font = get_theme_font("font", "Tree"); if (mb->get_position().y > font->get_height()) { //clicked outside return; @@ -1287,9 +1253,9 @@ VBoxContainer *EditorInspectorSection::get_vbox() { } void EditorInspectorSection::unfold() { - - if (!foldable) + if (!foldable) { return; + } _test_unfold(); @@ -1299,11 +1265,13 @@ void EditorInspectorSection::unfold() { } void EditorInspectorSection::fold() { - if (!foldable) + if (!foldable) { return; + } - if (!vbox_added) + if (!vbox_added) { return; //kinda pointless + } object->editor_set_section_unfold(section, false); vbox->hide(); @@ -1311,7 +1279,6 @@ void EditorInspectorSection::fold() { } void EditorInspectorSection::_bind_methods() { - ClassDB::bind_method(D_METHOD("setup", "section", "label", "object", "bg_color", "foldable"), &EditorInspectorSection::setup); ClassDB::bind_method(D_METHOD("get_vbox"), &EditorInspectorSection::get_vbox); ClassDB::bind_method(D_METHOD("unfold"), &EditorInspectorSection::unfold); @@ -1327,7 +1294,6 @@ EditorInspectorSection::EditorInspectorSection() { } EditorInspectorSection::~EditorInspectorSection() { - if (!vbox_added) { memdelete(vbox); } @@ -1340,9 +1306,7 @@ Ref<EditorInspectorPlugin> EditorInspector::inspector_plugins[MAX_PLUGINS]; int EditorInspector::inspector_plugin_count = 0; EditorProperty *EditorInspector::instantiate_property_editor(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage, bool p_wide) { - for (int i = inspector_plugin_count - 1; i >= 0; i--) { - inspector_plugins[i]->parse_property(p_object, p_type, p_path, p_hint, p_hint_text, p_usage, p_wide); if (inspector_plugins[i]->added_editors.size()) { for (int j = 1; j < inspector_plugins[i]->added_editors.size(); j++) { //only keep first one @@ -1351,7 +1315,6 @@ EditorProperty *EditorInspector::instantiate_property_editor(Object *p_object, V EditorProperty *prop = Object::cast_to<EditorProperty>(inspector_plugins[i]->added_editors[0].property_editor); if (prop) { - inspector_plugins[i]->added_editors.clear(); return prop; } else { @@ -1364,18 +1327,17 @@ EditorProperty *EditorInspector::instantiate_property_editor(Object *p_object, V } void EditorInspector::add_inspector_plugin(const Ref<EditorInspectorPlugin> &p_plugin) { - ERR_FAIL_COND(inspector_plugin_count == MAX_PLUGINS); for (int i = 0; i < inspector_plugin_count; i++) { - if (inspector_plugins[i] == p_plugin) + if (inspector_plugins[i] == p_plugin) { return; //already exists + } } inspector_plugins[inspector_plugin_count++] = p_plugin; } void EditorInspector::remove_inspector_plugin(const Ref<EditorInspectorPlugin> &p_plugin) { - ERR_FAIL_COND(inspector_plugin_count == MAX_PLUGINS); int idx = -1; @@ -1391,8 +1353,9 @@ void EditorInspector::remove_inspector_plugin(const Ref<EditorInspectorPlugin> & inspector_plugins[i] = inspector_plugins[i + 1]; } - if (idx == inspector_plugin_count - 1) + if (idx == inspector_plugin_count - 1) { inspector_plugins[idx] = Ref<EditorInspectorPlugin>(); + } inspector_plugin_count--; } @@ -1409,19 +1372,15 @@ void EditorInspector::set_undo_redo(UndoRedo *p_undo_redo) { } String EditorInspector::get_selected_path() const { - return property_selected; } void EditorInspector::_parse_added_editors(VBoxContainer *current_vbox, Ref<EditorInspectorPlugin> ped) { - for (List<EditorInspectorPlugin::AddedEditor>::Element *F = ped->added_editors.front(); F; F = F->next()) { - EditorProperty *ep = Object::cast_to<EditorProperty>(F->get().property_editor); current_vbox->add_child(F->get().property_editor); if (ep) { - ep->object = object; ep->connect("property_changed", callable_mp(this, &EditorInspector::_property_changed)); ep->connect("property_keyed", callable_mp(this, &EditorInspector::_property_keyed)); @@ -1434,7 +1393,6 @@ void EditorInspector::_parse_added_editors(VBoxContainer *current_vbox, Ref<Edit ep->connect("object_id_selected", callable_mp(this, &EditorInspector::_object_id_selected), varray(), CONNECT_DEFERRED); if (F->get().properties.size()) { - if (F->get().properties.size() == 1) { //since it's one, associate: ep->property = F->get().properties[0]; @@ -1465,7 +1423,6 @@ void EditorInspector::_parse_added_editors(VBoxContainer *current_vbox, Ref<Edit } bool EditorInspector::_is_property_disabled_by_feature_profile(const StringName &p_property) { - Ref<EditorFeatureProfile> profile = EditorFeatureProfileManager::get_singleton()->get_current_profile(); if (profile.is_null()) { return false; @@ -1474,7 +1431,6 @@ bool EditorInspector::_is_property_disabled_by_feature_profile(const StringName StringName class_name = object->get_class(); while (class_name != StringName()) { - if (profile->is_class_property_disabled(class_name, p_property)) { return true; } @@ -1489,7 +1445,6 @@ bool EditorInspector::_is_property_disabled_by_feature_profile(const StringName } void EditorInspector::update_tree() { - //to update properly if all is refreshed StringName current_selected = property_selected; int current_focusable = -1; @@ -1517,14 +1472,16 @@ void EditorInspector::update_tree() { _clear(); - if (!object) + if (!object) { return; + } List<Ref<EditorInspectorPlugin>> valid_plugins; for (int i = inspector_plugin_count - 1; i >= 0; i--) { //start by last, so lastly added can override newly added - if (!inspector_plugins[i]->can_handle(object)) + if (!inspector_plugins[i]->can_handle(object)) { continue; + } valid_plugins.push_back(inspector_plugins[i]); } @@ -1565,20 +1522,17 @@ void EditorInspector::update_tree() { } for (List<PropertyInfo>::Element *I = plist.front(); I; I = I->next()) { - PropertyInfo &p = I->get(); //make sure the property can be edited if (p.usage & PROPERTY_USAGE_SUBGROUP) { - subgroup = p.name; subgroup_base = p.hint_string; continue; } else if (p.usage & PROPERTY_USAGE_GROUP) { - group = p.name; group_base = p.hint_string; subgroup = ""; @@ -1587,29 +1541,31 @@ void EditorInspector::update_tree() { continue; } else if (p.usage & PROPERTY_USAGE_CATEGORY) { - group = ""; group_base = ""; subgroup = ""; subgroup_base = ""; - if (!show_categories) + if (!show_categories) { continue; + } List<PropertyInfo>::Element *N = I->next(); bool valid = true; //if no properties in category, skip while (N) { - if (N->get().usage & PROPERTY_USAGE_EDITOR) + if (N->get().usage & PROPERTY_USAGE_EDITOR) { break; + } if (N->get().usage & PROPERTY_USAGE_CATEGORY) { valid = false; break; } N = N->next(); } - if (!valid) + if (!valid) { continue; //empty, ignore + } EditorInspectorCategory *category = memnew(EditorInspectorCategory); main_vbox->add_child(category); @@ -1623,7 +1579,6 @@ void EditorInspector::update_tree() { if (use_doc_hints) { StringName type2 = p.name; if (!class_descr_cache.has(type2)) { - String descr; DocData *dd = EditorHelp::get_doc_data(); Map<String, DocData::ClassDoc>::Element *E = dd->class_list.find(type2); @@ -1644,11 +1599,13 @@ void EditorInspector::update_tree() { continue; - } else if (!(p.usage & PROPERTY_USAGE_EDITOR) || _is_property_disabled_by_feature_profile(p.name)) + } else if (!(p.usage & PROPERTY_USAGE_EDITOR) || _is_property_disabled_by_feature_profile(p.name)) { continue; + } - if (p.usage & PROPERTY_USAGE_HIGH_END_GFX && RS::get_singleton()->is_low_end()) + if (p.usage & PROPERTY_USAGE_HIGH_END_GFX && RS::get_singleton()->is_low_end()) { continue; //do not show this property in low end gfx + } if (p.name == "script" && (hide_script || bool(object->call("_hide_script_from_inspector")))) { continue; @@ -1704,14 +1661,15 @@ void EditorInspector::update_tree() { String path = basename.left(basename.find_last("/")); if (use_filter && filter != "") { - String cat = path; - if (capitalize_paths) + if (capitalize_paths) { cat = cat.capitalize(); + } - if (!filter.is_subsequence_ofi(cat) && !filter.is_subsequence_ofi(name) && property_prefix.to_lower().find(filter.to_lower()) == -1) + if (!filter.is_subsequence_ofi(cat) && !filter.is_subsequence_ofi(name) && property_prefix.to_lower().find(filter.to_lower()) == -1) { continue; + } } if (category_vbox == nullptr) { @@ -1722,21 +1680,22 @@ void EditorInspector::update_tree() { VBoxContainer *current_vbox = main_vbox; { - String acc_path = ""; int level = 1; for (int i = 0; i < path.get_slice_count("/"); i++) { String path_name = path.get_slice("/", i); - if (i > 0) + if (i > 0) { acc_path += "/"; + } acc_path += path_name; if (!item_path.has(acc_path)) { EditorInspectorSection *section = memnew(EditorInspectorSection); current_vbox->add_child(section); sections.push_back(section); - if (capitalize_paths) + if (capitalize_paths) { path_name = path_name.capitalize(); + } Color c = sscolor; c.a /= level; @@ -1773,7 +1732,6 @@ void EditorInspector::update_tree() { String doc_hint; if (use_doc_hints) { - StringName classname = object->get_class_name(); if (object_class != String()) { classname = object_class; @@ -1833,7 +1791,6 @@ void EditorInspector::update_tree() { ped->added_editors.clear(); for (List<EditorInspectorPlugin::AddedEditor>::Element *F = editors.front(); F; F = F->next()) { - EditorProperty *ep = Object::cast_to<EditorProperty>(F->get().property_editor); if (ep) { @@ -1841,7 +1798,6 @@ void EditorInspector::update_tree() { ep->object = object; if (F->get().properties.size()) { - if (F->get().properties.size() == 1) { //since it's one, associate: ep->property = F->get().properties[0]; @@ -1877,7 +1833,6 @@ void EditorInspector::update_tree() { current_vbox->add_child(F->get().property_editor); if (ep) { - ep->connect("property_changed", callable_mp(this, &EditorInspector::_property_changed)); if (p.usage & PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED) { ep->connect("property_changed", callable_mp(this, &EditorInspector::_property_changed_update_all), varray(), CONNECT_DEFERRED); @@ -1918,9 +1873,11 @@ void EditorInspector::update_tree() { //see if this property exists and should be kept } + void EditorInspector::update_property(const String &p_prop) { - if (!editor_property_map.has(p_prop)) + if (!editor_property_map.has(p_prop)) { return; + } for (List<EditorProperty *>::Element *E = editor_property_map[p_prop].front(); E; E = E->next()) { E->get()->update_property(); @@ -1929,7 +1886,6 @@ void EditorInspector::update_property(const String &p_prop) { } void EditorInspector::_clear() { - while (main_vbox->get_child_count()) { memdelete(main_vbox->get_child(0)); } @@ -1942,9 +1898,9 @@ void EditorInspector::_clear() { } void EditorInspector::refresh() { - - if (refresh_countdown > 0 || changing) + if (refresh_countdown > 0 || changing) { return; + } refresh_countdown = EditorSettings::get_singleton()->get("docks/property_editor/auto_refresh_interval"); } @@ -1953,10 +1909,10 @@ Object *EditorInspector::get_edited_object() { } void EditorInspector::edit(Object *p_object) { - if (object == p_object) + if (object == p_object) { return; + } if (object) { - _clear(); object->remove_change_receptor(this); } @@ -1974,20 +1930,22 @@ void EditorInspector::edit(Object *p_object) { } void EditorInspector::set_keying(bool p_active) { - if (keying == p_active) + if (keying == p_active) { return; + } keying = p_active; update_tree(); } + void EditorInspector::set_read_only(bool p_read_only) { read_only = p_read_only; update_tree(); } bool EditorInspector::is_capitalize_paths_enabled() const { - return capitalize_paths; } + void EditorInspector::set_enable_capitalize_paths(bool p_capitalize) { capitalize_paths = p_capitalize; update_tree(); @@ -2006,22 +1964,25 @@ void EditorInspector::set_use_doc_hints(bool p_enable) { use_doc_hints = p_enable; update_tree(); } + void EditorInspector::set_hide_script(bool p_hide) { hide_script = p_hide; update_tree(); } + void EditorInspector::set_use_filter(bool p_use) { use_filter = p_use; update_tree(); } + void EditorInspector::register_text_enter(Node *p_line_edit) { search_box = Object::cast_to<LineEdit>(p_line_edit); - if (search_box) + if (search_box) { search_box->connect("text_changed", callable_mp(this, &EditorInspector::_filter_changed)); + } } void EditorInspector::_filter_changed(const String &p_text) { - _clear(); update_tree(); } @@ -2036,7 +1997,6 @@ bool EditorInspector::is_using_folding() { } void EditorInspector::collapse_all_folding() { - for (List<EditorInspectorSection *>::Element *E = sections.front(); E; E = E->next()) { E->get()->fold(); } @@ -2072,10 +2032,10 @@ void EditorInspector::set_use_wide_editors(bool p_enable) { } void EditorInspector::set_sub_inspector(bool p_enable) { - sub_inspector = p_enable; - if (!is_inside_tree()) + if (!is_inside_tree()) { return; + } if (sub_inspector) { add_theme_style_override("bg", get_theme_stylebox("sub_inspector_bg", "Editor")); @@ -2089,22 +2049,22 @@ void EditorInspector::set_use_deletable_properties(bool p_enabled) { } void EditorInspector::_edit_request_change(Object *p_object, const String &p_property) { - - if (object != p_object) //may be undoing/redoing for a non edited object, so ignore + if (object != p_object) { //may be undoing/redoing for a non edited object, so ignore return; + } - if (changing) + if (changing) { return; + } - if (p_property == String()) + if (p_property == String()) { update_tree_pending = true; - else { + } else { pending.insert(p_property); } } void EditorInspector::_edit_set(const String &p_name, const Variant &p_value, bool p_refresh_all, const String &p_changed_field) { - if (autoclear && editor_property_map.has(p_name)) { for (List<EditorProperty *>::Element *E = editor_property_map[p_name].front(); E; E = E->next()) { if (E->get()->is_checkable()) { @@ -2114,22 +2074,20 @@ void EditorInspector::_edit_set(const String &p_name, const Variant &p_value, bo } if (!undo_redo || bool(object->call("_dont_undo_redo"))) { - object->set(p_name, p_value); - if (p_refresh_all) + if (p_refresh_all) { _edit_request_change(object, ""); - else + } else { _edit_request_change(object, p_name); + } emit_signal(_prop_edited, p_name); } else if (Object::cast_to<MultiNodeEdit>(object)) { - Object::cast_to<MultiNodeEdit>(object)->set_property_field(p_name, p_value, p_changed_field); _edit_request_change(object, p_name); emit_signal(_prop_edited, p_name); } else { - undo_redo->create_action(TTR("Set") + " " + p_name, UndoRedo::MERGE_ENDS); undo_redo->add_do_property(object, p_name, p_value); undo_redo->add_undo_property(object, p_name, object->get(p_name)); @@ -2138,14 +2096,12 @@ void EditorInspector::_edit_set(const String &p_name, const Variant &p_value, bo undo_redo->add_do_method(this, "_edit_request_change", object, ""); undo_redo->add_undo_method(this, "_edit_request_change", object, ""); } else { - undo_redo->add_do_method(this, "_edit_request_change", object, p_name); undo_redo->add_undo_method(this, "_edit_request_change", object, p_name); } Resource *r = Object::cast_to<Resource>(object); if (r) { - if (String(p_name) == "resource_local_to_scene") { bool prev = object->get(p_name); bool next = p_value; @@ -2170,16 +2126,17 @@ void EditorInspector::_edit_set(const String &p_name, const Variant &p_value, bo } void EditorInspector::_property_changed(const String &p_path, const Variant &p_value, const String &p_name, bool p_changing) { - // The "changing" variable must be true for properties that trigger events as typing occurs, // like "text_changed" signal. E.g. text property of Label, Button, RichTextLabel, etc. - if (p_changing) + if (p_changing) { this->changing++; + } _edit_set(p_path, p_value, false, p_name); - if (p_changing) + if (p_changing) { this->changing--; + } if (restart_request_props.has(p_path)) { emit_signal("restart_requested"); @@ -2191,13 +2148,13 @@ void EditorInspector::_property_changed_update_all(const String &p_path, const V } void EditorInspector::_multiple_properties_changed(Vector<String> p_paths, Array p_values) { - ERR_FAIL_COND(p_paths.size() == 0 || p_values.size() == 0); ERR_FAIL_COND(p_paths.size() != p_values.size()); String names; for (int i = 0; i < p_paths.size(); i++) { - if (i > 0) + if (i > 0) { names += ","; + } names += p_paths[i]; } undo_redo->create_action(TTR("Set Multiple:") + " " + names, UndoRedo::MERGE_ENDS); @@ -2213,42 +2170,40 @@ void EditorInspector::_multiple_properties_changed(Vector<String> p_paths, Array } void EditorInspector::_property_keyed(const String &p_path, bool p_advance) { - - if (!object) + if (!object) { return; + } emit_signal("property_keyed", p_path, object->get(p_path), p_advance); //second param is deprecated } void EditorInspector::_property_deleted(const String &p_path) { - print_line("deleted pressed?"); - if (!object) + if (!object) { return; + } emit_signal("property_deleted", p_path); //second param is deprecated } void EditorInspector::_property_keyed_with_value(const String &p_path, const Variant &p_value, bool p_advance) { - - if (!object) + if (!object) { return; + } emit_signal("property_keyed", p_path, p_value, p_advance); //second param is deprecated } void EditorInspector::_property_checked(const String &p_path, bool p_checked) { - - if (!object) + if (!object) { return; + } //property checked if (autoclear) { - if (!p_checked) { object->set(p_path, Variant()); } else { - Variant to_create; List<PropertyInfo> pinfo; object->get_property_list(&pinfo); @@ -2275,16 +2230,17 @@ void EditorInspector::_property_checked(const String &p_path, bool p_checked) { } void EditorInspector::_property_selected(const String &p_path, int p_focusable) { - property_selected = p_path; property_focusable = p_focusable; //deselect the others for (Map<StringName, List<EditorProperty *>>::Element *F = editor_property_map.front(); F; F = F->next()) { - if (F->key() == property_selected) + if (F->key() == property_selected) { continue; + } for (List<EditorProperty *>::Element *E = F->get().front(); E; E = E->next()) { - if (E->get()->is_selected()) + if (E->get()->is_selected()) { E->get()->deselect(); + } } } @@ -2292,7 +2248,6 @@ void EditorInspector::_property_selected(const String &p_path, int p_focusable) } void EditorInspector::_object_id_selected(const String &p_path, ObjectID p_id) { - emit_signal("object_id_selected", p_id); } @@ -2301,20 +2256,17 @@ void EditorInspector::_resource_selected(const String &p_path, RES p_resource) { } void EditorInspector::_node_removed(Node *p_node) { - if (p_node == object) { edit(nullptr); } } void EditorInspector::_notification(int p_what) { - if (p_what == NOTIFICATION_READY) { EditorFeatureProfileManager::get_singleton()->connect("current_feature_profile_changed", callable_mp(this, &EditorInspector::_feature_profile_changed)); } if (p_what == NOTIFICATION_ENTER_TREE) { - if (sub_inspector) { add_theme_style_override("bg", get_theme_stylebox("sub_inspector_bg", "Editor")); } else { @@ -2326,7 +2278,6 @@ void EditorInspector::_notification(int p_what) { edit(nullptr); //just in case } if (p_what == NOTIFICATION_EXIT_TREE) { - if (!sub_inspector) { get_tree()->disconnect("node_removed", callable_mp(this, &EditorInspector::_node_removed)); } @@ -2334,7 +2285,6 @@ void EditorInspector::_notification(int p_what) { } if (p_what == NOTIFICATION_PROCESS) { - if (update_scroll_request >= 0) { get_v_scrollbar()->call_deferred("set_value", update_scroll_request); update_scroll_request = -1; @@ -2354,13 +2304,11 @@ void EditorInspector::_notification(int p_what) { changing++; if (update_tree_pending) { - update_tree(); update_tree_pending = false; pending.clear(); } else { - while (pending.size()) { StringName prop = pending.front()->get(); if (editor_property_map.has(prop)) { @@ -2377,7 +2325,6 @@ void EditorInspector::_notification(int p_what) { } if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) { - if (sub_inspector) { add_theme_style_override("bg", get_theme_stylebox("sub_inspector_bg", "Editor")); } else if (is_inside_tree()) { @@ -2394,9 +2341,9 @@ void EditorInspector::_changed_callback(Object *p_changed, const char *p_prop) { } void EditorInspector::_vscroll_changed(double p_offset) { - - if (update_scroll_request >= 0) //waiting, do nothing + if (update_scroll_request >= 0) { //waiting, do nothing return; + } if (object) { scroll_cache[object->get_instance_id()] = p_offset; @@ -2420,12 +2367,10 @@ String EditorInspector::get_object_class() const { } void EditorInspector::_feature_profile_changed() { - update_tree(); } void EditorInspector::_bind_methods() { - ClassDB::bind_method("_edit_request_change", &EditorInspector::_edit_request_change); ClassDB::bind_method("refresh", &EditorInspector::refresh); |