diff options
Diffstat (limited to 'editor/editor_help.cpp')
-rw-r--r-- | editor/editor_help.cpp | 111 |
1 files changed, 57 insertions, 54 deletions
diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index b26fa77e16..a36e2f360e 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -30,7 +30,7 @@ #include "editor_help.h" -#include "core/os/input.h" +#include "core/input/input_filter.h" #include "core/os/keyboard.h" #include "doc_data_compressed.gen.h" #include "editor/plugins/script_editor_plugin.h" @@ -39,24 +39,22 @@ #include "editor_settings.h" #define CONTRIBUTE_URL "https://docs.godotengine.org/en/latest/community/contributing/updating_the_class_reference.html" -#define CONTRIBUTE2_URL "https://github.com/godotengine/godot-docs" -#define REQUEST_URL "https://github.com/godotengine/godot-docs/issues/new" -DocData *EditorHelp::doc = NULL; +DocData *EditorHelp::doc = nullptr; void EditorHelp::_init_colors() { - title_color = get_color("accent_color", "Editor"); - text_color = get_color("default_color", "RichTextLabel"); - headline_color = get_color("headline_color", "EditorHelp"); + title_color = get_theme_color("accent_color", "Editor"); + text_color = get_theme_color("default_color", "RichTextLabel"); + headline_color = get_theme_color("headline_color", "EditorHelp"); base_type_color = title_color.linear_interpolate(text_color, 0.5); comment_color = text_color * Color(1, 1, 1, 0.6); symbol_color = comment_color; value_color = text_color * Color(1, 1, 1, 0.6); qualifier_color = text_color * Color(1, 1, 1, 0.8); - type_color = get_color("accent_color", "Editor").linear_interpolate(text_color, 0.5); - class_desc->add_color_override("selection_color", get_color("accent_color", "Editor") * Color(1, 1, 1, 0.4)); - class_desc->add_constant_override("line_separation", Math::round(5 * EDSCALE)); + type_color = get_theme_color("accent_color", "Editor").linear_interpolate(text_color, 0.5); + class_desc->add_theme_color_override("selection_color", get_theme_color("accent_color", "Editor") * Color(1, 1, 1, 0.4)); + class_desc->add_theme_constant_override("line_separation", Math::round(5 * EDSCALE)); } void EditorHelp::_unhandled_key_input(const Ref<InputEvent> &p_ev) { @@ -109,7 +107,7 @@ void EditorHelp::_class_desc_select(const String &p_select) { String link = p_select.substr(tag_end + 1, p_select.length()).lstrip(" "); String topic; - Map<String, int> *table = NULL; + Map<String, int> *table = nullptr; if (tag == "method") { topic = "class_method"; @@ -173,14 +171,14 @@ void EditorHelp::_class_desc_input(const Ref<InputEvent> &p_input) { void EditorHelp::_class_desc_resized() { // Add extra horizontal margins for better readability. // The margins increase as the width of the editor help container increases. - Ref<Font> doc_code_font = get_font("doc_source", "EditorFonts"); + Ref<Font> doc_code_font = get_theme_font("doc_source", "EditorFonts"); real_t char_width = doc_code_font->get_char_size('x').width; const int display_margin = MAX(30 * EDSCALE, get_parent_anchorable_rect().size.width - char_width * 120 * EDSCALE) * 0.5; - Ref<StyleBox> class_desc_stylebox = EditorNode::get_singleton()->get_theme_base()->get_stylebox("normal", "RichTextLabel")->duplicate(); + Ref<StyleBox> class_desc_stylebox = EditorNode::get_singleton()->get_theme_base()->get_theme_stylebox("normal", "RichTextLabel")->duplicate(); class_desc_stylebox->set_default_margin(MARGIN_LEFT, display_margin); class_desc_stylebox->set_default_margin(MARGIN_RIGHT, display_margin); - class_desc->add_style_override("normal", class_desc_stylebox); + class_desc->add_theme_style_override("normal", class_desc_stylebox); } void EditorHelp::_add_type(const String &p_type, const String &p_enum) { @@ -197,8 +195,8 @@ void EditorHelp::_add_type(const String &p_type, const String &p_enum) { t = p_enum.get_slice(".", 0); } } - const Color text_color = get_color("default_color", "RichTextLabel"); - const Color type_color = get_color("accent_color", "Editor").linear_interpolate(text_color, 0.5); + const Color text_color = get_theme_color("default_color", "RichTextLabel"); + const Color type_color = get_theme_color("accent_color", "Editor").linear_interpolate(text_color, 0.5); class_desc->push_color(type_color); if (can_ref) { if (p_enum.empty()) { @@ -346,10 +344,10 @@ void EditorHelp::_update_doc() { DocData::ClassDoc cd = doc->class_list[edited_class]; //make a copy, so we can sort without worrying - Ref<Font> doc_font = get_font("doc", "EditorFonts"); - Ref<Font> doc_bold_font = get_font("doc_bold", "EditorFonts"); - Ref<Font> doc_title_font = get_font("doc_title", "EditorFonts"); - Ref<Font> doc_code_font = get_font("doc_source", "EditorFonts"); + Ref<Font> doc_font = get_theme_font("doc", "EditorFonts"); + Ref<Font> doc_bold_font = get_theme_font("doc_bold", "EditorFonts"); + Ref<Font> doc_title_font = get_theme_font("doc_title", "EditorFonts"); + Ref<Font> doc_code_font = get_theme_font("doc_source", "EditorFonts"); String link_color_text = title_color.to_html(false); // Class name @@ -433,7 +431,7 @@ void EditorHelp::_update_doc() { class_desc->push_color(text_color); class_desc->push_font(doc_bold_font); class_desc->push_indent(1); - _add_text(cd.brief_description); + _add_text(DTR(cd.brief_description)); class_desc->pop(); class_desc->pop(); class_desc->pop(); @@ -458,7 +456,7 @@ void EditorHelp::_update_doc() { class_desc->push_color(text_color); class_desc->push_font(doc_font); class_desc->push_indent(1); - _add_text(cd.description); + _add_text(DTR(cd.description)); class_desc->pop(); class_desc->pop(); class_desc->pop(); @@ -480,7 +478,7 @@ void EditorHelp::_update_doc() { class_desc->add_newline(); for (int i = 0; i < cd.tutorials.size(); i++) { - const String link = cd.tutorials[i]; + const String link = DTR(cd.tutorials[i]); String linktxt = link; const int seppos = linktxt.find("//"); if (seppos != -1) { @@ -726,7 +724,7 @@ void EditorHelp::_update_doc() { class_desc->push_font(doc_font); class_desc->add_text(" "); class_desc->push_color(comment_color); - _add_text(cd.theme_properties[i].description); + _add_text(DTR(cd.theme_properties[i].description)); class_desc->pop(); class_desc->pop(); } @@ -796,7 +794,7 @@ void EditorHelp::_update_doc() { class_desc->push_font(doc_font); class_desc->push_color(comment_color); class_desc->push_indent(1); - _add_text(cd.signals[i].description); + _add_text(DTR(cd.signals[i].description)); class_desc->pop(); // indent class_desc->pop(); class_desc->pop(); // font @@ -812,7 +810,7 @@ void EditorHelp::_update_doc() { // Constants and enums if (cd.constants.size()) { - Map<String, Vector<DocData::ConstantDoc> > enums; + Map<String, Vector<DocData::ConstantDoc>> enums; Vector<DocData::ConstantDoc> constants; for (int i = 0; i < cd.constants.size(); i++) { @@ -842,7 +840,7 @@ void EditorHelp::_update_doc() { class_desc->add_newline(); - for (Map<String, Vector<DocData::ConstantDoc> >::Element *E = enums.front(); E; E = E->next()) { + for (Map<String, Vector<DocData::ConstantDoc>>::Element *E = enums.front(); E; E = E->next()) { enum_line[E->key()] = class_desc->get_line_count() - 2; @@ -893,7 +891,7 @@ void EditorHelp::_update_doc() { //class_desc->add_text(" "); class_desc->push_indent(1); class_desc->push_color(comment_color); - _add_text(enum_list[i].description); + _add_text(DTR(enum_list[i].description)); class_desc->pop(); class_desc->pop(); class_desc->pop(); // indent @@ -959,7 +957,7 @@ void EditorHelp::_update_doc() { class_desc->push_font(doc_font); class_desc->push_indent(1); class_desc->push_color(comment_color); - _add_text(constants[i].description); + _add_text(DTR(constants[i].description)); class_desc->pop(); class_desc->pop(); class_desc->pop(); // indent @@ -1070,9 +1068,9 @@ void EditorHelp::_update_doc() { class_desc->push_font(doc_font); class_desc->push_indent(1); if (cd.properties[i].description.strip_edges() != String()) { - _add_text(cd.properties[i].description); + _add_text(DTR(cd.properties[i].description)); } else { - class_desc->add_image(get_icon("Error", "EditorIcons")); + class_desc->add_image(get_theme_icon("Error", "EditorIcons")); class_desc->add_text(" "); class_desc->push_color(comment_color); class_desc->append_bbcode(TTR("There is currently no description for this property. Please help us by [color=$color][url=$url]contributing one[/url][/color]!").replace("$url", CONTRIBUTE_URL).replace("$color", link_color_text)); @@ -1123,9 +1121,9 @@ void EditorHelp::_update_doc() { class_desc->push_font(doc_font); class_desc->push_indent(1); if (methods_filtered[i].description.strip_edges() != String()) { - _add_text(methods_filtered[i].description); + _add_text(DTR(methods_filtered[i].description)); } else { - class_desc->add_image(get_icon("Error", "EditorIcons")); + class_desc->add_image(get_theme_icon("Error", "EditorIcons")); class_desc->add_text(" "); class_desc->push_color(comment_color); class_desc->append_bbcode(TTR("There is currently no description for this method. Please help us by [color=$color][url=$url]contributing one[/url][/color]!").replace("$url", CONTRIBUTE_URL).replace("$color", link_color_text)); @@ -1188,7 +1186,7 @@ void EditorHelp::_help_callback(const String &p_topic) { if (constant_line.has(name)) line = constant_line[name]; else { - Map<String, Map<String, int> >::Element *iter = enum_values_line.front(); + Map<String, Map<String, int>>::Element *iter = enum_values_line.front(); while (true) { if (iter->value().has(name)) { line = iter->value()[name]; @@ -1209,12 +1207,12 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt) { DocData *doc = EditorHelp::get_doc_data(); String base_path; - Ref<Font> doc_font = p_rt->get_font("doc", "EditorFonts"); - Ref<Font> doc_bold_font = p_rt->get_font("doc_bold", "EditorFonts"); - Ref<Font> doc_code_font = p_rt->get_font("doc_source", "EditorFonts"); + Ref<Font> doc_font = p_rt->get_theme_font("doc", "EditorFonts"); + Ref<Font> doc_bold_font = p_rt->get_theme_font("doc_bold", "EditorFonts"); + Ref<Font> doc_code_font = p_rt->get_theme_font("doc_source", "EditorFonts"); - Color font_color_hl = p_rt->get_color("headline_color", "EditorHelp"); - Color accent_color = p_rt->get_color("accent_color", "Editor"); + Color font_color_hl = p_rt->get_theme_color("headline_color", "EditorHelp"); + Color accent_color = p_rt->get_theme_color("accent_color", "Editor"); Color link_color = accent_color.linear_interpolate(font_color_hl, 0.8); Color code_color = accent_color.linear_interpolate(font_color_hl, 0.6); @@ -1449,7 +1447,6 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt) { } void EditorHelp::_add_text(const String &p_bbcode) { - _add_text_to_rt(p_bbcode, class_desc); } @@ -1489,8 +1486,8 @@ void EditorHelp::go_to_class(const String &p_class, int p_scroll) { _goto_desc(p_class, p_scroll); } -Vector<Pair<String, int> > EditorHelp::get_sections() { - Vector<Pair<String, int> > sections; +Vector<Pair<String, int>> EditorHelp::get_sections() { + Vector<Pair<String, int>> sections; for (int i = 0; i < section_line.size(); i++) { sections.push_back(Pair<String, int>(section_line[i].first, i)); @@ -1546,7 +1543,7 @@ EditorHelp::EditorHelp() { class_desc = memnew(RichTextLabel); add_child(class_desc); class_desc->set_v_size_flags(SIZE_EXPAND_FILL); - class_desc->add_color_override("selection_color", get_color("accent_color", "Editor") * Color(1, 1, 1, 0.4)); + class_desc->add_theme_color_override("selection_color", get_theme_color("accent_color", "Editor") * Color(1, 1, 1, 0.4)); class_desc->connect("meta_clicked", callable_mp(this, &EditorHelp::_class_desc_select)); class_desc->connect("gui_input", callable_mp(this, &EditorHelp::_class_desc_input)); @@ -1611,9 +1608,14 @@ void EditorHelpBit::_bind_methods() { void EditorHelpBit::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_READY: { + rich_text->clear(); + _add_text_to_rt(text, rich_text); + + } break; case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { - rich_text->add_color_override("selection_color", get_color("accent_color", "Editor") * Color(1, 1, 1, 0.4)); + rich_text->add_theme_color_override("selection_color", get_theme_color("accent_color", "Editor") * Color(1, 1, 1, 0.4)); } break; default: break; } @@ -1621,8 +1623,9 @@ void EditorHelpBit::_notification(int p_what) { void EditorHelpBit::set_text(const String &p_text) { + text = p_text; rich_text->clear(); - _add_text_to_rt(p_text, rich_text); + _add_text_to_rt(text, rich_text); } EditorHelpBit::EditorHelpBit() { @@ -1630,7 +1633,7 @@ EditorHelpBit::EditorHelpBit() { rich_text = memnew(RichTextLabel); add_child(rich_text); rich_text->connect("meta_clicked", callable_mp(this, &EditorHelpBit::_meta_clicked)); - rich_text->add_color_override("selection_color", get_color("accent_color", "Editor") * Color(1, 1, 1, 0.4)); + rich_text->add_theme_color_override("selection_color", get_theme_color("accent_color", "Editor") * Color(1, 1, 1, 0.4)); rich_text->set_override_selected_font_color(false); set_custom_minimum_size(Size2(0, 70 * EDSCALE)); } @@ -1694,13 +1697,13 @@ void FindBar::_notification(int p_what) { case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { - find_prev->set_icon(get_icon("MoveUp", "EditorIcons")); - find_next->set_icon(get_icon("MoveDown", "EditorIcons")); - hide_button->set_normal_texture(get_icon("Close", "EditorIcons")); - hide_button->set_hover_texture(get_icon("Close", "EditorIcons")); - hide_button->set_pressed_texture(get_icon("Close", "EditorIcons")); + find_prev->set_icon(get_theme_icon("MoveUp", "EditorIcons")); + find_next->set_icon(get_theme_icon("MoveDown", "EditorIcons")); + hide_button->set_normal_texture(get_theme_icon("Close", "EditorIcons")); + hide_button->set_hover_texture(get_theme_icon("Close", "EditorIcons")); + hide_button->set_pressed_texture(get_theme_icon("Close", "EditorIcons")); hide_button->set_custom_minimum_size(hide_button->get_normal_texture()->get_size()); - matches_label->add_color_override("font_color", results_count > 0 ? get_color("font_color", "Label") : get_color("error_color", "Editor")); + matches_label->add_theme_color_override("font_color", results_count > 0 ? get_theme_color("font_color", "Label") : get_theme_color("error_color", "Editor")); } break; case NOTIFICATION_VISIBILITY_CHANGED: { @@ -1781,7 +1784,7 @@ void FindBar::_update_matches_label() { } else { matches_label->show(); - matches_label->add_color_override("font_color", results_count > 0 ? get_color("font_color", "Label") : get_color("error_color", "Editor")); + matches_label->add_theme_color_override("font_color", results_count > 0 ? get_theme_color("font_color", "Label") : get_theme_color("error_color", "Editor")); matches_label->set_text(vformat(results_count == 1 ? TTR("%d match.") : TTR("%d matches."), results_count)); } } @@ -1829,7 +1832,7 @@ void FindBar::_search_text_changed(const String &p_text) { void FindBar::_search_text_entered(const String &p_text) { - if (Input::get_singleton()->is_key_pressed(KEY_SHIFT)) { + if (InputFilter::get_singleton()->is_key_pressed(KEY_SHIFT)) { search_prev(); } else { search_next(); |