chairfull / GodotRichTextLabel2

Many more advanced features and animations for the RichTextLabel.
MIT License
84 stars 2 forks source link

RichTextLabel2

v1.8 Demo

Two Nodes:

https://github.com/user-attachments/assets/724558ad-f98e-40bb-8f30-dc413705c166

https://github.com/user-attachments/assets/caf703ad-44d3-43b0-b4f9-56f513ac572f

Features

[!NOTE] If fonts aren't showing up in the font drop down, clear font_cache. The entire project is scanned for fonts to display in the dropdown.

Tags

Tag Description Example
! meta Executes an expression on the context node when pressed.
If it starts with https:// it will load a browser.
[!print("Hey!")]
^ hint Expression that becomes a hint popup. [^sword.get_hover_text()]
dim Dims color by 33%.
lit Lightens color by 33%.
hue Shifts hue. 0 or 1 = no change. 0.5 = opposite end of spectrum. [hue 0.25]
beat Pulses in size and color.
curspull Pulls towards cursor. [curspull pull=-1]
cuss Animation to replace vowels with symbols. What the [cuss]heck[].
heart Animated love bounce. Demonstrates changing font and using emojis.
jit
jit2 Jittering nervous animation.
jump
jump2
l33t Animation to replace letters with numbers.
off Ignore. Offsets.
rain Simulates rain. What for? I don't know.
secret Hidden unless mouse cursor is nearbye.
sin Might not work as sin is now built in?
sparkle Animation to sparkle character colors. Meant to be used with color tags.
sway Just skews back and forth.
uwu Converts all R's and L's to W's.
wack Randomly animates rotation and scale for a wacky look.
woo Animates between upper and lower case, creating a sarcastic tone.
pulse Built in
wave Built in
tornado Built in
shake Built in
fade Built in
rainbow Built in

RichTextAnimation

This node is meant for dialogue systems and cinematics.

Animation Tags

Tag Description Arguments Example Self Closing
wait or w Waits a second. Number of seconds. Wait...[w=2] Did you hear...[w] *bang*
hold or h Holds until advance() is called. [h]
pace or p Sets animation speed. Scale. [p=2.0]Fast talker.[p=0.2]Slow talker.[p]Normal speed.
skip Skips animation across selected items. They call it [skip]The Neverending Forest[].
$ Runs an expression at this spot in the animation. Expression. Did you hear something...[$play_sound("gurgle")]
# Calls on_bookmark.emit() with the id when reached. Bookmark id. He told me [#quote]the haunted forest[#endquote] wasn't so haunted.[#end]

Animations

Tag Description Arguments
back Characters bounce back in.
console (Broken) Simulates a computer console.
fader Characters alpha fades in.
fallin Characters are scaled down from a large size.
focus Characters slide in from all random directions.
fromcursor Characters slide in from cursor position.
growin Characters scale up from tiny.
offin Characters slide in from a slight offset to the left.
prickle Character alpha fades in but with a random offset. Requires a low fade_in_speed to look right.
redact (Broken) Simulates redacted text being exposed.
wfc Characters start out as random 0's and 1's and eventually "collapse".

If shortcut_expression = true you can use the <code expression> pattern instead of the [!code expression] pattern.

Did you hear something...[wait][$play_sound("gurgle")] Uh oh![$player.fear = 100.0] Ahh...
Did you hear something...[wait]<play_sound("gurgle")> Uh oh!<player.fear = 100.0> Ahh...

If shortcut_bookmark = true you can use the #bookmark pattern instead of the [#bookmark] pattern.

He told me#quote the haunted forest#endquote wasn't so haunted.#end
He told me[#quote] the haunted forest[#endquote] wasn't so haunted.[#end]

Emoji Fonts

If a font has "emoji" (any case) in it's name, it will be used for emojis instead of the default font.

Emojis sometimes lag on some computers, which I get around by creating a custom FontVariant that uses the emoji font as a base and ThemeDB.fallback_font as a fallback font. This seems to prevent lag spikes.

If an emoji tag is used :smile: or [:smile:] an emoji_font metadata key will be created with the font.

Pipes

Pipes | post process strings.

There are two ways to use them.

# These are all doing the same thing.
"We'll visit {location|capitalize} tomorrow."
"We'll visit {location.capitalize()} tomorrow."
"We'll visit [|capitalize]$location[] tomorrow."

# Arguments can also be passed as a space seperated list:
# These are all the same.
"Day of week: {time.day_of_week|substr 0 3}"
"Day of week: {time.day_of_week.substr(0, 3)}"
"Day of week: [|substr 0 3]$time.day_of_week[]"

The real power is in adding your own. Pipes try to use a method inside the context node.

func cap(x):
    return x.capitalize()

func oooify(x):
    if cow_mode == CowMode.ACTIVATED:
        return x.replace("o", "[sin]ooo[/sin]").replace("O", "[sin]OOO[/sin]")
    else:
        return x

# Pipes can be chained.
# Location name gets capitalized, and all it's O's stretched out.
"We'll visit {location|cap|ooify}."

# Or we may want to change entire the dialogue based on state data.
[|ooify]Wow those cows were mooing.[]

Or maybe you want to stylize content based on the characters mood.

# If returning BBCode, it has to be old fashioned style.
func mood(s: String, npc_id: String):
    match npcs[npc_id].emotion:
        Emotion.HAPPY: return "[color=yellow]%s[/color]" % s
        Emotion.SAD: return "[color=aqua]%s[/color]" % s
        Emotion.ANGRY: return "[color=red]%s[/color]" % s
        _: return s

"Mary: [i;|mood mary]What I'm saying will be colored based on my mood.[]"
"John: [i;|mood john]What I'm saying will be colored based on my mood.[]"

[!NOTE] The BBCode [|pipe] tag function must return old fashioned BBCode. It doesn't support the labels features like Markdown replacement. Eventually I'll fix that.

Changes