godot-ui-rich-text

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Rich 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
    text = "[b]bold[/b]"
    without
    bbcode_enabled = true
    ? Literal brackets shown. ALWAYS enable BBCode first.
  • NEVER use [img] without res:// path
    [img]icon.png[/img]
    with relative path? Image not found. Use full resource path:
    [img]res://assets/icon.png[/img]
    .
  • NEVER skip newline preservation
    text = "Line1\nLine2"
    renders as "Line1Line2"? BBCode eats newlines. Use
    [br]
    OR
    \n
    with proper escaping.
  • NEVER use [url] without meta_clicked
    [url=shop]Buy[/url]
    without signal connection? Click does nothing. MUST connect
    meta_clicked
    signal.
  • NEVER nest same tag types
    [b][b]text[/b][/b]
    ? Undefined behavior. Nest different tags:
    [b][i]text[/i][/b]
    .
  • NEVER use [color] with invalid formats
    [color=redd]text[/color]
    typo? Falls back to white OR black. Use named colors OR hex:
    [color=#FF0000]
    for validation.

gdscript
$RichTextLabel.bbcode_enabled = true
$RichTextLabel.text = "[b]Bold[/b] and [i]italic[/i] text"
  • 切勿忘记启用bbcode_enabled
    text = "[b]bold[/b]"
    未设置
    bbcode_enabled = true
    时,会显示原始括号。务必先启用BBCode。
  • 切勿使用不带res://路径的[img]标签 — 使用相对路径的
    [img]icon.png[/img]
    会导致图片无法找到。请使用完整资源路径:
    [img]res://assets/icon.png[/img]
  • 切勿忽略换行符保留 — 设置
    text = "Line1\nLine2"
    会被渲染为"Line1Line2"?因为BBCode会忽略换行符。请使用
    [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