godot-ui-rich-text
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseRich Text & BBCode
富文本与BBCode
BBCode tags, meta clickable links, and RichTextEffect shaders define formatted text systems.
BBCode标签、可点击元链接和RichTextEffect着色器构成了格式化文本系统。
Available Scripts
可用脚本
custom_bbcode_effect.gd
custom_bbcode_effect.gd
Expert custom RichTextEffect examples (wave, rainbow, shake, typewriter).
专业的自定义RichTextEffect示例(波浪、彩虹、抖动、打字机效果)。
rich_text_animator.gd
rich_text_animator.gd
Typewriter effect for BBCode text with support for custom event tags and pausing.
为BBCode文本提供打字机效果,支持自定义事件标签和暂停功能。
NEVER Do in Rich Text
富文本使用禁忌
- NEVER forget bbcode_enabled — without
text = "[b]bold[/b]"? Literal brackets shown. ALWAYS enable BBCode first.bbcode_enabled = true - NEVER use [img] without res:// path — with relative path? Image not found. Use full resource path:
[img]icon.png[/img].[img]res://assets/icon.png[/img] - NEVER skip newline preservation — renders as "Line1Line2"? BBCode eats newlines. Use
text = "Line1\nLine2"OR[br]with proper escaping.\n - NEVER use [url] without meta_clicked — without signal connection? Click does nothing. MUST connect
[url=shop]Buy[/url]signal.meta_clicked - NEVER nest same tag types — ? Undefined behavior. Nest different tags:
[b][b]text[/b][/b].[b][i]text[/i][/b] - NEVER use [color] with invalid formats — typo? Falls back to white OR black. Use named colors OR hex:
[color=redd]text[/color]for validation.[color=#FF0000]
gdscript
$RichTextLabel.bbcode_enabled = true
$RichTextLabel.text = "[b]Bold[/b] and [i]italic[/i] text"- 切勿忘记启用bbcode_enabled — 未设置
text = "[b]bold[/b]"时,会显示原始括号。务必先启用BBCode。bbcode_enabled = true - 切勿使用不带res://路径的[img]标签 — 使用相对路径的 会导致图片无法找到。请使用完整资源路径:
[img]icon.png[/img]。[img]res://assets/icon.png[/img] - 切勿忽略换行符保留 — 设置 会被渲染为"Line1Line2"?因为BBCode会忽略换行符。请使用
text = "Line1\nLine2"标签,或对[br]进行正确转义。\n - 切勿在未绑定meta_clicked信号时使用[url]标签 — 使用 但未连接信号的话,点击将无任何反应。必须连接
[url=shop]Buy[/url]信号。meta_clicked - 切勿嵌套相同类型的标签 — 会导致未定义行为。请嵌套不同类型的标签,例如:
[b][b]text[/b][/b]。[b][i]text[/i][/b] - 切勿使用格式无效的[color]标签 — 像 这种拼写错误的标签,会默认显示白色或黑色。请使用命名颜色或十六进制格式,例如
[color=redd]text[/color]以确保有效性。[color=#FF0000]
gdscript
$RichTextLabel.bbcode_enabled = true
$RichTextLabel.text = "[b]Bold[/b] and [i]italic[/i] text"Common Tags
常用标签
bbcode
[b]Bold[/b]
[i]Italic[/i]
[u]Underline[/u]
[color=red]Red text[/color]
[color=#00FF00]Green hex[/color]
[center]Centered[/center]
[img]res://icon.png[/img]
[url=data]Clickable link[/url]bbcode
[b]Bold[/b]
[i]Italic[/i]
[u]Underline[/u]
[color=red]Red text[/color]
[color=#00FF00]Green hex[/color]
[center]Centered[/center]
[img]res://icon.png[/img]
[url=data]Clickable link[/url]Handle Link Clicks
处理链接点击
gdscript
func _ready() -> void:
$RichTextLabel.meta_clicked.connect(_on_meta_clicked)
func _on_meta_clicked(meta: Variant) -> void:
print("Clicked: ", meta)gdscript
func _ready() -> void:
$RichTextLabel.meta_clicked.connect(_on_meta_clicked)
func _on_meta_clicked(meta: Variant) -> void:
print("Clicked: ", meta)Reference
参考资料
Related
相关内容
- Master Skill: godot-master
- 进阶技能:godot-master