Browse Source

Improve the Rich Text Label with BBCode demo (#816)

Hugo Locurcio 2 years ago
parent
commit
ee5862a782

+ 2 - 2
gui/rich_text_bbcode/README.md

@@ -5,10 +5,10 @@ A demo showcasing the support for rich text and BBCode via
 
 
 Language: GDScript
 Language: GDScript
 
 
-Renderer: GLES 2
+Renderer: Compatibility
 
 
 Check out this demo on the asset library: https://godotengine.org/asset-library/asset/132
 Check out this demo on the asset library: https://godotengine.org/asset-library/asset/132
 
 
 ## Screenshots
 ## Screenshots
 
 
-![Screenshot](screenshots/rich_text.png)
+![Screenshot](screenshots/rich_text_bbcode.webp)

+ 0 - 155
gui/rich_text_bbcode/SIL Open Font License.txt

@@ -1,155 +0,0 @@
-Copyright (c) 2008-2010, Accademia di Belle Arti di Urbino (www.campivisivi.net|[email protected]),
-with Reserved Font Name Titillium.
-
-
-N: Luca Antonucci
-W: http://www.campivisivi.net
-D: Contributor
-
-N: Paola Bacchiocchi
-W: http://www.campivisivi.net
-D: Contributor
-
-N: Simone Bastianelli
-W: http://www.campivisivi.net
-D: Contributor
-
-N: Valerio Bosi
-W: http://www.campivisivi.net
-D: Contributor
-
-N: Fabio Cecchi
-W: http://www.campivisivi.net
-D: Contributor
-
-N: Giulia Di Grusa
-W: http://www.campivisivi.net
-D: Contributor
-
-N: Donatella Esposito
-W: http://www.campivisivi.net
-D: Contributor
-
-N: Giulia Giordani
-W: http://www.campivisivi.net
-D: Contributor
-
-N: Raffaele Mariotti
-W: http://www.campivisivi.net
-D: Contributor
-
-N: Leslie Ameto
-W: http://www.campivisivi.net
-D: Contributor
-
-N: Elisa Mearelli
-W: http://www.campivisivi.net
-D: Contributor
-
-N: Silvia Mengarelli
-W: http://www.campivisivi.net
-D: Contributor
-
-N: Roberto Mezzano
-W: http://www.campivisivi.net
-D: Contributor
-
-N: Valentina Mingucci
-W: http://www.campivisivi.net
-D: Contributor
-
-N: Andrea Monachesi
-W: http://www.campivisivi.net
-D: Contributor
-
-N: Manuel Pasini
-W: http://www.campivisivi.net
-D: Contributor
-
-N: David Pulga
-W: http://www.campivisivi.net
-D: Contributor
-
-N: Luca Silvestri
-W: http://www.campivisivi.net
-D: Contributor
-
-N: Paolo Tripodi
-W: http://www.campivisivi.net
-D: Contributor
-
-N: Fancesco Zamboni
-W: http://www.campivisivi.net
-D: Contributor
-
-N: Giuliano Chimenti
-W: http://www.isiaurbino.it
-D: Contributor
-
-N: Francesco Piarulli
-W: http://www.isiaurbino.it
-D: Contributor
-
-N: Ivan Abbattista
-W: http://www.isiaurbino.it
-D: Contributor
-
-N: Rita Colacicco
-W: http://www.isiaurbino.it
-D: Contributor
-
-N: Paolo Mazzetti
-W: http://www.scriptype.net
-D: Contributor
-
-N: Claudio Piccinini
-W: http://www.tht.it/
-D: Contributor
-
-N: Luciano Perondi
-E: [email protected]
-W: http://www.campivisivi.net
-D: Director of progect
-
-
-This Font Software is licensed under the SIL Open Font License, Version 1.1.
-This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL
-
------------------------------------------------------------
-SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
------------------------------------------------------------
-
-PREAMBLE
-The goals of the Open Font License (OFL) are to stimulate worldwide development of collaborative font projects, to support the font creation efforts of academic and linguistic communities, and to provide a free and open framework in which fonts may be shared and improved in partnership with others.
-
-The OFL allows the licensed fonts to be used, studied, modified and redistributed freely as long as they are not sold by themselves. The fonts, including any derivative works, can be bundled, embedded, redistributed and/or sold with any software provided that any reserved names are not used by derivative works. The fonts and derivatives, however, cannot be released under any other type of license. The requirement for fonts to remain under this license does not apply to any document created using the fonts or their derivatives.
-
-DEFINITIONS
-"Font Software" refers to the set of files released by the Copyright Holder(s) under this license and clearly marked as such. This may include source files, build scripts and documentation.
-
-"Reserved Font Name" refers to any names specified as such after the copyright statement(s).
-
-"Original Version" refers to the collection of Font Software components as distributed by the Copyright Holder(s).
-
-"Modified Version" refers to any derivative made by adding to, deleting, or substituting -- in part or in whole -- any of the components of the Original Version, by changing formats or by porting the Font Software to a new environment.
-
-"Author" refers to any designer, engineer, programmer, technical writer or other person who contributed to the Font Software.
-
-PERMISSION & CONDITIONS
-Permission is hereby granted, free of charge, to any person obtaining a copy of the Font Software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the Font Software, subject to the following conditions:
-
-1) Neither the Font Software nor any of its individual components, in Original or Modified Versions, may be sold by itself.
-
-2) Original or Modified Versions of the Font Software may be bundled, redistributed and/or sold with any software, provided that each copy contains the above copyright notice and this license. These can be included either as stand-alone text files, human-readable headers or in the appropriate machine-readable metadata fields within text or binary files as long as those fields can be easily viewed by the user.
-
-3) No Modified Version of the Font Software may use the Reserved Font Name(s) unless explicit written permission is granted by the corresponding Copyright Holder. This restriction only applies to the primary font name as presented to the users.
-
-4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software shall not be used to promote, endorse or advertise any Modified Version, except to acknowledge the contribution(s) of the Copyright Holder(s) and the Author(s) or with their explicit written permission.
-
-5) The Font Software, modified or unmodified, in part or in whole, must be distributed entirely under this license, and must not be distributed under any other license. The requirement for fonts to remain under this license does not apply to any document created using the Font Software.
-
-TERMINATION
-This license becomes null and void if any of the above conditions are not met.
-
-DISCLAIMER
-THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.

BIN
gui/rich_text_bbcode/Titillium-Bold.otf


BIN
gui/rich_text_bbcode/Titillium-BoldItalic.otf


BIN
gui/rich_text_bbcode/Titillium-Regular.otf


BIN
gui/rich_text_bbcode/Titillium-RegularItalic.otf


+ 14 - 15
gui/rich_text_bbcode/icon.png.import

@@ -1,8 +1,9 @@
 [remap]
 [remap]
 
 
 importer="texture"
 importer="texture"
-type="StreamTexture2D"
-path="res://.godot/imported/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
+type="CompressedTexture2D"
+uid="uid://c4r4qkq7klb3p"
+path="res://.godot/imported/icon.png-487276ed1e3a0c39cad0279d744ee560.ctex"
 metadata={
 metadata={
 "vram_texture": false
 "vram_texture": false
 }
 }
@@ -10,26 +11,24 @@ metadata={
 [deps]
 [deps]
 
 
 source_file="res://icon.png"
 source_file="res://icon.png"
-dest_files=["res://.godot/imported/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"]
+dest_files=["res://.godot/imported/icon.png-487276ed1e3a0c39cad0279d744ee560.ctex"]
 
 
 [params]
 [params]
 
 
 compress/mode=0
 compress/mode=0
 compress/lossy_quality=0.7
 compress/lossy_quality=0.7
-compress/hdr_mode=0
+compress/hdr_compression=1
 compress/bptc_ldr=0
 compress/bptc_ldr=0
 compress/normal_map=0
 compress/normal_map=0
-flags/repeat=0
-flags/filter=true
-flags/mipmaps=false
-flags/anisotropic=false
-flags/srgb=2
+compress/channel_pack=0
+mipmaps/generate=false
+mipmaps/limit=-1
+roughness/mode=0
+roughness/src_normal=""
 process/fix_alpha_border=true
 process/fix_alpha_border=true
 process/premult_alpha=false
 process/premult_alpha=false
-process/HDR_as_SRGB=false
-process/invert_color=false
 process/normal_map_invert_y=false
 process/normal_map_invert_y=false
-stream=false
-size_limit=0
-detect_3d=true
-svg/scale=1.0
+process/hdr_as_srgb=false
+process/hdr_clamp_exposure=false
+process/size_limit=0
+detect_3d/compress_to=1

+ 6 - 1
gui/rich_text_bbcode/project.godot

@@ -6,17 +6,20 @@
 ;   [section] ; section goes between []
 ;   [section] ; section goes between []
 ;   param=value ; assign values to parameters
 ;   param=value ; assign values to parameters
 
 
-config_version=4
+config_version=5
 
 
 [application]
 [application]
 
 
 config/name="Rich Text Label with BBCode"
 config/name="Rich Text Label with BBCode"
 config/description="A demo showcasing the support for rich text and BBCode via RichTextLabel."
 config/description="A demo showcasing the support for rich text and BBCode via RichTextLabel."
 run/main_scene="res://rich_text_bbcode.tscn"
 run/main_scene="res://rich_text_bbcode.tscn"
+config/features=PackedStringArray("4.0")
+run/low_processor_mode=true
 config/icon="res://icon.png"
 config/icon="res://icon.png"
 
 
 [display]
 [display]
 
 
+window/vsync/vsync_mode=0
 window/stretch/mode="canvas_items"
 window/stretch/mode="canvas_items"
 window/stretch/aspect="expand"
 window/stretch/aspect="expand"
 
 
@@ -26,4 +29,6 @@ multithread/thread_rid_pool_prealloc=60
 
 
 [rendering]
 [rendering]
 
 
+renderer/rendering_method="gl_compatibility"
+renderer/rendering_method.mobile="gl_compatibility"
 environment/defaults/default_clear_color=Color(0.145098, 0.145098, 0.164706, 1)
 environment/defaults/default_clear_color=Color(0.145098, 0.145098, 0.164706, 1)

+ 4 - 0
gui/rich_text_bbcode/rich_text_bbcode.gd

@@ -6,3 +6,7 @@ func _on_RichTextLabel_meta_clicked(meta):
 		print("Opened link '%s' successfully!" % meta)
 		print("Opened link '%s' successfully!" % meta)
 	else:
 	else:
 		print("Failed opening the link '%s'!" % meta)
 		print("Failed opening the link '%s'!" % meta)
+
+
+func _on_pause_toggled(button_pressed):
+	get_tree().paused = button_pressed

+ 59 - 47
gui/rich_text_bbcode/rich_text_bbcode.tscn

@@ -1,28 +1,12 @@
-[gd_scene load_steps=10 format=2]
+[gd_scene load_steps=3 format=3 uid="uid://oeg5vj7lpjw0"]
 
 
-[ext_resource path="res://rich_text_bbcode.gd" type="Script" id=1]
-[ext_resource path="res://Titillium-BoldItalic.otf" type="FontData" id=2]
-[ext_resource path="res://Titillium-RegularItalic.otf" type="FontData" id=3]
-[ext_resource path="res://Titillium-Bold.otf" type="FontData" id=4]
-[ext_resource path="res://Titillium-Regular.otf" type="FontData" id=5]
+[ext_resource type="Script" path="res://rich_text_bbcode.gd" id="1"]
 
 
-[sub_resource type="Font" id=1]
-size = 20
-font_data = ExtResource( 2 )
-
-[sub_resource type="Font" id=2]
-size = 20
-font_data = ExtResource( 3 )
-
-[sub_resource type="Font" id=3]
-size = 20
-font_data = ExtResource( 4 )
-
-[sub_resource type="Font" id=4]
-size = 20
-font_data = ExtResource( 5 )
+[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_q1hwu"]
 
 
 [node name="RichTextBBCode" type="Control"]
 [node name="RichTextBBCode" type="Control"]
+layout_mode = 3
+anchors_preset = 8
 anchor_left = 0.5
 anchor_left = 0.5
 anchor_top = 0.5
 anchor_top = 0.5
 anchor_right = 0.5
 anchor_right = 0.5
@@ -31,50 +15,78 @@ offset_left = -512.0
 offset_top = -300.0
 offset_top = -300.0
 offset_right = 512.0
 offset_right = 512.0
 offset_bottom = 300.0
 offset_bottom = 300.0
+grow_horizontal = 2
+grow_vertical = 2
 size_flags_horizontal = 2
 size_flags_horizontal = 2
 size_flags_vertical = 2
 size_flags_vertical = 2
-script = ExtResource( 1 )
+script = ExtResource("1")
 
 
 [node name="RichTextLabel" type="RichTextLabel" parent="."]
 [node name="RichTextLabel" type="RichTextLabel" parent="."]
+clip_contents = false
+layout_mode = 1
+anchors_preset = 15
 anchor_right = 1.0
 anchor_right = 1.0
 anchor_bottom = 1.0
 anchor_bottom = 1.0
-offset_left = 49.0
-offset_top = 55.0
-offset_right = -48.0
-offset_bottom = -62.0
+offset_top = -2.0
+offset_bottom = -2.0
+grow_horizontal = 2
+grow_vertical = 2
 size_flags_horizontal = 2
 size_flags_horizontal = 2
 size_flags_vertical = 2
 size_flags_vertical = 2
-custom_fonts/bold_italics_font = SubResource( 1 )
-custom_fonts/italics_font = SubResource( 2 )
-custom_fonts/bold_font = SubResource( 3 )
-custom_fonts/normal_font = SubResource( 4 )
+focus_mode = 2
+theme_override_colors/selection_color = Color(1, 1, 1, 0.164706)
+theme_override_constants/line_separation = 1
+theme_override_constants/table_h_separation = 120
+theme_override_constants/table_v_separation = 10
+theme_override_styles/focus = SubResource("StyleBoxEmpty_q1hwu")
 bbcode_enabled = true
 bbcode_enabled = true
-bbcode_text = "[b][u]Rich Text Test[/u][/b]
+text = "RichTextLabel is a flexible way of adding text to your project, with support for [i]italics[/i], [b]bold[/b] and [i][b]both[/b][/i].
+[u]Underline[/u] and [s]strikethrough[/s] work too, including with [u][i]italics[/i][/u], [u][b]bold[/b][/u] and [u][i][b]both[/b][/i][/u].
 
 
-RichTextLabel is a flexible way of adding text to your game, with support for [i]italics[/i], [b]bold[/b] and [i][b]both[/b][/i].
- [u]Underline[/u] works too, including with [u][i]italics[/i][/u], [u][b]bold[/b][/u] and [u][i][b]both[/b][/i][/u].
-It is also possible to include [img]res://unicorn_icon.png[/img] custom images, as well as [color=aqua][url=https://godotengine.org]custom URLs[/url][/color].
+Text [color=#4cf]color[/color], [fgcolor=#49c9]foreground [color=#4cf]color[/color][/fgcolor]  and  [bgcolor=#49c9]background [color=#4cf]color[/color][/bgcolor]  can be adjusted.
 
 
+It's also possible to include [img]res://unicorn_icon.png[/img] [font_size=24]custom images[/font_size], as well as [color=aqua][url=https://godotengine.org]custom URLs[/url][/color]. [hint=This displays a hint.]Hover this to display a tooltip![/hint]
 Left alignment is default,[center]but center alignment is supported,[/center][right]as well as right alignment.[/right]
 Left alignment is default,[center]but center alignment is supported,[/center][right]as well as right alignment.[/right]
 
 
-[fill]Fill alignment is also supported, and allows writing very long text that will end up fitting the horizontal space entirely with words of joy.[/fill]
+[fill][dropcap font_size=48 color=yellow margins=0,-10,0,-12]F[/dropcap]ill alignment is also supported, and allows writing very long text that will end up fitting the horizontal space entirely with words of joy. Drop caps are also supported. A drop cap is the where the first character of a paragraph is made larger, taking up several lines of text and optionally using a specific font or color.[/fill]
 
 
-For full reference, [color=aqua][url=https://docs.godotengine.org/en/latest/tutorials/gui/bbcode_in_richtextlabel.html]check the documentation.[/url][/color]
-"
-text = "Rich Text Test
+Several effects are also available:    [wave]Wave[/wave]    [tornado]Tornado[/tornado]    [shake]Shake[/shake]    [fade start=67 length=7]Fade[/fade]    [rainbow]Rainbow[/rainbow]
 
 
-RichTextLabel is a flexible way of adding text to your game, with support for italics, bold and both.
- Underline works too, including with italics, bold and both.
-It is also possible to include  custom images, as well as custom URLs.
+[table=2]
+[cell border=#fff3 bg=#fff1]
+[ul]
+Tables
+are supported.
+[/ul]
+[/cell]
+[cell border=#fc13 bg=#fc11]
+[ol]
+Ordered
+list example.
+[/ol]
+[/cell]
 
 
-Left alignment is default,but center alignment is supported,as well as right alignment.
+[/table]
 
 
-Fill alignment is also supported, and allows writing very long text that will end up fitting the horizontal space entirely with words of joy.
+You can also create custom tags/effects, or customize behavior of [lb]url[rb] tags on click. For full reference, [color=aqua][url=https://docs.godotengine.org/en/latest/tutorials/gui/bbcode_in_richtextlabel.html]check the documentation.[/url][/color]
 
 
-For full reference, check the documentation.
 "
 "
-__meta__ = {
-"_edit_use_anchors_": false
-}
+context_menu_enabled = true
+selection_enabled = true
+
+[node name="Pause" type="Button" parent="."]
+process_mode = 3
+layout_mode = 1
+anchors_preset = 2
+anchor_top = 1.0
+anchor_bottom = 1.0
+offset_top = -42.0
+offset_right = 96.0
+grow_vertical = 0
+toggle_mode = true
+shortcut_in_tooltip = false
+text = "Pause"
 
 
 [connection signal="meta_clicked" from="RichTextLabel" to="." method="_on_RichTextLabel_meta_clicked"]
 [connection signal="meta_clicked" from="RichTextLabel" to="." method="_on_RichTextLabel_meta_clicked"]
+[connection signal="pressed" from="Pause" to="." method="_on_pause_pressed"]
+[connection signal="toggled" from="Pause" to="." method="_on_pause_toggled"]

BIN
gui/rich_text_bbcode/screenshots/rich_text.png


BIN
gui/rich_text_bbcode/screenshots/rich_text_bbcode.webp


+ 14 - 15
gui/rich_text_bbcode/unicorn_icon.png.import

@@ -1,8 +1,9 @@
 [remap]
 [remap]
 
 
 importer="texture"
 importer="texture"
-type="StreamTexture2D"
-path="res://.godot/imported/unicorn_icon.png-7e6ed0493ce9bae1105057e782fcd0de.stex"
+type="CompressedTexture2D"
+uid="uid://6fo2aklbh36t"
+path="res://.godot/imported/unicorn_icon.png-7e6ed0493ce9bae1105057e782fcd0de.ctex"
 metadata={
 metadata={
 "vram_texture": false
 "vram_texture": false
 }
 }
@@ -10,26 +11,24 @@ metadata={
 [deps]
 [deps]
 
 
 source_file="res://unicorn_icon.png"
 source_file="res://unicorn_icon.png"
-dest_files=["res://.godot/imported/unicorn_icon.png-7e6ed0493ce9bae1105057e782fcd0de.stex"]
+dest_files=["res://.godot/imported/unicorn_icon.png-7e6ed0493ce9bae1105057e782fcd0de.ctex"]
 
 
 [params]
 [params]
 
 
 compress/mode=0
 compress/mode=0
 compress/lossy_quality=0.7
 compress/lossy_quality=0.7
-compress/hdr_mode=0
+compress/hdr_compression=1
 compress/bptc_ldr=0
 compress/bptc_ldr=0
 compress/normal_map=0
 compress/normal_map=0
-flags/repeat=0
-flags/filter=true
-flags/mipmaps=false
-flags/anisotropic=false
-flags/srgb=2
+compress/channel_pack=0
+mipmaps/generate=false
+mipmaps/limit=-1
+roughness/mode=0
+roughness/src_normal=""
 process/fix_alpha_border=true
 process/fix_alpha_border=true
 process/premult_alpha=false
 process/premult_alpha=false
-process/HDR_as_SRGB=false
-process/invert_color=false
 process/normal_map_invert_y=false
 process/normal_map_invert_y=false
-stream=false
-size_limit=0
-detect_3d=true
-svg/scale=1.0
+process/hdr_as_srgb=false
+process/hdr_clamp_exposure=false
+process/size_limit=0
+detect_3d/compress_to=1