Texte enrichi
Gras, couleur, wave, shake et rainbow, le tout en balises BBCode dans un seul label. Sans aucun nœud d'animation.
L'éditeur ci-dessus fait tourner ce projet. Changez une ligne et il se recharge.
Classes Godot utilisées
RichTextLabel
Le code
scripts/main.gd
extends Node
const SAMPLE: String = '[center][font_size=30]Rich text[/font_size][/center]
Plain text, then [b]bold[/b], [i]italic[/i] and [u]underline[/u].
[color=#8da5f3]color by hex[/color], [color=#8eef97]another one[/color].
[wave amp=40 freq=4]wave makes the letters float[/wave]
[shake rate=18 level=10]shake rattles them[/shake]
[rainbow freq=0.4 sat=0.7 val=1]rainbow cycles the hue[/rainbow]
[center]› [url=https://docs.godotengine.org]a url tag, click it and the signal fires[/url] ‹[/center]'
var status: Label
func _ready() -> void:
var column: VBoxContainer = _root()
var text: RichTextLabel = RichTextLabel.new()
text.bbcode_enabled = true
text.text = SAMPLE
text.fit_content = true
text.size_flags_vertical = Control.SIZE_EXPAND_FILL
text.meta_clicked.connect(_on_meta)
column.add_child(text)
status = Label.new()
status.text = 'the effects are BBCode tags, no animation node involved'
status.add_theme_color_override('font_color', Color('#999999'))
column.add_child(status)
func _on_meta(meta: Variant) -> void:
status.text = 'clicked %s' % meta
func _root() -> VBoxContainer:
var background: ColorRect = ColorRect.new()
background.color = Color('#12141a')
add_child(background)
background.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
var margin: MarginContainer = MarginContainer.new()
for side in ['margin_left', 'margin_right', 'margin_top', 'margin_bottom']:
margin.add_theme_constant_override(side, 56)
add_child(margin)
margin.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
var column: VBoxContainer = VBoxContainer.new()
column.add_theme_constant_override('separation', 18)
margin.add_child(column)
return column