diff options
Diffstat (limited to 'editor/editor_inspector.cpp')
-rw-r--r-- | editor/editor_inspector.cpp | 123 |
1 files changed, 86 insertions, 37 deletions
diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 3ecaa2b136..a564a2a113 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -374,14 +374,24 @@ bool EditorProperty::_get_instanced_node_original_property(const StringName &p_p node = node->get_owner(); } + if (!found) { + //if not found, try default class value + Variant attempt = ClassDB::class_get_default_property_value(object->get_class_name(), property); + if (attempt.get_type() != Variant::NIL) { + found = true; + value = attempt; + } + } + return found; } -bool EditorProperty::_is_property_different(const Variant &p_current, const Variant &p_orig, int p_usage) { +bool EditorProperty::_is_property_different(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 = Object::cast_to<Node>(object); if (!node) @@ -415,15 +425,6 @@ bool EditorProperty::_is_property_different(const Variant &p_current, const Vari return false; //pointless to check if we are not comparing against anything. } - if (p_orig.get_type() == Variant::NIL) { - // not found (was not saved) - // check if it was not saved due to being zero or one - if (p_current.is_zero() && property_usage & PROPERTY_USAGE_STORE_IF_NONZERO) - return false; - if (p_current.is_one() && property_usage & PROPERTY_USAGE_STORE_IF_NONONE) - return false; - } - if (p_current.get_type() == Variant::REAL && p_orig.get_type() == Variant::REAL) { float a = p_current; float b = p_orig; @@ -434,23 +435,6 @@ bool EditorProperty::_is_property_different(const Variant &p_current, const Vari return bool(Variant::evaluate(Variant::OP_NOT_EQUAL, p_current, p_orig)); } -bool EditorProperty::_is_instanced_node_with_original_property_different() { - - bool mbi = _might_be_in_instance(); - if (mbi) { - Variant vorig; - int usage = property_usage & (PROPERTY_USAGE_STORE_IF_NONONE | PROPERTY_USAGE_STORE_IF_NONZERO); - if (_get_instanced_node_original_property(property, vorig) || usage) { - Variant v = object->get(property); - - if (_is_property_different(v, vorig, usage)) { - return true; - } - } - } - return false; -} - void EditorProperty::update_reload_status() { if (property == StringName()) @@ -458,8 +442,22 @@ void EditorProperty::update_reload_status() { bool has_reload = false; - if (_is_instanced_node_with_original_property_different()) { - has_reload = true; + if (_might_be_in_instance()) { + //check for difference including instantiation + Variant vorig; + if (_get_instanced_node_original_property(property, vorig)) { + Variant v = object->get(property); + + if (_is_property_different(v, vorig)) { + has_reload = true; + } + } + } else { + //check for difference against default class value instead + Variant default_value = ClassDB::class_get_default_property_value(object->get_class_name(), property); + if (default_value != Variant() && default_value != object->get(property)) { + has_reload = true; + } } if (object->call("property_can_revert", property).operator bool()) { @@ -628,7 +626,7 @@ void EditorProperty::_gui_input(const Ref<InputEvent> &p_event) { } if (keying_rect.has_point(mb->get_position())) { - emit_signal("property_keyed", property); + emit_signal("property_keyed", property, use_keying_next()); if (use_keying_next()) { call_deferred("emit_signal", "property_changed", property, object->get(property).operator int64_t() + 1); @@ -651,6 +649,7 @@ void EditorProperty::_gui_input(const Ref<InputEvent> &p_event) { Variant rev = object->call("property_get_revert", property); emit_signal("property_changed", property, rev); update_property(); + return; } if (!object->get_script().is_null()) { @@ -659,8 +658,16 @@ void EditorProperty::_gui_input(const Ref<InputEvent> &p_event) { if (scr->get_property_default_value(property, orig_value)) { emit_signal("property_changed", property, orig_value); update_property(); + return; } } + + Variant default_value = ClassDB::class_get_default_property_value(object->get_class_name(), property); + if (default_value != Variant()) { + emit_signal("property_changed", property, default_value); + update_property(); + return; + } } if (check_rect.has_point(mb->get_position())) { checked = !checked; @@ -1082,10 +1089,8 @@ void EditorInspectorSection::_notification(int p_what) { Color color = get_color("font_color", "Tree"); draw_string(font, Point2(hs, font->get_ascent() + (h - font->get_height()) / 2).floor(), label, color, get_size().width); - int ofs = 0; if (arrow.is_valid()) { draw_texture(arrow, Point2(get_size().width - arrow->get_width(), (h - arrow->get_height()) / 2).floor()); - ofs += hs + arrow->get_width(); } } } @@ -1148,6 +1153,11 @@ void EditorInspectorSection::_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) { + Ref<Font> font = get_font("font", "Tree"); + if (mb->get_position().y > font->get_height()) { //clicked outside + return; + } + _test_unfold(); bool unfold = !object->editor_is_section_unfolded(section); @@ -1370,6 +1380,28 @@ void EditorInspector::update_tree() { // TreeItem *current_category = NULL; + bool unfold_if_edited = false; + + if (use_folding && auto_unfold_edited && get_tree()->get_edited_scene_root()) { + String path; + Node *node = Object::cast_to<Node>(object); + if (node) { + path = get_tree()->get_edited_scene_root()->get_filename(); + } + Resource *res = Object::cast_to<Resource>(object); + if (res) { + if (res->get_path().is_resource_file()) { + path = res->get_path(); + } else if (res->get_path().begins_with("res://")) { //internal resource + path = get_tree()->get_edited_scene_root()->get_filename(); + } + } + + if (!EditorNode::get_singleton()->get_editor_folding().has_folding_data(path)) { + unfold_if_edited = true; + } + } + String filter = search_box ? search_box->get_text() : ""; String group; String group_base; @@ -1380,6 +1412,8 @@ void EditorInspector::update_tree() { object->get_property_list(&plist, true); HashMap<String, VBoxContainer *> item_path; + Map<VBoxContainer *, EditorInspectorSection *> section_map; + item_path[""] = main_vbox; Color sscolor = get_color("prop_subsection", "Editor"); @@ -1542,7 +1576,9 @@ void EditorInspector::update_tree() { c.a /= level; section->setup(acc_path, path_name, object, c, use_folding); - item_path[acc_path] = section->get_vbox(); + VBoxContainer *vb = section->get_vbox(); + item_path[acc_path] = vb; + section_map[vb] = section; } current_vbox = item_path[acc_path]; level = (MIN(level + 1, 4)); @@ -1685,6 +1721,13 @@ void EditorInspector::update_tree() { if (current_selected && ep->property == current_selected) { ep->select(current_focusable); } + + if (unfold_if_edited && ep->can_revert_to_default()) { + //if edited and there is a parent section, unfold it. + if (current_vbox && section_map.has(current_vbox)) { + section_map[current_vbox]->unfold(); + } + } } } @@ -1992,20 +2035,20 @@ void EditorInspector::_multiple_properties_changed(Vector<String> p_paths, Array changing--; } -void EditorInspector::_property_keyed(const String &p_path) { +void EditorInspector::_property_keyed(const String &p_path, bool p_advance) { if (!object) return; - emit_signal("property_keyed", p_path, object->get(p_path), true); //second param is deprecated + emit_signal("property_keyed", p_path, object->get(p_path), p_advance); //second param is deprecated } -void EditorInspector::_property_keyed_with_value(const String &p_path, const Variant &p_value) { +void EditorInspector::_property_keyed_with_value(const String &p_path, const Variant &p_value, bool p_advance) { if (!object) return; - emit_signal("property_keyed", p_path, p_value, false); //second param is deprecated + 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) { @@ -2181,6 +2224,10 @@ String EditorInspector::get_object_class() const { return object_class; } +void EditorInspector::set_auto_unfold_edited(bool p_enable) { + auto_unfold_edited = p_enable; +} + void EditorInspector::_bind_methods() { ClassDB::bind_method("_property_changed", &EditorInspector::_property_changed, DEFVAL(false)); @@ -2205,6 +2252,7 @@ void EditorInspector::_bind_methods() { ADD_SIGNAL(MethodInfo("resource_selected", PropertyInfo(Variant::OBJECT, "res"), PropertyInfo(Variant::STRING, "prop"))); ADD_SIGNAL(MethodInfo("object_id_selected", PropertyInfo(Variant::INT, "id"))); ADD_SIGNAL(MethodInfo("property_edited", PropertyInfo(Variant::STRING, "property"))); + ADD_SIGNAL(MethodInfo("property_toggled", PropertyInfo(Variant::STRING, "property"), PropertyInfo(Variant::BOOL, "checked"))); ADD_SIGNAL(MethodInfo("restart_requested")); } @@ -2236,6 +2284,7 @@ EditorInspector::EditorInspector() { set_process(true); property_focusable = -1; use_sub_inspector_bg = false; + auto_unfold_edited = false; get_v_scrollbar()->connect("value_changed", this, "_vscroll_changed"); update_scroll_request = -1; |