From f5cbcdc1eb58533733ade432d23fdde52a209f05 Mon Sep 17 00:00:00 2001 From: LoafyLemon Date: Thu, 23 May 2024 23:16:45 +0100 Subject: [PATCH] Implement Kinetic Text Tags --- game/scripts/utility/text_tags.rpy | 129 +++++++++++++++++++++++++++-- 1 file changed, 121 insertions(+), 8 deletions(-) diff --git a/game/scripts/utility/text_tags.rpy b/game/scripts/utility/text_tags.rpy index 1df3ea6c..3ef92501 100644 --- a/game/scripts/utility/text_tags.rpy +++ b/game/scripts/utility/text_tags.rpy @@ -8,13 +8,6 @@ init python: # DejaVuSans is included by default in Ren'py return [(renpy.TEXT_TAG, "font=DejaVuSans.ttf")] + contents + [(renpy.TEXT_TAG, "/font")] - def text_tag_name(tag, argument): - """Use the name provided by a variable, or a contextual name. Usage {name=name_genie_hermione|Dude}""" - name_var, context_name = argument.split("|", 1) - name = getattr(renpy.store, name_var, None) - #TODO Contextual name logic - return [(renpy.TEXT_TEXT, name)] - @renpy.pure def text_tag_heart(tag, argument): """Insert a unicode heart symbol. Usage {heart}""" @@ -31,12 +24,132 @@ init python: words = num_to_word(num) if num < 100 or num % 100 == 0 else str(num) return [(renpy.TEXT_TEXT, words)] + @renpy.pure + def text_tag_wave(tag, argument, contents): + text = contents[0][1] + letters = [] + + for i, letter in enumerate(text): + start_pause = i/100.0 + end_pause = len(text)/100.0 + d = At(Text(letter, style="what", color=argument), wave_text(start_pause, end_pause)) + letters.append((renpy.TEXT_DISPLAYABLE, d)) + return letters + + @renpy.pure + def text_tag_bounce(tag, argument, contents): + text = contents[0][1] + letters = [] + + for i, letter in enumerate(text): + start_pause = i/100.0 + end_pause = len(text)/100.0 + d = At(Text(letter, style="what", color=argument, xsize=32), bounce_text(start_pause, end_pause)) + letters.append((renpy.TEXT_DISPLAYABLE, d)) + return letters + + @renpy.pure + def text_tag_shake(tag, argument, contents): + text = contents[0][1] + letters = [] + + for i, letter in enumerate(text): + d = At(Text(letter, style="what", color=argument, xsize=32), shake_text) + letters.append((renpy.TEXT_DISPLAYABLE, d)) + return letters + + @renpy.pure + def text_tag_pulse(tag, argument, contents): + text = contents[0][1] + d = At(Text(text, style="what", color=argument, xsize=32), pulse_text) + return [(renpy.TEXT_DISPLAYABLE, d)] + + @renpy.pure + def text_tag_love(tag, argument, contents): + text = contents[0][1] + d = Fixed(love_heart((15, 0), 12, 0.1), love_heart((20, -10), 6, 0.5), love_heart((10, 10), 6, 1), fit_first=True) + d2 = Transform(Fixed(love_heart((15, 0), 12, 1), love_heart((20, -10), 6, 0.1), love_heart((10, 10), 6, 0.5), fit_first=True), xzoom=-1) + return [(renpy.TEXT_DISPLAYABLE, d), (renpy.TEXT_TAG, "color=#ff69b4"), (renpy.TEXT_TEXT, text), (renpy.TEXT_TAG, "/color"), (renpy.TEXT_DISPLAYABLE, d2)] + + def random_timer(t, pause, rotation): + return t(renpy.random.uniform(*pause), renpy.random.uniform(*rotation)) + + def text_love_heart_func(pos, size, trans, st, at): + warper_rotate = _warper.easein(st / 0.5) + warper_alpha = _warper.easein(st / 1.0) + warper_yoffset = _warper.easein(st / 1.0) + warper_xoffset = _warper.easein(st / 0.2) + trans.child = Text("❤️", size=size) + trans.rotate = renpy.atl.interpolate(warper_rotate, -10, 10, renpy.atl.PROPERTIES["alpha"]) + trans.yoffset = renpy.atl.interpolate(warper_yoffset, 6, -6, renpy.atl.PROPERTIES["yoffset"]) + trans.xoffset = renpy.atl.interpolate(warper_xoffset, -1, 1, renpy.atl.PROPERTIES["xoffset"]) + trans.alpha = renpy.atl.interpolate(warper_alpha, 1, 0, renpy.atl.PROPERTIES["alpha"]) + return 0.01 + + def text_shake_func(trans, st, at): + trans.xoffset = absolute(renpy.random.randint(-1, 1)) + trans.yoffset = absolute(renpy.random.randint(-1, 1)) + return 0.02 + +transform wave_text(start_pause, end_pause): + animation + subpixel True + yoffset 0 + pos (240, -2) # Workaround; Xpos seems to not account for text box offset and text outline? + pause start_pause + easein 0.75 yoffset -6 + easein 0.75 yoffset 0 + pause end_pause + repeat + +transform bounce_text(start_pause, end_pause): + animation + subpixel True + yoffset 0 + pos (240, -2) # Workaround; Xpos seems to not account for text box offset and text outline? + pause start_pause + easeout_bounce 1 yoffset -6 yzoom 1.1 + easein_bounce 1 yoffset 0 yzoom 1.0 + pause end_pause + repeat + +transform pulse_text: + animation + subpixel True + yzoom 1 + pos (240, -2) # Workaround; Xpos seems to not account for text box offset and text outline? + pause 1 + easeout 0.5 yzoom 1.15 + easein 0.25 yzoom 1.0 + easeout 0.5 yzoom 1.15 + easein 0.25 yzoom 1.0 + repeat + +transform shake_text: + animation + subpixel True + pos (240, -2) # Workaround; Xpos seems to not account for text box offset and text outline? + function text_shake_func + +transform love_heart(pos, size, pause): + animation + subpixel True + anchor (0.5, 0.5) + pos (pos) + pause pause + function renpy.partial(text_love_heart_func, pos, size) + repeat + define config.custom_text_tags = { "unicode": text_tag_unicode, + "wave": text_tag_wave, + "bounce": text_tag_bounce, + "love": text_tag_love, + "shake": text_tag_shake, + "pulse": text_tag_pulse, } define config.self_closing_custom_text_tags = { - "name": text_tag_name, "heart": text_tag_heart, "number": text_tag_number, }