2014-02-10 01:10:30 +00:00
/*************************************************************************/
/* editor_help.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
2017-08-27 12:16:55 +00:00
/* https://godotengine.org */
2014-02-10 01:10:30 +00:00
/*************************************************************************/
2021-01-01 19:13:46 +00:00
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
2014-02-10 01:10:30 +00:00
/* */
/* 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
2020-04-28 13:19:37 +00:00
# include "core/input/input.h"
2018-09-11 16:13:45 +00:00
# include "core/os/keyboard.h"
2017-06-23 15:03:41 +00:00
# include "doc_data_compressed.gen.h"
2017-03-05 15:44:50 +00:00
# include "editor/plugins/script_editor_plugin.h"
2014-02-10 01:10:30 +00:00
# include "editor_node.h"
2019-12-24 07:17:23 +00:00
# include "editor_scale.h"
2014-02-10 01:10:30 +00:00
# include "editor_settings.h"
2014-02-21 02:01:44 +00:00
2018-11-05 07:46:27 +00:00
# define CONTRIBUTE_URL "https: //docs.godotengine.org/en/latest/community/contributing/updating_the_class_reference.html"
2017-09-12 22:16:18 +00:00
2020-11-29 03:42:06 +00:00
DocTools * EditorHelp : : doc = nullptr ;
2014-02-16 00:16:33 +00:00
2017-12-15 08:45:23 +00:00
void EditorHelp : : _init_colors ( ) {
2020-03-12 12:37:40 +00:00
title_color = get_theme_color ( " accent_color " , " Editor " ) ;
text_color = get_theme_color ( " default_color " , " RichTextLabel " ) ;
headline_color = get_theme_color ( " headline_color " , " EditorHelp " ) ;
2020-03-16 09:07:33 +00:00
base_type_color = title_color . lerp ( text_color , 0.5 ) ;
2020-02-13 22:34:15 +00:00
comment_color = text_color * Color ( 1 , 1 , 1 , 0.6 ) ;
2017-12-15 08:45:23 +00:00
symbol_color = comment_color ;
2019-06-01 13:42:22 +00:00
value_color = text_color * Color ( 1 , 1 , 1 , 0.6 ) ;
2019-03-27 19:39:36 +00:00
qualifier_color = text_color * Color ( 1 , 1 , 1 , 0.8 ) ;
2020-03-16 09:07:33 +00:00
type_color = get_theme_color ( " accent_color " , " Editor " ) . lerp ( text_color , 0.5 ) ;
2020-03-12 12:37:40 +00:00
class_desc - > add_theme_color_override ( " selection_color " , get_theme_color ( " accent_color " , " Editor " ) * Color ( 1 , 1 , 1 , 0.4 ) ) ;
class_desc - > add_theme_constant_override ( " line_separation " , Math : : round ( 5 * EDSCALE ) ) ;
2017-12-15 08:45:23 +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
}
2017-03-05 15:44:50 +00:00
void EditorHelp : : _class_list_select ( const String & p_select ) {
2014-02-10 01:10:30 +00:00
_goto_desc ( p_select ) ;
}
2017-03-05 15:44:50 +00:00
void EditorHelp : : _class_desc_select ( const String & p_select ) {
2017-08-23 22:10:32 +00:00
if ( p_select . begins_with ( " $ " ) ) { //enum
String select = p_select . substr ( 1 , p_select . length ( ) ) ;
String class_name ;
if ( select . find ( " . " ) ! = - 1 ) {
class_name = select . get_slice ( " . " , 0 ) ;
2018-08-02 08:40:36 +00:00
select = select . get_slice ( " . " , 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
}
emit_signal ( " go_to_help " , " class_enum: " + class_name + " : " + select ) ;
return ;
} else if ( p_select . begins_with ( " # " ) ) {
2017-03-05 15:44:50 +00:00
emit_signal ( " 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 ;
2020-04-01 23:20:12 +00:00
Map < 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 ;
2017-11-20 23:30:46 +00:00
} else {
return ;
}
2014-02-10 01:10:30 +00:00
2017-11-20 23:30:46 +00:00
if ( link . find ( " . " ) ! = - 1 ) {
emit_signal ( " go_to_help " , topic + " : " + link . get_slice ( " . " , 0 ) + " : " + link . get_slice ( " . " , 1 ) ) ;
2015-11-17 12:46:08 +00:00
} else {
2019-03-27 19:01:16 +00:00
if ( table - > has ( link ) ) {
// Found in the current page
class_desc - > scroll_to_line ( ( * table ) [ link ] ) ;
} else {
if ( topic = = " class_enum " ) {
// Try to find the enum in @GlobalScope
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 ( " go_to_help " , topic + " :@GlobalScope: " + link ) ;
break ;
}
}
} else if ( topic = = " class_constant " ) {
// Try to find the constant in @GlobalScope
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 ( " go_to_help " , topic + " :@GlobalScope: " + link ) ;
break ;
}
}
}
}
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
}
2019-06-05 18:47:34 +00:00
void EditorHelp : : _class_desc_resized ( ) {
// Add extra horizontal margins for better readability.
// The margins increase as the width of the editor help container increases.
2020-03-12 12:37:40 +00:00
Ref < Font > doc_code_font = get_theme_font ( " doc_source " , " EditorFonts " ) ;
2020-09-03 11:22:16 +00:00
int font_size = get_theme_font_size ( " doc_source_size " , " EditorFonts " ) ;
real_t char_width = doc_code_font - > get_char_size ( ' x ' , 0 , font_size ) . width ;
2019-10-24 18:04:07 +00:00
const int display_margin = MAX ( 30 * EDSCALE , get_parent_anchorable_rect ( ) . size . width - char_width * 120 * EDSCALE ) * 0.5 ;
2019-06-05 18:47:34 +00:00
2020-03-12 12:37:40 +00:00
Ref < StyleBox > class_desc_stylebox = EditorNode : : get_singleton ( ) - > get_theme_base ( ) - > get_theme_stylebox ( " normal " , " RichTextLabel " ) - > duplicate ( ) ;
2020-12-22 16:24:29 +00:00
class_desc_stylebox - > set_default_margin ( SIDE_LEFT , display_margin ) ;
class_desc_stylebox - > set_default_margin ( SIDE_RIGHT , display_margin ) ;
2020-03-12 12:37:40 +00:00
class_desc - > add_theme_style_override ( " normal " , class_desc_stylebox ) ;
2019-06-05 18:47:34 +00:00
}
2017-08-23 22:10:32 +00:00
void EditorHelp : : _add_type ( const String & p_type , const String & p_enum ) {
2014-02-10 01:10:30 +00:00
String t = p_type ;
2020-12-15 12:04:21 +00:00
if ( t . is_empty ( ) ) {
2017-03-05 15:44:50 +00:00
t = " void " ;
2020-05-14 14:41:43 +00:00
}
2020-12-15 12:04:21 +00:00
bool can_ref = ( t ! = " void " ) | | ! p_enum . is_empty ( ) ;
2014-02-10 01:10:30 +00:00
2020-12-15 12:04:21 +00:00
if ( ! p_enum . is_empty ( ) ) {
2017-08-23 22:10:32 +00:00
if ( p_enum . get_slice_count ( " . " ) > 1 ) {
t = p_enum . get_slice ( " . " , 1 ) ;
} else {
t = p_enum . get_slice ( " . " , 0 ) ;
}
}
2020-03-12 12:37:40 +00:00
const Color text_color = get_theme_color ( " default_color " , " RichTextLabel " ) ;
2020-03-16 09:07:33 +00:00
const Color type_color = get_theme_color ( " accent_color " , " Editor " ) . lerp ( text_color , 0.5 ) ;
2017-09-14 00:56:37 +00:00
class_desc - > push_color ( 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 ) {
2020-04-20 22:06:00 +00:00
if ( t . ends_with ( " [] " ) ) {
add_array = true ;
t = t . replace ( " [] " , " " ) ;
}
2020-12-15 12:04:21 +00:00
if ( p_enum . is_empty ( ) ) {
2017-08-23 22:10:32 +00:00
class_desc - > push_meta ( " # " + t ) ; //class
} else {
class_desc - > push_meta ( " $ " + p_enum ) ; //class
}
}
2014-02-10 01:10:30 +00:00
class_desc - > add_text ( t ) ;
2020-04-20 22:06:00 +00:00
if ( can_ref ) {
2014-02-10 01:10:30 +00:00
class_desc - > pop ( ) ;
2020-04-20 22:06:00 +00:00
if ( add_array ) {
class_desc - > add_text ( " " ) ;
class_desc - > push_meta ( " #Array " ) ; //class
class_desc - > add_text ( " [] " ) ;
class_desc - > pop ( ) ;
}
}
2014-02-10 01:10:30 +00:00
class_desc - > pop ( ) ;
}
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 ;
}
2017-12-15 08:45:23 +00:00
void EditorHelp : : _add_method ( const DocData : : MethodDoc & p_method , bool p_overview ) {
method_line [ p_method . name ] = class_desc - > get_line_count ( ) - 2 ; //gets overridden if description
const bool is_vararg = p_method . qualifiers . find ( " vararg " ) ! = - 1 ;
if ( p_overview ) {
class_desc - > push_cell ( ) ;
2020-10-02 12:02:02 +00:00
class_desc - > push_paragraph ( RichTextLabel : : ALIGN_RIGHT , Control : : TEXT_DIRECTION_AUTO , " " ) ;
2020-05-21 09:01:31 +00:00
} else {
2020-07-27 10:43:20 +00:00
static const char32_t prefix [ 3 ] = { 0x25CF /* filled circle */ , ' ' , 0 } ;
2020-05-21 09:01:31 +00:00
class_desc - > add_text ( String ( prefix ) ) ;
2017-12-15 08:45:23 +00:00
}
_add_type ( p_method . return_type , p_method . return_enum ) ;
if ( p_overview ) {
class_desc - > pop ( ) ; //align
class_desc - > pop ( ) ; //cell
class_desc - > push_cell ( ) ;
} else {
class_desc - > add_text ( " " ) ;
}
if ( p_overview & & p_method . description ! = " " ) {
2019-04-27 19:15:07 +00:00
class_desc - > push_meta ( " @method " + p_method . name ) ;
2017-12-15 08:45:23 +00:00
}
class_desc - > push_color ( headline_color ) ;
_add_text ( p_method . name ) ;
class_desc - > pop ( ) ;
if ( p_overview & & p_method . description ! = " " ) {
class_desc - > pop ( ) ; //meta
}
class_desc - > push_color ( 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 + + ) {
class_desc - > push_color ( 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 ( " : " ) ;
_add_type ( p_method . arguments [ j ] . type , p_method . arguments [ j ] . enumeration ) ;
2017-12-15 08:45:23 +00:00
if ( p_method . arguments [ j ] . default_value ! = " " ) {
class_desc - > push_color ( 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 ( ) ;
2019-06-01 13:42:22 +00:00
class_desc - > push_color ( 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 ) {
class_desc - > push_color ( 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
}
2017-12-15 08:45:23 +00:00
class_desc - > push_color ( symbol_color ) ;
class_desc - > add_text ( " ... " ) ;
class_desc - > pop ( ) ;
class_desc - > pop ( ) ;
}
class_desc - > push_color ( 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 ( ) ;
if ( p_method . qualifiers ! = " " ) {
class_desc - > push_color ( qualifier_color ) ;
class_desc - > add_text ( " " ) ;
_add_text ( p_method . qualifiers ) ;
class_desc - > pop ( ) ;
}
2020-05-14 14:41:43 +00:00
if ( p_overview ) {
2017-12-15 08:45:23 +00:00
class_desc - > pop ( ) ; //cell
2020-05-14 14:41:43 +00:00
}
2017-12-15 08:45:23 +00:00
}
2017-03-05 15:44:50 +00:00
Error EditorHelp : : _goto_desc ( const String & p_class , int p_vscr ) {
2020-05-14 14:41:43 +00:00
if ( ! doc - > class_list . has ( 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
2017-03-05 15:44:50 +00:00
select_locked = true ;
2014-06-23 15:43:37 +00:00
2014-02-10 01:10:30 +00:00
class_desc - > show ( ) ;
2017-12-18 17:46:17 +00:00
2017-03-05 15:44:50 +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 ) {
2014-05-06 09:41:19 +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 ;
}
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
2017-03-05 15:44:50 +00:00
scroll_locked = true ;
2014-02-10 01:10:30 +00:00
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
2017-12-15 08:45:23 +00:00
_init_colors ( ) ;
2014-02-10 01:10:30 +00:00
2018-08-13 00:40:06 +00:00
DocData : : ClassDoc cd = doc - > class_list [ edited_class ] ; //make a copy, so we can sort without worrying
2014-02-10 01:10:30 +00:00
2020-03-12 12:37:40 +00:00
Ref < Font > doc_font = get_theme_font ( " doc " , " EditorFonts " ) ;
Ref < Font > doc_bold_font = get_theme_font ( " doc_bold " , " EditorFonts " ) ;
Ref < Font > doc_title_font = get_theme_font ( " doc_title " , " EditorFonts " ) ;
Ref < Font > doc_code_font = get_theme_font ( " doc_source " , " EditorFonts " ) ;
2017-09-14 00:56:37 +00:00
String link_color_text = title_color . to_html ( false ) ;
2014-02-10 01:10:30 +00:00
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 ) ) ;
2014-02-21 02:01:44 +00:00
class_desc - > push_font ( doc_title_font ) ;
2017-09-14 00:56:37 +00:00
class_desc - > push_color ( title_color ) ;
2017-03-05 15:44:50 +00:00
class_desc - > add_text ( TTR ( " Class: " ) + " " ) ;
2017-09-28 21:21:44 +00:00
class_desc - > push_color ( headline_color ) ;
2018-08-13 00:40:06 +00:00
_add_text ( edited_class ) ;
2014-02-21 02:01:44 +00:00
class_desc - > pop ( ) ;
class_desc - > pop ( ) ;
class_desc - > pop ( ) ;
class_desc - > add_newline ( ) ;
2018-09-12 15:12:23 +00:00
// Inheritance tree
// Ascendents
2017-03-05 15:44:50 +00:00
if ( cd . inherits ! = " " ) {
2017-09-14 00:56:37 +00:00
class_desc - > push_color ( title_color ) ;
2018-09-12 15:12:23 +00:00
class_desc - > push_font ( doc_font ) ;
2017-03-05 15:44:50 +00:00
class_desc - > add_text ( TTR ( " Inherits: " ) + " " ) ;
2016-03-05 15:28:25 +00:00
String inherits = cd . inherits ;
while ( inherits ! = " " ) {
_add_type ( inherits ) ;
inherits = doc - > class_list [ inherits ] . inherits ;
if ( inherits ! = " " ) {
2017-10-09 16:59:53 +00:00
class_desc - > add_text ( " < " ) ;
2016-03-05 15:28:25 +00:00
}
}
2020-05-21 09:01:31 +00:00
class_desc - > pop ( ) ;
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 ;
2020-05-21 09:01:31 +00:00
class_desc - > push_font ( doc_font ) ;
2017-03-05 15:44:50 +00:00
for ( Map < String , DocData : : ClassDoc > : : Element * E = doc - > class_list . front ( ) ; E ; E = E - > next ( ) ) {
2016-03-05 15:28:25 +00:00
if ( E - > get ( ) . inherits = = cd . name ) {
if ( ! found ) {
2017-09-14 00:56:37 +00:00
class_desc - > push_color ( title_color ) ;
2017-03-05 15:44:50 +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 ( " , " ) ;
}
_add_type ( E - > get ( ) . name ) ;
prev = true ;
}
}
2020-05-21 09:01:31 +00:00
class_desc - > pop ( ) ;
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
}
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
2017-03-05 15:44:50 +00:00
if ( cd . brief_description ! = " " ) {
2020-01-14 20:38:54 +00:00
class_desc - > push_color ( text_color ) ;
class_desc - > push_font ( doc_bold_font ) ;
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 ( ) ;
class_desc - > add_newline ( ) ;
class_desc - > add_newline ( ) ;
class_desc - > add_newline ( ) ;
}
// Class description
if ( cd . description ! = " " ) {
section_line . push_back ( Pair < String , int > ( TTR ( " Description " ) , class_desc - > get_line_count ( ) - 2 ) ) ;
description_line = class_desc - > get_line_count ( ) - 2 ;
2017-09-14 00:56:37 +00:00
class_desc - > push_color ( title_color ) ;
2014-02-10 01:10:30 +00:00
class_desc - > push_font ( doc_title_font ) ;
2020-01-14 20:38:54 +00:00
class_desc - > add_text ( TTR ( " Description " ) ) ;
2014-02-10 01:10:30 +00:00
class_desc - > pop ( ) ;
class_desc - > pop ( ) ;
2019-06-20 10:42:25 +00:00
class_desc - > add_newline ( ) ;
2014-02-10 01:10:30 +00:00
class_desc - > add_newline ( ) ;
2017-09-14 00:56:37 +00:00
class_desc - > push_color ( text_color ) ;
2017-03-05 15:44:50 +00:00
class_desc - > push_font ( doc_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 ( ) ;
2015-10-20 15:41:27 +00:00
class_desc - > pop ( ) ;
class_desc - > pop ( ) ;
2020-01-14 20:38:54 +00:00
class_desc - > add_newline ( ) ;
class_desc - > add_newline ( ) ;
class_desc - > add_newline ( ) ;
}
// Online tutorials
2020-01-26 23:58:53 +00:00
if ( cd . tutorials . size ( ) ) {
2020-01-14 20:38:54 +00:00
class_desc - > push_color ( title_color ) ;
class_desc - > push_font ( doc_title_font ) ;
class_desc - > add_text ( TTR ( " Online Tutorials " ) ) ;
class_desc - > pop ( ) ;
2015-10-20 15:41:27 +00:00
class_desc - > pop ( ) ;
2020-01-14 20:38:54 +00:00
2020-01-26 23:58:53 +00:00
class_desc - > push_indent ( 1 ) ;
2020-01-14 20:38:54 +00:00
class_desc - > push_font ( doc_code_font ) ;
2014-02-10 01:10:30 +00:00
class_desc - > add_newline ( ) ;
2020-01-14 20:38:54 +00:00
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 ) {
linktxt = link . right ( seppos + 2 ) ;
2020-01-14 20:38:54 +00:00
}
2020-01-26 23:58:53 +00:00
class_desc - > push_color ( symbol_color ) ;
class_desc - > append_bbcode ( " [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
2020-01-14 20:38:54 +00:00
class_desc - > pop ( ) ;
class_desc - > pop ( ) ;
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
2017-01-04 04:16:14 +00:00
Set < String > skip_methods ;
2017-03-05 15:44:50 +00:00
bool property_descr = false ;
2017-01-04 04:16:14 +00:00
2020-11-29 02:37:57 +00:00
bool has_properties = cd . properties . size ( ) ! = 0 ;
if ( cd . is_script_doc ) {
has_properties = false ;
for ( int i = 0 ; i < cd . properties . size ( ) ; i + + ) {
2020-12-15 12:04:21 +00:00
if ( cd . properties [ i ] . name . begins_with ( " _ " ) & & cd . properties [ i ] . description . is_empty ( ) ) {
2020-11-29 02:37:57 +00:00
continue ;
}
has_properties = true ;
break ;
}
}
if ( has_properties ) {
2018-09-12 15:12:23 +00:00
section_line . push_back ( Pair < String , int > ( TTR ( " Properties " ) , class_desc - > get_line_count ( ) - 2 ) ) ;
2017-09-14 00:56:37 +00:00
class_desc - > push_color ( title_color ) ;
2017-01-04 04:16:14 +00:00
class_desc - > push_font ( doc_title_font ) ;
2019-09-20 20:40:22 +00:00
class_desc - > add_text ( TTR ( " Properties " ) ) ;
2017-01-04 04:16:14 +00:00
class_desc - > pop ( ) ;
class_desc - > pop ( ) ;
2019-06-20 10:42:25 +00:00
class_desc - > add_newline ( ) ;
2019-07-15 13:48:51 +00:00
class_desc - > push_font ( doc_code_font ) ;
2017-01-04 04:16:14 +00:00
class_desc - > push_indent ( 1 ) ;
class_desc - > push_table ( 2 ) ;
2020-05-14 09:00:19 +00:00
class_desc - > set_table_column_expand ( 1 , true ) ;
2017-01-04 04:16:14 +00:00
2017-03-05 15:44:50 +00:00
for ( int i = 0 ; i < cd . properties . size ( ) ; i + + ) {
2020-11-29 02:37:57 +00:00
// Ignore undocumented private.
2020-12-15 12:04:21 +00:00
if ( cd . properties [ i ] . name . begins_with ( " _ " ) & & cd . properties [ i ] . description . is_empty ( ) ) {
2020-11-29 02:37:57 +00:00
continue ;
}
2017-03-24 20:45:31 +00:00
property_line [ cd . properties [ i ] . name ] = class_desc - > get_line_count ( ) - 2 ; //gets overridden if description
2017-01-04 04:16:14 +00:00
class_desc - > push_cell ( ) ;
2020-10-02 12:02:02 +00:00
class_desc - > push_paragraph ( RichTextLabel : : ALIGN_RIGHT , Control : : TEXT_DIRECTION_AUTO , " " ) ;
2017-01-04 04:16:14 +00:00
class_desc - > push_font ( doc_code_font ) ;
2017-08-23 22:10:32 +00:00
_add_type ( cd . properties [ i ] . type , cd . properties [ i ] . enumeration ) ;
2017-01-04 04:16:14 +00:00
class_desc - > pop ( ) ;
class_desc - > pop ( ) ;
class_desc - > pop ( ) ;
2017-03-05 15:44:50 +00:00
bool describe = false ;
2017-01-04 04:16:14 +00:00
2017-03-05 15:44:50 +00:00
if ( cd . properties [ i ] . setter ! = " " ) {
2017-01-04 04:16:14 +00:00
skip_methods . insert ( cd . properties [ i ] . setter ) ;
2017-03-05 15:44:50 +00:00
describe = true ;
2017-01-04 04:16:14 +00:00
}
2017-03-05 15:44:50 +00:00
if ( cd . properties [ i ] . getter ! = " " ) {
2017-01-04 04:16:14 +00:00
skip_methods . insert ( cd . properties [ i ] . getter ) ;
2017-03-05 15:44:50 +00:00
describe = true ;
2017-01-04 04:16:14 +00:00
}
2017-03-05 15:44:50 +00:00
if ( cd . properties [ i ] . description ! = " " ) {
describe = true ;
2017-01-04 04:16:14 +00:00
}
2019-06-01 13:42:22 +00:00
2019-09-03 10:42:34 +00:00
if ( cd . properties [ i ] . overridden ) {
describe = false ;
}
2017-01-04 04:16:14 +00:00
class_desc - > push_cell ( ) ;
2019-06-01 13:42:22 +00:00
class_desc - > push_font ( doc_code_font ) ;
class_desc - > push_color ( headline_color ) ;
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 ( ) ;
2017-03-05 15:44:50 +00:00
property_descr = true ;
2017-01-04 04:16:14 +00:00
}
2019-06-01 13:42:22 +00:00
if ( cd . properties [ i ] . default_value ! = " " ) {
class_desc - > push_color ( symbol_color ) ;
2020-01-16 22:47:18 +00:00
class_desc - > add_text ( cd . properties [ i ] . overridden ? " [ " + TTR ( " override: " ) + " " : " [ " + TTR ( " default: " ) + " " ) ;
2019-06-01 13:42:22 +00:00
class_desc - > pop ( ) ;
class_desc - > push_color ( value_color ) ;
_add_text ( _fix_constant ( cd . properties [ i ] . default_value ) ) ;
class_desc - > pop ( ) ;
class_desc - > push_color ( symbol_color ) ;
class_desc - > add_text ( " ] " ) ;
class_desc - > pop ( ) ;
}
2020-11-29 02:37:57 +00:00
if ( cd . is_script_doc & & ( cd . properties [ i ] . setter ! = " " | | cd . properties [ i ] . getter ! = " " ) ) {
class_desc - > push_color ( symbol_color ) ;
class_desc - > add_text ( " [ " + TTR ( " property: " ) + " " ) ;
class_desc - > pop ( ) ; // color
if ( cd . properties [ i ] . setter ! = " " ) {
class_desc - > push_color ( value_color ) ;
class_desc - > add_text ( " setter " ) ;
class_desc - > pop ( ) ; // color
}
if ( cd . properties [ i ] . getter ! = " " ) {
if ( cd . properties [ i ] . setter ! = " " ) {
class_desc - > push_color ( symbol_color ) ;
class_desc - > add_text ( " , " ) ;
class_desc - > pop ( ) ; // color
}
class_desc - > push_color ( value_color ) ;
class_desc - > add_text ( " getter " ) ;
class_desc - > pop ( ) ; // color
}
class_desc - > push_color ( symbol_color ) ;
class_desc - > add_text ( " ] " ) ;
class_desc - > pop ( ) ; // color
}
2019-06-01 13:42:22 +00:00
class_desc - > pop ( ) ;
class_desc - > pop ( ) ;
2017-01-04 04:16:14 +00:00
class_desc - > pop ( ) ;
}
class_desc - > pop ( ) ; //table
class_desc - > pop ( ) ;
2019-07-15 13:48:51 +00:00
class_desc - > pop ( ) ; // 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
2017-12-19 00:47:17 +00:00
bool method_descr = false ;
2017-01-05 22:41:36 +00:00
bool sort_methods = EditorSettings : : get_singleton ( ) - > 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-03-05 15:44:50 +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 ;
}
}
2020-11-29 02:37:57 +00:00
// Ignore undocumented private.
2020-12-15 12:04:21 +00:00
if ( cd . methods [ i ] . name . begins_with ( " _ " ) & & cd . methods [ i ] . description . is_empty ( ) ) {
2020-11-29 02:37:57 +00:00
continue ;
}
2017-01-04 04:16:14 +00:00
methods . push_back ( cd . methods [ i ] ) ;
}
if ( methods . size ( ) ) {
2020-05-14 14:41:43 +00:00
if ( sort_methods ) {
2017-01-04 04:16:14 +00:00
methods . sort ( ) ;
2020-05-14 14:41:43 +00:00
}
2016-05-29 14:37:26 +00:00
2018-09-12 15:12:23 +00:00
section_line . push_back ( Pair < String , int > ( TTR ( " Methods " ) , class_desc - > get_line_count ( ) - 2 ) ) ;
2017-09-14 00:56:37 +00:00
class_desc - > push_color ( title_color ) ;
2014-02-10 01:10:30 +00:00
class_desc - > push_font ( doc_title_font ) ;
2019-09-20 20:40:22 +00:00
class_desc - > add_text ( TTR ( " Methods " ) ) ;
2014-02-10 01:10:30 +00:00
class_desc - > pop ( ) ;
class_desc - > pop ( ) ;
2019-06-20 10:42:25 +00:00
class_desc - > add_newline ( ) ;
2017-12-27 16:34:20 +00:00
class_desc - > push_font ( doc_code_font ) ;
2014-02-10 01:10:30 +00:00
class_desc - > push_indent ( 1 ) ;
2015-12-26 13:25:17 +00:00
class_desc - > push_table ( 2 ) ;
2020-05-14 09:00:19 +00:00
class_desc - > set_table_column_expand ( 1 , true ) ;
2014-02-10 01:10:30 +00:00
2017-12-15 08:45:23 +00:00
bool any_previous = false ;
for ( int pass = 0 ; pass < 2 ; pass + + ) {
Vector < DocData : : MethodDoc > m ;
2017-09-14 00:56:37 +00:00
2017-12-15 08:45:23 +00:00
for ( int i = 0 ; i < methods . size ( ) ; i + + ) {
const String & q = methods [ i ] . qualifiers ;
if ( ( pass = = 0 & & q . find ( " virtual " ) ! = - 1 ) | | ( pass = = 1 & & q . find ( " virtual " ) = = - 1 ) ) {
m . push_back ( methods [ i ] ) ;
}
}
2015-12-26 13:25:17 +00:00
2020-12-15 12:04:21 +00:00
if ( any_previous & & ! m . is_empty ( ) ) {
2017-12-15 08:45:23 +00:00
class_desc - > push_cell ( ) ;
class_desc - > pop ( ) ; //cell
class_desc - > push_cell ( ) ;
class_desc - > pop ( ) ; //cell
2014-02-10 01:10:30 +00:00
}
2017-12-15 08:45:23 +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 ;
} else if ( group_prefix ! = " " & & new_prefix ! = group_prefix ) {
is_new_group = true ;
group_prefix = " " ;
2014-02-10 01:10:30 +00:00
}
2017-12-15 08:45:23 +00:00
if ( is_new_group & & pass = = 1 ) {
class_desc - > push_cell ( ) ;
class_desc - > pop ( ) ; //cell
class_desc - > push_cell ( ) ;
class_desc - > pop ( ) ; //cell
}
2014-02-10 01:10:30 +00:00
2017-12-19 00:47:17 +00:00
if ( m [ i ] . description ! = " " ) {
method_descr = true ;
}
2017-12-15 08:45:23 +00:00
_add_method ( m [ i ] , true ) ;
2016-09-07 22:39:02 +00:00
}
2020-12-15 12:04:21 +00:00
any_previous = ! m . is_empty ( ) ;
2014-02-10 01:10:30 +00:00
}
2017-12-15 08:45:23 +00:00
2015-12-26 13:25:17 +00:00
class_desc - > pop ( ) ; //table
2014-02-10 01:10:30 +00:00
class_desc - > pop ( ) ;
2017-12-27 16:34:20 +00:00
class_desc - > pop ( ) ; // font
2014-02-10 01:10:30 +00:00
class_desc - > add_newline ( ) ;
2015-12-26 13:25:17 +00:00
class_desc - > add_newline ( ) ;
2014-02-10 01:10:30 +00:00
}
2018-09-12 15:12:23 +00:00
// Theme properties
2014-06-30 01:41:02 +00:00
if ( cd . theme_properties . size ( ) ) {
2018-09-12 15:12:23 +00:00
section_line . push_back ( Pair < String , int > ( TTR ( " Theme Properties " ) , class_desc - > get_line_count ( ) - 2 ) ) ;
2017-09-14 00:56:37 +00:00
class_desc - > push_color ( title_color ) ;
2014-06-30 01:41:02 +00:00
class_desc - > push_font ( doc_title_font ) ;
2019-09-20 20:40:22 +00:00
class_desc - > add_text ( TTR ( " Theme Properties " ) ) ;
2014-06-30 01:41:02 +00:00
class_desc - > pop ( ) ;
class_desc - > pop ( ) ;
class_desc - > push_indent ( 1 ) ;
2017-09-14 00:56:37 +00:00
class_desc - > push_table ( 2 ) ;
2020-05-14 09:00:19 +00:00
class_desc - > set_table_column_expand ( 1 , true ) ;
2014-06-30 01:41:02 +00:00
2017-03-05 15:44:50 +00:00
for ( int i = 0 ; i < cd . theme_properties . size ( ) ; i + + ) {
2017-03-24 20:45:31 +00:00
theme_property_line [ cd . theme_properties [ i ] . name ] = class_desc - > get_line_count ( ) - 2 ; //gets overridden if description
2017-09-14 00:56:37 +00:00
class_desc - > push_cell ( ) ;
2020-10-02 12:02:02 +00:00
class_desc - > push_paragraph ( RichTextLabel : : ALIGN_RIGHT , Control : : TEXT_DIRECTION_AUTO , " " ) ;
2014-06-30 01:41:02 +00:00
class_desc - > push_font ( doc_code_font ) ;
_add_type ( cd . theme_properties [ i ] . type ) ;
2017-09-14 00:56:37 +00:00
class_desc - > pop ( ) ;
class_desc - > pop ( ) ;
class_desc - > pop ( ) ;
class_desc - > push_cell ( ) ;
class_desc - > push_font ( doc_code_font ) ;
2017-09-28 21:21:44 +00:00
class_desc - > push_color ( headline_color ) ;
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
if ( cd . theme_properties [ i ] . default_value ! = " " ) {
class_desc - > push_color ( 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 ( ) ;
class_desc - > push_color ( value_color ) ;
_add_text ( _fix_constant ( cd . theme_properties [ i ] . default_value ) ) ;
class_desc - > pop ( ) ;
class_desc - > push_color ( symbol_color ) ;
class_desc - > add_text ( " ] " ) ;
class_desc - > pop ( ) ;
}
2014-06-30 01:41:02 +00:00
class_desc - > pop ( ) ;
2014-02-10 01:10:30 +00:00
2017-09-14 00:56:37 +00:00
if ( cd . theme_properties [ i ] . description ! = " " ) {
2014-06-30 01:41:02 +00:00
class_desc - > push_font ( doc_font ) ;
class_desc - > add_text ( " " ) ;
2017-09-14 00:56:37 +00:00
class_desc - > push_color ( comment_color ) ;
2020-03-18 17:34:36 +00:00
_add_text ( DTR ( cd . theme_properties [ i ] . description ) ) ;
2014-06-30 01:41:02 +00:00
class_desc - > pop ( ) ;
class_desc - > pop ( ) ;
}
2017-09-14 00:56:37 +00:00
class_desc - > pop ( ) ; // cell
2014-06-30 01:41:02 +00:00
}
2017-09-14 00:56:37 +00:00
class_desc - > pop ( ) ; // table
2014-06-30 01:41:02 +00:00
class_desc - > pop ( ) ;
2016-08-01 08:30:09 +00:00
class_desc - > add_newline ( ) ;
2017-09-14 00:56:37 +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
2014-02-10 01:10:30 +00:00
if ( cd . signals . size ( ) ) {
2016-05-29 14:37:26 +00:00
if ( sort_methods ) {
cd . signals . sort ( ) ;
}
2017-09-14 00:56:37 +00:00
section_line . push_back ( Pair < String , int > ( TTR ( " Signals " ) , class_desc - > get_line_count ( ) - 2 ) ) ;
class_desc - > push_color ( title_color ) ;
2014-02-10 01:10:30 +00:00
class_desc - > push_font ( doc_title_font ) ;
2019-09-20 20:40:22 +00:00
class_desc - > add_text ( TTR ( " Signals " ) ) ;
2014-02-10 01:10:30 +00:00
class_desc - > pop ( ) ;
class_desc - > pop ( ) ;
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 ) ;
2017-03-05 15:44:50 +00:00
for ( int i = 0 ; i < cd . signals . size ( ) ; i + + ) {
2017-03-24 20:45:31 +00:00
signal_line [ cd . signals [ i ] . name ] = class_desc - > get_line_count ( ) - 2 ; //gets overridden if description
2017-03-05 15:44:50 +00:00
class_desc - > push_font ( doc_code_font ) ; // monofont
2017-09-28 21:21:44 +00:00
class_desc - > push_color ( headline_color ) ;
2020-07-27 10:43:20 +00:00
static const char32_t prefix [ 3 ] = { 0x25CF /* filled circle */ , ' ' , 0 } ;
2020-05-21 09:01:31 +00:00
class_desc - > add_text ( String ( prefix ) ) ;
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 ( ) ;
2017-09-14 00:56:37 +00:00
class_desc - > push_color ( 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 ( ) ;
2017-03-05 15:44:50 +00:00
for ( int j = 0 ; j < cd . signals [ i ] . arguments . size ( ) ; j + + ) {
2017-09-14 00:56:37 +00:00
class_desc - > push_color ( 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 ( " : " ) ;
_add_type ( cd . signals [ i ] . arguments [ j ] . type ) ;
2017-03-05 15:44:50 +00:00
if ( cd . signals [ i ] . arguments [ j ] . default_value ! = " " ) {
2017-09-14 00:56:37 +00:00
class_desc - > push_color ( 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 ( ) ;
}
2017-09-14 00:56:37 +00:00
class_desc - > push_color ( 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 ( ) ;
2015-10-20 15:41:27 +00:00
class_desc - > pop ( ) ; // end monofont
2017-03-05 15:44:50 +00:00
if ( cd . signals [ i ] . description ! = " " ) {
2017-11-04 13:09:45 +00:00
class_desc - > push_font ( doc_font ) ;
2017-09-14 00:56:37 +00:00
class_desc - > push_color ( comment_color ) ;
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
2014-02-10 01:10:30 +00:00
class_desc - > pop ( ) ;
2017-11-04 13:09:45 +00:00
class_desc - > pop ( ) ; // font
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
2014-02-10 01:10:30 +00:00
if ( cd . constants . size ( ) ) {
2020-03-17 06:33:00 +00:00
Map < 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
2017-03-05 15:44:50 +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.
2020-12-15 12:04:21 +00:00
if ( cd . constants [ i ] . name . begins_with ( " _ " ) & & cd . constants [ i ] . description . 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 ( ) ) {
2017-09-14 00:56:37 +00:00
section_line . push_back ( Pair < String , int > ( TTR ( " Enumerations " ) , class_desc - > get_line_count ( ) - 2 ) ) ;
class_desc - > push_color ( title_color ) ;
2017-08-23 22:10:32 +00:00
class_desc - > push_font ( doc_title_font ) ;
2019-09-20 20:40:22 +00:00
class_desc - > add_text ( TTR ( " Enumerations " ) ) ;
2014-02-10 01:10:30 +00:00
class_desc - > pop ( ) ;
class_desc - > pop ( ) ;
2017-08-23 22:10:32 +00:00
class_desc - > push_indent ( 1 ) ;
class_desc - > add_newline ( ) ;
2020-03-17 06:33:00 +00:00
for ( Map < String , Vector < DocData : : ConstantDoc > > : : Element * E = enums . front ( ) ; E ; E = E - > next ( ) ) {
2017-08-23 22:10:32 +00:00
enum_line [ E - > key ( ) ] = class_desc - > get_line_count ( ) - 2 ;
2020-05-21 09:01:31 +00:00
class_desc - > push_font ( doc_code_font ) ;
2017-09-14 00:56:37 +00:00
class_desc - > push_color ( title_color ) ;
2020-01-16 22:47:18 +00:00
class_desc - > add_text ( " enum " ) ;
2017-08-23 22:10:32 +00:00
class_desc - > pop ( ) ;
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 ) ;
}
2017-09-28 21:21:44 +00:00
class_desc - > push_color ( headline_color ) ;
2017-08-23 22:10:32 +00:00
class_desc - > add_text ( e ) ;
class_desc - > pop ( ) ;
2017-09-14 00:56:37 +00:00
class_desc - > pop ( ) ;
class_desc - > push_color ( 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
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.
if ( e ! = " @unnamed_enums " & & cd . enums . has ( e ) ) {
class_desc - > push_color ( text_color ) ;
class_desc - > push_font ( doc_font ) ;
class_desc - > push_indent ( 1 ) ;
_add_text ( cd . enums [ e ] ) ;
class_desc - > pop ( ) ;
class_desc - > pop ( ) ;
class_desc - > pop ( ) ;
class_desc - > add_newline ( ) ;
class_desc - > add_newline ( ) ;
}
2017-08-23 22:10:32 +00:00
class_desc - > push_indent ( 1 ) ;
Vector < DocData : : ConstantDoc > enum_list = E - > get ( ) ;
2018-03-30 14:20:24 +00:00
Map < String , int > enumValuesContainer ;
int enumStartingLine = enum_line [ E - > key ( ) ] ;
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
2019-03-27 19:01:16 +00:00
// Add the enum constant line to the constant_line map so we can locate it as a constant
constant_line [ enum_list [ i ] . name ] = class_desc - > get_line_count ( ) - 2 ;
2017-08-23 22:10:32 +00:00
class_desc - > push_font ( doc_code_font ) ;
2017-09-28 21:21:44 +00:00
class_desc - > push_color ( headline_color ) ;
2020-07-27 10:43:20 +00:00
static const char32_t prefix [ 3 ] = { 0x25CF /* filled circle */ , ' ' , 0 } ;
2020-05-21 09:01:31 +00:00
class_desc - > add_text ( String ( prefix ) ) ;
2017-08-23 22:10:32 +00:00
_add_text ( enum_list [ i ] . name ) ;
class_desc - > pop ( ) ;
2017-09-14 00:56:37 +00:00
class_desc - > push_color ( symbol_color ) ;
2017-08-23 22:10:32 +00:00
class_desc - > add_text ( " = " ) ;
class_desc - > pop ( ) ;
2017-09-14 00:56:37 +00:00
class_desc - > push_color ( 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 ( ) ;
class_desc - > pop ( ) ;
if ( enum_list [ i ] . description ! = " " ) {
class_desc - > push_font ( doc_font ) ;
2017-09-14 00:56:37 +00:00
class_desc - > push_color ( comment_color ) ;
2020-07-27 10:43:20 +00:00
static const char32_t dash [ 6 ] = { ' ' , ' ' , 0x2013 /* en dash */ , ' ' , ' ' , 0 } ;
2020-05-21 09:01:31 +00:00
class_desc - > add_text ( String ( dash ) ) ;
2020-03-18 17:34:36 +00:00
_add_text ( DTR ( enum_list [ i ] . description ) ) ;
2017-08-23 22:10:32 +00:00
class_desc - > pop ( ) ;
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 " ) {
2018-03-30 14:20:24 +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 ( ) ) {
2017-09-14 00:56:37 +00:00
section_line . push_back ( Pair < String , int > ( TTR ( " Constants " ) , class_desc - > get_line_count ( ) - 2 ) ) ;
class_desc - > push_color ( title_color ) ;
2017-08-23 22:10:32 +00:00
class_desc - > push_font ( doc_title_font ) ;
2019-09-20 20:40:22 +00:00
class_desc - > add_text ( TTR ( " Constants " ) ) ;
2014-02-10 01:10:30 +00:00
class_desc - > pop ( ) ;
class_desc - > pop ( ) ;
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 + + ) {
constant_line [ constants [ i ] . name ] = class_desc - > get_line_count ( ) - 2 ;
class_desc - > push_font ( doc_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 ( " ) " , " " ) ;
Vector < float > color = stripped . split_floats ( " , " ) ;
if ( color . size ( ) > = 3 ) {
class_desc - > push_color ( Color ( color [ 0 ] , color [ 1 ] , color [ 2 ] ) ) ;
2020-07-27 10:43:20 +00:00
static const char32_t prefix [ 3 ] = { 0x25CF /* filled circle */ , ' ' , 0 } ;
2017-12-15 15:43:27 +00:00
class_desc - > add_text ( String ( prefix ) ) ;
class_desc - > pop ( ) ;
}
2020-05-21 09:01:31 +00:00
} else {
2020-07-27 10:43:20 +00:00
static const char32_t prefix [ 3 ] = { 0x25CF /* filled circle */ , ' ' , 0 } ;
2020-05-21 09:01:31 +00:00
class_desc - > add_text ( String ( prefix ) ) ;
2017-12-15 15:43:27 +00:00
}
2017-09-28 21:21:44 +00:00
class_desc - > push_color ( headline_color ) ;
2017-08-23 22:10:32 +00:00
_add_text ( constants [ i ] . name ) ;
class_desc - > pop ( ) ;
2017-09-14 00:56:37 +00:00
class_desc - > push_color ( symbol_color ) ;
2017-08-23 22:10:32 +00:00
class_desc - > add_text ( " = " ) ;
class_desc - > pop ( ) ;
2017-09-14 00:56:37 +00:00
class_desc - > push_color ( 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
2014-02-10 01:10:30 +00:00
class_desc - > pop ( ) ;
2017-08-23 22:10:32 +00:00
if ( constants [ i ] . description ! = " " ) {
class_desc - > push_font ( doc_font ) ;
2017-09-14 00:56:37 +00:00
class_desc - > push_color ( comment_color ) ;
2020-07-27 10:43:20 +00:00
static const char32_t dash [ 6 ] = { ' ' , ' ' , 0x2013 /* en dash */ , ' ' , ' ' , 0 } ;
2020-05-21 09:01:31 +00:00
class_desc - > add_text ( String ( dash ) ) ;
2020-03-18 17:34:36 +00:00
_add_text ( DTR ( constants [ i ] . description ) ) ;
2017-08-23 22:10:32 +00:00
class_desc - > pop ( ) ;
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 ( ) ;
}
}
2018-09-12 15:12:23 +00:00
// Property descriptions
2017-01-04 04:16:14 +00:00
if ( property_descr ) {
2018-09-12 15:12:23 +00:00
section_line . push_back ( Pair < String , int > ( TTR ( " Property Descriptions " ) , class_desc - > get_line_count ( ) - 2 ) ) ;
2017-09-14 00:56:37 +00:00
class_desc - > push_color ( title_color ) ;
2017-01-04 04:16:14 +00:00
class_desc - > push_font ( doc_title_font ) ;
2019-09-20 20:40:22 +00:00
class_desc - > add_text ( TTR ( " Property Descriptions " ) ) ;
2017-01-04 04:16:14 +00:00
class_desc - > pop ( ) ;
class_desc - > pop ( ) ;
class_desc - > add_newline ( ) ;
class_desc - > add_newline ( ) ;
2017-03-05 15:44:50 +00:00
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
}
2019-09-03 10:42:34 +00:00
2017-11-20 23:30:46 +00:00
property_line [ cd . properties [ i ] . name ] = class_desc - > get_line_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 ( ) ;
2017-01-04 04:16:14 +00:00
class_desc - > push_font ( doc_code_font ) ;
2020-07-27 10:43:20 +00:00
static const char32_t prefix [ 3 ] = { 0x25CF /* filled circle */ , ' ' , 0 } ;
2020-05-21 09:01:31 +00:00
class_desc - > add_text ( String ( prefix ) ) ;
2017-08-23 22:10:32 +00:00
_add_type ( cd . properties [ i ] . type , cd . properties [ i ] . enumeration ) ;
2017-01-04 04:16:14 +00:00
class_desc - > add_text ( " " ) ;
2017-11-04 13:09:45 +00:00
class_desc - > pop ( ) ; // font
class_desc - > pop ( ) ; // cell
class_desc - > push_cell ( ) ;
class_desc - > push_font ( doc_code_font ) ;
2017-09-28 21:21:44 +00:00
class_desc - > push_color ( 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
if ( cd . properties [ i ] . default_value ! = " " ) {
class_desc - > push_color ( 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
class_desc - > push_color ( value_color ) ;
_add_text ( _fix_constant ( cd . properties [ i ] . default_value ) ) ;
class_desc - > pop ( ) ; // color
class_desc - > push_color ( symbol_color ) ;
class_desc - > add_text ( " ] " ) ;
class_desc - > pop ( ) ; // color
}
2020-11-29 02:37:57 +00:00
if ( cd . is_script_doc & & ( cd . properties [ i ] . setter ! = " " | | cd . properties [ i ] . getter ! = " " ) ) {
class_desc - > push_color ( symbol_color ) ;
class_desc - > add_text ( " [ " + TTR ( " property: " ) + " " ) ;
class_desc - > pop ( ) ; // color
if ( cd . properties [ i ] . setter ! = " " ) {
class_desc - > push_color ( value_color ) ;
class_desc - > add_text ( " setter " ) ;
class_desc - > pop ( ) ; // color
}
if ( cd . properties [ i ] . getter ! = " " ) {
if ( cd . properties [ i ] . setter ! = " " ) {
class_desc - > push_color ( symbol_color ) ;
class_desc - > add_text ( " , " ) ;
class_desc - > pop ( ) ; // color
}
class_desc - > push_color ( value_color ) ;
class_desc - > add_text ( " getter " ) ;
class_desc - > pop ( ) ; // color
}
class_desc - > push_color ( symbol_color ) ;
class_desc - > add_text ( " ] " ) ;
class_desc - > pop ( ) ; // color
}
2017-11-04 13:09:45 +00:00
class_desc - > pop ( ) ; // font
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 ) {
Map < String , DocData : : MethodDoc > method_map ;
for ( int j = 0 ; j < methods . size ( ) ; j + + ) {
method_map [ methods [ j ] . name ] = methods [ j ] ;
}
2020-05-21 19:07:44 +00:00
2020-11-29 02:37:57 +00:00
if ( cd . properties [ i ] . setter ! = " " ) {
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 ( ) ;
class_desc - > push_font ( doc_code_font ) ;
class_desc - > push_color ( text_color ) ;
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) " ) ) ;
}
class_desc - > pop ( ) ; // color
class_desc - > push_color ( comment_color ) ;
class_desc - > add_text ( " setter " ) ;
class_desc - > pop ( ) ; // color
class_desc - > pop ( ) ; // font
class_desc - > pop ( ) ; // cell
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
2020-11-29 02:37:57 +00:00
if ( cd . properties [ i ] . getter ! = " " ) {
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 ( ) ;
class_desc - > push_font ( doc_code_font ) ;
class_desc - > push_color ( text_color ) ;
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 + " () " ) ;
}
class_desc - > pop ( ) ; //color
class_desc - > push_color ( comment_color ) ;
class_desc - > add_text ( " getter " ) ;
class_desc - > pop ( ) ; //color
class_desc - > pop ( ) ; //font
class_desc - > pop ( ) ; //cell
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 ( ) ;
2017-09-14 00:56:37 +00:00
class_desc - > push_color ( text_color ) ;
2017-03-05 15:44:50 +00:00
class_desc - > push_font ( doc_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 {
2020-03-12 12:37:40 +00:00
class_desc - > add_image ( get_theme_icon ( " Error " , " EditorIcons " ) ) ;
2017-09-12 22:16:18 +00:00
class_desc - > add_text ( " " ) ;
2017-09-14 00:56:37 +00:00
class_desc - > push_color ( comment_color ) ;
2020-11-29 02:37:57 +00:00
if ( cd . is_script_doc ) {
class_desc - > append_bbcode ( TTR ( " There is currently no description for this property. " ) ) ;
} else {
class_desc - > append_bbcode ( TTR ( " There is currently no description for this property. Please help us by [color=$color][url=$url]contributing one[/url][/color]! " ) . replace ( " $url " , CONTRIBUTE_URL ) . replace ( " $color " , link_color_text ) ) ;
}
2017-09-12 22:16:18 +00:00
class_desc - > pop ( ) ;
}
2017-01-04 04:16:14 +00:00
class_desc - > pop ( ) ;
class_desc - > pop ( ) ;
class_desc - > pop ( ) ;
class_desc - > add_newline ( ) ;
class_desc - > add_newline ( ) ;
class_desc - > add_newline ( ) ;
}
}
2018-09-12 15:12:23 +00:00
// Method descriptions
2017-12-19 00:47:17 +00:00
if ( method_descr ) {
2018-09-12 15:12:23 +00:00
section_line . push_back ( Pair < String , int > ( TTR ( " Method Descriptions " ) , class_desc - > get_line_count ( ) - 2 ) ) ;
2017-12-19 00:47:17 +00:00
class_desc - > push_color ( title_color ) ;
class_desc - > push_font ( doc_title_font ) ;
2019-09-20 20:40:22 +00:00
class_desc - > add_text ( TTR ( " Method Descriptions " ) ) ;
2017-12-19 00:47:17 +00:00
class_desc - > pop ( ) ;
class_desc - > pop ( ) ;
2014-02-10 01:10:30 +00:00
2017-12-19 00:47:17 +00:00
class_desc - > add_newline ( ) ;
class_desc - > add_newline ( ) ;
2014-02-10 01:10:30 +00:00
2019-10-03 16:31:41 +00:00
for ( int pass = 0 ; pass < 2 ; pass + + ) {
Vector < DocData : : MethodDoc > methods_filtered ;
2017-09-12 22:16:18 +00:00
2019-10-03 16:31:41 +00:00
for ( int i = 0 ; i < methods . size ( ) ; i + + ) {
const String & q = methods [ i ] . qualifiers ;
if ( ( pass = = 0 & & q . find ( " virtual " ) ! = - 1 ) | | ( pass = = 1 & & q . find ( " virtual " ) = = - 1 ) ) {
methods_filtered . push_back ( methods [ i ] ) ;
}
}
2017-12-19 00:47:17 +00:00
2019-10-03 16:31:41 +00:00
for ( int i = 0 ; i < methods_filtered . size ( ) ; i + + ) {
class_desc - > push_font ( doc_code_font ) ;
_add_method ( methods_filtered [ i ] , false ) ;
2017-12-19 00:47:17 +00:00
class_desc - > pop ( ) ;
2019-10-03 16:31:41 +00:00
class_desc - > add_newline ( ) ;
class_desc - > add_newline ( ) ;
class_desc - > push_color ( text_color ) ;
class_desc - > push_font ( doc_font ) ;
class_desc - > push_indent ( 1 ) ;
2020-12-15 12:04:21 +00:00
if ( ! methods_filtered [ i ] . description . strip_edges ( ) . is_empty ( ) ) {
2020-03-18 17:34:36 +00:00
_add_text ( DTR ( methods_filtered [ i ] . description ) ) ;
2019-10-03 16:31:41 +00:00
} else {
2020-03-12 12:37:40 +00:00
class_desc - > add_image ( get_theme_icon ( " Error " , " EditorIcons " ) ) ;
2019-10-03 16:31:41 +00:00
class_desc - > add_text ( " " ) ;
class_desc - > push_color ( comment_color ) ;
2020-11-29 02:37:57 +00:00
if ( cd . is_script_doc ) {
class_desc - > append_bbcode ( TTR ( " There is currently no description for this method. " ) ) ;
} else {
class_desc - > append_bbcode ( TTR ( " There is currently no description for this method. Please help us by [color=$color][url=$url]contributing one[/url][/color]! " ) . replace ( " $url " , CONTRIBUTE_URL ) . replace ( " $color " , link_color_text ) ) ;
}
2019-10-03 16:31:41 +00:00
class_desc - > pop ( ) ;
}
class_desc - > pop ( ) ;
class_desc - > pop ( ) ;
class_desc - > pop ( ) ;
class_desc - > add_newline ( ) ;
class_desc - > add_newline ( ) ;
class_desc - > add_newline ( ) ;
}
2014-02-10 01:10:30 +00:00
}
}
2017-03-05 15:44:50 +00:00
scroll_locked = false ;
2014-02-10 01:10:30 +00:00
}
2017-03-05 15:44:50 +00:00
void EditorHelp : : _request_help ( const String & p_string ) {
2014-05-06 09:41:19 +00:00
Error err = _goto_desc ( p_string ) ;
2017-03-05 15:44:50 +00:00
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-21 02:01:44 +00:00
//100 palabras
2014-02-10 01:10:30 +00:00
}
2017-03-05 15:44:50 +00:00
void EditorHelp : : _help_callback ( const String & p_topic ) {
String what = p_topic . get_slice ( " : " , 0 ) ;
String clss = p_topic . get_slice ( " : " , 1 ) ;
2014-02-21 02:01:44 +00:00
String name ;
2020-05-14 14:41:43 +00:00
if ( p_topic . get_slice_count ( " : " ) = = 3 ) {
2017-03-05 15:44:50 +00:00
name = p_topic . get_slice ( " : " , 2 ) ;
2020-05-14 14:41:43 +00:00
}
2014-02-21 02:01:44 +00:00
_request_help ( clss ) ; //first go to class
2017-03-05 15:44:50 +00:00
int line = 0 ;
2014-02-21 02:01:44 +00:00
2017-03-05 15:44:50 +00:00
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 ) ) {
2017-03-05 15:44:50 +00:00
line = signal_line [ name ] ;
2020-05-14 14:41:43 +00:00
}
2017-03-05 15:44:50 +00:00
} else if ( what = = " class_method " | | what = = " class_method_desc " ) {
2020-05-14 14:41:43 +00:00
if ( method_line . has ( name ) ) {
2017-03-05 15:44:50 +00:00
line = method_line [ name ] ;
2020-05-14 14:41:43 +00:00
}
2017-03-05 15:44:50 +00:00
} else if ( what = = " class_property " ) {
2020-05-14 14:41:43 +00:00
if ( property_line . has ( name ) ) {
2017-03-05 15:44:50 +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
}
2017-03-05 15:44:50 +00:00
} else if ( what = = " class_theme_item " ) {
2020-05-14 14:41:43 +00:00
if ( theme_property_line . has ( name ) ) {
2017-03-05 15:44:50 +00:00
line = theme_property_line [ name ] ;
2020-05-14 14:41:43 +00:00
}
2017-03-05 15:44:50 +00:00
} else if ( what = = " class_constant " ) {
2020-05-14 14:41:43 +00:00
if ( constant_line . has ( name ) ) {
2017-03-05 15:44:50 +00:00
line = constant_line [ name ] ;
2020-05-14 14:41:43 +00:00
}
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 ] ;
2020-05-14 14:41:43 +00:00
} else {
2020-03-17 06:33:00 +00:00
Map < String , Map < String , int > > : : Element * iter = enum_values_line . front ( ) ;
2018-03-30 14:20:24 +00:00
while ( true ) {
if ( iter - > value ( ) . has ( name ) ) {
line = iter - > value ( ) [ name ] ;
break ;
2020-05-14 14:41:43 +00:00
} else if ( iter = = enum_values_line . back ( ) ) {
2018-03-30 14:20:24 +00:00
break ;
2020-05-14 14:41:43 +00:00
} else {
2018-03-30 14:20:24 +00:00
iter = iter - > next ( ) ;
2020-05-14 14:41:43 +00:00
}
2018-03-30 14:20:24 +00:00
}
}
2014-02-21 02:01:44 +00:00
}
2015-11-27 23:11:49 +00:00
class_desc - > call_deferred ( " scroll_to_line " , line ) ;
2014-02-21 02:01:44 +00:00
}
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
static void _add_text_to_rt ( const String & p_bbcode , RichTextLabel * p_rt ) {
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 ;
2020-03-12 12:37:40 +00:00
Ref < Font > doc_font = p_rt - > get_theme_font ( " doc " , " EditorFonts " ) ;
Ref < Font > doc_bold_font = p_rt - > get_theme_font ( " doc_bold " , " EditorFonts " ) ;
Ref < Font > doc_code_font = p_rt - > get_theme_font ( " doc_source " , " EditorFonts " ) ;
2020-03-10 10:41:36 +00:00
Ref < Font > doc_kbd_font = p_rt - > get_theme_font ( " doc_keyboard " , " EditorFonts " ) ;
2019-10-31 17:47:12 +00:00
2020-12-08 13:11:45 +00:00
Color headline_color = p_rt - > get_theme_color ( " headline_color " , " EditorHelp " ) ;
2020-03-12 12:37:40 +00:00
Color accent_color = p_rt - > get_theme_color ( " accent_color " , " Editor " ) ;
2020-03-10 10:41:36 +00:00
Color property_color = p_rt - > get_theme_color ( " property_color " , " Editor " ) ;
2020-12-08 13:11:45 +00:00
Color link_color = accent_color . lerp ( headline_color , 0.8 ) ;
Color code_color = accent_color . lerp ( headline_color , 0.6 ) ;
2020-03-16 09:07:33 +00:00
Color kbd_color = accent_color . lerp ( property_color , 0.6 ) ;
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
2020-07-22 20:41:10 +00:00
// Select the correct code examples
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] " ) ) {
if ( bbcode . find ( " [/csharp] " ) = = - 1 ) {
WARN_PRINT ( " Unclosed [csharp] block or parse fail in code (search for tag errors) " ) ;
break ;
}
bbcode . erase ( pos , bbcode . find ( " [/csharp] " ) + 9 - pos ) ;
while ( bbcode [ pos ] = = ' \n ' ) {
bbcode . erase ( pos , 1 ) ;
}
}
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] " ) ) {
if ( bbcode . find ( " [/gdscript] " ) = = - 1 ) {
WARN_PRINT ( " Unclosed [gdscript] block or parse fail in code (search for tag errors) " ) ;
break ;
}
bbcode . erase ( pos , bbcode . find ( " [/gdscript] " ) + 11 - pos ) ;
while ( bbcode [ pos ] = = ' \n ' ) {
bbcode . erase ( pos , 1 ) ;
}
}
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 ;
}
// Remove codeblocks (they would be printed otherwise)
bbcode = bbcode . replace ( " [codeblocks] \n " , " " ) ;
bbcode = bbcode . replace ( " \n [/codeblocks] " , " " ) ;
bbcode = bbcode . replace ( " [codeblocks] " , " " ) ;
bbcode = bbcode . replace ( " [/codeblocks] " , " " ) ;
2019-10-31 17:47:12 +00:00
// remove extra new lines around code blocks
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 ;
2014-02-10 01:10:30 +00:00
2017-09-14 00:56:37 +00:00
int pos = 0 ;
2017-03-05 15:44:50 +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 ) {
2017-03-05 15:44:50 +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 ) ;
2020-05-14 14:41:43 +00:00
if ( ! code_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 ( ) ) {
2017-12-18 17:46:17 +00:00
break ; //nothing else to add
2020-05-14 14:41:43 +00:00
}
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
int brk_end = bbcode . find ( " ] " , brk_pos + 1 ) ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
if ( brk_end = = - 1 ) {
2017-11-11 01:11:24 +00:00
String text = bbcode . substr ( brk_pos , bbcode . length ( ) - brk_pos ) ;
2020-05-14 14:41:43 +00:00
if ( ! code_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 ;
}
2017-03-05 15:44:50 +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 ( " / " ) ) {
2017-03-05 15:44:50 +00:00
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 ( ) ;
2017-03-05 15:44:50 +00:00
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 ) {
p_rt - > pop ( ) ;
}
}
code_tag = false ;
2017-11-11 01:11:24 +00:00
} else if ( code_tag ) {
p_rt - > add_text ( " [ " ) ;
pos = brk_pos + 1 ;
2014-02-10 01:10:30 +00:00
2019-03-27 19:01:16 +00:00
} else if ( tag . begins_with ( " method " ) | | tag . begins_with ( " member " ) | | tag . begins_with ( " signal " ) | | tag . begins_with ( " enum " ) | | tag . begins_with ( " constant " ) ) {
2019-04-27 19:15:07 +00:00
int tag_end = tag . find ( " " ) ;
String link_tag = tag . substr ( 0 , tag_end ) ;
String link_target = tag . substr ( tag_end + 1 , tag . length ( ) ) . lstrip ( " " ) ;
2017-09-14 00:56:37 +00:00
p_rt - > push_color ( link_color ) ;
2019-04-27 19:15:07 +00:00
p_rt - > push_meta ( " @ " + link_tag + " " + link_target ) ;
2017-11-20 23:30:46 +00:00
p_rt - > add_text ( link_target + ( tag . begins_with ( " method " ) ? " () " : " " ) ) ;
2016-08-24 02:15:16 +00:00
p_rt - > pop ( ) ;
p_rt - > pop ( ) ;
2017-03-05 15:44:50 +00:00
pos = brk_end + 1 ;
2014-02-10 01:10:30 +00:00
2014-02-16 00:16:33 +00:00
} else if ( doc - > class_list . has ( tag ) ) {
2017-09-14 00:56:37 +00:00
p_rt - > push_color ( link_color ) ;
2017-03-05 15:44:50 +00:00
p_rt - > push_meta ( " # " + tag ) ;
2016-08-24 02:15:16 +00:00
p_rt - > add_text ( tag ) ;
p_rt - > pop ( ) ;
p_rt - > pop ( ) ;
2017-03-05 15:44:50 +00:00
pos = brk_end + 1 ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
} else if ( tag = = " b " ) {
2014-02-10 01:10:30 +00:00
//use bold font
2019-06-15 16:18:32 +00:00
p_rt - > push_font ( doc_bold_font ) ;
2017-03-05 15:44:50 +00:00
pos = brk_end + 1 ;
2014-02-10 01:10:30 +00:00
tag_stack . push_front ( tag ) ;
2017-03-05 15:44:50 +00:00
} else if ( tag = = " i " ) {
2014-02-10 01:10:30 +00:00
//use italics font
2020-12-08 13:11:45 +00:00
p_rt - > push_color ( headline_color ) ;
2017-03-05 15:44:50 +00:00
pos = brk_end + 1 ;
2014-02-10 01:10:30 +00:00
tag_stack . push_front ( tag ) ;
2017-03-05 15:44:50 +00:00
} else if ( tag = = " code " | | tag = = " codeblock " ) {
2014-02-10 01:10:30 +00:00
//use monospace font
2016-08-24 02:15:16 +00:00
p_rt - > push_font ( doc_code_font ) ;
2019-10-31 17:47:12 +00:00
p_rt - > push_color ( code_color ) ;
2017-11-11 01:11:24 +00:00
code_tag = true ;
2017-03-05 15:44:50 +00:00
pos = brk_end + 1 ;
2014-02-10 01:10:30 +00:00
tag_stack . push_front ( tag ) ;
2020-03-10 10:41:36 +00:00
} else if ( tag = = " kbd " ) {
//use keyboard font with custom color
p_rt - > push_font ( doc_kbd_font ) ;
p_rt - > push_color ( kbd_color ) ;
code_tag = true ; // though not strictly a code tag, logic is similar
pos = brk_end + 1 ;
tag_stack . push_front ( tag ) ;
2017-03-05 15:44:50 +00:00
} else if ( tag = = " center " ) {
2019-06-15 16:18:32 +00:00
//align to center
2020-10-02 12:02:02 +00:00
p_rt - > push_paragraph ( RichTextLabel : : ALIGN_CENTER , Control : : TEXT_DIRECTION_AUTO , " " ) ;
2017-03-05 15:44:50 +00:00
pos = brk_end + 1 ;
2014-02-10 01:10:30 +00:00
tag_stack . push_front ( tag ) ;
2017-03-05 15:44:50 +00:00
} else if ( tag = = " br " ) {
2019-06-15 16:18:32 +00:00
//force a line break
2016-08-24 02:15:16 +00:00
p_rt - > add_newline ( ) ;
2017-03-05 15:44:50 +00:00
pos = brk_end + 1 ;
} else if ( tag = = " u " ) {
2014-02-10 01:10:30 +00:00
//use underline
2016-08-24 02:15:16 +00:00
p_rt - > push_underline ( ) ;
2017-03-05 15:44:50 +00:00
pos = brk_end + 1 ;
2014-02-10 01:10:30 +00:00
tag_stack . push_front ( tag ) ;
2017-03-05 15:44:50 +00:00
} else if ( tag = = " s " ) {
2019-06-15 16:18:32 +00:00
//use strikethrough
p_rt - > push_strikethrough ( ) ;
2017-03-05 15:44:50 +00:00
pos = brk_end + 1 ;
2014-02-10 01:10:30 +00:00
tag_stack . push_front ( tag ) ;
2017-03-05 15:44:50 +00:00
} else if ( tag = = " url " ) {
int end = bbcode . find ( " [ " , brk_end ) ;
2020-05-14 14:41:43 +00:00
if ( end = = - 1 ) {
2017-03-05 15:44:50 +00:00
end = bbcode . length ( ) ;
2020-05-14 14:41:43 +00:00
}
2017-03-05 15:44:50 +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
2017-03-05 15:44:50 +00:00
pos = brk_end + 1 ;
2014-02-10 01:10:30 +00:00
tag_stack . push_front ( tag ) ;
} else if ( tag . begins_with ( " url= " ) ) {
2017-03-05 15:44:50 +00:00
String url = tag . substr ( 4 , tag . length ( ) ) ;
2016-08-24 02:15:16 +00:00
p_rt - > push_meta ( url ) ;
2017-03-05 15:44:50 +00:00
pos = brk_end + 1 ;
2014-02-10 01:10:30 +00:00
tag_stack . push_front ( " url " ) ;
2017-03-05 15:44:50 +00:00
} else if ( tag = = " img " ) {
int end = bbcode . find ( " [ " , brk_end ) ;
2020-05-14 14:41:43 +00:00
if ( end = = - 1 ) {
2017-03-05 15:44:50 +00:00
end = bbcode . length ( ) ;
2020-05-14 14:41:43 +00:00
}
2017-03-05 15:44:50 +00:00
String image = bbcode . substr ( brk_end + 1 , end - brk_end - 1 ) ;
2014-02-10 01:10:30 +00:00
2019-06-11 18:43:37 +00:00
Ref < Texture2D > texture = ResourceLoader : : load ( base_path . plus_file ( 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
2017-03-05 15:44:50 +00:00
pos = end ;
2014-02-10 01:10:30 +00:00
tag_stack . push_front ( tag ) ;
} else if ( tag . begins_with ( " color= " ) ) {
2017-03-05 15:44:50 +00:00
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 ) ;
2017-03-05 15:44:50 +00:00
pos = brk_end + 1 ;
2014-02-10 01:10:30 +00:00
tag_stack . push_front ( " color " ) ;
} else if ( tag . begins_with ( " font= " ) ) {
2017-03-05 15:44:50 +00:00
String fnt = tag . substr ( 5 , tag . length ( ) ) ;
2014-02-10 01:10:30 +00:00
2019-06-16 12:31:57 +00:00
Ref < Font > font = ResourceLoader : : load ( base_path . plus_file ( 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
}
2017-03-05 15:44:50 +00:00
pos = brk_end + 1 ;
2014-02-10 01:10:30 +00:00
tag_stack . push_front ( " font " ) ;
} else {
2016-08-24 02:15:16 +00:00
p_rt - > add_text ( " [ " ) ; //ignore
2017-03-05 15:44:50 +00:00
pos = brk_pos + 1 ;
2014-02-10 01:10:30 +00:00
}
}
2016-08-24 02:15:16 +00:00
}
2017-03-05 15:44:50 +00:00
void EditorHelp : : _add_text ( const String & p_bbcode ) {
_add_text_to_rt ( p_bbcode , class_desc ) ;
2014-02-10 01:10:30 +00:00
}
2015-11-17 12:46:08 +00:00
void EditorHelp : : generate_doc ( ) {
2020-11-29 03:42:06 +00:00
doc = memnew ( DocTools ) ;
2015-11-17 12:46:08 +00:00
doc - > generate ( true ) ;
2020-11-29 03:42:06 +00:00
DocTools compdoc ;
2017-03-05 15:44:50 +00:00
compdoc . load_compressed ( _doc_data_compressed , _doc_data_compressed_size , _doc_data_uncompressed_size ) ;
2015-11-17 12:46:08 +00:00
doc - > merge_from ( compdoc ) ; //ensure all is up to date
2014-02-10 01:10:30 +00:00
}
2015-11-17 12:46:08 +00:00
void EditorHelp : : _notification ( int p_what ) {
2017-03-05 15:44:50 +00:00
switch ( p_what ) {
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 : {
2019-08-09 04:00:44 +00:00
_update_doc ( ) ;
2017-09-02 17:16:31 +00:00
} break ;
2019-10-15 06:54:28 +00:00
case NOTIFICATION_THEME_CHANGED : {
2021-04-11 10:29:35 +00:00
if ( is_inside_tree ( ) ) {
2019-10-22 13:01:11 +00:00
_class_desc_resized ( ) ;
}
2019-10-15 06:54:28 +00:00
} break ;
2020-05-10 11:00:47 +00:00
default :
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
2017-03-05 15:44:50 +00:00
void EditorHelp : : go_to_help ( const String & p_help ) {
2015-11-17 12:46:08 +00:00
_help_callback ( p_help ) ;
2014-02-10 01:10:30 +00:00
}
2017-03-05 15:44:50 +00:00
void EditorHelp : : go_to_class ( const String & p_class , int p_scroll ) {
_goto_desc ( p_class , p_scroll ) ;
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 ( ) {
ERR_FAIL_COND ( ! doc - > class_list . has ( edited_class ) ) ;
ERR_FAIL_COND ( ! doc - > class_list [ edited_class ] . is_script_doc ) ;
_update_doc ( ) ;
}
2020-03-17 06:33:00 +00:00
Vector < Pair < String , int > > EditorHelp : : get_sections ( ) {
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 ) {
int line = section_line [ p_section_index ] . second ;
class_desc - > scroll_to_line ( line ) ;
}
2015-11-17 12:46:08 +00:00
void EditorHelp : : popup_search ( ) {
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 {
2017-01-04 04:16:14 +00:00
return class_desc - > get_v_scroll ( ) - > 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 ) {
2017-01-04 04:16:14 +00:00
class_desc - > get_v_scroll ( ) - > set_value ( p_scroll ) ;
2014-02-10 01:10:30 +00:00
}
void EditorHelp : : _bind_methods ( ) {
2017-03-05 15:44:50 +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-03-05 15:44:50 +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 ) ;
class_desc - > set_v_size_flags ( SIZE_EXPAND_FILL ) ;
2020-03-12 12:37:40 +00:00
class_desc - > add_theme_color_override ( " selection_color " , get_theme_color ( " accent_color " , " Editor " ) * Color ( 1 , 1 , 1 , 0.4 ) ) ;
2019-06-05 18:47:34 +00:00
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 ) ) ;
class_desc - > connect ( " resized " , callable_mp ( this , & EditorHelp : : _class_desc_resized ) ) ;
2019-06-05 18:47:34 +00:00
_class_desc_resized ( ) ;
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 ) ;
2014-02-10 01:10:30 +00:00
class_desc - > set_selection_enabled ( true ) ;
2015-11-17 12:46:08 +00:00
2017-03-05 15:44:50 +00:00
scroll_locked = false ;
select_locked = false ;
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
}
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 ) ;
emit_signal ( " request_hide " ) ;
}
void EditorHelpBit : : _meta_clicked ( String p_select ) {
2017-08-23 22:10:32 +00:00
if ( p_select . begins_with ( " $ " ) ) { //enum
2017-12-18 17:46:17 +00:00
2017-08-23 22:10:32 +00:00
String select = p_select . substr ( 1 , p_select . length ( ) ) ;
String class_name ;
if ( select . find ( " . " ) ! = - 1 ) {
class_name = select . get_slice ( " . " , 0 ) ;
} else {
class_name = " @Global " ;
}
_go_to_help ( " class_enum: " + class_name + " : " + select ) ;
return ;
} else if ( p_select . begins_with ( " # " ) ) {
2017-03-05 15:44:50 +00:00
_go_to_help ( " class_name: " + p_select . substr ( 1 , p_select . length ( ) ) ) ;
2016-08-24 02:15:16 +00:00
return ;
} else if ( p_select . begins_with ( " @ " ) ) {
2017-03-05 15:44:50 +00:00
String m = p_select . substr ( 1 , p_select . length ( ) ) ;
2016-08-24 02:15:16 +00:00
2020-05-14 14:41:43 +00:00
if ( m . find ( " . " ) ! = - 1 ) {
2017-12-18 17:46:17 +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 " ) ) ;
}
2017-03-05 15:44:50 +00:00
void EditorHelpBit : : _notification ( int p_what ) {
2017-09-02 17:16:31 +00:00
switch ( p_what ) {
2020-03-20 20:51:53 +00:00
case NOTIFICATION_READY : {
rich_text - > clear ( ) ;
_add_text_to_rt ( text , rich_text ) ;
} break ;
2017-09-02 17:16:31 +00:00
case EditorSettings : : NOTIFICATION_EDITOR_SETTINGS_CHANGED : {
2020-03-12 12:37:40 +00:00
rich_text - > add_theme_color_override ( " selection_color " , get_theme_color ( " accent_color " , " Editor " ) * Color ( 1 , 1 , 1 , 0.4 ) ) ;
2017-09-02 17:16:31 +00:00
} break ;
2020-05-10 11:00:47 +00:00
default :
break ;
2017-09-02 17:16:31 +00:00
}
2016-08-24 02:15:16 +00:00
}
2017-03-05 15:44:50 +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 ( ) ;
2020-03-20 20:51:53 +00:00
_add_text_to_rt ( text , rich_text ) ;
2016-08-24 02:15:16 +00:00
}
EditorHelpBit : : EditorHelpBit ( ) {
2017-03-05 15:44:50 +00:00
rich_text = memnew ( RichTextLabel ) ;
2016-08-24 02:15:16 +00:00
add_child ( rich_text ) ;
2020-02-21 17:28:45 +00:00
rich_text - > connect ( " meta_clicked " , callable_mp ( this , & EditorHelpBit : : _meta_clicked ) ) ;
2020-03-12 12:37:40 +00:00
rich_text - > add_theme_color_override ( " selection_color " , get_theme_color ( " accent_color " , " Editor " ) * Color ( 1 , 1 , 1 , 0.4 ) ) ;
2017-09-27 17:24:05 +00:00
rich_text - > set_override_selected_font_color ( false ) ;
2019-02-17 22:06:42 +00:00
set_custom_minimum_size ( Size2 ( 0 , 70 * EDSCALE ) ) ;
2016-08-24 02:15:16 +00:00
}
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 ) ) ;
search_text - > connect ( " text_entered " , callable_mp ( this , & FindBar : : _search_text_entered ) ) ;
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 ) ;
hide_button - > set_expand ( true ) ;
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 ( ) ;
search_text - > set_cursor_position ( search_text - > get_text ( ) . length ( ) ) ;
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_ENTER_TREE :
case NOTIFICATION_THEME_CHANGED : {
2020-03-12 12:37:40 +00:00
find_prev - > set_icon ( get_theme_icon ( " MoveUp " , " EditorIcons " ) ) ;
find_next - > set_icon ( get_theme_icon ( " MoveDown " , " EditorIcons " ) ) ;
hide_button - > set_normal_texture ( get_theme_icon ( " Close " , " EditorIcons " ) ) ;
hide_button - > set_hover_texture ( get_theme_icon ( " Close " , " EditorIcons " ) ) ;
hide_button - > set_pressed_texture ( get_theme_icon ( " Close " , " EditorIcons " ) ) ;
2019-08-09 04:00:44 +00:00
hide_button - > set_custom_minimum_size ( hide_button - > get_normal_texture ( ) - > get_size ( ) ) ;
2020-03-12 12:37:40 +00:00
matches_label - > add_theme_color_override ( " font_color " , results_count > 0 ? get_theme_color ( " font_color " , " Label " ) : get_theme_color ( " error_color " , " Editor " ) ) ;
2019-08-09 04:00:44 +00:00
} break ;
case NOTIFICATION_VISIBILITY_CHANGED : {
set_process_unhandled_input ( is_visible_in_tree ( ) ) ;
} break ;
2017-12-22 18:09:31 +00:00
}
}
void FindBar : : _bind_methods ( ) {
ClassDB : : bind_method ( " _unhandled_input " , & FindBar : : _unhandled_input ) ;
ADD_SIGNAL ( MethodInfo ( " search " ) ) ;
}
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 ) ;
if ( ! ret ) {
ret = rich_text_label - > search ( stext , false , 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 ( ) ) {
2020-05-10 10:56:01 +00:00
return ;
2020-05-14 14:41:43 +00:00
}
2019-08-09 04:00:44 +00:00
String full_text = rich_text_label - > get_text ( ) ;
int from_pos = 0 ;
while ( true ) {
int pos = full_text . find ( 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 ( ) ;
2020-03-12 12:37:40 +00:00
matches_label - > add_theme_color_override ( " font_color " , results_count > 0 ? get_theme_color ( " font_color " , " Label " ) : get_theme_color ( " error_color " , " 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 ( ) ;
}
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 ;
if ( k . is_valid ( ) ) {
2019-02-10 16:17:29 +00:00
if ( k - > is_pressed ( ) & & ( rich_text_label - > has_focus ( ) | | is_a_parent_of ( get_focus_owner ( ) ) ) ) {
2017-12-22 18:09:31 +00:00
bool accepted = true ;
2018-04-05 17:59:35 +00:00
switch ( k - > get_keycode ( ) ) {
2017-12-22 18:09:31 +00:00
case KEY_ESCAPE : {
_hide_bar ( ) ;
} break ;
default : {
accepted = false ;
} break ;
}
if ( accepted ) {
accept_event ( ) ;
}
}
}
}
void FindBar : : _search_text_changed ( const String & p_text ) {
search_next ( ) ;
}
void FindBar : : _search_text_entered ( const String & p_text ) {
2020-04-28 13:19:37 +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
}