How to define styles for inline text in order to reduce boilerplate code

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
mirbb
Newbie
Posts: 3
Joined: Sun Apr 18, 2021 9:39 am
Contact:

How to define styles for inline text in order to reduce boilerplate code

#1 Post by mirbb »

In my dialogue, I would like to make proper nouns for places look distinct from other text by giving them an outline. In order to reduce boilerplate code and to make my game more manageable, I have been searching in vain for a way to define how these place names should look, and to apply the style inline (like a CSS class).

Is this possible to achieve?

Code: Select all

em "After some days of sight-seeing in Paris, to which we were almost strangers, on an August afternoon, 1901, Miss Lamont and I went to {i}{outlinecolor=#00ff00}Versailles{/outlinecolor}{/i}."

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2384
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: How to define styles for inline text in order to reduce boilerplate code

#2 Post by Ocelot »

You can try style text tag:
https://www.renpy.org/doc/html/text.htm ... -text-tags

You will need to define your own style for that:
https://www.renpy.org/doc/html/style.ht ... -statement

Note that outline is not stated as explicitely supported for text style tag, so you will have to test it first. In case it won't work, you can define your own tag:
https://www.renpy.org/doc/html/custom_text_tags.html
< < insert Rick Cook quote here > >

nomocha12
Newbie
Posts: 4
Joined: Sun Mar 28, 2021 8:34 am
Contact:

Re: How to define styles for inline text in order to reduce boilerplate code

#3 Post by nomocha12 »

I found your question interesting and I'm going to need something similar, so I've been messing around with styles and text tags for a while.
Would have been nice to be able to do everything with just style text tags, but for some reason those don't support the outlines property. The only way I found to use outlines is combining style text tags with custom text tags.

Have in mind that {outlinecolor} only works if your dialogue text style is already using outlines. If you want outlines only for your highlighted text, a workaround would be to define transparent text outlines for your dialogue text style, with an hex color in the form "#RRGGBBAA" and using 00 as the alpha value.

Fully working sample with my approach:

Code: Select all

init python:

    # custom tag, apply {=style} + {outlinecolor}
    def highlight_tag(tag, argument, contents):

        return [
                (renpy.TEXT_TAG, u"={}".format(argument)),
                (renpy.TEXT_TAG, u"outlinecolor={}".format(highlight_colors[argument])),
            ] + contents + [
                (renpy.TEXT_TAG, u"/outlinecolor"),
                (renpy.TEXT_TAG, u"/"),
            ]

    config.custom_text_tags["highlight"] = highlight_tag

define gui.dialogue_text_outlines = [ (1, "#FFFFFF00") ] # default fully transparent white outlines
define highlight_colors = { "place": "#00FF00", "name": "#F0F56E" } # dictionary with our outline colors
define e = Character("Eileen")

# text style definitions
style place:
    color "#B01C90"
    italic True
    
style name:
    color "#EB6234"

# game starts here
label start:
    e "After some days of sight-seeing in Paris, to which we were almost strangers, on an August afternoon, 1901, {highlight=name}Miss Lamont{/highlight} and I went to {highlight=place}Versailles{/highlight}."
    return

mirbb
Newbie
Posts: 3
Joined: Sun Apr 18, 2021 9:39 am
Contact:

Re: How to define styles for inline text in order to reduce boilerplate code

#4 Post by mirbb »

This is the perfect solution, thanks a lot!

Post Reply

Who is online

Users browsing this forum: Ocelot