Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor: Fix some issues with EditorHelpTooltip #83094

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions editor/editor_help.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2264,7 +2264,12 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt, Control
p_rt->push_strikethrough();
pos = brk_end + 1;
tag_stack.push_front(tag);

} else if (tag == "lb") {
p_rt->add_text("[");
pos = brk_end + 1;
} else if (tag == "rb") {
p_rt->add_text("]");
pos = brk_end + 1;
} else if (tag == "url") {
int end = bbcode.find("[", brk_end);
if (end == -1) {
Expand Down Expand Up @@ -2850,7 +2855,7 @@ void EditorHelpTooltip::_notification(int p_what) {
// `p_text` is expected to be something like these:
// - `class|Control||`;
// - `property|Control|size|`;
// - `signal|Control|gui_input|(event: InputEvent)`
// - `signal|Control|gui_input|(event: InputEvent)`.
void EditorHelpTooltip::parse_tooltip(const String &p_text) {
tooltip_text = p_text;

Expand Down Expand Up @@ -2895,7 +2900,7 @@ void EditorHelpTooltip::parse_tooltip(const String &p_text) {
}

// Metadata special handling replaces "Property:" with "Metadata": above.
formatted_text += " [u][b]" + title.trim_prefix("metadata/") + "[/b][/u]" + property_args + "\n";
formatted_text += " [u][b]" + title.trim_prefix("metadata/") + "[/b][/u]" + property_args.replace("[", "[lb]") + "\n";
formatted_text += description.is_empty() ? "[i]" + TTR("No description available.") + "[/i]" : description;
set_text(formatted_text);
}
Expand Down
20 changes: 16 additions & 4 deletions editor/editor_inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -906,12 +906,24 @@ void EditorProperty::_update_pin_flags() {
}

Control *EditorProperty::make_custom_tooltip(const String &p_text) const {
EditorHelpTooltip *tooltip = memnew(EditorHelpTooltip(p_text));
EditorHelpBit *tooltip = nullptr;

if (has_doc_tooltip) {
tooltip = memnew(EditorHelpTooltip(p_text));
}

if (object->has_method("_get_property_warning")) {
String warn = object->call("_get_property_warning", property);
if (!warn.is_empty()) {
tooltip->set_text(tooltip->get_rich_text()->get_text() + "\n[b][color=" + get_theme_color(SNAME("warning_color")).to_html(false) + "]" + warn + "[/color][/b]");
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";
}
tooltip->set_text(prev_text + "[b][color=" + get_theme_color(SNAME("warning_color")).to_html(false) + "]" + warn + "[/color][/b]");
}
}

Expand Down Expand Up @@ -1148,8 +1160,7 @@ void EditorInspectorCategory::_notification(int p_what) {
}

Control *EditorInspectorCategory::make_custom_tooltip(const String &p_text) const {
// Far from perfect solution, as there's nothing that prevents a category from having a name that starts with that.
return p_text.begins_with("class|") ? memnew(EditorHelpTooltip(p_text)) : nullptr;
return doc_class_name.is_empty() ? nullptr : memnew(EditorHelpTooltip(p_text));
}

Size2 EditorInspectorCategory::get_minimum_size() const {
Expand Down Expand Up @@ -3316,6 +3327,7 @@ void EditorInspector::update_tree() {
} else {
ep->set_tooltip_text("theme_item|" + classname + "|" + theme_item_name + "|");
}
ep->has_doc_tooltip = true;
}

ep->set_doc_path(doc_path);
Expand Down
1 change: 1 addition & 0 deletions editor/editor_inspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class EditorProperty : public Container {
StringName property;
String property_path;
String doc_path;
bool has_doc_tooltip = false;

int property_usage;

Expand Down
Loading