diff options
Diffstat (limited to 'editor/editor_inspector.cpp')
-rw-r--r-- | editor/editor_inspector.cpp | 89 |
1 files changed, 71 insertions, 18 deletions
diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index e8ee5069a5..ecb9ea5f35 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -82,7 +82,10 @@ 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) { - emit_signal("property_changed", p_property, p_value, p_field, 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] }; + + emit_signal("property_changed", (const Variant **)argptrs, 4); } void EditorProperty::_notification(int p_what) { @@ -208,12 +211,14 @@ void EditorProperty::_notification(int p_what) { } int ofs = 0; + int text_limit = text_size; + if (checkable) { Ref<Texture> checkbox; if (checked) - checkbox = get_icon("checked", "CheckBox"); + checkbox = get_icon("GuiChecked", "EditorIcons"); else - checkbox = get_icon("unchecked", "CheckBox"); + checkbox = get_icon("GuiUnchecked", "EditorIcons"); Color color2(1, 1, 1); if (check_hover) { @@ -225,12 +230,11 @@ void EditorProperty::_notification(int p_what) { draw_texture(checkbox, check_rect.position, color2); ofs += get_constant("hseparator", "Tree"); ofs += checkbox->get_width(); + text_limit -= ofs; } else { check_rect = Rect2(); } - int text_limit = text_size; - if (can_revert) { Ref<Texture> reload_icon = get_icon("ReloadSmall", "EditorIcons"); text_limit -= reload_icon->get_width() + get_constant("hseparator", "Tree") * 2; @@ -430,7 +434,7 @@ bool EditorPropertyRevert::is_node_property_different(Node *p_node, const Varian float a = p_current; float b = p_orig; - return Math::abs(a - b) > CMP_EPSILON; //this must be done because, as some scenes save as text, there might be a tiny difference in floats due to numerical error + return !Math::is_equal_approx(a, b); //this must be done because, as some scenes save as text, there might be a tiny difference in floats due to numerical error } return bool(Variant::evaluate(Variant::OP_NOT_EQUAL, p_current, p_orig)); @@ -467,10 +471,12 @@ bool EditorPropertyRevert::can_property_revert(Object *p_object, const StringNam 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(p_property, orig_value)) { - if (orig_value != p_object->get(p_property)) { - has_revert = true; + if (scr.is_valid()) { + Variant orig_value; + if (scr->get_property_default_value(p_property, orig_value)) { + if (orig_value != p_object->get(p_property)) { + has_revert = true; + } } } } @@ -665,11 +671,13 @@ void EditorProperty::_gui_input(const Ref<InputEvent> &p_event) { if (!object->get_script().is_null()) { Ref<Script> scr = object->get_script(); - Variant orig_value; - if (scr->get_property_default_value(property, orig_value)) { - emit_changed(property, orig_value); - update_property(); - return; + if (scr.is_valid()) { + Variant orig_value; + if (scr->get_property_default_value(property, orig_value)) { + emit_changed(property, orig_value); + update_property(); + return; + } } } @@ -797,6 +805,9 @@ void EditorProperty::_bind_methods() { ClassDB::bind_method(D_METHOD("get_tooltip_text"), &EditorProperty::get_tooltip_text); + ClassDB::bind_method(D_METHOD("add_focusable", "control"), &EditorProperty::add_focusable); + ClassDB::bind_method(D_METHOD("set_bottom_editor", "editor"), &EditorProperty::set_bottom_editor); + ClassDB::bind_method(D_METHOD("emit_changed", "property", "value", "field", "changing"), &EditorProperty::emit_changed, DEFVAL(StringName()), DEFVAL(false)); ADD_PROPERTY(PropertyInfo(Variant::STRING, "label"), "set_label", "get_label"); @@ -1233,6 +1244,7 @@ EditorInspectorSection::EditorInspectorSection() { } EditorInspectorSection::~EditorInspectorSection() { + if (!vbox_added) { memdelete(vbox); } @@ -1294,6 +1306,10 @@ void EditorInspector::remove_inspector_plugin(const Ref<EditorInspectorPlugin> & for (int i = idx; i < inspector_plugin_count - 1; i++) { inspector_plugins[i] = inspector_plugins[i + 1]; } + + if (idx == inspector_plugin_count - 1) + inspector_plugins[idx] = Ref<EditorInspectorPlugin>(); + inspector_plugin_count--; } @@ -1362,6 +1378,30 @@ void EditorInspector::_parse_added_editors(VBoxContainer *current_vbox, Ref<Edit ped->added_editors.clear(); } +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; + } + + StringName class_name = object->get_class(); + + while (class_name != StringName()) { + + if (profile->is_class_property_disabled(class_name, p_property)) { + return true; + } + if (profile->is_class_disabled(class_name)) { + //won't see properties of a disabled class + return true; + } + class_name = ClassDB::get_parent_class(class_name); + } + + return false; +} + void EditorInspector::update_tree() { //to update properly if all is refreshed @@ -1491,7 +1531,7 @@ void EditorInspector::update_tree() { if (E) { descr = E->get().brief_description; } - class_descr_cache[type2] = descr.word_wrap(80); + class_descr_cache[type2] = descr; } category->set_tooltip(p.name + "::" + (class_descr_cache[type2] == "" ? "" : class_descr_cache[type2])); @@ -1505,7 +1545,7 @@ void EditorInspector::update_tree() { continue; - } else if (!(p.usage & PROPERTY_USAGE_EDITOR)) + } else if (!(p.usage & PROPERTY_USAGE_EDITOR) || _is_property_disabled_by_feature_profile(p.name)) continue; if (p.usage & PROPERTY_USAGE_HIGH_END_GFX && VS::get_singleton()->is_low_end()) @@ -1643,7 +1683,7 @@ void EditorInspector::update_tree() { while (F && descr == String()) { for (int i = 0; i < F->get().properties.size(); i++) { if (F->get().properties[i].name == propname.operator String()) { - descr = F->get().properties[i].description.strip_edges().word_wrap(80); + descr = F->get().properties[i].description.strip_edges(); break; } } @@ -2124,6 +2164,10 @@ void EditorInspector::_node_removed(Node *p_node) { void EditorInspector::_notification(int p_what) { + if (p_what == NOTIFICATION_READY) { + EditorFeatureProfileManager::get_singleton()->connect("current_feature_profile_changed", this, "_feature_profile_changed"); + } + if (p_what == NOTIFICATION_ENTER_TREE) { if (sub_inspector) { @@ -2133,6 +2177,9 @@ void EditorInspector::_notification(int p_what) { get_tree()->connect("node_removed", this, "_node_removed"); } } + if (p_what == NOTIFICATION_PREDELETE) { + edit(NULL); //just in case + } if (p_what == NOTIFICATION_EXIT_TREE) { if (!sub_inspector) { @@ -2227,6 +2274,11 @@ String EditorInspector::get_object_class() const { return object_class; } +void EditorInspector::_feature_profile_changed() { + + update_tree(); +} + void EditorInspector::_bind_methods() { ClassDB::bind_method("_property_changed", &EditorInspector::_property_changed, DEFVAL(""), DEFVAL(false)); @@ -2243,6 +2295,7 @@ void EditorInspector::_bind_methods() { ClassDB::bind_method("_resource_selected", &EditorInspector::_resource_selected); ClassDB::bind_method("_object_id_selected", &EditorInspector::_object_id_selected); ClassDB::bind_method("_vscroll_changed", &EditorInspector::_vscroll_changed); + ClassDB::bind_method("_feature_profile_changed", &EditorInspector::_feature_profile_changed); ClassDB::bind_method("refresh", &EditorInspector::refresh); |