diff options
Diffstat (limited to 'editor/editor_inspector.cpp')
-rw-r--r-- | editor/editor_inspector.cpp | 188 |
1 files changed, 116 insertions, 72 deletions
diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 2c4168f1a0..10c9974cdd 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -128,18 +128,22 @@ void EditorProperty::_notification(int p_what) { bottom_rect = Rect2(m, rect.size.height + get_constant("vseparation", "Tree"), size.width - m, bottom_editor->get_combined_minimum_size().height); } - } - if (keying) { - Ref<Texture> key; + if (keying) { + Ref<Texture> key; - if (use_keying_next()) { - key = get_icon("KeyNext", "EditorIcons"); - } else { - key = get_icon("Key", "EditorIcons"); - } + if (use_keying_next()) { + key = get_icon("KeyNext", "EditorIcons"); + } else { + key = get_icon("Key", "EditorIcons"); + } - rect.size.x -= key->get_width() + get_constant("hseparator", "Tree"); + rect.size.x -= key->get_width() + get_constant("hseparator", "Tree"); + + if (no_children) { + text_size -= key->get_width() + 4 * EDSCALE; + } + } } //set children @@ -297,16 +301,12 @@ bool EditorProperty::is_read_only() const { return read_only; } -bool EditorProperty::_might_be_in_instance() { - - if (!object) - return false; - - Node *node = Object::cast_to<Node>(object); +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) { @@ -328,13 +328,9 @@ bool EditorProperty::_might_be_in_instance() { return might_be; // or might not be } -bool EditorProperty::_get_instanced_node_original_property(const StringName &p_prop, Variant &value) { - - Node *node = Object::cast_to<Node>(object); - - if (!node) - return false; +bool EditorPropertyRevert::get_instanced_node_original_property(Node *p_node, const StringName &p_prop, Variant &value) { + Node *node = p_node; Node *orig = node; Node *edited_scene = EditorNode::get_singleton()->get_edited_scene(); @@ -374,16 +370,26 @@ 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(node->get_class_name(), p_prop); + 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 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 = Object::cast_to<Node>(object); + Node *node = p_node; if (!node) return false; @@ -415,15 +421,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,49 +431,55 @@ 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 EditorPropertyRevert::can_property_revert(Object *p_object, const StringName &p_property) { + + bool has_revert = false; + + Node *node = Object::cast_to<Node>(p_object); - bool mbi = _might_be_in_instance(); - if (mbi) { + if (node && EditorPropertyRevert::may_node_be_in_instance(node)) { + //check for difference including instantiation 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 (EditorPropertyRevert::get_instanced_node_original_property(node, p_property, vorig)) { + Variant v = p_object->get(p_property); - if (_is_property_different(v, vorig, usage)) { - return true; + if (EditorPropertyRevert::is_node_property_different(node, v, vorig)) { + has_revert = true; } } - } - return false; -} - -void EditorProperty::update_reload_status() { - - if (property == StringName()) - return; //no property, so nothing to do - - bool has_reload = false; - - if (_is_instanced_node_with_original_property_different()) { - has_reload = true; + } else { + //check for difference against default class value instead + Variant default_value = ClassDB::class_get_default_property_value(p_object->get_class_name(), p_property); + if (default_value != Variant() && default_value != p_object->get(p_property)) { + has_revert = true; + } } - if (object->call("property_can_revert", property).operator bool()) { + if (p_object->call("property_can_revert", p_property).operator bool()) { - has_reload = true; + has_revert = true; } - if (!has_reload && !object->get_script().is_null()) { - Ref<Script> scr = object->get_script(); + if (!has_revert && !p_object->get_script().is_null()) { + Ref<Script> scr = p_object->get_script(); Variant orig_value; - if (scr->get_property_default_value(property, orig_value)) { - if (orig_value != object->get(property)) { - has_reload = true; + if (scr->get_property_default_value(p_property, orig_value)) { + if (orig_value != p_object->get(p_property)) { + has_revert = true; } } } + return has_revert; +} + +void EditorProperty::update_reload_status() { + + if (property == StringName()) + return; //no property, so nothing to do + + bool has_reload = EditorPropertyRevert::can_property_revert(object, property); + if (has_reload != can_revert) { can_revert = has_reload; update(); @@ -484,6 +487,17 @@ void EditorProperty::update_reload_status() { } bool EditorProperty::use_keying_next() const { + List<PropertyInfo> plist; + object->get_property_list(&plist, true); + + for (List<PropertyInfo>::Element *I = plist.front(); I; I = I->next()) { + PropertyInfo &p = I->get(); + + if (p.name == property) { + return p.hint == PROPERTY_HINT_SPRITE_FRAME; + } + } + return false; } void EditorProperty::set_checkable(bool p_checkable) { @@ -617,14 +631,20 @@ 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); + call_deferred("update_property"); + } } if (revert_rect.has_point(mb->get_position())) { Variant vorig; - if (_might_be_in_instance() && _get_instanced_node_original_property(property, 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_signal("property_changed", property, vorig.duplicate(true)); update_property(); @@ -635,6 +655,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()) { @@ -643,8 +664,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; @@ -722,9 +751,9 @@ Control *EditorProperty::make_custom_tooltip(const String &p_text) const { tooltip_text = p_text; EditorHelpBit *help_bit = memnew(EditorHelpBit); help_bit->add_style_override("panel", get_stylebox("panel", "TooltipPanel")); - help_bit->get_rich_text()->set_fixed_size_to_width(300); + help_bit->get_rich_text()->set_fixed_size_to_width(360 * EDSCALE); - String text = TTR("Property: ") + "[u][b]" + p_text.get_slice("::", 0) + "[/b][/u]\n"; + String text = TTR("Property:") + " [u][b]" + p_text.get_slice("::", 0) + "[/b][/u]\n"; text += p_text.get_slice("::", 1).strip_edges(); help_bit->set_text(text); help_bit->call_deferred("set_text", text); //hack so it uses proper theme once inside scene @@ -944,7 +973,7 @@ Control *EditorInspectorCategory::make_custom_tooltip(const String &p_text) cons tooltip_text = p_text; EditorHelpBit *help_bit = memnew(EditorHelpBit); help_bit->add_style_override("panel", get_stylebox("panel", "TooltipPanel")); - help_bit->get_rich_text()->set_fixed_size_to_width(300); + help_bit->get_rich_text()->set_fixed_size_to_width(360 * EDSCALE); String text = "[u][b]" + p_text.get_slice("::", 0) + "[/b][/u]\n"; text += p_text.get_slice("::", 1).strip_edges(); @@ -1066,10 +1095,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(); } } } @@ -1132,6 +1159,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); @@ -1364,6 +1396,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"); @@ -1526,7 +1560,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)); @@ -1976,20 +2012,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) { @@ -2123,6 +2159,13 @@ void EditorInspector::_notification(int p_what) { } if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) { + + if (use_sub_inspector_bg) { + add_style_override("bg", get_stylebox("sub_inspector_bg", "Editor")); + } else if (is_inside_tree()) { + add_style_override("bg", get_stylebox("bg", "Tree")); + } + update_tree(); } } @@ -2182,6 +2225,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")); } |