diff options
author | Danil Alexeev <danil@alexeev.xyz> | 2024-04-11 11:21:44 +0300 |
---|---|---|
committer | Danil Alexeev <danil@alexeev.xyz> | 2024-04-18 14:32:04 +0300 |
commit | a714cb9f65faefaa21bef240397ca6d249edd53c (patch) | |
tree | 9ce34904d2641410dafd914d9f816df99e21b5b5 /editor/editor_inspector.cpp | |
parent | 3b1806182a3564736ad64793b203c2c13c251f56 (diff) | |
download | redot-engine-a714cb9f65faefaa21bef240397ca6d249edd53c.tar.gz |
Editor: Display deprecated/experimental messages in tooltips
Diffstat (limited to 'editor/editor_inspector.cpp')
-rw-r--r-- | editor/editor_inspector.cpp | 65 |
1 files changed, 37 insertions, 28 deletions
diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index aed1462eb6..50cc89c618 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -44,6 +44,7 @@ #include "editor/plugins/script_editor_plugin.h" #include "editor/themes/editor_scale.h" #include "editor/themes/editor_theme_manager.h" +#include "scene/gui/margin_container.h" #include "scene/gui/spin_box.h" #include "scene/gui/texture_rect.h" #include "scene/property_utils.h" @@ -916,34 +917,35 @@ void EditorProperty::_update_pin_flags() { } Control *EditorProperty::make_custom_tooltip(const String &p_text) const { - EditorHelpBit *tooltip = nullptr; + String custom_warning; + if (object->has_method("_get_property_warning")) { + custom_warning = object->call("_get_property_warning", property); + } - if (has_doc_tooltip) { - String custom_description; + if (has_doc_tooltip || !custom_warning.is_empty()) { + EditorHelpBit *help_bit = memnew(EditorHelpBit); - const EditorInspector *inspector = get_parent_inspector(); - if (inspector) { - custom_description = inspector->get_custom_property_description(p_text); - } - tooltip = memnew(EditorHelpTooltip(p_text, custom_description)); - } + if (has_doc_tooltip) { + help_bit->parse_symbol(p_text); - if (object->has_method("_get_property_warning")) { - String warn = object->call("_get_property_warning", property); - if (!warn.is_empty()) { - String prev_text; - if (tooltip == nullptr) { - tooltip = memnew(EditorHelpBit()); - tooltip->set_text(p_text); - tooltip->get_rich_text()->set_custom_minimum_size(Size2(360 * EDSCALE, 0)); - } else { - prev_text = tooltip->get_rich_text()->get_text() + "\n"; + const EditorInspector *inspector = get_parent_inspector(); + if (inspector) { + const String custom_description = inspector->get_custom_property_description(p_text); + if (!custom_description.is_empty()) { + help_bit->prepend_description(custom_description); + } } - tooltip->set_text(prev_text + "[b][color=" + get_theme_color(SNAME("warning_color")).to_html(false) + "]" + warn + "[/color][/b]"); } + + if (!custom_warning.is_empty()) { + help_bit->prepend_description("[b][color=" + get_theme_color(SNAME("warning_color")).to_html(false) + "]" + custom_warning + "[/color][/b]"); + } + + EditorHelpBitTooltip::show_tooltip(help_bit, const_cast<EditorProperty *>(this)); + return memnew(Control); // Make the standard tooltip invisible. } - return tooltip; + return nullptr; } void EditorProperty::menu_option(int p_option) { @@ -1178,7 +1180,14 @@ void EditorInspectorCategory::_notification(int p_what) { } Control *EditorInspectorCategory::make_custom_tooltip(const String &p_text) const { - return doc_class_name.is_empty() ? nullptr : memnew(EditorHelpTooltip(p_text)); + // If it's not a doc tooltip, fallback to the default one. + if (doc_class_name.is_empty()) { + return nullptr; + } + + EditorHelpBit *help_bit = memnew(EditorHelpBit(p_text)); + EditorHelpBitTooltip::show_tooltip(help_bit, const_cast<EditorInspectorCategory *>(this)); + return memnew(Control); // Make the standard tooltip invisible. } Size2 EditorInspectorCategory::get_minimum_size() const { @@ -2887,8 +2896,8 @@ void EditorInspector::update_tree() { category->doc_class_name = doc_name; if (use_doc_hints) { - // `|` separator used in `EditorHelpTooltip` for formatting. - category->set_tooltip_text("class|" + doc_name + "||"); + // `|` separators used in `EditorHelpBit`. + category->set_tooltip_text("class|" + doc_name + "|"); } } @@ -3368,15 +3377,15 @@ void EditorInspector::update_tree() { ep->connect("object_id_selected", callable_mp(this, &EditorInspector::_object_id_selected), CONNECT_DEFERRED); if (use_doc_hints) { - // `|` separator used in `EditorHelpTooltip` for formatting. + // `|` separators used in `EditorHelpBit`. if (theme_item_name.is_empty()) { if (p.usage & PROPERTY_USAGE_INTERNAL) { - ep->set_tooltip_text("internal_property|" + classname + "|" + property_prefix + p.name + "|"); + ep->set_tooltip_text("internal_property|" + classname + "|" + property_prefix + p.name); } else { - ep->set_tooltip_text("property|" + classname + "|" + property_prefix + p.name + "|"); + ep->set_tooltip_text("property|" + classname + "|" + property_prefix + p.name); } } else { - ep->set_tooltip_text("theme_item|" + classname + "|" + theme_item_name + "|"); + ep->set_tooltip_text("theme_item|" + classname + "|" + theme_item_name); } ep->has_doc_tooltip = true; } |