2023-01-05 12:25:55 +00:00
/**************************************************************************/
/* editor_help.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
2018-01-04 23:50:27 +00:00
2014-02-10 01:10:30 +00:00
# include "editor_help.h"
2017-01-16 07:04:19 +00:00
2021-08-24 18:16:25 +00:00
# include "core/core_constants.h"
2020-04-28 13:19:37 +00:00
# include "core/input/input.h"
2023-04-21 13:32:26 +00:00
# include "core/object/script_language.h"
2018-09-11 16:13:45 +00:00
# include "core/os/keyboard.h"
2023-02-07 20:14:00 +00:00
# include "core/version.h"
2017-06-23 15:03:41 +00:00
# include "doc_data_compressed.gen.h"
2022-02-12 01:46:22 +00:00
# include "editor/editor_node.h"
2023-02-07 20:14:00 +00:00
# include "editor/editor_paths.h"
2022-02-12 01:46:22 +00:00
# include "editor/editor_scale.h"
# include "editor/editor_settings.h"
2017-03-05 13:21:25 +00:00
# include "editor/plugins/script_editor_plugin.h"
2022-11-19 11:45:49 +00:00
# include "scene/gui/line_edit.h"
2014-02-21 02:01:44 +00:00
2023-01-14 16:38:00 +00:00
# define CONTRIBUTE_URL vformat("%s / contributing / documentation / updating_the_class_reference.html", VERSION_DOCS_URL)
2017-09-12 22:16:18 +00:00
2023-07-08 11:17:41 +00:00
# ifdef MODULE_MONO_ENABLED
// Sync with the types mentioned in https://docs.godotengine.org/en/stable/tutorials/scripting/c_sharp/c_sharp_differences.html
const Vector < String > classes_with_csharp_differences = {
" @GlobalScope " ,
" String " ,
" NodePath " ,
" Signal " ,
" Callable " ,
" RID " ,
" Basis " ,
" Transform2D " ,
" Transform3D " ,
" Rect2 " ,
" Rect2i " ,
" AABB " ,
" Quaternion " ,
" Projection " ,
" Color " ,
" Array " ,
" Dictionary " ,
" PackedByteArray " ,
" PackedColorArray " ,
" PackedFloat32Array " ,
" PackedFloat64Array " ,
" PackedInt32Array " ,
" PackedInt64Array " ,
" PackedStringArray " ,
" PackedVector2Array " ,
" PackedVector3Array " ,
" Variant " ,
} ;
# endif
2023-04-21 13:32:26 +00:00
// TODO: this is sometimes used directly as doc->something, other times as EditorHelp::get_doc_data(), which is thread-safe.
// Might this be a problem?
2020-11-29 03:42:06 +00:00
DocTools * EditorHelp : : doc = nullptr ;
2014-02-16 00:16:33 +00:00
2023-04-21 13:32:26 +00:00
static bool _attempt_doc_load ( const String & p_class ) {
// Docgen always happens in the outer-most class: it also generates docs for inner classes.
String outer_class = p_class . get_slice ( " . " , 0 ) ;
if ( ! ScriptServer : : is_global_class ( outer_class ) ) {
return false ;
}
// ResourceLoader is used in order to have a script-agnostic way to load scripts.
// This forces GDScript to compile the code, which is unnecessary for docgen, but it's a good compromise right now.
Ref < Script > script = ResourceLoader : : load ( ScriptServer : : get_global_class_path ( outer_class ) , outer_class ) ;
if ( script . is_valid ( ) ) {
Vector < DocData : : ClassDoc > docs = script - > get_documentation ( ) ;
for ( int j = 0 ; j < docs . size ( ) ; j + + ) {
const DocData : : ClassDoc & doc = docs . get ( j ) ;
EditorHelp : : get_doc_data ( ) - > add_doc ( doc ) ;
}
return true ;
}
return false ;
}
// Removes unnecessary prefix from p_class_specifier when within the p_edited_class context
static String _contextualize_class_specifier ( const String & p_class_specifier , const String & p_edited_class ) {
// If this is a completely different context than the current class, then keep full path
if ( ! p_class_specifier . begins_with ( p_edited_class ) ) {
return p_class_specifier ;
}
// Here equal length + begins_with from above implies p_class_specifier == p_edited_class :)
if ( p_class_specifier . length ( ) = = p_edited_class . length ( ) ) {
int rfind = p_class_specifier . rfind ( " . " ) ;
if ( rfind = = - 1 ) { // Single identifier
return p_class_specifier ;
}
// Multiple specifiers: keep last one only
return p_class_specifier . substr ( rfind + 1 ) ;
}
2023-04-28 10:49:24 +00:00
// They share a _name_ prefix but not a _class specifier_ prefix, e.g. Tree & TreeItem
// begins_with + lengths being different implies p_class_specifier.length() > p_edited_class.length() so this is safe
if ( p_class_specifier [ p_edited_class . length ( ) ] ! = ' . ' ) {
return p_class_specifier ;
}
// Remove class specifier prefix
2023-04-21 13:32:26 +00:00
return p_class_specifier . substr ( p_edited_class . length ( ) + 1 ) ;
}
2023-02-11 15:29:44 +00:00
void EditorHelp : : _update_theme_item_cache ( ) {
VBoxContainer : : _update_theme_item_cache ( ) ;
theme_cache . text_color = get_theme_color ( SNAME ( " text_color " ) , SNAME ( " EditorHelp " ) ) ;
theme_cache . title_color = get_theme_color ( SNAME ( " title_color " ) , SNAME ( " EditorHelp " ) ) ;
theme_cache . headline_color = get_theme_color ( SNAME ( " headline_color " ) , SNAME ( " EditorHelp " ) ) ;
theme_cache . comment_color = get_theme_color ( SNAME ( " comment_color " ) , SNAME ( " EditorHelp " ) ) ;
theme_cache . symbol_color = get_theme_color ( SNAME ( " symbol_color " ) , SNAME ( " EditorHelp " ) ) ;
theme_cache . value_color = get_theme_color ( SNAME ( " value_color " ) , SNAME ( " EditorHelp " ) ) ;
theme_cache . qualifier_color = get_theme_color ( SNAME ( " qualifier_color " ) , SNAME ( " EditorHelp " ) ) ;
theme_cache . type_color = get_theme_color ( SNAME ( " type_color " ) , SNAME ( " EditorHelp " ) ) ;
theme_cache . doc_font = get_theme_font ( SNAME ( " doc " ) , SNAME ( " EditorFonts " ) ) ;
theme_cache . doc_bold_font = get_theme_font ( SNAME ( " doc_bold " ) , SNAME ( " EditorFonts " ) ) ;
2023-02-11 16:33:38 +00:00
theme_cache . doc_italic_font = get_theme_font ( SNAME ( " doc_italic " ) , SNAME ( " EditorFonts " ) ) ;
2023-02-11 15:29:44 +00:00
theme_cache . doc_title_font = get_theme_font ( SNAME ( " doc_title " ) , SNAME ( " EditorFonts " ) ) ;
theme_cache . doc_code_font = get_theme_font ( SNAME ( " doc_source " ) , SNAME ( " EditorFonts " ) ) ;
theme_cache . doc_kbd_font = get_theme_font ( SNAME ( " doc_keyboard " ) , SNAME ( " EditorFonts " ) ) ;
theme_cache . doc_font_size = get_theme_font_size ( SNAME ( " doc_size " ) , SNAME ( " EditorFonts " ) ) ;
theme_cache . doc_title_font_size = get_theme_font_size ( SNAME ( " doc_title_size " ) , SNAME ( " EditorFonts " ) ) ;
theme_cache . doc_code_font_size = get_theme_font_size ( SNAME ( " doc_source_size " ) , SNAME ( " EditorFonts " ) ) ;
theme_cache . doc_kbd_font_size = get_theme_font_size ( SNAME ( " doc_keyboard_size " ) , SNAME ( " EditorFonts " ) ) ;
theme_cache . background_style = get_theme_stylebox ( SNAME ( " background " ) , SNAME ( " EditorHelp " ) ) ;
2022-08-29 09:04:31 +00:00
2023-02-11 16:33:38 +00:00
class_desc - > add_theme_font_override ( " normal_font " , theme_cache . doc_font ) ;
class_desc - > add_theme_font_size_override ( " normal_font_size " , theme_cache . doc_font_size ) ;
2022-08-29 09:04:31 +00:00
class_desc - > add_theme_color_override ( " selection_color " , get_theme_color ( SNAME ( " selection_color " ) , SNAME ( " EditorHelp " ) ) ) ;
class_desc - > add_theme_constant_override ( " line_separation " , get_theme_constant ( SNAME ( " line_separation " ) , SNAME ( " EditorHelp " ) ) ) ;
class_desc - > add_theme_constant_override ( " table_h_separation " , get_theme_constant ( SNAME ( " table_h_separation " ) , SNAME ( " EditorHelp " ) ) ) ;
class_desc - > add_theme_constant_override ( " table_v_separation " , get_theme_constant ( SNAME ( " table_v_separation " ) , SNAME ( " EditorHelp " ) ) ) ;
2022-10-31 18:51:48 +00:00
class_desc - > add_theme_constant_override ( " text_highlight_h_padding " , get_theme_constant ( SNAME ( " text_highlight_h_padding " ) , SNAME ( " EditorHelp " ) ) ) ;
class_desc - > add_theme_constant_override ( " text_highlight_v_padding " , get_theme_constant ( SNAME ( " text_highlight_v_padding " ) , SNAME ( " EditorHelp " ) ) ) ;
2022-08-29 09:04:31 +00:00
}
2019-10-09 15:41:49 +00:00
void EditorHelp : : _search ( bool p_search_previous ) {
2020-05-14 14:41:43 +00:00
if ( p_search_previous ) {
2019-10-09 15:41:49 +00:00
find_bar - > search_prev ( ) ;
2020-05-14 14:41:43 +00:00
} else {
2019-10-09 15:41:49 +00:00
find_bar - > search_next ( ) ;
2020-05-14 14:41:43 +00:00
}
2014-02-10 01:10:30 +00:00
}
2022-05-30 07:04:07 +00:00
void EditorHelp : : _class_desc_finished ( ) {
if ( scroll_to > = 0 ) {
class_desc - > scroll_to_paragraph ( scroll_to ) ;
}
scroll_to = - 1 ;
}
2014-02-10 01:10:30 +00:00
void EditorHelp : : _class_list_select ( const String & p_select ) {
_goto_desc ( p_select ) ;
}
void EditorHelp : : _class_desc_select ( const String & p_select ) {
2023-04-21 13:32:26 +00:00
if ( p_select . begins_with ( " $ " ) ) { // enum
2017-08-23 22:10:32 +00:00
String select = p_select . substr ( 1 , p_select . length ( ) ) ;
String class_name ;
2023-04-21 13:32:26 +00:00
int rfind = select . rfind ( " . " ) ;
if ( rfind ! = - 1 ) {
class_name = select . substr ( 0 , rfind ) ;
select = select . substr ( rfind + 1 ) ;
2017-08-23 22:10:32 +00:00
} else {
2017-11-15 17:45:34 +00:00
class_name = " @GlobalScope " ;
2017-08-23 22:10:32 +00:00
}
2021-07-17 21:22:52 +00:00
emit_signal ( SNAME ( " go_to_help " ) , " class_enum: " + class_name + " : " + select ) ;
2017-08-23 22:10:32 +00:00
return ;
} else if ( p_select . begins_with ( " # " ) ) {
2021-07-17 21:22:52 +00:00
emit_signal ( SNAME ( " go_to_help " ) , " class_name: " + p_select . substr ( 1 , p_select . length ( ) ) ) ;
2014-02-10 01:10:30 +00:00
return ;
} else if ( p_select . begins_with ( " @ " ) ) {
2019-04-27 19:15:07 +00:00
int tag_end = p_select . find ( " " ) ;
String tag = p_select . substr ( 1 , tag_end - 1 ) ;
String link = p_select . substr ( tag_end + 1 , p_select . length ( ) ) . lstrip ( " " ) ;
2017-11-20 23:30:46 +00:00
String topic ;
2022-05-13 13:04:37 +00:00
HashMap < String , int > * table = nullptr ;
2017-11-20 23:30:46 +00:00
if ( tag = = " method " ) {
topic = " class_method " ;
table = & this - > method_line ;
} else if ( tag = = " member " ) {
topic = " class_property " ;
table = & this - > property_line ;
2019-03-27 19:01:16 +00:00
} else if ( tag = = " enum " ) {
2017-11-20 23:30:46 +00:00
topic = " class_enum " ;
table = & this - > enum_line ;
} else if ( tag = = " signal " ) {
topic = " class_signal " ;
table = & this - > signal_line ;
2019-03-27 19:01:16 +00:00
} else if ( tag = = " constant " ) {
topic = " class_constant " ;
table = & this - > constant_line ;
2022-07-04 15:56:34 +00:00
} else if ( tag = = " annotation " ) {
topic = " class_annotation " ;
table = & this - > annotation_line ;
2021-11-18 14:03:03 +00:00
} else if ( tag = = " theme_item " ) {
topic = " theme_item " ;
table = & this - > theme_property_line ;
2017-11-20 23:30:46 +00:00
} else {
return ;
}
2014-02-10 01:10:30 +00:00
2022-04-26 16:57:36 +00:00
// Case order is important here to correctly handle edge cases like Variant.Type in @GlobalScope.
if ( table - > has ( link ) ) {
// Found in the current page.
2022-05-30 07:04:07 +00:00
if ( class_desc - > is_ready ( ) ) {
class_desc - > scroll_to_paragraph ( ( * table ) [ link ] ) ;
} else {
scroll_to = ( * table ) [ link ] ;
}
2022-05-20 22:11:48 +00:00
} else {
// Look for link in @GlobalScope.
// Note that a link like @GlobalScope.enum_name will not be found in this section, only enum_name will be.
if ( topic = = " class_enum " ) {
const DocData : : ClassDoc & cd = doc - > class_list [ " @GlobalScope " ] ;
for ( int i = 0 ; i < cd . constants . size ( ) ; i + + ) {
if ( cd . constants [ i ] . enumeration = = link ) {
// Found in @GlobalScope.
emit_signal ( SNAME ( " go_to_help " ) , topic + " :@GlobalScope: " + link ) ;
return ;
}
2019-03-27 19:01:16 +00:00
}
2022-05-20 22:11:48 +00:00
} else if ( topic = = " class_constant " ) {
const DocData : : ClassDoc & cd = doc - > class_list [ " @GlobalScope " ] ;
for ( int i = 0 ; i < cd . constants . size ( ) ; i + + ) {
if ( cd . constants [ i ] . name = = link ) {
// Found in @GlobalScope.
emit_signal ( SNAME ( " go_to_help " ) , topic + " :@GlobalScope: " + link ) ;
return ;
}
2022-04-26 16:57:36 +00:00
}
}
2022-05-20 22:11:48 +00:00
if ( link . contains ( " . " ) ) {
int class_end = link . find ( " . " ) ;
emit_signal ( SNAME ( " go_to_help " ) , topic + " : " + link . substr ( 0 , class_end ) + " : " + link . substr ( class_end + 1 , link . length ( ) ) ) ;
}
2015-11-17 12:46:08 +00:00
}
2017-09-12 22:16:18 +00:00
} else if ( p_select . begins_with ( " http " ) ) {
OS : : get_singleton ( ) - > shell_open ( p_select ) ;
2014-02-10 01:10:30 +00:00
}
}
2017-05-20 15:38:03 +00:00
void EditorHelp : : _class_desc_input ( const Ref < InputEvent > & p_input ) {
2016-06-03 18:11:34 +00:00
}
2022-01-29 17:48:30 +00:00
void EditorHelp : : _class_desc_resized ( bool p_force_update_theme ) {
2019-06-05 18:47:34 +00:00
// Add extra horizontal margins for better readability.
// The margins increase as the width of the editor help container increases.
2023-02-11 15:29:44 +00:00
real_t char_width = theme_cache . doc_code_font - > get_char_size ( ' x ' , theme_cache . doc_code_font_size ) . width ;
2022-01-24 07:51:35 +00:00
const int new_display_margin = MAX ( 30 * EDSCALE , get_parent_anchorable_rect ( ) . size . width - char_width * 120 * EDSCALE ) * 0.5 ;
2022-01-29 17:48:30 +00:00
if ( display_margin ! = new_display_margin | | p_force_update_theme ) {
2022-01-24 07:51:35 +00:00
display_margin = new_display_margin ;
2023-02-11 15:29:44 +00:00
Ref < StyleBox > class_desc_stylebox = theme_cache . background_style - > duplicate ( ) ;
2023-01-19 16:14:09 +00:00
class_desc_stylebox - > set_content_margin ( SIDE_LEFT , display_margin ) ;
class_desc_stylebox - > set_content_margin ( SIDE_RIGHT , display_margin ) ;
2022-02-08 09:14:58 +00:00
class_desc - > add_theme_style_override ( " normal " , class_desc_stylebox ) ;
2022-12-09 17:54:52 +00:00
class_desc - > add_theme_style_override ( " focused " , class_desc_stylebox ) ;
2022-01-24 07:51:35 +00:00
}
2019-06-05 18:47:34 +00:00
}
2023-06-15 14:06:22 +00:00
void EditorHelp : : _add_type ( const String & p_type , const String & p_enum , bool p_is_bitfield ) {
2022-11-01 22:45:40 +00:00
if ( p_type . is_empty ( ) | | p_type = = " void " ) {
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( Color ( theme_cache . type_color , 0.5 ) ) ;
2022-11-01 22:45:40 +00:00
class_desc - > push_hint ( TTR ( " No return value. " ) ) ;
class_desc - > add_text ( " void " ) ;
class_desc - > pop ( ) ;
class_desc - > pop ( ) ;
return ;
2020-05-14 14:41:43 +00:00
}
2014-02-10 01:10:30 +00:00
2022-11-01 22:45:40 +00:00
bool is_enum_type = ! p_enum . is_empty ( ) ;
2023-06-15 14:06:22 +00:00
bool is_bitfield = p_is_bitfield & & is_enum_type ;
2022-11-01 22:45:40 +00:00
bool can_ref = ! p_type . contains ( " * " ) | | is_enum_type ;
2023-04-21 13:32:26 +00:00
String link_t = p_type ; // For links in metadata
2023-06-09 15:00:50 +00:00
String display_t ; // For display purposes.
2022-11-01 22:45:40 +00:00
if ( is_enum_type ) {
2023-04-21 13:32:26 +00:00
link_t = p_enum ; // The link for enums is always the full enum description
display_t = _contextualize_class_specifier ( p_enum , edited_class ) ;
} else {
display_t = _contextualize_class_specifier ( p_type , edited_class ) ;
2017-08-23 22:10:32 +00:00
}
2022-01-18 20:01:30 +00:00
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . type_color ) ;
2020-04-20 22:06:00 +00:00
bool add_array = false ;
2017-08-23 22:10:32 +00:00
if ( can_ref ) {
2023-04-21 13:32:26 +00:00
if ( link_t . ends_with ( " [] " ) ) {
2020-04-20 22:06:00 +00:00
add_array = true ;
2023-05-13 13:09:35 +00:00
link_t = link_t . trim_suffix ( " [] " ) ;
display_t = display_t . trim_suffix ( " [] " ) ;
2022-11-01 22:45:40 +00:00
2023-04-21 13:32:26 +00:00
class_desc - > push_meta ( " #Array " ) ; // class
2022-11-01 22:45:40 +00:00
class_desc - > add_text ( " Array " ) ;
class_desc - > pop ( ) ;
class_desc - > add_text ( " [ " ) ;
2023-06-15 14:06:22 +00:00
} else if ( is_bitfield ) {
class_desc - > push_color ( Color ( theme_cache . type_color , 0.5 ) ) ;
class_desc - > push_hint ( TTR ( " This value is an integer composed as a bitmask of the following flags. " ) ) ;
class_desc - > add_text ( " BitField " ) ;
class_desc - > pop ( ) ;
class_desc - > add_text ( " [ " ) ;
class_desc - > pop ( ) ;
2020-04-20 22:06:00 +00:00
}
2022-11-01 22:45:40 +00:00
if ( is_enum_type ) {
2023-04-21 13:32:26 +00:00
class_desc - > push_meta ( " $ " + link_t ) ; // enum
2022-11-01 22:45:40 +00:00
} else {
2023-04-21 13:32:26 +00:00
class_desc - > push_meta ( " # " + link_t ) ; // class
2017-08-23 22:10:32 +00:00
}
}
2023-04-21 13:32:26 +00:00
class_desc - > add_text ( display_t ) ;
2020-04-20 22:06:00 +00:00
if ( can_ref ) {
2022-11-01 22:45:40 +00:00
class_desc - > pop ( ) ; // Pushed meta above.
2020-04-20 22:06:00 +00:00
if ( add_array ) {
2022-11-01 22:45:40 +00:00
class_desc - > add_text ( " ] " ) ;
2023-06-15 14:06:22 +00:00
} else if ( is_bitfield ) {
class_desc - > push_color ( Color ( theme_cache . type_color , 0.5 ) ) ;
class_desc - > add_text ( " ] " ) ;
class_desc - > pop ( ) ;
2020-04-20 22:06:00 +00:00
}
}
2014-02-10 01:10:30 +00:00
class_desc - > pop ( ) ;
}
2023-03-31 19:17:59 +00:00
void EditorHelp : : _add_type_icon ( const String & p_type , int p_size , const String & p_fallback ) {
Ref < Texture2D > icon = EditorNode : : get_singleton ( ) - > get_class_icon ( p_type , p_fallback ) ;
2022-08-24 18:41:31 +00:00
Vector2i size = Vector2i ( icon - > get_width ( ) , icon - > get_height ( ) ) ;
if ( p_size > 0 ) {
2023-08-01 17:04:28 +00:00
// Ensures icon scales proportionally on both axes, based on icon height.
2022-08-24 18:41:31 +00:00
float ratio = p_size / float ( size . height ) ;
size . width * = ratio ;
size . height * = ratio ;
}
class_desc - > add_image ( icon , size . width , size . height ) ;
}
2018-08-21 20:12:55 +00:00
String EditorHelp : : _fix_constant ( const String & p_constant ) const {
if ( p_constant . strip_edges ( ) = = " 4294967295 " ) {
return " 0xFFFFFFFF " ;
}
if ( p_constant . strip_edges ( ) = = " 2147483647 " ) {
return " 0x7FFFFFFF " ;
}
2019-06-05 14:44:20 +00:00
2018-08-21 20:12:55 +00:00
if ( p_constant . strip_edges ( ) = = " 1048575 " ) {
2019-06-05 14:44:20 +00:00
return " 0xFFFFF " ;
2018-08-21 20:12:55 +00:00
}
return p_constant ;
}
2022-08-28 06:17:25 +00:00
// Macros for assigning the deprecation/experimental information to class members
# define DEPRECATED_DOC_TAG \
class_desc - > push_color ( get_theme_color ( SNAME ( " error_color " ) , SNAME ( " Editor " ) ) ) ; \
Ref < Texture2D > error_icon = get_theme_icon ( SNAME ( " StatusError " ) , SNAME ( " EditorIcons " ) ) ; \
class_desc - > add_text ( " " ) ; \
class_desc - > add_image ( error_icon , error_icon - > get_width ( ) , error_icon - > get_height ( ) ) ; \
class_desc - > add_text ( " ( " + TTR ( " Deprecated " ) + " ) " ) ; \
class_desc - > pop ( ) ;
# define EXPERIMENTAL_DOC_TAG \
class_desc - > push_color ( get_theme_color ( SNAME ( " warning_color " ) , SNAME ( " Editor " ) ) ) ; \
Ref < Texture2D > warning_icon = get_theme_icon ( SNAME ( " NodeWarning " ) , SNAME ( " EditorIcons " ) ) ; \
class_desc - > add_text ( " " ) ; \
class_desc - > add_image ( warning_icon , warning_icon - > get_width ( ) , warning_icon - > get_height ( ) ) ; \
class_desc - > add_text ( " ( " + TTR ( " Experimental " ) + " ) " ) ; \
class_desc - > pop ( ) ;
2017-12-15 08:45:23 +00:00
void EditorHelp : : _add_method ( const DocData : : MethodDoc & p_method , bool p_overview ) {
2023-04-21 13:32:26 +00:00
method_line [ p_method . name ] = class_desc - > get_paragraph_count ( ) - 2 ; // Gets overridden if description
2017-12-15 08:45:23 +00:00
2022-02-03 16:03:38 +00:00
const bool is_vararg = p_method . qualifiers . contains ( " vararg " ) ;
2017-12-15 08:45:23 +00:00
if ( p_overview ) {
class_desc - > push_cell ( ) ;
2021-11-25 02:58:47 +00:00
class_desc - > push_paragraph ( HORIZONTAL_ALIGNMENT_RIGHT , Control : : TEXT_DIRECTION_AUTO , " " ) ;
2020-05-21 09:01:31 +00:00
} else {
2021-12-01 18:02:20 +00:00
_add_bulletpoint ( ) ;
2017-12-15 08:45:23 +00:00
}
2023-06-15 14:06:22 +00:00
_add_type ( p_method . return_type , p_method . return_enum , p_method . return_is_bitfield ) ;
2017-12-15 08:45:23 +00:00
if ( p_overview ) {
2023-04-21 13:32:26 +00:00
class_desc - > pop ( ) ; // align
class_desc - > pop ( ) ; // cell
2017-12-15 08:45:23 +00:00
class_desc - > push_cell ( ) ;
} else {
class_desc - > add_text ( " " ) ;
}
2022-07-04 15:56:34 +00:00
if ( p_overview & & ! p_method . description . strip_edges ( ) . is_empty ( ) ) {
2019-04-27 19:15:07 +00:00
class_desc - > push_meta ( " @method " + p_method . name ) ;
2017-12-15 08:45:23 +00:00
}
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . headline_color ) ;
2017-12-15 08:45:23 +00:00
_add_text ( p_method . name ) ;
class_desc - > pop ( ) ;
2022-07-04 15:56:34 +00:00
if ( p_overview & & ! p_method . description . strip_edges ( ) . is_empty ( ) ) {
2023-04-21 13:32:26 +00:00
class_desc - > pop ( ) ; // meta
2017-12-15 08:45:23 +00:00
}
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . symbol_color ) ;
2019-09-20 20:40:22 +00:00
class_desc - > add_text ( " ( " ) ;
2017-12-15 08:45:23 +00:00
class_desc - > pop ( ) ;
for ( int j = 0 ; j < p_method . arguments . size ( ) ; j + + ) {
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . text_color ) ;
2020-05-14 14:41:43 +00:00
if ( j > 0 ) {
2017-12-15 08:45:23 +00:00
class_desc - > add_text ( " , " ) ;
2020-05-14 14:41:43 +00:00
}
2019-09-20 20:40:22 +00:00
2017-12-15 08:45:23 +00:00
_add_text ( p_method . arguments [ j ] . name ) ;
2019-09-20 20:40:22 +00:00
class_desc - > add_text ( " : " ) ;
2023-06-15 14:06:22 +00:00
_add_type ( p_method . arguments [ j ] . type , p_method . arguments [ j ] . enumeration , p_method . arguments [ j ] . is_bitfield ) ;
2021-12-09 09:42:46 +00:00
if ( ! p_method . arguments [ j ] . default_value . is_empty ( ) ) {
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . symbol_color ) ;
2019-06-01 13:42:22 +00:00
class_desc - > add_text ( " = " ) ;
2017-12-15 08:45:23 +00:00
class_desc - > pop ( ) ;
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . value_color ) ;
2018-08-21 20:12:55 +00:00
_add_text ( _fix_constant ( p_method . arguments [ j ] . default_value ) ) ;
2019-06-01 13:42:22 +00:00
class_desc - > pop ( ) ;
2017-12-15 08:45:23 +00:00
}
class_desc - > pop ( ) ;
}
if ( is_vararg ) {
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . text_color ) ;
2020-05-14 14:41:43 +00:00
if ( p_method . arguments . size ( ) ) {
2017-12-15 08:45:23 +00:00
class_desc - > add_text ( " , " ) ;
2020-05-14 14:41:43 +00:00
}
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . symbol_color ) ;
2017-12-15 08:45:23 +00:00
class_desc - > add_text ( " ... " ) ;
class_desc - > pop ( ) ;
class_desc - > pop ( ) ;
}
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . symbol_color ) ;
2019-09-20 20:40:22 +00:00
class_desc - > add_text ( " ) " ) ;
2017-12-15 08:45:23 +00:00
class_desc - > pop ( ) ;
2021-12-09 09:42:46 +00:00
if ( ! p_method . qualifiers . is_empty ( ) ) {
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . qualifier_color ) ;
2022-10-31 10:27:10 +00:00
PackedStringArray qualifiers = p_method . qualifiers . split_spaces ( ) ;
for ( const String & qualifier : qualifiers ) {
String hint ;
if ( qualifier = = " vararg " ) {
hint = TTR ( " This method supports a variable number of arguments. " ) ;
} else if ( qualifier = = " virtual " ) {
2022-11-01 14:29:38 +00:00
hint = TTR ( " This method is called by the engine. \n It can be overridden to customize built-in behavior. " ) ;
2022-10-31 10:27:10 +00:00
} else if ( qualifier = = " const " ) {
hint = TTR ( " This method has no side effects. \n It does not modify the object in any way. " ) ;
} else if ( qualifier = = " static " ) {
hint = TTR ( " This method does not need an instance to be called. \n It can be called directly using the class name. " ) ;
}
class_desc - > add_text ( " " ) ;
if ( ! hint . is_empty ( ) ) {
class_desc - > push_hint ( hint ) ;
class_desc - > add_text ( qualifier ) ;
class_desc - > pop ( ) ;
} else {
class_desc - > add_text ( qualifier ) ;
}
}
2017-12-15 08:45:23 +00:00
class_desc - > pop ( ) ;
}
2022-08-28 06:17:25 +00:00
if ( p_method . is_deprecated ) {
DEPRECATED_DOC_TAG ;
}
if ( p_method . is_experimental ) {
EXPERIMENTAL_DOC_TAG ;
}
2020-05-14 14:41:43 +00:00
if ( p_overview ) {
2023-04-21 13:32:26 +00:00
class_desc - > pop ( ) ; // cell
2020-05-14 14:41:43 +00:00
}
2017-12-15 08:45:23 +00:00
}
2021-12-01 18:02:20 +00:00
void EditorHelp : : _add_bulletpoint ( ) {
static const char32_t prefix [ 3 ] = { 0x25CF /* filled circle */ , ' ' , 0 } ;
class_desc - > add_text ( String ( prefix ) ) ;
}
2023-02-11 16:33:38 +00:00
void EditorHelp : : _push_normal_font ( ) {
class_desc - > push_font ( theme_cache . doc_font ) ;
class_desc - > push_font_size ( theme_cache . doc_font_size ) ;
}
void EditorHelp : : _pop_normal_font ( ) {
class_desc - > pop ( ) ;
class_desc - > pop ( ) ;
}
void EditorHelp : : _push_title_font ( ) {
class_desc - > push_color ( theme_cache . title_color ) ;
class_desc - > push_font ( theme_cache . doc_title_font ) ;
class_desc - > push_font_size ( theme_cache . doc_title_font_size ) ;
}
void EditorHelp : : _pop_title_font ( ) {
class_desc - > pop ( ) ;
class_desc - > pop ( ) ;
class_desc - > pop ( ) ;
}
void EditorHelp : : _push_code_font ( ) {
class_desc - > push_font ( theme_cache . doc_code_font ) ;
class_desc - > push_font_size ( theme_cache . doc_code_font_size ) ;
}
void EditorHelp : : _pop_code_font ( ) {
class_desc - > pop ( ) ;
class_desc - > pop ( ) ;
}
2023-04-21 13:32:26 +00:00
Error EditorHelp : : _goto_desc ( const String & p_class ) {
// If class doesn't have docs listed, attempt on-demand docgen
if ( ! doc - > class_list . has ( p_class ) & & ! _attempt_doc_load ( p_class ) ) {
2014-05-06 09:41:19 +00:00
return ERR_DOES_NOT_EXIST ;
2020-05-14 14:41:43 +00:00
}
2014-02-10 01:10:30 +00:00
2014-06-23 15:43:37 +00:00
select_locked = true ;
2014-02-10 01:10:30 +00:00
class_desc - > show ( ) ;
2017-12-18 17:46:17 +00:00
2014-02-21 02:01:44 +00:00
description_line = 0 ;
2014-02-10 01:10:30 +00:00
2020-05-14 14:41:43 +00:00
if ( p_class = = edited_class ) {
2022-04-26 16:57:36 +00:00
return OK ; // Already there.
2020-05-14 14:41:43 +00:00
}
2014-02-10 01:10:30 +00:00
2018-08-13 00:40:06 +00:00
edited_class = p_class ;
_update_doc ( ) ;
return OK ;
}
2022-07-19 15:17:04 +00:00
void EditorHelp : : _update_method_list ( const Vector < DocData : : MethodDoc > p_methods ) {
2021-09-21 02:49:02 +00:00
class_desc - > add_newline ( ) ;
2023-02-11 16:33:38 +00:00
_push_code_font ( ) ;
2021-09-21 02:49:02 +00:00
class_desc - > push_indent ( 1 ) ;
class_desc - > push_table ( 2 ) ;
class_desc - > set_table_column_expand ( 1 , true ) ;
bool any_previous = false ;
for ( int pass = 0 ; pass < 2 ; pass + + ) {
Vector < DocData : : MethodDoc > m ;
for ( int i = 0 ; i < p_methods . size ( ) ; i + + ) {
const String & q = p_methods [ i ] . qualifiers ;
2022-02-03 16:03:38 +00:00
if ( ( pass = = 0 & & q . contains ( " virtual " ) ) | | ( pass = = 1 & & ! q . contains ( " virtual " ) ) ) {
2021-09-21 02:49:02 +00:00
m . push_back ( p_methods [ i ] ) ;
}
}
if ( any_previous & & ! m . is_empty ( ) ) {
class_desc - > push_cell ( ) ;
2023-04-21 13:32:26 +00:00
class_desc - > pop ( ) ; // cell
2021-09-21 02:49:02 +00:00
class_desc - > push_cell ( ) ;
2023-04-21 13:32:26 +00:00
class_desc - > pop ( ) ; // cell
2021-09-21 02:49:02 +00:00
}
String group_prefix ;
for ( int i = 0 ; i < m . size ( ) ; i + + ) {
const String new_prefix = m [ i ] . name . substr ( 0 , 3 ) ;
bool is_new_group = false ;
if ( i < m . size ( ) - 1 & & new_prefix = = m [ i + 1 ] . name . substr ( 0 , 3 ) & & new_prefix ! = group_prefix ) {
is_new_group = i > 0 ;
group_prefix = new_prefix ;
2021-12-09 09:42:46 +00:00
} else if ( ! group_prefix . is_empty ( ) & & new_prefix ! = group_prefix ) {
2021-09-21 02:49:02 +00:00
is_new_group = true ;
group_prefix = " " ;
}
if ( is_new_group & & pass = = 1 ) {
class_desc - > push_cell ( ) ;
2023-04-21 13:32:26 +00:00
class_desc - > pop ( ) ; // cell
2021-09-21 02:49:02 +00:00
class_desc - > push_cell ( ) ;
2023-04-21 13:32:26 +00:00
class_desc - > pop ( ) ; // cell
2021-09-21 02:49:02 +00:00
}
_add_method ( m [ i ] , true ) ;
}
any_previous = ! m . is_empty ( ) ;
}
2023-04-21 13:32:26 +00:00
class_desc - > pop ( ) ; // table
2021-09-21 02:49:02 +00:00
class_desc - > pop ( ) ;
2023-02-11 16:33:38 +00:00
_pop_code_font ( ) ;
2021-09-21 02:49:02 +00:00
class_desc - > add_newline ( ) ;
class_desc - > add_newline ( ) ;
}
void EditorHelp : : _update_method_descriptions ( const DocData : : ClassDoc p_classdoc , const Vector < DocData : : MethodDoc > p_methods , const String & p_method_type ) {
2023-02-11 15:29:44 +00:00
String link_color_text = theme_cache . title_color . to_html ( false ) ;
2021-09-21 02:49:02 +00:00
class_desc - > add_newline ( ) ;
class_desc - > add_newline ( ) ;
for ( int pass = 0 ; pass < 2 ; pass + + ) {
Vector < DocData : : MethodDoc > methods_filtered ;
for ( int i = 0 ; i < p_methods . size ( ) ; i + + ) {
const String & q = p_methods [ i ] . qualifiers ;
2022-02-03 16:03:38 +00:00
if ( ( pass = = 0 & & q . contains ( " virtual " ) ) | | ( pass = = 1 & & ! q . contains ( " virtual " ) ) ) {
2021-09-21 02:49:02 +00:00
methods_filtered . push_back ( p_methods [ i ] ) ;
}
}
for ( int i = 0 ; i < methods_filtered . size ( ) ; i + + ) {
2023-02-11 16:33:38 +00:00
_push_code_font ( ) ;
2021-09-21 02:49:02 +00:00
_add_method ( methods_filtered [ i ] , false ) ;
2023-02-11 16:33:38 +00:00
_pop_code_font ( ) ;
2021-09-21 02:49:02 +00:00
class_desc - > add_newline ( ) ;
class_desc - > add_newline ( ) ;
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . text_color ) ;
2023-02-11 16:33:38 +00:00
_push_normal_font ( ) ;
2021-09-21 02:49:02 +00:00
class_desc - > push_indent ( 1 ) ;
if ( methods_filtered [ i ] . errors_returned . size ( ) ) {
class_desc - > append_text ( TTR ( " Error codes returned: " ) ) ;
class_desc - > add_newline ( ) ;
class_desc - > push_list ( 0 , RichTextLabel : : LIST_DOTS , false ) ;
for ( int j = 0 ; j < methods_filtered [ i ] . errors_returned . size ( ) ; j + + ) {
if ( j > 0 ) {
class_desc - > add_newline ( ) ;
}
int val = methods_filtered [ i ] . errors_returned [ j ] ;
String text = itos ( val ) ;
for ( int k = 0 ; k < CoreConstants : : get_global_constant_count ( ) ; k + + ) {
if ( CoreConstants : : get_global_constant_value ( k ) = = val & & CoreConstants : : get_global_constant_enum ( k ) = = SNAME ( " Error " ) ) {
text = CoreConstants : : get_global_constant_name ( k ) ;
break ;
}
}
class_desc - > push_bold ( ) ;
class_desc - > append_text ( text ) ;
class_desc - > pop ( ) ;
}
class_desc - > pop ( ) ;
class_desc - > add_newline ( ) ;
class_desc - > add_newline ( ) ;
}
if ( ! methods_filtered [ i ] . description . strip_edges ( ) . is_empty ( ) ) {
_add_text ( DTR ( methods_filtered [ i ] . description ) ) ;
} else {
class_desc - > add_image ( get_theme_icon ( SNAME ( " Error " ) , SNAME ( " EditorIcons " ) ) ) ;
class_desc - > add_text ( " " ) ;
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . comment_color ) ;
2021-09-21 02:49:02 +00:00
if ( p_classdoc . is_script_doc ) {
2022-03-03 09:55:37 +00:00
class_desc - > append_text ( vformat ( TTR ( " There is currently no description for this %s. " ) , p_method_type ) ) ;
2021-09-21 02:49:02 +00:00
} else {
2022-03-03 09:55:37 +00:00
class_desc - > append_text ( vformat ( TTR ( " There is currently no description for this %s. Please help us by [color=$color][url=$url]contributing one[/url][/color]! " ) , p_method_type ) . replace ( " $url " , CONTRIBUTE_URL ) . replace ( " $color " , link_color_text ) ) ;
2021-09-21 02:49:02 +00:00
}
class_desc - > pop ( ) ;
}
class_desc - > pop ( ) ;
2023-02-11 16:33:38 +00:00
_pop_normal_font ( ) ;
2021-09-21 02:49:02 +00:00
class_desc - > pop ( ) ;
2023-02-11 16:33:38 +00:00
2021-09-21 02:49:02 +00:00
class_desc - > add_newline ( ) ;
class_desc - > add_newline ( ) ;
class_desc - > add_newline ( ) ;
}
}
}
2018-08-13 00:40:06 +00:00
void EditorHelp : : _update_doc ( ) {
2020-05-14 14:41:43 +00:00
if ( ! doc - > class_list . has ( edited_class ) ) {
2018-09-16 22:17:07 +00:00
return ;
2020-05-14 14:41:43 +00:00
}
2018-08-13 00:40:06 +00:00
2014-02-10 01:10:30 +00:00
scroll_locked = true ;
class_desc - > clear ( ) ;
method_line . clear ( ) ;
2017-09-14 00:56:37 +00:00
section_line . clear ( ) ;
2014-02-10 01:10:30 +00:00
2023-02-11 15:29:44 +00:00
String link_color_text = theme_cache . title_color . to_html ( false ) ;
2014-02-10 01:10:30 +00:00
2022-01-18 20:01:30 +00:00
DocData : : ClassDoc cd = doc - > class_list [ edited_class ] ; // Make a copy, so we can sort without worrying.
2018-09-12 15:12:23 +00:00
// Class name
2017-09-14 00:56:37 +00:00
section_line . push_back ( Pair < String , int > ( TTR ( " Top " ) , 0 ) ) ;
2023-02-11 16:33:38 +00:00
_push_title_font ( ) ;
2016-05-18 22:08:12 +00:00
class_desc - > add_text ( TTR ( " Class: " ) + " " ) ;
2023-03-31 19:17:59 +00:00
_add_type_icon ( edited_class , theme_cache . doc_title_font_size , " Object " ) ;
2022-04-24 16:55:51 +00:00
class_desc - > add_text ( " " ) ;
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . headline_color ) ;
2018-08-13 00:40:06 +00:00
_add_text ( edited_class ) ;
2022-06-29 04:57:16 +00:00
class_desc - > pop ( ) ; // color
2023-02-11 16:33:38 +00:00
_pop_title_font ( ) ;
2022-08-28 06:17:25 +00:00
if ( cd . is_deprecated ) {
class_desc - > add_text ( " " ) ;
Ref < Texture2D > error_icon = get_theme_icon ( SNAME ( " StatusError " ) , SNAME ( " EditorIcons " ) ) ;
class_desc - > add_image ( error_icon , error_icon - > get_width ( ) , error_icon - > get_height ( ) ) ;
}
if ( cd . is_experimental ) {
class_desc - > add_text ( " " ) ;
Ref < Texture2D > warning_icon = get_theme_icon ( SNAME ( " NodeWarning " ) , SNAME ( " EditorIcons " ) ) ;
class_desc - > add_image ( warning_icon , warning_icon - > get_width ( ) , warning_icon - > get_height ( ) ) ;
}
2014-02-21 02:01:44 +00:00
class_desc - > add_newline ( ) ;
2022-09-02 13:56:28 +00:00
const String non_breaking_space = String : : chr ( 160 ) ;
2018-09-12 15:12:23 +00:00
// Inheritance tree
// Ascendents
2021-12-09 09:42:46 +00:00
if ( ! cd . inherits . is_empty ( ) ) {
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . title_color ) ;
2023-02-11 16:33:38 +00:00
_push_normal_font ( ) ;
2016-05-18 22:08:12 +00:00
class_desc - > add_text ( TTR ( " Inherits: " ) + " " ) ;
2016-03-05 15:28:25 +00:00
String inherits = cd . inherits ;
2021-12-09 09:42:46 +00:00
while ( ! inherits . is_empty ( ) ) {
2023-03-31 19:17:59 +00:00
_add_type_icon ( inherits , theme_cache . doc_font_size , " ArrowRight " ) ;
2022-09-02 13:56:28 +00:00
class_desc - > add_text ( non_breaking_space ) ; // Otherwise icon borrows hyperlink from _add_type().
2016-03-05 15:28:25 +00:00
_add_type ( inherits ) ;
inherits = doc - > class_list [ inherits ] . inherits ;
2021-12-09 09:42:46 +00:00
if ( ! inherits . is_empty ( ) ) {
2017-10-09 16:59:53 +00:00
class_desc - > add_text ( " < " ) ;
2016-03-05 15:28:25 +00:00
}
}
2023-02-11 16:33:38 +00:00
_pop_normal_font ( ) ;
2014-02-10 01:10:30 +00:00
class_desc - > pop ( ) ;
class_desc - > add_newline ( ) ;
2016-03-05 15:28:25 +00:00
}
2018-09-12 15:12:23 +00:00
// Descendents
2020-11-29 02:37:57 +00:00
if ( cd . is_script_doc | | ClassDB : : class_exists ( cd . name ) ) {
2016-03-05 15:28:25 +00:00
bool found = false ;
bool prev = false ;
2023-02-11 16:33:38 +00:00
_push_normal_font ( ) ;
2021-08-09 20:13:42 +00:00
for ( const KeyValue < String , DocData : : ClassDoc > & E : doc - > class_list ) {
if ( E . value . inherits = = cd . name ) {
2016-03-05 15:28:25 +00:00
if ( ! found ) {
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . title_color ) ;
2016-05-18 22:08:12 +00:00
class_desc - > add_text ( TTR ( " Inherited by: " ) + " " ) ;
2016-03-05 15:28:25 +00:00
found = true ;
}
if ( prev ) {
class_desc - > add_text ( " , " ) ;
}
2023-03-31 19:17:59 +00:00
_add_type_icon ( E . value . name , theme_cache . doc_font_size , " ArrowRight " ) ;
2022-09-02 13:56:28 +00:00
class_desc - > add_text ( non_breaking_space ) ; // Otherwise icon borrows hyperlink from _add_type().
2021-08-09 20:13:42 +00:00
_add_type ( E . value . name ) ;
2016-03-05 15:28:25 +00:00
prev = true ;
}
}
2023-02-11 16:33:38 +00:00
_pop_normal_font ( ) ;
2016-03-05 15:28:25 +00:00
2020-01-14 20:38:54 +00:00
if ( found ) {
2016-03-05 15:28:25 +00:00
class_desc - > pop ( ) ;
2020-01-14 20:38:54 +00:00
class_desc - > add_newline ( ) ;
}
2014-02-10 01:10:30 +00:00
}
2022-08-28 06:17:25 +00:00
// Note if deprecated.
if ( cd . is_deprecated ) {
Ref < Texture2D > error_icon = get_theme_icon ( SNAME ( " StatusError " ) , SNAME ( " EditorIcons " ) ) ;
class_desc - > push_color ( get_theme_color ( SNAME ( " error_color " ) , SNAME ( " Editor " ) ) ) ;
class_desc - > add_image ( error_icon , error_icon - > get_width ( ) , error_icon - > get_height ( ) ) ;
class_desc - > add_text ( String ( " " ) + TTR ( " This class is marked as deprecated. It will be removed in future versions. " ) ) ;
class_desc - > pop ( ) ;
class_desc - > add_newline ( ) ;
}
// Note if experimental.
if ( cd . is_experimental ) {
Ref < Texture2D > warning_icon = get_theme_icon ( SNAME ( " NodeWarning " ) , SNAME ( " EditorIcons " ) ) ;
class_desc - > push_color ( get_theme_color ( SNAME ( " warning_color " ) , SNAME ( " Editor " ) ) ) ;
class_desc - > add_image ( warning_icon , warning_icon - > get_width ( ) , warning_icon - > get_height ( ) ) ;
class_desc - > add_text ( String ( " " ) + TTR ( " This class is marked as experimental. It is subject to likely change or possible removal in future versions. Use at your own discretion. " ) ) ;
class_desc - > pop ( ) ;
class_desc - > add_newline ( ) ;
}
2022-07-19 15:17:04 +00:00
bool has_description = false ;
2017-09-14 00:56:37 +00:00
class_desc - > add_newline ( ) ;
2016-03-05 15:28:25 +00:00
class_desc - > add_newline ( ) ;
2018-09-12 15:12:23 +00:00
// Brief description
2022-07-04 15:56:34 +00:00
if ( ! cd . brief_description . strip_edges ( ) . is_empty ( ) ) {
2022-07-19 15:17:04 +00:00
has_description = true ;
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . text_color ) ;
class_desc - > push_font ( theme_cache . doc_bold_font ) ;
2020-01-14 20:38:54 +00:00
class_desc - > push_indent ( 1 ) ;
2020-03-18 17:34:36 +00:00
_add_text ( DTR ( cd . brief_description ) ) ;
2020-01-14 20:38:54 +00:00
class_desc - > pop ( ) ;
class_desc - > pop ( ) ;
class_desc - > pop ( ) ;
2023-02-11 16:33:38 +00:00
2020-01-14 20:38:54 +00:00
class_desc - > add_newline ( ) ;
class_desc - > add_newline ( ) ;
class_desc - > add_newline ( ) ;
}
// Class description
2022-07-04 15:56:34 +00:00
if ( ! cd . description . strip_edges ( ) . is_empty ( ) ) {
2022-07-19 15:17:04 +00:00
has_description = true ;
2022-05-18 07:17:55 +00:00
section_line . push_back ( Pair < String , int > ( TTR ( " Description " ) , class_desc - > get_paragraph_count ( ) - 2 ) ) ;
description_line = class_desc - > get_paragraph_count ( ) - 2 ;
2023-02-11 16:33:38 +00:00
_push_title_font ( ) ;
2020-01-14 20:38:54 +00:00
class_desc - > add_text ( TTR ( " Description " ) ) ;
2023-02-11 16:33:38 +00:00
_pop_title_font ( ) ;
2014-02-10 01:10:30 +00:00
2019-06-20 10:42:25 +00:00
class_desc - > add_newline ( ) ;
2014-02-10 01:10:30 +00:00
class_desc - > add_newline ( ) ;
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . text_color ) ;
2023-02-11 16:33:38 +00:00
_push_normal_font ( ) ;
2015-10-20 15:41:27 +00:00
class_desc - > push_indent ( 1 ) ;
2020-03-18 17:34:36 +00:00
_add_text ( DTR ( cd . description ) ) ;
2020-01-14 20:38:54 +00:00
class_desc - > pop ( ) ;
2023-02-11 16:33:38 +00:00
_pop_normal_font ( ) ;
2015-10-20 15:41:27 +00:00
class_desc - > pop ( ) ;
2023-02-11 16:33:38 +00:00
2020-01-14 20:38:54 +00:00
class_desc - > add_newline ( ) ;
class_desc - > add_newline ( ) ;
class_desc - > add_newline ( ) ;
}
2022-07-19 15:17:04 +00:00
if ( ! has_description ) {
class_desc - > add_image ( get_theme_icon ( SNAME ( " Error " ) , SNAME ( " EditorIcons " ) ) ) ;
class_desc - > add_text ( " " ) ;
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . comment_color ) ;
2022-07-19 15:17:04 +00:00
if ( cd . is_script_doc ) {
class_desc - > append_text ( TTR ( " There is currently no description for this class. " ) ) ;
} else {
class_desc - > append_text ( TTR ( " There is currently no description for this class. Please help us by [color=$color][url=$url]contributing one[/url][/color]! " ) . replace ( " $url " , CONTRIBUTE_URL ) . replace ( " $color " , link_color_text ) ) ;
}
2023-07-08 11:17:41 +00:00
class_desc - > add_newline ( ) ;
class_desc - > add_newline ( ) ;
}
# ifdef MODULE_MONO_ENABLED
if ( classes_with_csharp_differences . has ( cd . name ) ) {
const String & csharp_differences_url = vformat ( " %s/tutorials/scripting/c_sharp/c_sharp_differences.html " , VERSION_DOCS_URL ) ;
class_desc - > push_color ( theme_cache . text_color ) ;
_push_normal_font ( ) ;
class_desc - > push_indent ( 1 ) ;
_add_text ( " [b] " + TTR ( " Note: " ) + " [/b] " + vformat ( TTR ( " There are notable differences when using this API with C#. See [url=%s]C# API differences to GDScript[/url] for more information. " ) , csharp_differences_url ) ) ;
2022-07-19 15:17:04 +00:00
class_desc - > pop ( ) ;
2023-07-08 11:17:41 +00:00
_pop_normal_font ( ) ;
class_desc - > pop ( ) ;
2022-07-19 15:17:04 +00:00
class_desc - > add_newline ( ) ;
class_desc - > add_newline ( ) ;
}
2023-07-08 11:17:41 +00:00
# endif
2022-07-19 15:17:04 +00:00
2020-01-14 20:38:54 +00:00
// Online tutorials
2020-01-26 23:58:53 +00:00
if ( cd . tutorials . size ( ) ) {
2023-02-11 16:33:38 +00:00
_push_title_font ( ) ;
2020-01-14 20:38:54 +00:00
class_desc - > add_text ( TTR ( " Online Tutorials " ) ) ;
2023-02-11 16:33:38 +00:00
_pop_title_font ( ) ;
2020-01-14 20:38:54 +00:00
2014-02-10 01:10:30 +00:00
class_desc - > add_newline ( ) ;
2020-01-14 20:38:54 +00:00
2023-02-11 16:33:38 +00:00
class_desc - > push_indent ( 1 ) ;
_push_code_font ( ) ;
2020-01-26 23:58:53 +00:00
for ( int i = 0 ; i < cd . tutorials . size ( ) ; i + + ) {
2020-06-07 01:26:35 +00:00
const String link = DTR ( cd . tutorials [ i ] . link ) ;
2020-12-15 12:04:21 +00:00
String linktxt = ( cd . tutorials [ i ] . title . is_empty ( ) ) ? link : DTR ( cd . tutorials [ i ] . title ) ;
2020-01-26 23:58:53 +00:00
const int seppos = linktxt . find ( " // " ) ;
if ( seppos ! = - 1 ) {
2020-02-13 15:42:49 +00:00
linktxt = link . substr ( seppos + 2 ) ;
2020-01-14 20:38:54 +00:00
}
2020-01-26 23:58:53 +00:00
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . symbol_color ) ;
2020-05-29 14:25:12 +00:00
class_desc - > append_text ( " [url= " + link + " ] " + linktxt + " [/url] " ) ;
2020-01-14 20:38:54 +00:00
class_desc - > pop ( ) ;
2020-01-26 23:58:53 +00:00
class_desc - > add_newline ( ) ;
2020-01-14 20:38:54 +00:00
}
2020-01-26 23:58:53 +00:00
2023-02-11 16:33:38 +00:00
_pop_code_font ( ) ;
2020-01-14 20:38:54 +00:00
class_desc - > pop ( ) ;
2023-02-11 16:33:38 +00:00
2015-09-30 02:38:23 +00:00
class_desc - > add_newline ( ) ;
2017-09-14 00:56:37 +00:00
class_desc - > add_newline ( ) ;
2014-02-10 01:10:30 +00:00
}
2018-09-12 15:12:23 +00:00
// Properties overview
2022-05-19 15:00:06 +00:00
HashSet < String > skip_methods ;
2017-01-04 04:16:14 +00:00
2023-05-13 09:57:44 +00:00
bool has_properties = false ;
bool has_property_descriptions = false ;
for ( const DocData : : PropertyDoc & prop : cd . properties ) {
if ( cd . is_script_doc & & prop . name . begins_with ( " _ " ) & & prop . description . strip_edges ( ) . is_empty ( ) ) {
continue ;
}
has_properties = true ;
if ( ! prop . overridden ) {
has_property_descriptions = true ;
2020-11-29 02:37:57 +00:00
break ;
}
}
if ( has_properties ) {
2022-05-18 07:17:55 +00:00
section_line . push_back ( Pair < String , int > ( TTR ( " Properties " ) , class_desc - > get_paragraph_count ( ) - 2 ) ) ;
2023-02-11 16:33:38 +00:00
_push_title_font ( ) ;
2019-09-20 20:40:22 +00:00
class_desc - > add_text ( TTR ( " Properties " ) ) ;
2023-02-11 16:33:38 +00:00
_pop_title_font ( ) ;
2017-01-04 04:16:14 +00:00
2019-06-20 10:42:25 +00:00
class_desc - > add_newline ( ) ;
2023-02-11 16:33:38 +00:00
_push_code_font ( ) ;
2017-01-04 04:16:14 +00:00
class_desc - > push_indent ( 1 ) ;
2021-12-02 19:38:49 +00:00
class_desc - > push_table ( 4 ) ;
2020-05-14 09:00:19 +00:00
class_desc - > set_table_column_expand ( 1 , true ) ;
2017-01-04 04:16:14 +00:00
for ( int i = 0 ; i < cd . properties . size ( ) ; i + + ) {
2020-11-29 02:37:57 +00:00
// Ignore undocumented private.
2022-07-04 15:56:34 +00:00
if ( cd . properties [ i ] . name . begins_with ( " _ " ) & & cd . properties [ i ] . description . strip_edges ( ) . is_empty ( ) ) {
2020-11-29 02:37:57 +00:00
continue ;
}
2022-05-18 07:17:55 +00:00
property_line [ cd . properties [ i ] . name ] = class_desc - > get_paragraph_count ( ) - 2 ; //gets overridden if description
2017-01-04 04:16:14 +00:00
2021-12-02 19:38:49 +00:00
// Property type.
2017-01-04 04:16:14 +00:00
class_desc - > push_cell ( ) ;
2021-11-25 02:58:47 +00:00
class_desc - > push_paragraph ( HORIZONTAL_ALIGNMENT_RIGHT , Control : : TEXT_DIRECTION_AUTO , " " ) ;
2023-02-11 16:33:38 +00:00
_push_code_font ( ) ;
2023-06-15 14:06:22 +00:00
_add_type ( cd . properties [ i ] . type , cd . properties [ i ] . enumeration , cd . properties [ i ] . is_bitfield ) ;
2023-02-11 16:33:38 +00:00
_pop_code_font ( ) ;
2017-01-04 04:16:14 +00:00
class_desc - > pop ( ) ;
2021-12-02 19:38:49 +00:00
class_desc - > pop ( ) ; // cell
2017-01-04 04:16:14 +00:00
bool describe = false ;
2021-12-09 09:42:46 +00:00
if ( ! cd . properties [ i ] . setter . is_empty ( ) ) {
2017-01-04 04:16:14 +00:00
skip_methods . insert ( cd . properties [ i ] . setter ) ;
describe = true ;
}
2021-12-09 09:42:46 +00:00
if ( ! cd . properties [ i ] . getter . is_empty ( ) ) {
2017-01-04 04:16:14 +00:00
skip_methods . insert ( cd . properties [ i ] . getter ) ;
describe = true ;
}
2022-07-04 15:56:34 +00:00
if ( ! cd . properties [ i ] . description . strip_edges ( ) . is_empty ( ) ) {
2017-01-04 04:16:14 +00:00
describe = true ;
}
2019-06-01 13:42:22 +00:00
2019-09-03 10:42:34 +00:00
if ( cd . properties [ i ] . overridden ) {
describe = false ;
}
2021-12-02 19:38:49 +00:00
// Property name.
2017-01-04 04:16:14 +00:00
class_desc - > push_cell ( ) ;
2023-02-11 16:33:38 +00:00
_push_code_font ( ) ;
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . headline_color ) ;
2019-06-01 13:42:22 +00:00
2017-01-04 04:16:14 +00:00
if ( describe ) {
2019-04-27 19:15:07 +00:00
class_desc - > push_meta ( " @member " + cd . properties [ i ] . name ) ;
2017-01-04 04:16:14 +00:00
}
_add_text ( cd . properties [ i ] . name ) ;
if ( describe ) {
class_desc - > pop ( ) ;
}
2021-12-02 19:38:49 +00:00
class_desc - > pop ( ) ;
2023-02-11 16:33:38 +00:00
_pop_code_font ( ) ;
2021-12-02 19:38:49 +00:00
class_desc - > pop ( ) ; // cell
// Property value.
class_desc - > push_cell ( ) ;
2023-02-11 16:33:38 +00:00
_push_code_font ( ) ;
2021-12-02 19:38:49 +00:00
2021-12-09 09:42:46 +00:00
if ( ! cd . properties [ i ] . default_value . is_empty ( ) ) {
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . symbol_color ) ;
2021-12-02 19:38:49 +00:00
if ( cd . properties [ i ] . overridden ) {
class_desc - > add_text ( " [ " ) ;
class_desc - > push_meta ( " @member " + cd . properties [ i ] . overrides + " . " + cd . properties [ i ] . name ) ;
_add_text ( vformat ( TTR ( " overrides %s: " ) , cd . properties [ i ] . overrides ) ) ;
class_desc - > pop ( ) ;
class_desc - > add_text ( " " ) ;
} else {
class_desc - > add_text ( " [ " + TTR ( " default: " ) + " " ) ;
}
2019-06-01 13:42:22 +00:00
class_desc - > pop ( ) ;
2021-12-02 19:38:49 +00:00
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . value_color ) ;
2019-06-01 13:42:22 +00:00
_add_text ( _fix_constant ( cd . properties [ i ] . default_value ) ) ;
class_desc - > pop ( ) ;
2021-12-02 19:38:49 +00:00
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . symbol_color ) ;
2019-06-01 13:42:22 +00:00
class_desc - > add_text ( " ] " ) ;
class_desc - > pop ( ) ;
}
2022-08-28 06:17:25 +00:00
if ( cd . properties [ i ] . is_deprecated ) {
DEPRECATED_DOC_TAG ;
}
2023-07-02 10:13:38 +00:00
2022-08-28 06:17:25 +00:00
if ( cd . properties [ i ] . is_experimental ) {
EXPERIMENTAL_DOC_TAG ;
}
2023-02-11 16:33:38 +00:00
_pop_code_font ( ) ;
2021-12-02 19:38:49 +00:00
class_desc - > pop ( ) ; // cell
// Property setters and getters.
class_desc - > push_cell ( ) ;
2023-02-11 16:33:38 +00:00
_push_code_font ( ) ;
2021-12-02 19:38:49 +00:00
2021-12-09 09:42:46 +00:00
if ( cd . is_script_doc & & ( ! cd . properties [ i ] . setter . is_empty ( ) | | ! cd . properties [ i ] . getter . is_empty ( ) ) ) {
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . symbol_color ) ;
2020-11-29 02:37:57 +00:00
class_desc - > add_text ( " [ " + TTR ( " property: " ) + " " ) ;
class_desc - > pop ( ) ; // color
2021-12-09 09:42:46 +00:00
if ( ! cd . properties [ i ] . setter . is_empty ( ) ) {
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . value_color ) ;
2020-11-29 02:37:57 +00:00
class_desc - > add_text ( " setter " ) ;
class_desc - > pop ( ) ; // color
}
2021-12-09 09:42:46 +00:00
if ( ! cd . properties [ i ] . getter . is_empty ( ) ) {
if ( ! cd . properties [ i ] . setter . is_empty ( ) ) {
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . symbol_color ) ;
2020-11-29 02:37:57 +00:00
class_desc - > add_text ( " , " ) ;
class_desc - > pop ( ) ; // color
}
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . value_color ) ;
2020-11-29 02:37:57 +00:00
class_desc - > add_text ( " getter " ) ;
class_desc - > pop ( ) ; // color
}
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . symbol_color ) ;
2020-11-29 02:37:57 +00:00
class_desc - > add_text ( " ] " ) ;
class_desc - > pop ( ) ; // color
}
2023-02-11 16:33:38 +00:00
_pop_code_font ( ) ;
2021-12-02 19:38:49 +00:00
class_desc - > pop ( ) ; // cell
2017-01-04 04:16:14 +00:00
}
2021-12-02 19:38:49 +00:00
class_desc - > pop ( ) ; // table
2017-01-04 04:16:14 +00:00
class_desc - > pop ( ) ;
2023-02-11 16:33:38 +00:00
_pop_code_font ( ) ;
2017-01-04 04:16:14 +00:00
class_desc - > add_newline ( ) ;
class_desc - > add_newline ( ) ;
}
2018-09-12 15:12:23 +00:00
// Methods overview
2022-10-18 14:43:37 +00:00
bool sort_methods = EDITOR_GET ( " text_editor/help/sort_functions_alphabetically " ) ;
2016-05-29 14:37:26 +00:00
2017-01-04 04:16:14 +00:00
Vector < DocData : : MethodDoc > methods ;
2014-02-10 01:10:30 +00:00
2017-01-04 04:16:14 +00:00
for ( int i = 0 ; i < cd . methods . size ( ) ; i + + ) {
2020-01-17 09:40:59 +00:00
if ( skip_methods . has ( cd . methods [ i ] . name ) ) {
if ( cd . methods [ i ] . arguments . size ( ) = = 0 /* getter */ | | ( cd . methods [ i ] . arguments . size ( ) = = 1 & & cd . methods [ i ] . return_type = = " void " /* setter */ ) ) {
continue ;
}
}
2021-08-23 17:53:27 +00:00
// Ignore undocumented non virtual private.
2022-07-04 15:56:34 +00:00
if ( cd . methods [ i ] . name . begins_with ( " _ " ) & & cd . methods [ i ] . description . strip_edges ( ) . is_empty ( ) & & ! cd . methods [ i ] . qualifiers . contains ( " virtual " ) ) {
2020-11-29 02:37:57 +00:00
continue ;
}
2017-01-04 04:16:14 +00:00
methods . push_back ( cd . methods [ i ] ) ;
}
2021-09-21 02:49:02 +00:00
if ( ! cd . constructors . is_empty ( ) ) {
2020-05-14 14:41:43 +00:00
if ( sort_methods ) {
2021-09-21 02:49:02 +00:00
cd . constructors . sort ( ) ;
2020-05-14 14:41:43 +00:00
}
2016-05-29 14:37:26 +00:00
2022-05-18 07:17:55 +00:00
section_line . push_back ( Pair < String , int > ( TTR ( " Constructors " ) , class_desc - > get_paragraph_count ( ) - 2 ) ) ;
2023-02-11 16:33:38 +00:00
_push_title_font ( ) ;
2021-09-21 02:49:02 +00:00
class_desc - > add_text ( TTR ( " Constructors " ) ) ;
2023-02-11 16:33:38 +00:00
_pop_title_font ( ) ;
2022-07-19 15:17:04 +00:00
_update_method_list ( cd . constructors ) ;
2021-09-21 02:49:02 +00:00
}
if ( ! methods . is_empty ( ) ) {
if ( sort_methods ) {
methods . sort ( ) ;
}
2022-07-19 15:17:04 +00:00
2022-05-18 07:17:55 +00:00
section_line . push_back ( Pair < String , int > ( TTR ( " Methods " ) , class_desc - > get_paragraph_count ( ) - 2 ) ) ;
2023-02-11 16:33:38 +00:00
_push_title_font ( ) ;
2019-09-20 20:40:22 +00:00
class_desc - > add_text ( TTR ( " Methods " ) ) ;
2023-02-11 16:33:38 +00:00
_pop_title_font ( ) ;
2022-07-19 15:17:04 +00:00
_update_method_list ( methods ) ;
2021-09-21 02:49:02 +00:00
}
2016-09-07 22:39:02 +00:00
2021-09-21 02:49:02 +00:00
if ( ! cd . operators . is_empty ( ) ) {
if ( sort_methods ) {
cd . operators . sort ( ) ;
2014-02-10 01:10:30 +00:00
}
2017-12-15 08:45:23 +00:00
2022-05-18 07:17:55 +00:00
section_line . push_back ( Pair < String , int > ( TTR ( " Operators " ) , class_desc - > get_paragraph_count ( ) - 2 ) ) ;
2023-02-11 16:33:38 +00:00
_push_title_font ( ) ;
2021-09-21 02:49:02 +00:00
class_desc - > add_text ( TTR ( " Operators " ) ) ;
2023-02-11 16:33:38 +00:00
_pop_title_font ( ) ;
2022-07-19 15:17:04 +00:00
_update_method_list ( cd . operators ) ;
2014-02-10 01:10:30 +00:00
}
2018-09-12 15:12:23 +00:00
// Theme properties
2021-09-21 02:49:02 +00:00
if ( ! cd . theme_properties . is_empty ( ) ) {
2022-05-18 07:17:55 +00:00
section_line . push_back ( Pair < String , int > ( TTR ( " Theme Properties " ) , class_desc - > get_paragraph_count ( ) - 2 ) ) ;
2023-02-11 16:33:38 +00:00
_push_title_font ( ) ;
2019-09-20 20:40:22 +00:00
class_desc - > add_text ( TTR ( " Theme Properties " ) ) ;
2023-02-11 16:33:38 +00:00
_pop_title_font ( ) ;
2014-06-30 01:41:02 +00:00
2021-12-01 18:02:20 +00:00
class_desc - > add_newline ( ) ;
class_desc - > add_newline ( ) ;
2014-06-30 01:41:02 +00:00
class_desc - > push_indent ( 1 ) ;
2021-12-01 18:02:20 +00:00
String theme_data_type ;
2022-05-13 13:04:37 +00:00
HashMap < String , String > data_type_names ;
2021-12-01 18:02:20 +00:00
data_type_names [ " color " ] = TTR ( " Colors " ) ;
data_type_names [ " constant " ] = TTR ( " Constants " ) ;
data_type_names [ " font " ] = TTR ( " Fonts " ) ;
data_type_names [ " font_size " ] = TTR ( " Font Sizes " ) ;
data_type_names [ " icon " ] = TTR ( " Icons " ) ;
data_type_names [ " style " ] = TTR ( " Styles " ) ;
2014-06-30 01:41:02 +00:00
for ( int i = 0 ; i < cd . theme_properties . size ( ) ; i + + ) {
2022-05-18 07:17:55 +00:00
theme_property_line [ cd . theme_properties [ i ] . name ] = class_desc - > get_paragraph_count ( ) - 2 ; // Gets overridden if description.
2017-09-14 00:56:37 +00:00
2021-12-01 18:02:20 +00:00
if ( theme_data_type ! = cd . theme_properties [ i ] . data_type ) {
theme_data_type = cd . theme_properties [ i ] . data_type ;
2023-02-11 16:33:38 +00:00
_push_title_font ( ) ;
2021-12-01 18:02:20 +00:00
if ( data_type_names . has ( theme_data_type ) ) {
class_desc - > add_text ( data_type_names [ theme_data_type ] ) ;
} else {
class_desc - > add_text ( " " ) ;
}
2023-02-11 16:33:38 +00:00
_pop_title_font ( ) ;
2021-12-01 18:02:20 +00:00
class_desc - > add_newline ( ) ;
class_desc - > add_newline ( ) ;
}
// Theme item header.
2023-02-11 16:33:38 +00:00
_push_code_font ( ) ;
2021-12-01 18:02:20 +00:00
_add_bulletpoint ( ) ;
// Theme item object type.
2014-06-30 01:41:02 +00:00
_add_type ( cd . theme_properties [ i ] . type ) ;
2017-09-14 00:56:37 +00:00
2021-12-01 18:02:20 +00:00
// Theme item name.
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . headline_color ) ;
2021-12-01 18:02:20 +00:00
class_desc - > add_text ( " " ) ;
2015-10-20 15:41:27 +00:00
_add_text ( cd . theme_properties [ i ] . name ) ;
2014-06-30 01:41:02 +00:00
class_desc - > pop ( ) ;
2019-06-01 13:42:22 +00:00
2021-12-01 18:02:20 +00:00
// Theme item default value.
2021-12-09 09:42:46 +00:00
if ( ! cd . theme_properties [ i ] . default_value . is_empty ( ) ) {
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . symbol_color ) ;
2020-01-16 22:47:18 +00:00
class_desc - > add_text ( " [ " + TTR ( " default: " ) + " " ) ;
2019-06-01 13:42:22 +00:00
class_desc - > pop ( ) ;
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . value_color ) ;
2019-06-01 13:42:22 +00:00
_add_text ( _fix_constant ( cd . theme_properties [ i ] . default_value ) ) ;
class_desc - > pop ( ) ;
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . symbol_color ) ;
2019-06-01 13:42:22 +00:00
class_desc - > add_text ( " ] " ) ;
class_desc - > pop ( ) ;
}
2023-02-11 16:33:38 +00:00
_pop_code_font ( ) ;
2014-02-10 01:10:30 +00:00
2021-12-01 18:02:20 +00:00
// Theme item description.
2022-07-04 15:56:34 +00:00
if ( ! cd . theme_properties [ i ] . description . strip_edges ( ) . is_empty ( ) ) {
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . comment_color ) ;
2023-02-11 16:33:38 +00:00
_push_normal_font ( ) ;
2021-12-01 18:02:20 +00:00
class_desc - > push_indent ( 1 ) ;
2020-03-18 17:34:36 +00:00
_add_text ( DTR ( cd . theme_properties [ i ] . description ) ) ;
2021-12-01 18:02:20 +00:00
class_desc - > pop ( ) ; // indent
2023-02-11 16:33:38 +00:00
_pop_normal_font ( ) ;
2021-12-01 18:02:20 +00:00
class_desc - > pop ( ) ; // color
2014-06-30 01:41:02 +00:00
}
2021-12-01 18:02:20 +00:00
class_desc - > add_newline ( ) ;
class_desc - > add_newline ( ) ;
2014-06-30 01:41:02 +00:00
}
class_desc - > pop ( ) ;
2016-08-01 08:30:09 +00:00
class_desc - > add_newline ( ) ;
2014-06-30 01:41:02 +00:00
}
2016-08-01 08:30:09 +00:00
2018-09-12 15:12:23 +00:00
// Signals
2021-09-21 02:49:02 +00:00
if ( ! cd . signals . is_empty ( ) ) {
2016-05-29 14:37:26 +00:00
if ( sort_methods ) {
cd . signals . sort ( ) ;
}
2017-09-14 00:56:37 +00:00
2022-05-18 07:17:55 +00:00
section_line . push_back ( Pair < String , int > ( TTR ( " Signals " ) , class_desc - > get_paragraph_count ( ) - 2 ) ) ;
2023-02-11 16:33:38 +00:00
_push_title_font ( ) ;
2019-09-20 20:40:22 +00:00
class_desc - > add_text ( TTR ( " Signals " ) ) ;
2023-02-11 16:33:38 +00:00
_pop_title_font ( ) ;
2014-02-10 01:10:30 +00:00
2017-12-27 16:34:20 +00:00
class_desc - > add_newline ( ) ;
2014-02-10 01:10:30 +00:00
class_desc - > add_newline ( ) ;
class_desc - > push_indent ( 1 ) ;
for ( int i = 0 ; i < cd . signals . size ( ) ; i + + ) {
2022-05-18 07:17:55 +00:00
signal_line [ cd . signals [ i ] . name ] = class_desc - > get_paragraph_count ( ) - 2 ; // Gets overridden if description.
2021-12-01 18:02:20 +00:00
2023-02-11 16:33:38 +00:00
_push_code_font ( ) ;
2021-12-01 18:02:20 +00:00
_add_bulletpoint ( ) ;
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . headline_color ) ;
2015-10-20 15:41:27 +00:00
_add_text ( cd . signals [ i ] . name ) ;
2014-02-10 01:10:30 +00:00
class_desc - > pop ( ) ;
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . symbol_color ) ;
2019-09-20 20:40:22 +00:00
class_desc - > add_text ( " ( " ) ;
2014-02-10 01:10:30 +00:00
class_desc - > pop ( ) ;
for ( int j = 0 ; j < cd . signals [ i ] . arguments . size ( ) ; j + + ) {
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . text_color ) ;
2020-05-14 14:41:43 +00:00
if ( j > 0 ) {
2014-02-10 01:10:30 +00:00
class_desc - > add_text ( " , " ) ;
2020-05-14 14:41:43 +00:00
}
2019-09-20 20:40:22 +00:00
2015-10-20 15:41:27 +00:00
_add_text ( cd . signals [ i ] . arguments [ j ] . name ) ;
2019-09-20 20:40:22 +00:00
class_desc - > add_text ( " : " ) ;
2023-06-15 14:06:22 +00:00
_add_type ( cd . signals [ i ] . arguments [ j ] . type , cd . signals [ i ] . arguments [ j ] . enumeration , cd . signals [ i ] . arguments [ j ] . is_bitfield ) ;
2021-12-09 09:42:46 +00:00
if ( ! cd . signals [ i ] . arguments [ j ] . default_value . is_empty ( ) ) {
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . symbol_color ) ;
2019-06-01 13:42:22 +00:00
class_desc - > add_text ( " = " ) ;
2014-02-10 01:10:30 +00:00
class_desc - > pop ( ) ;
2015-10-20 15:41:27 +00:00
_add_text ( cd . signals [ i ] . arguments [ j ] . default_value ) ;
2014-02-10 01:10:30 +00:00
}
class_desc - > pop ( ) ;
}
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . symbol_color ) ;
2019-09-20 20:40:22 +00:00
class_desc - > add_text ( " ) " ) ;
2022-08-28 06:17:25 +00:00
if ( cd . signals [ i ] . is_deprecated ) {
DEPRECATED_DOC_TAG ;
}
2023-07-02 10:13:38 +00:00
2022-08-28 06:17:25 +00:00
if ( cd . signals [ i ] . is_experimental ) {
EXPERIMENTAL_DOC_TAG ;
}
2014-02-10 01:10:30 +00:00
class_desc - > pop ( ) ;
2023-02-11 16:33:38 +00:00
_pop_code_font ( ) ;
2022-07-04 15:56:34 +00:00
if ( ! cd . signals [ i ] . description . strip_edges ( ) . is_empty ( ) ) {
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . comment_color ) ;
2023-02-11 16:33:38 +00:00
_push_normal_font ( ) ;
2017-11-04 13:09:45 +00:00
class_desc - > push_indent ( 1 ) ;
2020-03-18 17:34:36 +00:00
_add_text ( DTR ( cd . signals [ i ] . description ) ) ;
2017-11-04 13:09:45 +00:00
class_desc - > pop ( ) ; // indent
2023-02-11 16:33:38 +00:00
_pop_normal_font ( ) ;
class_desc - > pop ( ) ; // color
2014-02-10 01:10:30 +00:00
}
2023-02-11 16:33:38 +00:00
2014-02-10 01:10:30 +00:00
class_desc - > add_newline ( ) ;
2017-11-04 13:09:45 +00:00
class_desc - > add_newline ( ) ;
2014-02-10 01:10:30 +00:00
}
class_desc - > pop ( ) ;
class_desc - > add_newline ( ) ;
}
2018-09-12 15:12:23 +00:00
// Constants and enums
2021-09-21 02:49:02 +00:00
if ( ! cd . constants . is_empty ( ) ) {
2022-05-13 13:04:37 +00:00
HashMap < String , Vector < DocData : : ConstantDoc > > enums ;
2017-08-23 22:10:32 +00:00
Vector < DocData : : ConstantDoc > constants ;
2014-02-10 01:10:30 +00:00
for ( int i = 0 ; i < cd . constants . size ( ) ; i + + ) {
2020-12-15 12:04:21 +00:00
if ( ! cd . constants [ i ] . enumeration . is_empty ( ) ) {
2017-08-23 22:10:32 +00:00
if ( ! enums . has ( cd . constants [ i ] . enumeration ) ) {
enums [ cd . constants [ i ] . enumeration ] = Vector < DocData : : ConstantDoc > ( ) ;
}
enums [ cd . constants [ i ] . enumeration ] . push_back ( cd . constants [ i ] ) ;
} else {
2020-11-29 02:37:57 +00:00
// Ignore undocumented private.
2022-07-04 15:56:34 +00:00
if ( cd . constants [ i ] . name . begins_with ( " _ " ) & & cd . constants [ i ] . description . strip_edges ( ) . is_empty ( ) ) {
2020-11-29 02:37:57 +00:00
continue ;
}
2017-08-23 22:10:32 +00:00
constants . push_back ( cd . constants [ i ] ) ;
}
}
2018-09-12 15:12:23 +00:00
// Enums
2017-08-23 22:10:32 +00:00
if ( enums . size ( ) ) {
2022-05-18 07:17:55 +00:00
section_line . push_back ( Pair < String , int > ( TTR ( " Enumerations " ) , class_desc - > get_paragraph_count ( ) - 2 ) ) ;
2023-02-11 16:33:38 +00:00
_push_title_font ( ) ;
2019-09-20 20:40:22 +00:00
class_desc - > add_text ( TTR ( " Enumerations " ) ) ;
2023-02-11 16:33:38 +00:00
_pop_title_font ( ) ;
2017-08-23 22:10:32 +00:00
class_desc - > push_indent ( 1 ) ;
class_desc - > add_newline ( ) ;
2021-08-09 20:13:42 +00:00
for ( KeyValue < String , Vector < DocData : : ConstantDoc > > & E : enums ) {
2022-05-18 07:17:55 +00:00
enum_line [ E . key ] = class_desc - > get_paragraph_count ( ) - 2 ;
2017-08-23 22:10:32 +00:00
2023-02-11 16:33:38 +00:00
_push_code_font ( ) ;
2023-07-02 10:13:38 +00:00
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . title_color ) ;
2022-06-24 09:16:37 +00:00
if ( E . value . size ( ) & & E . value [ 0 ] . is_bitfield ) {
class_desc - > add_text ( " flags " ) ;
} else {
class_desc - > add_text ( " enum " ) ;
}
2017-08-23 22:10:32 +00:00
class_desc - > pop ( ) ;
2023-02-11 16:33:38 +00:00
2021-08-09 20:13:42 +00:00
String e = E . key ;
2019-12-14 10:46:34 +00:00
if ( ( e . get_slice_count ( " . " ) > 1 ) & & ( e . get_slice ( " . " , 0 ) = = edited_class ) ) {
2017-08-23 22:10:32 +00:00
e = e . get_slice ( " . " , 1 ) ;
}
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . headline_color ) ;
2017-08-23 22:10:32 +00:00
class_desc - > add_text ( e ) ;
class_desc - > pop ( ) ;
2023-02-11 16:33:38 +00:00
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . symbol_color ) ;
2017-08-23 22:10:32 +00:00
class_desc - > add_text ( " : " ) ;
class_desc - > pop ( ) ;
2020-05-21 09:01:31 +00:00
2023-07-02 10:13:38 +00:00
if ( cd . enums . has ( e ) ) {
if ( cd . enums [ e ] . is_deprecated ) {
DEPRECATED_DOC_TAG ;
}
if ( cd . enums [ e ] . is_experimental ) {
EXPERIMENTAL_DOC_TAG ;
}
}
_pop_code_font ( ) ;
2020-05-21 09:01:31 +00:00
class_desc - > add_newline ( ) ;
2017-08-23 22:10:32 +00:00
class_desc - > add_newline ( ) ;
2020-11-29 02:37:57 +00:00
// Enum description.
2023-07-02 10:13:38 +00:00
if ( e ! = " @unnamed_enums " & & cd . enums . has ( e ) & & ! cd . enums [ e ] . description . strip_edges ( ) . is_empty ( ) ) {
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . text_color ) ;
2023-02-11 16:33:38 +00:00
_push_normal_font ( ) ;
2020-11-29 02:37:57 +00:00
class_desc - > push_indent ( 1 ) ;
2023-07-02 10:13:38 +00:00
_add_text ( cd . enums [ e ] . description ) ;
2020-11-29 02:37:57 +00:00
class_desc - > pop ( ) ;
2023-02-11 16:33:38 +00:00
_pop_normal_font ( ) ;
2020-11-29 02:37:57 +00:00
class_desc - > pop ( ) ;
2023-02-11 16:33:38 +00:00
2020-11-29 02:37:57 +00:00
class_desc - > add_newline ( ) ;
class_desc - > add_newline ( ) ;
}
2017-08-23 22:10:32 +00:00
class_desc - > push_indent ( 1 ) ;
2021-08-09 20:13:42 +00:00
Vector < DocData : : ConstantDoc > enum_list = E . value ;
2017-08-23 22:10:32 +00:00
2022-05-13 13:04:37 +00:00
HashMap < String , int > enumValuesContainer ;
2021-08-09 20:13:42 +00:00
int enumStartingLine = enum_line [ E . key ] ;
2018-03-30 14:20:24 +00:00
2017-08-23 22:10:32 +00:00
for ( int i = 0 ; i < enum_list . size ( ) ; i + + ) {
2020-05-14 14:41:43 +00:00
if ( cd . name = = " @GlobalScope " ) {
2018-03-30 14:20:24 +00:00
enumValuesContainer [ enum_list [ i ] . name ] = enumStartingLine ;
2020-05-14 14:41:43 +00:00
}
2017-08-23 22:10:32 +00:00
2022-04-26 16:57:36 +00:00
// Add the enum constant line to the constant_line map so we can locate it as a constant.
2022-05-18 07:17:55 +00:00
constant_line [ enum_list [ i ] . name ] = class_desc - > get_paragraph_count ( ) - 2 ;
2019-03-27 19:01:16 +00:00
2023-02-11 16:33:38 +00:00
_push_code_font ( ) ;
2023-07-02 10:13:38 +00:00
2021-12-01 18:02:20 +00:00
_add_bulletpoint ( ) ;
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . headline_color ) ;
2017-08-23 22:10:32 +00:00
_add_text ( enum_list [ i ] . name ) ;
class_desc - > pop ( ) ;
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . symbol_color ) ;
2017-08-23 22:10:32 +00:00
class_desc - > add_text ( " = " ) ;
class_desc - > pop ( ) ;
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . value_color ) ;
2019-06-01 13:42:22 +00:00
_add_text ( _fix_constant ( enum_list [ i ] . value ) ) ;
2017-08-23 22:10:32 +00:00
class_desc - > pop ( ) ;
2021-12-01 18:02:20 +00:00
2022-08-28 06:17:25 +00:00
if ( enum_list [ i ] . is_deprecated ) {
DEPRECATED_DOC_TAG ;
}
if ( enum_list [ i ] . is_experimental ) {
EXPERIMENTAL_DOC_TAG ;
}
2023-07-02 10:13:38 +00:00
_pop_code_font ( ) ;
2021-12-01 18:02:20 +00:00
class_desc - > add_newline ( ) ;
2021-12-09 09:42:46 +00:00
if ( ! enum_list [ i ] . description . strip_edges ( ) . is_empty ( ) ) {
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . comment_color ) ;
2023-02-11 16:33:38 +00:00
_push_normal_font ( ) ;
2020-03-18 17:34:36 +00:00
_add_text ( DTR ( enum_list [ i ] . description ) ) ;
2023-02-11 16:33:38 +00:00
_pop_normal_font ( ) ;
2017-08-23 22:10:32 +00:00
class_desc - > pop ( ) ;
2020-05-21 09:01:31 +00:00
if ( DTR ( enum_list [ i ] . description ) . find ( " \n " ) > 0 ) {
class_desc - > add_newline ( ) ;
}
2017-08-23 22:10:32 +00:00
}
class_desc - > add_newline ( ) ;
}
2020-05-14 14:41:43 +00:00
if ( cd . name = = " @GlobalScope " ) {
2021-08-09 20:13:42 +00:00
enum_values_line [ E . key ] = enumValuesContainer ;
2020-05-14 14:41:43 +00:00
}
2018-03-30 14:20:24 +00:00
2017-08-23 22:10:32 +00:00
class_desc - > pop ( ) ;
class_desc - > add_newline ( ) ;
}
class_desc - > pop ( ) ;
class_desc - > add_newline ( ) ;
}
2018-09-12 15:12:23 +00:00
// Constants
2017-08-23 22:10:32 +00:00
if ( constants . size ( ) ) {
2022-05-18 07:17:55 +00:00
section_line . push_back ( Pair < String , int > ( TTR ( " Constants " ) , class_desc - > get_paragraph_count ( ) - 2 ) ) ;
2023-02-11 16:33:38 +00:00
_push_title_font ( ) ;
2019-09-20 20:40:22 +00:00
class_desc - > add_text ( TTR ( " Constants " ) ) ;
2023-02-11 16:33:38 +00:00
_pop_title_font ( ) ;
2017-08-23 22:10:32 +00:00
class_desc - > push_indent ( 1 ) ;
class_desc - > add_newline ( ) ;
for ( int i = 0 ; i < constants . size ( ) ; i + + ) {
2022-05-18 07:17:55 +00:00
constant_line [ constants [ i ] . name ] = class_desc - > get_paragraph_count ( ) - 2 ;
2023-02-11 16:33:38 +00:00
_push_code_font ( ) ;
2017-12-15 15:43:27 +00:00
if ( constants [ i ] . value . begins_with ( " Color( " ) & & constants [ i ] . value . ends_with ( " ) " ) ) {
String stripped = constants [ i ] . value . replace ( " " , " " ) . replace ( " Color( " , " " ) . replace ( " ) " , " " ) ;
2022-11-20 11:29:50 +00:00
PackedFloat64Array color = stripped . split_floats ( " , " ) ;
2017-12-15 15:43:27 +00:00
if ( color . size ( ) > = 3 ) {
class_desc - > push_color ( Color ( color [ 0 ] , color [ 1 ] , color [ 2 ] ) ) ;
2021-12-01 18:02:20 +00:00
_add_bulletpoint ( ) ;
2017-12-15 15:43:27 +00:00
class_desc - > pop ( ) ;
}
2020-05-21 09:01:31 +00:00
} else {
2021-12-01 18:02:20 +00:00
_add_bulletpoint ( ) ;
2017-12-15 15:43:27 +00:00
}
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . headline_color ) ;
2017-08-23 22:10:32 +00:00
_add_text ( constants [ i ] . name ) ;
class_desc - > pop ( ) ;
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . symbol_color ) ;
2017-08-23 22:10:32 +00:00
class_desc - > add_text ( " = " ) ;
class_desc - > pop ( ) ;
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . value_color ) ;
2019-06-01 13:42:22 +00:00
_add_text ( _fix_constant ( constants [ i ] . value ) ) ;
2014-02-10 01:10:30 +00:00
class_desc - > pop ( ) ;
2017-12-15 15:43:27 +00:00
2022-08-28 06:17:25 +00:00
if ( constants [ i ] . is_deprecated ) {
DEPRECATED_DOC_TAG ;
}
if ( constants [ i ] . is_experimental ) {
EXPERIMENTAL_DOC_TAG ;
}
2023-07-02 10:13:38 +00:00
_pop_code_font ( ) ;
2021-12-01 18:02:20 +00:00
class_desc - > add_newline ( ) ;
2022-07-04 15:56:34 +00:00
if ( ! constants [ i ] . description . strip_edges ( ) . is_empty ( ) ) {
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . comment_color ) ;
2023-02-11 16:33:38 +00:00
_push_normal_font ( ) ;
2020-03-18 17:34:36 +00:00
_add_text ( DTR ( constants [ i ] . description ) ) ;
2023-02-11 16:33:38 +00:00
_pop_normal_font ( ) ;
2017-08-23 22:10:32 +00:00
class_desc - > pop ( ) ;
2020-05-21 09:01:31 +00:00
if ( DTR ( constants [ i ] . description ) . find ( " \n " ) > 0 ) {
class_desc - > add_newline ( ) ;
}
2017-08-23 22:10:32 +00:00
}
class_desc - > add_newline ( ) ;
2014-02-10 01:10:30 +00:00
}
2017-08-23 22:10:32 +00:00
class_desc - > pop ( ) ;
2014-02-10 01:10:30 +00:00
class_desc - > add_newline ( ) ;
}
}
2022-07-04 15:56:34 +00:00
// Annotations
if ( ! cd . annotations . is_empty ( ) ) {
if ( sort_methods ) {
cd . annotations . sort ( ) ;
}
section_line . push_back ( Pair < String , int > ( TTR ( " Annotations " ) , class_desc - > get_paragraph_count ( ) - 2 ) ) ;
2023-02-11 16:33:38 +00:00
_push_title_font ( ) ;
2022-07-04 15:56:34 +00:00
class_desc - > add_text ( TTR ( " Annotations " ) ) ;
2023-02-11 16:33:38 +00:00
_pop_title_font ( ) ;
2022-07-04 15:56:34 +00:00
class_desc - > add_newline ( ) ;
class_desc - > add_newline ( ) ;
class_desc - > push_indent ( 1 ) ;
for ( int i = 0 ; i < cd . annotations . size ( ) ; i + + ) {
annotation_line [ cd . annotations [ i ] . name ] = class_desc - > get_paragraph_count ( ) - 2 ; // Gets overridden if description.
2023-02-11 16:33:38 +00:00
_push_code_font ( ) ;
2022-07-04 15:56:34 +00:00
_add_bulletpoint ( ) ;
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . headline_color ) ;
2022-07-04 15:56:34 +00:00
_add_text ( cd . annotations [ i ] . name ) ;
class_desc - > pop ( ) ;
if ( cd . annotations [ i ] . arguments . size ( ) > 0 ) {
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . symbol_color ) ;
2022-07-04 15:56:34 +00:00
class_desc - > add_text ( " ( " ) ;
class_desc - > pop ( ) ;
for ( int j = 0 ; j < cd . annotations [ i ] . arguments . size ( ) ; j + + ) {
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . text_color ) ;
2022-07-04 15:56:34 +00:00
if ( j > 0 ) {
class_desc - > add_text ( " , " ) ;
}
_add_text ( cd . annotations [ i ] . arguments [ j ] . name ) ;
class_desc - > add_text ( " : " ) ;
_add_type ( cd . annotations [ i ] . arguments [ j ] . type ) ;
if ( ! cd . annotations [ i ] . arguments [ j ] . default_value . is_empty ( ) ) {
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . symbol_color ) ;
2022-07-04 15:56:34 +00:00
class_desc - > add_text ( " = " ) ;
class_desc - > pop ( ) ;
_add_text ( cd . annotations [ i ] . arguments [ j ] . default_value ) ;
}
class_desc - > pop ( ) ;
}
if ( cd . annotations [ i ] . qualifiers . contains ( " vararg " ) ) {
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . text_color ) ;
2022-07-04 15:56:34 +00:00
if ( cd . annotations [ i ] . arguments . size ( ) ) {
class_desc - > add_text ( " , " ) ;
}
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . symbol_color ) ;
2022-07-04 15:56:34 +00:00
class_desc - > add_text ( " ... " ) ;
class_desc - > pop ( ) ;
class_desc - > pop ( ) ;
}
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . symbol_color ) ;
2022-07-04 15:56:34 +00:00
class_desc - > add_text ( " ) " ) ;
class_desc - > pop ( ) ;
}
if ( ! cd . annotations [ i ] . qualifiers . is_empty ( ) ) {
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . qualifier_color ) ;
2022-07-04 15:56:34 +00:00
class_desc - > add_text ( " " ) ;
_add_text ( cd . annotations [ i ] . qualifiers ) ;
class_desc - > pop ( ) ;
}
2023-02-11 16:33:38 +00:00
_pop_code_font ( ) ;
2022-07-04 15:56:34 +00:00
if ( ! cd . annotations [ i ] . description . strip_edges ( ) . is_empty ( ) ) {
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . comment_color ) ;
2023-02-11 16:33:38 +00:00
_push_normal_font ( ) ;
2022-07-04 15:56:34 +00:00
class_desc - > push_indent ( 1 ) ;
_add_text ( DTR ( cd . annotations [ i ] . description ) ) ;
class_desc - > pop ( ) ; // indent
2023-02-11 16:33:38 +00:00
_pop_normal_font ( ) ;
class_desc - > pop ( ) ; // color
2022-07-04 15:56:34 +00:00
} else {
class_desc - > push_indent ( 1 ) ;
class_desc - > add_image ( get_theme_icon ( SNAME ( " Error " ) , SNAME ( " EditorIcons " ) ) ) ;
class_desc - > add_text ( " " ) ;
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . comment_color ) ;
2022-07-04 15:56:34 +00:00
if ( cd . is_script_doc ) {
class_desc - > append_text ( TTR ( " There is currently no description for this annotation. " ) ) ;
} else {
class_desc - > append_text ( TTR ( " There is currently no description for this annotation. Please help us by [color=$color][url=$url]contributing one[/url][/color]! " ) . replace ( " $url " , CONTRIBUTE_URL ) . replace ( " $color " , link_color_text ) ) ;
}
class_desc - > pop ( ) ;
class_desc - > pop ( ) ; // indent
}
class_desc - > add_newline ( ) ;
class_desc - > add_newline ( ) ;
}
class_desc - > pop ( ) ;
class_desc - > add_newline ( ) ;
}
2018-09-12 15:12:23 +00:00
// Property descriptions
2023-05-13 09:57:44 +00:00
if ( has_property_descriptions ) {
2022-05-18 07:17:55 +00:00
section_line . push_back ( Pair < String , int > ( TTR ( " Property Descriptions " ) , class_desc - > get_paragraph_count ( ) - 2 ) ) ;
2023-02-11 16:33:38 +00:00
_push_title_font ( ) ;
2019-09-20 20:40:22 +00:00
class_desc - > add_text ( TTR ( " Property Descriptions " ) ) ;
2023-02-11 16:33:38 +00:00
_pop_title_font ( ) ;
2017-01-04 04:16:14 +00:00
class_desc - > add_newline ( ) ;
class_desc - > add_newline ( ) ;
for ( int i = 0 ; i < cd . properties . size ( ) ; i + + ) {
2020-05-14 14:41:43 +00:00
if ( cd . properties [ i ] . overridden ) {
2019-09-03 10:42:34 +00:00
continue ;
2020-05-14 14:41:43 +00:00
}
2022-10-21 11:06:53 +00:00
// Ignore undocumented private.
if ( cd . properties [ i ] . name . begins_with ( " _ " ) & & cd . properties [ i ] . description . strip_edges ( ) . is_empty ( ) ) {
continue ;
}
2019-09-03 10:42:34 +00:00
2022-05-18 07:17:55 +00:00
property_line [ cd . properties [ i ] . name ] = class_desc - > get_paragraph_count ( ) - 2 ;
2017-01-04 04:16:14 +00:00
2017-11-04 13:09:45 +00:00
class_desc - > push_table ( 2 ) ;
2020-05-14 09:00:19 +00:00
class_desc - > set_table_column_expand ( 1 , true ) ;
2017-11-04 13:09:45 +00:00
class_desc - > push_cell ( ) ;
2023-02-11 16:33:38 +00:00
_push_code_font ( ) ;
2021-12-01 18:02:20 +00:00
_add_bulletpoint ( ) ;
2020-05-21 09:01:31 +00:00
2023-06-15 14:06:22 +00:00
_add_type ( cd . properties [ i ] . type , cd . properties [ i ] . enumeration , cd . properties [ i ] . is_bitfield ) ;
2017-01-04 04:16:14 +00:00
class_desc - > add_text ( " " ) ;
2023-02-11 16:33:38 +00:00
_pop_code_font ( ) ;
2017-11-04 13:09:45 +00:00
class_desc - > pop ( ) ; // cell
class_desc - > push_cell ( ) ;
2023-02-11 16:33:38 +00:00
_push_code_font ( ) ;
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . headline_color ) ;
2017-01-04 04:16:14 +00:00
_add_text ( cd . properties [ i ] . name ) ;
2017-11-04 13:09:45 +00:00
class_desc - > pop ( ) ; // color
2019-06-01 13:42:22 +00:00
2021-12-09 09:42:46 +00:00
if ( ! cd . properties [ i ] . default_value . is_empty ( ) ) {
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . symbol_color ) ;
2020-01-16 22:47:18 +00:00
class_desc - > add_text ( " [ " + TTR ( " default: " ) + " " ) ;
2019-06-01 13:42:22 +00:00
class_desc - > pop ( ) ; // color
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . value_color ) ;
2019-06-01 13:42:22 +00:00
_add_text ( _fix_constant ( cd . properties [ i ] . default_value ) ) ;
class_desc - > pop ( ) ; // color
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . symbol_color ) ;
2019-06-01 13:42:22 +00:00
class_desc - > add_text ( " ] " ) ;
class_desc - > pop ( ) ; // color
2022-08-28 06:17:25 +00:00
}
if ( cd . properties [ i ] . is_deprecated ) {
DEPRECATED_DOC_TAG ;
}
2023-07-02 10:13:38 +00:00
2022-08-28 06:17:25 +00:00
if ( cd . properties [ i ] . is_experimental ) {
EXPERIMENTAL_DOC_TAG ;
2019-06-01 13:42:22 +00:00
}
2021-12-09 09:42:46 +00:00
if ( cd . is_script_doc & & ( ! cd . properties [ i ] . setter . is_empty ( ) | | ! cd . properties [ i ] . getter . is_empty ( ) ) ) {
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . symbol_color ) ;
2020-11-29 02:37:57 +00:00
class_desc - > add_text ( " [ " + TTR ( " property: " ) + " " ) ;
class_desc - > pop ( ) ; // color
2021-12-09 09:42:46 +00:00
if ( ! cd . properties [ i ] . setter . is_empty ( ) ) {
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . value_color ) ;
2020-11-29 02:37:57 +00:00
class_desc - > add_text ( " setter " ) ;
class_desc - > pop ( ) ; // color
}
2021-12-09 09:42:46 +00:00
if ( ! cd . properties [ i ] . getter . is_empty ( ) ) {
if ( ! cd . properties [ i ] . setter . is_empty ( ) ) {
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . symbol_color ) ;
2020-11-29 02:37:57 +00:00
class_desc - > add_text ( " , " ) ;
class_desc - > pop ( ) ; // color
}
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . value_color ) ;
2020-11-29 02:37:57 +00:00
class_desc - > add_text ( " getter " ) ;
class_desc - > pop ( ) ; // color
}
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . symbol_color ) ;
2020-11-29 02:37:57 +00:00
class_desc - > add_text ( " ] " ) ;
class_desc - > pop ( ) ; // color
}
2023-02-11 16:33:38 +00:00
_pop_code_font ( ) ;
2017-11-04 13:09:45 +00:00
class_desc - > pop ( ) ; // cell
2017-01-04 04:16:14 +00:00
2020-11-29 02:37:57 +00:00
// Script doc doesn't have setter, getter.
if ( ! cd . is_script_doc ) {
2022-05-13 13:04:37 +00:00
HashMap < String , DocData : : MethodDoc > method_map ;
2020-11-29 02:37:57 +00:00
for ( int j = 0 ; j < methods . size ( ) ; j + + ) {
method_map [ methods [ j ] . name ] = methods [ j ] ;
}
2020-05-21 19:07:44 +00:00
2021-12-09 09:42:46 +00:00
if ( ! cd . properties [ i ] . setter . is_empty ( ) ) {
2020-11-29 02:37:57 +00:00
class_desc - > push_cell ( ) ;
class_desc - > pop ( ) ; // cell
2017-01-04 04:16:14 +00:00
2020-11-29 02:37:57 +00:00
class_desc - > push_cell ( ) ;
2023-02-11 16:33:38 +00:00
_push_code_font ( ) ;
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . text_color ) ;
2023-02-11 16:33:38 +00:00
2020-11-29 02:37:57 +00:00
if ( method_map [ cd . properties [ i ] . setter ] . arguments . size ( ) > 1 ) {
// Setters with additional arguments are exposed in the method list, so we link them here for quick access.
class_desc - > push_meta ( " @method " + cd . properties [ i ] . setter ) ;
class_desc - > add_text ( cd . properties [ i ] . setter + TTR ( " (value) " ) ) ;
class_desc - > pop ( ) ;
} else {
class_desc - > add_text ( cd . properties [ i ] . setter + TTR ( " (value) " ) ) ;
}
2023-02-11 16:33:38 +00:00
2020-11-29 02:37:57 +00:00
class_desc - > pop ( ) ; // color
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . comment_color ) ;
2020-11-29 02:37:57 +00:00
class_desc - > add_text ( " setter " ) ;
class_desc - > pop ( ) ; // color
2023-02-11 16:33:38 +00:00
_pop_code_font ( ) ;
2020-11-29 02:37:57 +00:00
class_desc - > pop ( ) ; // cell
2023-02-11 16:33:38 +00:00
2020-11-29 02:37:57 +00:00
method_line [ cd . properties [ i ] . setter ] = property_line [ cd . properties [ i ] . name ] ;
2020-05-21 19:07:44 +00:00
}
2017-01-04 04:16:14 +00:00
2021-12-09 09:42:46 +00:00
if ( ! cd . properties [ i ] . getter . is_empty ( ) ) {
2020-11-29 02:37:57 +00:00
class_desc - > push_cell ( ) ;
class_desc - > pop ( ) ; // cell
2017-01-04 04:16:14 +00:00
2020-11-29 02:37:57 +00:00
class_desc - > push_cell ( ) ;
2023-02-11 16:33:38 +00:00
_push_code_font ( ) ;
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . text_color ) ;
2023-02-11 16:33:38 +00:00
2020-11-29 02:37:57 +00:00
if ( method_map [ cd . properties [ i ] . getter ] . arguments . size ( ) > 0 ) {
// Getters with additional arguments are exposed in the method list, so we link them here for quick access.
class_desc - > push_meta ( " @method " + cd . properties [ i ] . getter ) ;
class_desc - > add_text ( cd . properties [ i ] . getter + " () " ) ;
class_desc - > pop ( ) ;
} else {
class_desc - > add_text ( cd . properties [ i ] . getter + " () " ) ;
}
2023-02-11 16:33:38 +00:00
class_desc - > pop ( ) ; // color
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . comment_color ) ;
2020-11-29 02:37:57 +00:00
class_desc - > add_text ( " getter " ) ;
2023-02-11 16:33:38 +00:00
class_desc - > pop ( ) ; // color
_pop_code_font ( ) ;
class_desc - > pop ( ) ; // cell
2020-11-29 02:37:57 +00:00
method_line [ cd . properties [ i ] . getter ] = property_line [ cd . properties [ i ] . name ] ;
2020-05-21 19:07:44 +00:00
}
2017-01-04 04:16:14 +00:00
}
2017-11-04 13:09:45 +00:00
class_desc - > pop ( ) ; // table
2019-06-20 10:42:25 +00:00
class_desc - > add_newline ( ) ;
2017-01-04 04:16:14 +00:00
class_desc - > add_newline ( ) ;
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . text_color ) ;
2023-02-11 16:33:38 +00:00
_push_normal_font ( ) ;
2017-01-04 04:16:14 +00:00
class_desc - > push_indent ( 1 ) ;
2020-12-15 12:04:21 +00:00
if ( ! cd . properties [ i ] . description . strip_edges ( ) . is_empty ( ) ) {
2020-03-18 17:34:36 +00:00
_add_text ( DTR ( cd . properties [ i ] . description ) ) ;
2017-09-12 22:16:18 +00:00
} else {
2021-07-17 21:22:52 +00:00
class_desc - > add_image ( get_theme_icon ( SNAME ( " Error " ) , SNAME ( " EditorIcons " ) ) ) ;
2017-09-12 22:16:18 +00:00
class_desc - > add_text ( " " ) ;
2023-02-11 15:29:44 +00:00
class_desc - > push_color ( theme_cache . comment_color ) ;
2020-11-29 02:37:57 +00:00
if ( cd . is_script_doc ) {
2020-05-29 14:25:12 +00:00
class_desc - > append_text ( TTR ( " There is currently no description for this property. " ) ) ;
2020-11-29 02:37:57 +00:00
} else {
2020-05-29 14:25:12 +00:00
class_desc - > append_text ( 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 ) ) ;
2020-11-29 02:37:57 +00:00
}
2017-09-12 22:16:18 +00:00
class_desc - > pop ( ) ;
}
2017-01-04 04:16:14 +00:00
class_desc - > pop ( ) ;
2023-02-11 16:33:38 +00:00
_pop_normal_font ( ) ;
2017-01-04 04:16:14 +00:00
class_desc - > pop ( ) ;
2023-02-11 16:33:38 +00:00
2017-01-04 04:16:14 +00:00
class_desc - > add_newline ( ) ;
class_desc - > add_newline ( ) ;
class_desc - > add_newline ( ) ;
}
}
2021-09-21 02:49:02 +00:00
// Constructor descriptions
2022-07-19 15:17:04 +00:00
if ( ! cd . constructors . is_empty ( ) ) {
2022-05-18 07:17:55 +00:00
section_line . push_back ( Pair < String , int > ( TTR ( " Constructor Descriptions " ) , class_desc - > get_paragraph_count ( ) - 2 ) ) ;
2023-02-11 16:33:38 +00:00
_push_title_font ( ) ;
2021-09-21 02:49:02 +00:00
class_desc - > add_text ( TTR ( " Constructor Descriptions " ) ) ;
2023-02-11 16:33:38 +00:00
_pop_title_font ( ) ;
2021-09-21 02:49:02 +00:00
_update_method_descriptions ( cd , cd . constructors , " constructor " ) ;
}
2018-09-12 15:12:23 +00:00
// Method descriptions
2022-07-19 15:17:04 +00:00
if ( ! methods . is_empty ( ) ) {
2022-05-18 07:17:55 +00:00
section_line . push_back ( Pair < String , int > ( TTR ( " Method Descriptions " ) , class_desc - > get_paragraph_count ( ) - 2 ) ) ;
2023-02-11 16:33:38 +00:00
_push_title_font ( ) ;
2019-09-20 20:40:22 +00:00
class_desc - > add_text ( TTR ( " Method Descriptions " ) ) ;
2023-02-11 16:33:38 +00:00
_pop_title_font ( ) ;
2021-09-21 02:49:02 +00:00
_update_method_descriptions ( cd , methods , " method " ) ;
}
2019-10-03 16:31:41 +00:00
2021-09-21 02:49:02 +00:00
// Operator descriptions
2022-07-19 15:17:04 +00:00
if ( ! cd . operators . is_empty ( ) ) {
2022-05-18 07:17:55 +00:00
section_line . push_back ( Pair < String , int > ( TTR ( " Operator Descriptions " ) , class_desc - > get_paragraph_count ( ) - 2 ) ) ;
2023-02-11 16:33:38 +00:00
_push_title_font ( ) ;
2021-09-21 02:49:02 +00:00
class_desc - > add_text ( TTR ( " Operator Descriptions " ) ) ;
2023-02-11 16:33:38 +00:00
_pop_title_font ( ) ;
2021-09-21 02:49:02 +00:00
_update_method_descriptions ( cd , cd . operators , " operator " ) ;
2014-02-10 01:10:30 +00:00
}
2022-07-19 15:17:04 +00:00
// Free the scroll.
2014-02-10 01:10:30 +00:00
scroll_locked = false ;
}
2014-06-23 15:43:37 +00:00
void EditorHelp : : _request_help ( const String & p_string ) {
2014-05-06 09:41:19 +00:00
Error err = _goto_desc ( p_string ) ;
if ( err = = OK ) {
2017-06-06 15:23:48 +00:00
EditorNode : : get_singleton ( ) - > set_visible_editor ( EditorNode : : EDITOR_SCRIPT ) ;
2014-05-06 09:41:19 +00:00
}
2014-02-10 01:10:30 +00:00
}
2014-02-21 02:01:44 +00:00
void EditorHelp : : _help_callback ( const String & p_topic ) {
String what = p_topic . get_slice ( " : " , 0 ) ;
String clss = p_topic . get_slice ( " : " , 1 ) ;
String name ;
2020-05-14 14:41:43 +00:00
if ( p_topic . get_slice_count ( " : " ) = = 3 ) {
2014-02-21 02:01:44 +00:00
name = p_topic . get_slice ( " : " , 2 ) ;
2020-05-14 14:41:43 +00:00
}
2014-02-21 02:01:44 +00:00
2022-04-26 16:57:36 +00:00
_request_help ( clss ) ; // First go to class.
2014-02-21 02:01:44 +00:00
int line = 0 ;
if ( what = = " class_desc " ) {
line = description_line ;
} else if ( what = = " class_signal " ) {
2020-05-14 14:41:43 +00:00
if ( signal_line . has ( name ) ) {
2014-02-21 02:01:44 +00:00
line = signal_line [ name ] ;
2020-05-14 14:41:43 +00:00
}
2014-02-21 02:01:44 +00:00
} else if ( what = = " class_method " | | what = = " class_method_desc " ) {
2020-05-14 14:41:43 +00:00
if ( method_line . has ( name ) ) {
2014-02-21 02:01:44 +00:00
line = method_line [ name ] ;
2020-05-14 14:41:43 +00:00
}
2014-02-21 02:01:44 +00:00
} else if ( what = = " class_property " ) {
2020-05-14 14:41:43 +00:00
if ( property_line . has ( name ) ) {
2014-02-21 02:01:44 +00:00
line = property_line [ name ] ;
2020-05-14 14:41:43 +00:00
}
2017-08-23 22:10:32 +00:00
} else if ( what = = " class_enum " ) {
2020-05-14 14:41:43 +00:00
if ( enum_line . has ( name ) ) {
2017-08-23 22:10:32 +00:00
line = enum_line [ name ] ;
2020-05-14 14:41:43 +00:00
}
2014-06-30 01:41:02 +00:00
} else if ( what = = " class_theme_item " ) {
2020-05-14 14:41:43 +00:00
if ( theme_property_line . has ( name ) ) {
2014-06-30 01:41:02 +00:00
line = theme_property_line [ name ] ;
2020-05-14 14:41:43 +00:00
}
2014-02-21 02:01:44 +00:00
} else if ( what = = " class_constant " ) {
2020-05-14 14:41:43 +00:00
if ( constant_line . has ( name ) ) {
2014-02-21 02:01:44 +00:00
line = constant_line [ name ] ;
2020-05-14 14:41:43 +00:00
}
2022-07-04 15:56:34 +00:00
} else if ( what = = " class_annotation " ) {
if ( annotation_line . has ( name ) ) {
line = annotation_line [ name ] ;
}
2018-03-30 14:20:24 +00:00
} else if ( what = = " class_global " ) {
2020-05-14 14:41:43 +00:00
if ( constant_line . has ( name ) ) {
2018-03-30 14:20:24 +00:00
line = constant_line [ name ] ;
2021-08-30 19:51:56 +00:00
} else if ( method_line . has ( name ) ) {
line = method_line [ name ] ;
2020-05-14 14:41:43 +00:00
} else {
2022-05-13 13:04:37 +00:00
HashMap < String , HashMap < String , int > > : : Iterator iter = enum_values_line . begin ( ) ;
2018-03-30 14:20:24 +00:00
while ( true ) {
2022-05-13 13:04:37 +00:00
if ( iter - > value . has ( name ) ) {
line = iter - > value [ name ] ;
2018-03-30 14:20:24 +00:00
break ;
2022-05-13 13:04:37 +00:00
} else if ( iter = = enum_values_line . last ( ) ) {
2018-03-30 14:20:24 +00:00
break ;
2020-05-14 14:41:43 +00:00
} else {
2022-05-13 13:04:37 +00:00
+ + iter ;
2020-05-14 14:41:43 +00:00
}
2018-03-30 14:20:24 +00:00
}
}
2014-02-21 02:01:44 +00:00
}
2022-05-30 07:04:07 +00:00
if ( class_desc - > is_ready ( ) ) {
class_desc - > call_deferred ( SNAME ( " scroll_to_paragraph " ) , line ) ;
} else {
scroll_to = line ;
}
2014-02-21 02:01:44 +00:00
}
2014-02-10 01:10:30 +00:00
2023-06-24 16:09:31 +00:00
static void _add_text_to_rt ( const String & p_bbcode , RichTextLabel * p_rt , Control * p_owner_node , const String & p_class = " " ) {
2020-11-29 03:42:06 +00:00
DocTools * doc = EditorHelp : : get_doc_data ( ) ;
2016-08-24 02:15:16 +00:00
String base_path ;
2022-09-06 13:08:40 +00:00
Ref < Font > doc_font = p_owner_node - > get_theme_font ( SNAME ( " doc " ) , SNAME ( " EditorFonts " ) ) ;
Ref < Font > doc_bold_font = p_owner_node - > get_theme_font ( SNAME ( " doc_bold " ) , SNAME ( " EditorFonts " ) ) ;
Ref < Font > doc_italic_font = p_owner_node - > get_theme_font ( SNAME ( " doc_italic " ) , SNAME ( " EditorFonts " ) ) ;
Ref < Font > doc_code_font = p_owner_node - > get_theme_font ( SNAME ( " doc_source " ) , SNAME ( " EditorFonts " ) ) ;
Ref < Font > doc_kbd_font = p_owner_node - > get_theme_font ( SNAME ( " doc_keyboard " ) , SNAME ( " EditorFonts " ) ) ;
2019-10-31 17:47:12 +00:00
2023-02-11 16:33:38 +00:00
int doc_code_font_size = p_owner_node - > get_theme_font_size ( SNAME ( " doc_source_size " ) , SNAME ( " EditorFonts " ) ) ;
int doc_kbd_font_size = p_owner_node - > get_theme_font_size ( SNAME ( " doc_keyboard_size " ) , SNAME ( " EditorFonts " ) ) ;
2022-10-31 18:51:48 +00:00
const Color type_color = p_owner_node - > get_theme_color ( SNAME ( " type_color " ) , SNAME ( " EditorHelp " ) ) ;
const Color code_color = p_owner_node - > get_theme_color ( SNAME ( " code_color " ) , SNAME ( " EditorHelp " ) ) ;
const Color kbd_color = p_owner_node - > get_theme_color ( SNAME ( " kbd_color " ) , SNAME ( " EditorHelp " ) ) ;
const Color code_dark_color = Color ( code_color , 0.8 ) ;
const Color link_color = p_owner_node - > get_theme_color ( SNAME ( " link_color " ) , SNAME ( " EditorHelp " ) ) ;
const Color link_method_color = p_owner_node - > get_theme_color ( SNAME ( " accent_color " ) , SNAME ( " Editor " ) ) ;
const Color link_property_color = link_color . lerp ( p_owner_node - > get_theme_color ( SNAME ( " accent_color " ) , SNAME ( " Editor " ) ) , 0.25 ) ;
const Color link_annotation_color = link_color . lerp ( p_owner_node - > get_theme_color ( SNAME ( " accent_color " ) , SNAME ( " Editor " ) ) , 0.5 ) ;
const Color code_bg_color = p_owner_node - > get_theme_color ( SNAME ( " code_bg_color " ) , SNAME ( " EditorHelp " ) ) ;
const Color kbd_bg_color = p_owner_node - > get_theme_color ( SNAME ( " kbd_bg_color " ) , SNAME ( " EditorHelp " ) ) ;
const Color param_bg_color = p_owner_node - > get_theme_color ( SNAME ( " param_bg_color " ) , SNAME ( " EditorHelp " ) ) ;
2016-05-29 14:37:26 +00:00
2017-11-11 01:11:24 +00:00
String bbcode = p_bbcode . dedent ( ) . replace ( " \t " , " " ) . replace ( " \r " , " " ) . strip_edges ( ) ;
2016-02-28 02:10:44 +00:00
2022-04-26 16:57:36 +00:00
// Select the correct code examples.
2020-07-22 20:41:10 +00:00
switch ( ( int ) EDITOR_GET ( " text_editor/help/class_reference_examples " ) ) {
case 0 : // GDScript
bbcode = bbcode . replace ( " [gdscript] " , " [codeblock] " ) ;
bbcode = bbcode . replace ( " [/gdscript] " , " [/codeblock] " ) ;
for ( int pos = bbcode . find ( " [csharp] " ) ; pos ! = - 1 ; pos = bbcode . find ( " [csharp] " ) ) {
2021-11-11 08:08:08 +00:00
int end_pos = bbcode . find ( " [/csharp] " ) ;
if ( end_pos = = - 1 ) {
2020-07-22 20:41:10 +00:00
WARN_PRINT ( " Unclosed [csharp] block or parse fail in code (search for tag errors) " ) ;
break ;
}
2021-11-11 08:08:08 +00:00
bbcode = bbcode . left ( pos ) + bbcode . substr ( end_pos + 9 ) ; // 9 is length of "[/csharp]".
2020-07-22 20:41:10 +00:00
while ( bbcode [ pos ] = = ' \n ' ) {
2021-11-11 08:08:08 +00:00
bbcode = bbcode . left ( pos ) + bbcode . substr ( pos + 1 ) ;
2020-07-22 20:41:10 +00:00
}
}
break ;
case 1 : // C#
bbcode = bbcode . replace ( " [csharp] " , " [codeblock] " ) ;
bbcode = bbcode . replace ( " [/csharp] " , " [/codeblock] " ) ;
for ( int pos = bbcode . find ( " [gdscript] " ) ; pos ! = - 1 ; pos = bbcode . find ( " [gdscript] " ) ) {
2021-11-11 08:08:08 +00:00
int end_pos = bbcode . find ( " [/gdscript] " ) ;
if ( end_pos = = - 1 ) {
2020-07-22 20:41:10 +00:00
WARN_PRINT ( " Unclosed [gdscript] block or parse fail in code (search for tag errors) " ) ;
break ;
}
2021-11-11 08:08:08 +00:00
bbcode = bbcode . left ( pos ) + bbcode . substr ( end_pos + 11 ) ; // 11 is length of "[/gdscript]".
2020-07-22 20:41:10 +00:00
while ( bbcode [ pos ] = = ' \n ' ) {
2021-11-11 08:08:08 +00:00
bbcode = bbcode . left ( pos ) + bbcode . substr ( pos + 1 ) ;
2020-07-22 20:41:10 +00:00
}
}
break ;
case 2 : // GDScript and C#
bbcode = bbcode . replace ( " [csharp] " , " [b]C#:[/b] \n [codeblock] " ) ;
bbcode = bbcode . replace ( " [gdscript] " , " [b]GDScript:[/b] \n [codeblock] " ) ;
bbcode = bbcode . replace ( " [/csharp] " , " [/codeblock] " ) ;
bbcode = bbcode . replace ( " [/gdscript] " , " [/codeblock] " ) ;
break ;
}
2022-04-26 16:57:36 +00:00
// Remove codeblocks (they would be printed otherwise).
2020-07-22 20:41:10 +00:00
bbcode = bbcode . replace ( " [codeblocks] \n " , " " ) ;
bbcode = bbcode . replace ( " \n [/codeblocks] " , " " ) ;
bbcode = bbcode . replace ( " [codeblocks] " , " " ) ;
bbcode = bbcode . replace ( " [/codeblocks] " , " " ) ;
2022-04-26 16:57:36 +00:00
// Remove extra new lines around code blocks.
2019-10-31 17:47:12 +00:00
bbcode = bbcode . replace ( " [codeblock] \n " , " [codeblock] " ) ;
bbcode = bbcode . replace ( " \n [/codeblock] " , " [/codeblock] " ) ;
2014-02-10 01:10:30 +00:00
List < String > tag_stack ;
2017-11-11 01:11:24 +00:00
bool code_tag = false ;
2022-07-04 15:14:50 +00:00
bool codeblock_tag = false ;
2014-02-10 01:10:30 +00:00
2017-09-14 00:56:37 +00:00
int pos = 0 ;
2016-02-28 02:10:44 +00:00
while ( pos < bbcode . length ( ) ) {
int brk_pos = bbcode . find ( " [ " , pos ) ;
2014-02-10 01:10:30 +00:00
2020-05-14 14:41:43 +00:00
if ( brk_pos < 0 ) {
2016-02-28 02:10:44 +00:00
brk_pos = bbcode . length ( ) ;
2020-05-14 14:41:43 +00:00
}
2014-02-10 01:10:30 +00:00
if ( brk_pos > pos ) {
2017-11-11 01:11:24 +00:00
String text = bbcode . substr ( pos , brk_pos - pos ) ;
2022-07-04 15:14:50 +00:00
if ( ! code_tag & & ! codeblock_tag ) {
2017-11-11 01:11:24 +00:00
text = text . replace ( " \n " , " \n \n " ) ;
2020-05-14 14:41:43 +00:00
}
2017-11-11 01:11:24 +00:00
p_rt - > add_text ( text ) ;
2014-02-10 01:10:30 +00:00
}
2020-05-14 14:41:43 +00:00
if ( brk_pos = = bbcode . length ( ) ) {
2022-04-26 16:57:36 +00:00
break ; // Nothing else to add.
2020-05-14 14:41:43 +00:00
}
2014-02-10 01:10:30 +00:00
2016-02-28 02:10:44 +00:00
int brk_end = bbcode . find ( " ] " , brk_pos + 1 ) ;
2014-02-10 01:10:30 +00:00
if ( brk_end = = - 1 ) {
2017-11-11 01:11:24 +00:00
String text = bbcode . substr ( brk_pos , bbcode . length ( ) - brk_pos ) ;
2022-07-04 15:14:50 +00:00
if ( ! code_tag & & ! codeblock_tag ) {
2017-11-11 01:11:24 +00:00
text = text . replace ( " \n " , " \n \n " ) ;
2020-05-14 14:41:43 +00:00
}
2017-11-11 01:11:24 +00:00
p_rt - > add_text ( text ) ;
2014-02-10 01:10:30 +00:00
break ;
}
2016-02-28 02:10:44 +00:00
String tag = bbcode . substr ( brk_pos + 1 , brk_end - brk_pos - 1 ) ;
2014-02-10 01:10:30 +00:00
if ( tag . begins_with ( " / " ) ) {
bool tag_ok = tag_stack . size ( ) & & tag_stack . front ( ) - > get ( ) = = tag . substr ( 1 , tag . length ( ) ) ;
2017-09-14 00:56:37 +00:00
2014-02-10 01:10:30 +00:00
if ( ! tag_ok ) {
2016-08-24 02:15:16 +00:00
p_rt - > add_text ( " [ " ) ;
2017-11-11 01:11:24 +00:00
pos = brk_pos + 1 ;
2014-02-10 01:10:30 +00:00
continue ;
}
tag_stack . pop_front ( ) ;
pos = brk_end + 1 ;
2019-10-31 17:47:12 +00:00
if ( tag ! = " /img " ) {
2016-08-24 02:15:16 +00:00
p_rt - > pop ( ) ;
2019-10-31 17:47:12 +00:00
if ( code_tag ) {
2023-02-11 16:33:38 +00:00
p_rt - > pop ( ) ; // font size
2022-07-04 15:14:50 +00:00
// Pop both color and background color.
p_rt - > pop ( ) ;
p_rt - > pop ( ) ;
} else if ( codeblock_tag ) {
2023-02-11 16:33:38 +00:00
p_rt - > pop ( ) ; // font size
2022-07-04 15:14:50 +00:00
// Pop color, cell and table.
p_rt - > pop ( ) ;
p_rt - > pop ( ) ;
2019-10-31 17:47:12 +00:00
p_rt - > pop ( ) ;
}
}
code_tag = false ;
2022-07-04 15:14:50 +00:00
codeblock_tag = false ;
2019-10-31 17:47:12 +00:00
2022-07-04 15:14:50 +00:00
} else if ( code_tag | | codeblock_tag ) {
2017-11-11 01:11:24 +00:00
p_rt - > add_text ( " [ " ) ;
pos = brk_pos + 1 ;
2014-02-10 01:10:30 +00:00
2022-08-09 17:41:54 +00:00
} else if ( tag . begins_with ( " method " ) | | tag . begins_with ( " member " ) | | tag . begins_with ( " signal " ) | | tag . begins_with ( " enum " ) | | tag . begins_with ( " constant " ) | | tag . begins_with ( " annotation " ) | | tag . begins_with ( " theme_item " ) ) {
2020-01-24 12:29:19 +00:00
const int tag_end = tag . find ( " " ) ;
const String link_tag = tag . substr ( 0 , tag_end ) ;
const String link_target = tag . substr ( tag_end + 1 , tag . length ( ) ) . lstrip ( " " ) ;
2019-04-27 19:15:07 +00:00
2022-10-31 18:51:48 +00:00
// Use monospace font to make clickable references
2022-07-04 15:14:50 +00:00
// easier to distinguish from inline code and other text.
2020-01-24 12:29:19 +00:00
p_rt - > push_font ( doc_code_font ) ;
2023-02-11 16:33:38 +00:00
p_rt - > push_font_size ( doc_code_font_size ) ;
2022-10-31 18:51:48 +00:00
Color target_color = link_color ;
if ( link_tag = = " method " ) {
target_color = link_method_color ;
} else if ( link_tag = = " member " | | link_tag = = " signal " | | link_tag = = " theme property " ) {
target_color = link_property_color ;
} else if ( link_tag = = " annotation " ) {
target_color = link_annotation_color ;
}
p_rt - > push_color ( target_color ) ;
2019-04-27 19:15:07 +00:00
p_rt - > push_meta ( " @ " + link_tag + " " + link_target ) ;
2022-10-31 18:51:48 +00:00
p_rt - > add_text ( link_target + ( link_tag = = " method " ? " () " : " " ) ) ;
2016-08-24 02:15:16 +00:00
p_rt - > pop ( ) ;
2020-01-24 12:29:19 +00:00
p_rt - > pop ( ) ;
2023-02-11 16:33:38 +00:00
p_rt - > pop ( ) ; // font size
p_rt - > pop ( ) ; // font
2014-02-10 01:10:30 +00:00
pos = brk_end + 1 ;
2022-08-06 17:48:54 +00:00
} else if ( tag . begins_with ( " param " ) ) {
const int tag_end = tag . find ( " " ) ;
const String param_name = tag . substr ( tag_end + 1 , tag . length ( ) ) . lstrip ( " " ) ;
// Use monospace font with translucent background color to make code easier to distinguish from other text.
p_rt - > push_font ( doc_code_font ) ;
2023-02-11 16:33:38 +00:00
p_rt - > push_font_size ( doc_code_font_size ) ;
2022-10-31 18:51:48 +00:00
p_rt - > push_bgcolor ( param_bg_color ) ;
2022-08-06 17:48:54 +00:00
p_rt - > push_color ( code_color ) ;
p_rt - > add_text ( param_name ) ;
p_rt - > pop ( ) ;
p_rt - > pop ( ) ;
2023-02-11 16:33:38 +00:00
p_rt - > pop ( ) ; // font size
p_rt - > pop ( ) ; // font
2022-08-06 17:48:54 +00:00
pos = brk_end + 1 ;
2023-06-24 16:09:31 +00:00
} else if ( tag = = p_class ) {
// Use a bold font when class reference tags are in their own page.
p_rt - > push_font ( doc_bold_font ) ;
p_rt - > add_text ( tag ) ;
p_rt - > pop ( ) ;
pos = brk_end + 1 ;
2014-02-16 00:16:33 +00:00
} else if ( doc - > class_list . has ( tag ) ) {
2023-06-24 16:09:31 +00:00
// Use a monospace font for class reference tags such as [Node2D] or [SceneTree].
2020-01-24 12:29:19 +00:00
p_rt - > push_font ( doc_code_font ) ;
2023-02-11 16:33:38 +00:00
p_rt - > push_font_size ( doc_code_font_size ) ;
2022-10-31 18:51:48 +00:00
p_rt - > push_color ( type_color ) ;
2016-08-24 02:15:16 +00:00
p_rt - > push_meta ( " # " + tag ) ;
p_rt - > add_text ( tag ) ;
2023-06-24 16:09:31 +00:00
2016-08-24 02:15:16 +00:00
p_rt - > pop ( ) ;
p_rt - > pop ( ) ;
2023-06-24 16:09:31 +00:00
p_rt - > pop ( ) ; // Font size
p_rt - > pop ( ) ; // Font
2023-02-11 16:33:38 +00:00
2014-02-10 01:10:30 +00:00
pos = brk_end + 1 ;
} else if ( tag = = " b " ) {
2022-04-26 16:57:36 +00:00
// Use bold font.
2019-06-15 16:18:32 +00:00
p_rt - > push_font ( doc_bold_font ) ;
2023-02-11 16:33:38 +00:00
2014-02-10 01:10:30 +00:00
pos = brk_end + 1 ;
tag_stack . push_front ( tag ) ;
} else if ( tag = = " i " ) {
2022-04-26 16:57:36 +00:00
// Use italics font.
2022-03-11 14:22:04 +00:00
p_rt - > push_font ( doc_italic_font ) ;
2023-02-11 16:33:38 +00:00
2014-02-10 01:10:30 +00:00
pos = brk_end + 1 ;
tag_stack . push_front ( tag ) ;
2022-07-04 15:14:50 +00:00
} else if ( tag = = " code " ) {
2022-10-31 18:51:48 +00:00
// Use monospace font with darkened background color to make code easier to distinguish from other text.
2016-08-24 02:15:16 +00:00
p_rt - > push_font ( doc_code_font ) ;
2023-02-11 16:33:38 +00:00
p_rt - > push_font_size ( doc_code_font_size ) ;
2022-10-31 18:51:48 +00:00
p_rt - > push_bgcolor ( code_bg_color ) ;
p_rt - > push_color ( code_color . lerp ( p_owner_node - > get_theme_color ( SNAME ( " error_color " ) , SNAME ( " Editor " ) ) , 0.6 ) ) ;
2023-02-11 16:33:38 +00:00
2017-11-11 01:11:24 +00:00
code_tag = true ;
2014-02-10 01:10:30 +00:00
pos = brk_end + 1 ;
tag_stack . push_front ( tag ) ;
2022-07-04 15:14:50 +00:00
} else if ( tag = = " codeblock " ) {
2022-10-31 18:51:48 +00:00
// Use monospace font with darkened background color to make code easier to distinguish from other text.
2022-07-04 15:14:50 +00:00
// Use a single-column table with cell row background color instead of `[bgcolor]`.
// This makes the background color highlight cover the entire block, rather than individual lines.
p_rt - > push_font ( doc_code_font ) ;
2023-02-11 16:33:38 +00:00
p_rt - > push_font_size ( doc_code_font_size ) ;
2022-07-04 15:14:50 +00:00
p_rt - > push_table ( 1 ) ;
p_rt - > push_cell ( ) ;
2022-10-31 18:51:48 +00:00
p_rt - > set_cell_row_background_color ( code_bg_color , Color ( code_bg_color , 0.99 ) ) ;
2022-07-17 20:55:20 +00:00
p_rt - > set_cell_padding ( Rect2 ( 10 * EDSCALE , 10 * EDSCALE , 10 * EDSCALE , 10 * EDSCALE ) ) ;
2022-10-31 18:51:48 +00:00
p_rt - > push_color ( code_dark_color ) ;
2023-02-11 16:33:38 +00:00
2022-07-04 15:14:50 +00:00
codeblock_tag = true ;
pos = brk_end + 1 ;
tag_stack . push_front ( tag ) ;
2020-03-10 10:41:36 +00:00
} else if ( tag = = " kbd " ) {
2022-07-04 15:14:50 +00:00
// Use keyboard font with custom color and background color.
2020-03-10 10:41:36 +00:00
p_rt - > push_font ( doc_kbd_font ) ;
2023-02-11 16:33:38 +00:00
p_rt - > push_font_size ( doc_kbd_font_size ) ;
2022-10-31 18:51:48 +00:00
p_rt - > push_bgcolor ( kbd_bg_color ) ;
2020-03-10 10:41:36 +00:00
p_rt - > push_color ( kbd_color ) ;
2023-02-11 16:33:38 +00:00
2022-04-26 16:57:36 +00:00
code_tag = true ; // Though not strictly a code tag, logic is similar.
2020-03-10 10:41:36 +00:00
pos = brk_end + 1 ;
tag_stack . push_front ( tag ) ;
2023-02-11 16:33:38 +00:00
2014-02-10 01:10:30 +00:00
} else if ( tag = = " center " ) {
2022-04-26 16:57:36 +00:00
// Align to center.
2021-11-25 02:58:47 +00:00
p_rt - > push_paragraph ( HORIZONTAL_ALIGNMENT_CENTER , Control : : TEXT_DIRECTION_AUTO , " " ) ;
2014-02-10 01:10:30 +00:00
pos = brk_end + 1 ;
tag_stack . push_front ( tag ) ;
} else if ( tag = = " br " ) {
2022-04-26 16:57:36 +00:00
// Force a line break.
2016-08-24 02:15:16 +00:00
p_rt - > add_newline ( ) ;
2014-02-10 01:10:30 +00:00
pos = brk_end + 1 ;
} else if ( tag = = " u " ) {
2022-04-26 16:57:36 +00:00
// Use underline.
2016-08-24 02:15:16 +00:00
p_rt - > push_underline ( ) ;
2014-02-10 01:10:30 +00:00
pos = brk_end + 1 ;
tag_stack . push_front ( tag ) ;
} else if ( tag = = " s " ) {
2022-04-26 16:57:36 +00:00
// Use strikethrough.
2019-06-15 16:18:32 +00:00
p_rt - > push_strikethrough ( ) ;
2014-02-10 01:10:30 +00:00
pos = brk_end + 1 ;
tag_stack . push_front ( tag ) ;
} else if ( tag = = " url " ) {
2016-02-28 02:10:44 +00:00
int end = bbcode . find ( " [ " , brk_end ) ;
2020-05-14 14:41:43 +00:00
if ( end = = - 1 ) {
2016-02-28 02:10:44 +00:00
end = bbcode . length ( ) ;
2020-05-14 14:41:43 +00:00
}
2016-02-28 02:10:44 +00:00
String url = bbcode . substr ( brk_end + 1 , end - brk_end - 1 ) ;
2016-08-24 02:15:16 +00:00
p_rt - > push_meta ( url ) ;
2014-02-10 01:10:30 +00:00
pos = brk_end + 1 ;
tag_stack . push_front ( tag ) ;
} else if ( tag . begins_with ( " url= " ) ) {
String url = tag . substr ( 4 , tag . length ( ) ) ;
2016-08-24 02:15:16 +00:00
p_rt - > push_meta ( url ) ;
2023-02-11 16:33:38 +00:00
2014-02-10 01:10:30 +00:00
pos = brk_end + 1 ;
tag_stack . push_front ( " url " ) ;
} else if ( tag = = " img " ) {
2016-02-28 02:10:44 +00:00
int end = bbcode . find ( " [ " , brk_end ) ;
2020-05-14 14:41:43 +00:00
if ( end = = - 1 ) {
2016-02-28 02:10:44 +00:00
end = bbcode . length ( ) ;
2020-05-14 14:41:43 +00:00
}
2016-02-28 02:10:44 +00:00
String image = bbcode . substr ( brk_end + 1 , end - brk_end - 1 ) ;
2014-02-10 01:10:30 +00:00
2022-08-30 00:34:01 +00:00
Ref < Texture2D > texture = ResourceLoader : : load ( base_path . path_join ( image ) , " Texture2D " ) ;
2020-05-14 14:41:43 +00:00
if ( texture . is_valid ( ) ) {
2016-08-24 02:15:16 +00:00
p_rt - > add_image ( texture ) ;
2020-05-14 14:41:43 +00:00
}
2014-02-10 01:10:30 +00:00
pos = end ;
tag_stack . push_front ( tag ) ;
} else if ( tag . begins_with ( " color= " ) ) {
String col = tag . substr ( 6 , tag . length ( ) ) ;
2020-11-16 13:31:58 +00:00
Color color = Color : : from_string ( col , Color ( ) ) ;
2016-08-24 02:15:16 +00:00
p_rt - > push_color ( color ) ;
2023-02-11 16:33:38 +00:00
2014-02-10 01:10:30 +00:00
pos = brk_end + 1 ;
tag_stack . push_front ( " color " ) ;
} else if ( tag . begins_with ( " font= " ) ) {
String fnt = tag . substr ( 5 , tag . length ( ) ) ;
2022-08-30 00:34:01 +00:00
Ref < Font > font = ResourceLoader : : load ( base_path . path_join ( fnt ) , " Font " ) ;
2020-05-14 14:41:43 +00:00
if ( font . is_valid ( ) ) {
2016-08-24 02:15:16 +00:00
p_rt - > push_font ( font ) ;
2020-05-14 14:41:43 +00:00
} else {
2016-08-24 02:15:16 +00:00
p_rt - > push_font ( doc_font ) ;
2014-02-10 01:10:30 +00:00
}
pos = brk_end + 1 ;
tag_stack . push_front ( " font " ) ;
} else {
2023-04-21 13:32:26 +00:00
p_rt - > add_text ( " [ " ) ; // ignore
2014-02-10 01:10:30 +00:00
pos = brk_pos + 1 ;
}
}
2016-08-24 02:15:16 +00:00
}
void EditorHelp : : _add_text ( const String & p_bbcode ) {
2023-06-24 16:09:31 +00:00
_add_text_to_rt ( p_bbcode , class_desc , this , edited_class ) ;
2014-02-10 01:10:30 +00:00
}
2021-07-25 17:44:03 +00:00
Thread EditorHelp : : thread ;
void EditorHelp : : _wait_for_thread ( ) {
if ( thread . is_started ( ) ) {
thread . wait_to_finish ( ) ;
}
}
2023-02-07 20:14:00 +00:00
String EditorHelp : : get_cache_full_path ( ) {
2023-06-23 14:39:51 +00:00
return EditorPaths : : get_singleton ( ) - > get_cache_dir ( ) . path_join ( " editor_doc_cache.res " ) ;
2023-02-07 20:14:00 +00:00
}
static bool first_attempt = true ;
2023-04-25 09:40:56 +00:00
static String _compute_doc_version_hash ( ) {
2023-06-23 14:39:51 +00:00
uint32_t version_hash = Engine : : get_singleton ( ) - > get_version_info ( ) . hash ( ) ;
return vformat ( " %d/%d/%d/%s " , version_hash , ClassDB : : get_api_hash ( ClassDB : : API_CORE ) , ClassDB : : get_api_hash ( ClassDB : : API_EDITOR ) , _doc_data_hash ) ;
2023-04-25 09:40:56 +00:00
}
2023-02-07 20:14:00 +00:00
void EditorHelp : : _load_doc_thread ( void * p_udata ) {
DEV_ASSERT ( first_attempt ) ;
2023-06-23 14:39:51 +00:00
Ref < Resource > cache_res = ResourceLoader : : load ( get_cache_full_path ( ) ) ;
if ( cache_res . is_valid ( ) & & cache_res - > get_meta ( " version_hash " , " " ) = = _compute_doc_version_hash ( ) ) {
Array classes = cache_res - > get_meta ( " classes " , Array ( ) ) ;
for ( int i = 0 ; i < classes . size ( ) ; i + + ) {
doc - > add_doc ( DocData : : ClassDoc : : from_dict ( classes [ i ] ) ) ;
2023-02-07 20:14:00 +00:00
}
} else {
// We have to go back to the main thread to start from scratch.
first_attempt = false ;
2023-04-20 23:25:47 +00:00
callable_mp_static ( & EditorHelp : : generate_doc ) . bind ( true ) . call_deferred ( ) ;
2023-02-07 20:14:00 +00:00
}
}
2021-07-25 17:44:03 +00:00
void EditorHelp : : _gen_doc_thread ( void * p_udata ) {
2020-11-29 03:42:06 +00:00
DocTools compdoc ;
2015-11-17 12:46:08 +00:00
compdoc . load_compressed ( _doc_data_compressed , _doc_data_compressed_size , _doc_data_uncompressed_size ) ;
2022-04-26 16:57:36 +00:00
doc - > merge_from ( compdoc ) ; // Ensure all is up to date.
2023-02-07 20:14:00 +00:00
2023-06-23 14:39:51 +00:00
Ref < Resource > cache_res ;
2023-02-07 20:14:00 +00:00
cache_res . instantiate ( ) ;
2023-06-23 14:39:51 +00:00
cache_res - > set_meta ( " version_hash " , _compute_doc_version_hash ( ) ) ;
2023-02-07 20:14:00 +00:00
Array classes ;
for ( const KeyValue < String , DocData : : ClassDoc > & E : doc - > class_list ) {
classes . push_back ( DocData : : ClassDoc : : to_dict ( E . value ) ) ;
}
2023-06-23 14:39:51 +00:00
cache_res - > set_meta ( " classes " , classes ) ;
2023-02-07 20:14:00 +00:00
Error err = ResourceSaver : : save ( cache_res , get_cache_full_path ( ) , ResourceSaver : : FLAG_COMPRESS ) ;
if ( err ) {
ERR_PRINT ( " Cannot save editor help cache ( " + get_cache_full_path ( ) + " ). " ) ;
}
2014-02-10 01:10:30 +00:00
}
2021-07-25 17:44:03 +00:00
static bool doc_gen_use_threads = true ;
2023-04-20 12:02:47 +00:00
void EditorHelp : : generate_doc ( bool p_use_cache ) {
2023-01-13 19:24:12 +00:00
OS : : get_singleton ( ) - > benchmark_begin_measure ( " EditorHelp::generate_doc " ) ;
2021-07-25 17:44:03 +00:00
if ( doc_gen_use_threads ) {
2023-02-07 20:14:00 +00:00
// In case not the first attempt.
_wait_for_thread ( ) ;
}
DEV_ASSERT ( first_attempt = = ( doc = = nullptr ) ) ;
if ( ! doc ) {
doc = memnew ( DocTools ) ;
}
2023-04-20 12:02:47 +00:00
if ( p_use_cache & & first_attempt & & FileAccess : : exists ( get_cache_full_path ( ) ) ) {
2023-02-07 20:14:00 +00:00
if ( doc_gen_use_threads ) {
thread . start ( _load_doc_thread , nullptr ) ;
} else {
_load_doc_thread ( nullptr ) ;
}
2021-07-25 17:44:03 +00:00
} else {
2023-02-07 20:14:00 +00:00
print_verbose ( " Regenerating editor help cache " ) ;
// Not doable on threads unfortunately, since it instantiates all sorts of classes to get default values.
doc - > generate ( true ) ;
if ( doc_gen_use_threads ) {
thread . start ( _gen_doc_thread , nullptr ) ;
} else {
_gen_doc_thread ( nullptr ) ;
}
2021-07-25 17:44:03 +00:00
}
2023-01-13 19:24:12 +00:00
OS : : get_singleton ( ) - > benchmark_end_measure ( " EditorHelp::generate_doc " ) ;
2021-07-25 17:44:03 +00:00
}
2021-09-14 09:17:47 +00:00
void EditorHelp : : _toggle_scripts_pressed ( ) {
ScriptEditor : : get_singleton ( ) - > toggle_scripts_panel ( ) ;
update_toggle_scripts_button ( ) ;
}
2015-11-17 12:46:08 +00:00
void EditorHelp : : _notification ( int p_what ) {
switch ( p_what ) {
2023-02-11 15:29:44 +00:00
case NOTIFICATION_POSTINITIALIZE : {
// Requires theme to be up to date.
_class_desc_resized ( false ) ;
} break ;
2019-03-27 19:39:36 +00:00
case NOTIFICATION_READY :
2017-09-02 17:16:31 +00:00
case EditorSettings : : NOTIFICATION_EDITOR_SETTINGS_CHANGED : {
2021-07-25 17:44:03 +00:00
_wait_for_thread ( ) ;
2019-08-09 04:00:44 +00:00
_update_doc ( ) ;
2017-09-02 17:16:31 +00:00
} break ;
2022-02-15 23:52:32 +00:00
2019-10-15 06:54:28 +00:00
case NOTIFICATION_THEME_CHANGED : {
2022-08-29 09:04:31 +00:00
if ( is_inside_tree ( ) ) {
_class_desc_resized ( true ) ;
}
2021-09-14 09:17:47 +00:00
update_toggle_scripts_button ( ) ;
2019-10-15 06:54:28 +00:00
} break ;
2022-02-15 23:52:32 +00:00
case NOTIFICATION_VISIBILITY_CHANGED : {
2021-09-14 09:17:47 +00:00
update_toggle_scripts_button ( ) ;
2022-02-15 23:52:32 +00:00
} break ;
2014-02-10 01:10:30 +00:00
}
2015-11-17 12:46:08 +00:00
}
2014-02-10 01:10:30 +00:00
2015-11-17 12:46:08 +00:00
void EditorHelp : : go_to_help ( const String & p_help ) {
2021-07-25 17:44:03 +00:00
_wait_for_thread ( ) ;
2015-11-17 12:46:08 +00:00
_help_callback ( p_help ) ;
2014-02-10 01:10:30 +00:00
}
2023-04-21 13:32:26 +00:00
void EditorHelp : : go_to_class ( const String & p_class ) {
2021-07-25 17:44:03 +00:00
_wait_for_thread ( ) ;
2023-04-21 13:32:26 +00:00
_goto_desc ( p_class ) ;
2015-11-17 12:46:08 +00:00
}
2014-02-16 00:16:33 +00:00
2020-11-29 02:37:57 +00:00
void EditorHelp : : update_doc ( ) {
2021-07-25 17:44:03 +00:00
_wait_for_thread ( ) ;
2020-11-29 02:37:57 +00:00
ERR_FAIL_COND ( ! doc - > class_list . has ( edited_class ) ) ;
ERR_FAIL_COND ( ! doc - > class_list [ edited_class ] . is_script_doc ) ;
_update_doc ( ) ;
}
2021-07-25 17:44:03 +00:00
void EditorHelp : : cleanup_doc ( ) {
_wait_for_thread ( ) ;
memdelete ( doc ) ;
}
2020-03-17 06:33:00 +00:00
Vector < Pair < String , int > > EditorHelp : : get_sections ( ) {
2021-07-25 17:44:03 +00:00
_wait_for_thread ( ) ;
2020-03-17 06:33:00 +00:00
Vector < Pair < String , int > > sections ;
2017-09-14 00:56:37 +00:00
for ( int i = 0 ; i < section_line . size ( ) ; i + + ) {
sections . push_back ( Pair < String , int > ( section_line [ i ] . first , i ) ) ;
}
return sections ;
}
void EditorHelp : : scroll_to_section ( int p_section_index ) {
2021-07-25 17:44:03 +00:00
_wait_for_thread ( ) ;
2017-09-14 00:56:37 +00:00
int line = section_line [ p_section_index ] . second ;
2022-05-30 07:04:07 +00:00
if ( class_desc - > is_ready ( ) ) {
class_desc - > scroll_to_paragraph ( line ) ;
} else {
scroll_to = line ;
}
2017-09-14 00:56:37 +00:00
}
2015-11-17 12:46:08 +00:00
void EditorHelp : : popup_search ( ) {
2021-07-25 17:44:03 +00:00
_wait_for_thread ( ) ;
2017-12-22 18:09:31 +00:00
find_bar - > popup_search ( ) ;
2015-11-17 12:46:08 +00:00
}
2014-02-10 01:10:30 +00:00
2017-01-03 02:03:46 +00:00
String EditorHelp : : get_class ( ) {
2015-11-17 12:46:08 +00:00
return edited_class ;
}
2014-02-10 01:10:30 +00:00
2019-10-09 15:41:49 +00:00
void EditorHelp : : search_again ( bool p_search_previous ) {
_search ( p_search_previous ) ;
2015-11-17 12:46:08 +00:00
}
2014-02-10 01:10:30 +00:00
2015-11-17 12:46:08 +00:00
int EditorHelp : : get_scroll ( ) const {
2021-11-30 16:46:36 +00:00
return class_desc - > get_v_scroll_bar ( ) - > get_value ( ) ;
2014-02-10 01:10:30 +00:00
}
2020-05-14 12:29:06 +00:00
2015-11-17 12:46:08 +00:00
void EditorHelp : : set_scroll ( int p_scroll ) {
2021-11-30 16:46:36 +00:00
class_desc - > get_v_scroll_bar ( ) - > set_value ( p_scroll ) ;
2014-02-10 01:10:30 +00:00
}
2021-09-14 09:17:47 +00:00
void EditorHelp : : update_toggle_scripts_button ( ) {
if ( is_layout_rtl ( ) ) {
toggle_scripts_button - > set_icon ( get_theme_icon ( ScriptEditor : : get_singleton ( ) - > is_scripts_panel_toggled ( ) ? SNAME ( " Forward " ) : SNAME ( " Back " ) , SNAME ( " EditorIcons " ) ) ) ;
} else {
toggle_scripts_button - > set_icon ( get_theme_icon ( ScriptEditor : : get_singleton ( ) - > is_scripts_panel_toggled ( ) ? SNAME ( " Back " ) : SNAME ( " Forward " ) , SNAME ( " EditorIcons " ) ) ) ;
}
2022-08-25 10:42:17 +00:00
toggle_scripts_button - > set_tooltip_text ( vformat ( " %s (%s) " , TTR ( " Toggle Scripts Panel " ) , ED_GET_SHORTCUT ( " script_editor/toggle_scripts_panel " ) - > get_as_text ( ) ) ) ;
2021-09-14 09:17:47 +00:00
}
2014-02-10 01:10:30 +00:00
void EditorHelp : : _bind_methods ( ) {
2017-01-03 02:03:46 +00:00
ClassDB : : bind_method ( " _class_list_select " , & EditorHelp : : _class_list_select ) ;
ClassDB : : bind_method ( " _request_help " , & EditorHelp : : _request_help ) ;
ClassDB : : bind_method ( " _search " , & EditorHelp : : _search ) ;
ClassDB : : bind_method ( " _help_callback " , & EditorHelp : : _help_callback ) ;
2014-02-10 01:10:30 +00:00
2015-11-17 12:46:08 +00:00
ADD_SIGNAL ( MethodInfo ( " go_to_help " ) ) ;
2014-02-10 01:10:30 +00:00
}
2015-11-17 12:46:08 +00:00
EditorHelp : : EditorHelp ( ) {
2017-12-18 17:46:17 +00:00
set_custom_minimum_size ( Size2 ( 150 * EDSCALE , 0 ) ) ;
2014-02-10 01:10:30 +00:00
2017-01-05 22:41:36 +00:00
EDITOR_DEF ( " text_editor/help/sort_functions_alphabetically " , true ) ;
2014-02-10 01:10:30 +00:00
2017-12-18 17:46:17 +00:00
class_desc = memnew ( RichTextLabel ) ;
add_child ( class_desc ) ;
2022-05-18 07:17:55 +00:00
class_desc - > set_threaded ( true ) ;
2017-12-18 17:46:17 +00:00
class_desc - > set_v_size_flags ( SIZE_EXPAND_FILL ) ;
2019-06-05 18:47:34 +00:00
2022-05-30 07:04:07 +00:00
class_desc - > connect ( " finished " , callable_mp ( this , & EditorHelp : : _class_desc_finished ) ) ;
2020-02-21 17:28:45 +00:00
class_desc - > connect ( " meta_clicked " , callable_mp ( this , & EditorHelp : : _class_desc_select ) ) ;
class_desc - > connect ( " gui_input " , callable_mp ( this , & EditorHelp : : _class_desc_input ) ) ;
2022-07-28 20:56:41 +00:00
class_desc - > connect ( " resized " , callable_mp ( this , & EditorHelp : : _class_desc_resized ) . bind ( false ) ) ;
2014-02-10 01:10:30 +00:00
2019-02-10 16:17:29 +00:00
// Added second so it opens at the bottom so it won't offset the entire widget.
2019-01-31 14:24:33 +00:00
find_bar = memnew ( FindBar ) ;
add_child ( find_bar ) ;
find_bar - > hide ( ) ;
2017-12-22 18:09:31 +00:00
find_bar - > set_rich_text_label ( class_desc ) ;
2021-09-14 09:17:47 +00:00
status_bar = memnew ( HBoxContainer ) ;
add_child ( status_bar ) ;
status_bar - > set_h_size_flags ( SIZE_EXPAND_FILL ) ;
status_bar - > set_custom_minimum_size ( Size2 ( 0 , 24 * EDSCALE ) ) ;
toggle_scripts_button = memnew ( Button ) ;
toggle_scripts_button - > set_flat ( true ) ;
toggle_scripts_button - > connect ( " pressed " , callable_mp ( this , & EditorHelp : : _toggle_scripts_pressed ) ) ;
status_bar - > add_child ( toggle_scripts_button ) ;
2014-02-10 01:10:30 +00:00
class_desc - > set_selection_enabled ( true ) ;
2023-02-28 13:19:48 +00:00
class_desc - > set_context_menu_enabled ( true ) ;
2015-11-17 12:46:08 +00:00
2014-02-10 01:10:30 +00:00
class_desc - > hide ( ) ;
}
2015-11-17 12:46:08 +00:00
EditorHelp : : ~ EditorHelp ( ) {
2014-02-10 01:10:30 +00:00
}
2021-07-25 17:44:03 +00:00
DocTools * EditorHelp : : get_doc_data ( ) {
_wait_for_thread ( ) ;
return doc ;
}
2022-02-02 13:10:15 +00:00
//// EditorHelpBit ///
2016-08-24 02:15:16 +00:00
void EditorHelpBit : : _go_to_help ( String p_what ) {
EditorNode : : get_singleton ( ) - > set_visible_editor ( EditorNode : : EDITOR_SCRIPT ) ;
ScriptEditor : : get_singleton ( ) - > goto_help ( p_what ) ;
2021-07-17 21:22:52 +00:00
emit_signal ( SNAME ( " request_hide " ) ) ;
2016-08-24 02:15:16 +00:00
}
void EditorHelpBit : : _meta_clicked ( String p_select ) {
2023-04-21 13:32:26 +00:00
if ( p_select . begins_with ( " $ " ) ) { // enum
2017-08-23 22:10:32 +00:00
String select = p_select . substr ( 1 , p_select . length ( ) ) ;
String class_name ;
2023-04-21 13:32:26 +00:00
int rfind = select . rfind ( " . " ) ;
if ( rfind ! = - 1 ) {
class_name = select . substr ( 0 , rfind ) ;
select = select . substr ( rfind + 1 ) ;
2017-08-23 22:10:32 +00:00
} else {
2023-04-21 13:32:26 +00:00
class_name = " @GlobalScope " ;
2017-08-23 22:10:32 +00:00
}
_go_to_help ( " class_enum: " + class_name + " : " + select ) ;
return ;
} else if ( p_select . begins_with ( " # " ) ) {
2016-08-24 02:15:16 +00:00
_go_to_help ( " class_name: " + p_select . substr ( 1 , p_select . length ( ) ) ) ;
return ;
} else if ( p_select . begins_with ( " @ " ) ) {
String m = p_select . substr ( 1 , p_select . length ( ) ) ;
2022-02-03 16:03:38 +00:00
if ( m . contains ( " . " ) ) {
2022-04-26 16:57:36 +00:00
_go_to_help ( " class_method: " + m . get_slice ( " . " , 0 ) + " : " + m . get_slice ( " . " , 0 ) ) ; // Must go somewhere else.
2020-05-14 14:41:43 +00:00
}
2016-08-24 02:15:16 +00:00
}
}
void EditorHelpBit : : _bind_methods ( ) {
2018-07-20 21:14:33 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_text " , " text " ) , & EditorHelpBit : : set_text ) ;
2016-08-24 02:15:16 +00:00
ADD_SIGNAL ( MethodInfo ( " request_hide " ) ) ;
}
void EditorHelpBit : : _notification ( int p_what ) {
2017-09-02 17:16:31 +00:00
switch ( p_what ) {
2022-01-18 20:01:30 +00:00
case NOTIFICATION_THEME_CHANGED : {
2022-02-08 09:14:58 +00:00
rich_text - > add_theme_color_override ( " selection_color " , get_theme_color ( SNAME ( " selection_color " ) , SNAME ( " EditorHelp " ) ) ) ;
2020-03-20 20:51:53 +00:00
rich_text - > clear ( ) ;
2022-09-06 13:08:40 +00:00
_add_text_to_rt ( text , rich_text , this ) ;
2022-02-02 13:10:15 +00:00
rich_text - > reset_size ( ) ; // Force recalculating size after parsing bbcode.
2020-03-20 20:51:53 +00:00
} break ;
2017-09-02 17:16:31 +00:00
}
2016-08-24 02:15:16 +00:00
}
void EditorHelpBit : : set_text ( const String & p_text ) {
2020-03-20 20:51:53 +00:00
text = p_text ;
2016-08-24 02:15:16 +00:00
rich_text - > clear ( ) ;
2022-09-06 13:08:40 +00:00
_add_text_to_rt ( text , rich_text , this ) ;
2016-08-24 02:15:16 +00:00
}
EditorHelpBit : : EditorHelpBit ( ) {
rich_text = memnew ( RichTextLabel ) ;
add_child ( rich_text ) ;
2020-02-21 17:28:45 +00:00
rich_text - > connect ( " meta_clicked " , callable_mp ( this , & EditorHelpBit : : _meta_clicked ) ) ;
2023-01-13 14:17:26 +00:00
rich_text - > set_fit_content ( true ) ;
2022-02-02 13:10:15 +00:00
set_custom_minimum_size ( Size2 ( 0 , 50 * EDSCALE ) ) ;
2016-08-24 02:15:16 +00:00
}
2017-12-22 18:09:31 +00:00
2022-02-02 13:10:15 +00:00
//// FindBar ///
2017-12-22 18:09:31 +00:00
FindBar : : FindBar ( ) {
search_text = memnew ( LineEdit ) ;
2019-02-10 16:17:29 +00:00
add_child ( search_text ) ;
2017-12-22 18:09:31 +00:00
search_text - > set_custom_minimum_size ( Size2 ( 100 * EDSCALE , 0 ) ) ;
2019-02-10 16:17:29 +00:00
search_text - > set_h_size_flags ( SIZE_EXPAND_FILL ) ;
2020-02-21 17:28:45 +00:00
search_text - > connect ( " text_changed " , callable_mp ( this , & FindBar : : _search_text_changed ) ) ;
2021-06-16 16:43:34 +00:00
search_text - > connect ( " text_submitted " , callable_mp ( this , & FindBar : : _search_text_submitted ) ) ;
2017-12-22 18:09:31 +00:00
2019-08-09 04:00:44 +00:00
matches_label = memnew ( Label ) ;
add_child ( matches_label ) ;
matches_label - > hide ( ) ;
2020-06-19 18:49:04 +00:00
find_prev = memnew ( Button ) ;
find_prev - > set_flat ( true ) ;
2019-02-10 16:17:29 +00:00
add_child ( find_prev ) ;
2017-12-22 18:09:31 +00:00
find_prev - > set_focus_mode ( FOCUS_NONE ) ;
2020-02-21 17:28:45 +00:00
find_prev - > connect ( " pressed " , callable_mp ( this , & FindBar : : search_prev ) ) ;
2017-12-22 18:09:31 +00:00
2020-06-19 18:49:04 +00:00
find_next = memnew ( Button ) ;
find_next - > set_flat ( true ) ;
2019-02-10 16:17:29 +00:00
add_child ( find_next ) ;
2017-12-22 18:09:31 +00:00
find_next - > set_focus_mode ( FOCUS_NONE ) ;
2020-02-21 17:28:45 +00:00
find_next - > connect ( " pressed " , callable_mp ( this , & FindBar : : search_next ) ) ;
2017-12-22 18:09:31 +00:00
2019-08-09 04:00:44 +00:00
Control * space = memnew ( Control ) ;
add_child ( space ) ;
space - > set_custom_minimum_size ( Size2 ( 4 , 0 ) * EDSCALE ) ;
2017-12-22 18:09:31 +00:00
hide_button = memnew ( TextureButton ) ;
add_child ( hide_button ) ;
hide_button - > set_focus_mode ( FOCUS_NONE ) ;
2022-02-05 01:11:32 +00:00
hide_button - > set_ignore_texture_size ( true ) ;
2017-12-22 18:09:31 +00:00
hide_button - > set_stretch_mode ( TextureButton : : STRETCH_KEEP_CENTERED ) ;
2020-02-21 17:28:45 +00:00
hide_button - > connect ( " pressed " , callable_mp ( this , & FindBar : : _hide_bar ) ) ;
2017-12-22 18:09:31 +00:00
}
void FindBar : : popup_search ( ) {
show ( ) ;
2018-05-16 14:43:00 +00:00
bool grabbed_focus = false ;
if ( ! search_text - > has_focus ( ) ) {
search_text - > grab_focus ( ) ;
grabbed_focus = true ;
}
2020-12-15 12:04:21 +00:00
if ( ! search_text - > get_text ( ) . is_empty ( ) ) {
2018-05-16 14:43:00 +00:00
search_text - > select_all ( ) ;
2021-03-28 18:31:25 +00:00
search_text - > set_caret_column ( search_text - > get_text ( ) . length ( ) ) ;
2018-05-16 14:43:00 +00:00
if ( grabbed_focus ) {
_search ( ) ;
}
}
2017-12-22 18:09:31 +00:00
}
void FindBar : : _notification ( int p_what ) {
2019-08-09 04:00:44 +00:00
switch ( p_what ) {
case NOTIFICATION_THEME_CHANGED : {
2021-07-17 21:22:52 +00:00
find_prev - > set_icon ( get_theme_icon ( SNAME ( " MoveUp " ) , SNAME ( " EditorIcons " ) ) ) ;
find_next - > set_icon ( get_theme_icon ( SNAME ( " MoveDown " ) , SNAME ( " EditorIcons " ) ) ) ;
2022-11-07 08:09:13 +00:00
hide_button - > set_texture_normal ( get_theme_icon ( SNAME ( " Close " ) , SNAME ( " EditorIcons " ) ) ) ;
hide_button - > set_texture_hover ( get_theme_icon ( SNAME ( " Close " ) , SNAME ( " EditorIcons " ) ) ) ;
hide_button - > set_texture_pressed ( get_theme_icon ( SNAME ( " Close " ) , SNAME ( " EditorIcons " ) ) ) ;
hide_button - > set_custom_minimum_size ( hide_button - > get_texture_normal ( ) - > get_size ( ) ) ;
2022-02-08 09:14:58 +00:00
matches_label - > add_theme_color_override ( " font_color " , results_count > 0 ? get_theme_color ( SNAME ( " font_color " ) , SNAME ( " Label " ) ) : get_theme_color ( SNAME ( " error_color " ) , SNAME ( " Editor " ) ) ) ;
2019-08-09 04:00:44 +00:00
} break ;
2022-02-15 23:52:32 +00:00
2019-08-09 04:00:44 +00:00
case NOTIFICATION_VISIBILITY_CHANGED : {
set_process_unhandled_input ( is_visible_in_tree ( ) ) ;
} break ;
2017-12-22 18:09:31 +00:00
}
}
void FindBar : : set_rich_text_label ( RichTextLabel * p_rich_text_label ) {
rich_text_label = p_rich_text_label ;
}
bool FindBar : : search_next ( ) {
return _search ( ) ;
}
bool FindBar : : search_prev ( ) {
return _search ( true ) ;
}
bool FindBar : : _search ( bool p_search_previous ) {
String stext = search_text - > get_text ( ) ;
bool keep = prev_search = = stext ;
bool ret = rich_text_label - > search ( stext , keep , p_search_previous ) ;
prev_search = stext ;
if ( ret ) {
2019-08-09 04:00:44 +00:00
_update_results_count ( ) ;
2017-12-22 18:09:31 +00:00
} else {
2019-08-09 04:00:44 +00:00
results_count = 0 ;
2017-12-22 18:09:31 +00:00
}
2019-08-09 04:00:44 +00:00
_update_matches_label ( ) ;
2017-12-22 18:09:31 +00:00
return ret ;
}
2019-08-09 04:00:44 +00:00
void FindBar : : _update_results_count ( ) {
results_count = 0 ;
String searched = search_text - > get_text ( ) ;
2020-12-15 12:04:21 +00:00
if ( searched . is_empty ( ) ) {
2019-08-09 04:00:44 +00:00
return ;
2020-05-14 14:41:43 +00:00
}
2019-08-09 04:00:44 +00:00
2021-10-01 15:36:37 +00:00
String full_text = rich_text_label - > get_parsed_text ( ) ;
2019-08-09 04:00:44 +00:00
int from_pos = 0 ;
while ( true ) {
2021-06-16 16:43:34 +00:00
int pos = full_text . findn ( searched , from_pos ) ;
2020-05-14 14:41:43 +00:00
if ( pos = = - 1 ) {
2019-08-09 04:00:44 +00:00
break ;
2020-05-14 14:41:43 +00:00
}
2019-08-09 04:00:44 +00:00
results_count + + ;
from_pos = pos + searched . length ( ) ;
}
}
void FindBar : : _update_matches_label ( ) {
2020-12-15 12:04:21 +00:00
if ( search_text - > get_text ( ) . is_empty ( ) | | results_count = = - 1 ) {
2019-08-09 04:00:44 +00:00
matches_label - > hide ( ) ;
} else {
matches_label - > show ( ) ;
2022-02-08 09:14:58 +00:00
matches_label - > add_theme_color_override ( " font_color " , results_count > 0 ? get_theme_color ( SNAME ( " font_color " ) , SNAME ( " Label " ) ) : get_theme_color ( SNAME ( " error_color " ) , SNAME ( " Editor " ) ) ) ;
2019-08-09 06:47:09 +00:00
matches_label - > set_text ( vformat ( results_count = = 1 ? TTR ( " %d match. " ) : TTR ( " %d matches. " ) , results_count ) ) ;
2019-08-09 04:00:44 +00:00
}
2017-12-22 18:09:31 +00:00
}
void FindBar : : _hide_bar ( ) {
2020-05-14 14:41:43 +00:00
if ( search_text - > has_focus ( ) ) {
2017-12-22 18:09:31 +00:00
rich_text_label - > grab_focus ( ) ;
2020-05-14 14:41:43 +00:00
}
2017-12-22 18:09:31 +00:00
hide ( ) ;
}
2021-08-22 15:37:22 +00:00
void FindBar : : unhandled_input ( const Ref < InputEvent > & p_event ) {
2021-04-05 06:52:21 +00:00
ERR_FAIL_COND ( p_event . is_null ( ) ) ;
2017-12-22 18:09:31 +00:00
Ref < InputEventKey > k = p_event ;
2023-05-21 00:26:13 +00:00
if ( k . is_valid ( ) & & k - > is_action_pressed ( SNAME ( " ui_cancel " ) , false , true ) ) {
if ( rich_text_label - > has_focus ( ) | | is_ancestor_of ( get_viewport ( ) - > gui_get_focus_owner ( ) ) ) {
_hide_bar ( ) ;
accept_event ( ) ;
2017-12-22 18:09:31 +00:00
}
}
}
void FindBar : : _search_text_changed ( const String & p_text ) {
search_next ( ) ;
}
2021-06-16 16:43:34 +00:00
void FindBar : : _search_text_submitted ( const String & p_text ) {
2021-08-13 21:31:57 +00:00
if ( Input : : get_singleton ( ) - > is_key_pressed ( Key : : SHIFT ) ) {
2019-09-08 13:09:52 +00:00
search_prev ( ) ;
} else {
search_next ( ) ;
}
2017-12-22 18:09:31 +00:00
}