Different colour speech bubble per character

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
RewindTheGame
Regular
Posts: 62
Joined: Thu Dec 31, 2020 3:37 pm
Contact:

Different colour speech bubble per character

#1 Post by RewindTheGame »

Sorry to post again, but I'm new to the speech bubble system. I've already make extensive changes to the default say screen to support multiple text boxes on screen at once, different colour and style say windows for each character, etc, but the same sort of thing doesn't seem to work with bubbles.

What I want, as per the title, is to have a different colour speech bubble for each character. I've created differently coloured versions of the bubble and thought bubble png files in the GUI folder, and imagined that just changing the value of bubble.frame and bubble.thoughtframe within the bubble screen so that it points at the relevant files according to the value of the who variable would work, but it does not. The frame is always the same.

Can anyone point me in the right direction? Cheers :)

jeffster
Veteran
Posts: 409
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: Different colour speech bubble per character

#2 Post by jeffster »

RewindTheGame wrote: Mon Mar 25, 2024 9:20 am Sorry to post again, but I'm new to the speech bubble system. I've already make extensive changes to the default say screen to support multiple text boxes on screen at once, different colour and style say windows for each character, etc, but the same sort of thing doesn't seem to work with bubbles.

What I want, as per the title, is to have a different colour speech bubble for each character. I've created differently coloured versions of the bubble and thought bubble png files in the GUI folder, and imagined that just changing the value of bubble.frame and bubble.thoughtframe within the bubble screen so that it points at the relevant files according to the value of the who variable would work, but it does not. The frame is always the same.

Can anyone point me in the right direction? Cheers :)
I'm new to the speech bubble system too, so I may be wrong here, but I think that ATM there's no convenient functionality to change the bubble color or background.

Perhaps it's something that should be discussed in "Development of Ren'Py" section.

Right now I can imagine a hack like this:

- Set bubble.properties_callback function, which would take a character ("image tag", like "eileen" or "lucy"), and return a list of modified bubble properties, to substitute "normal" properties.

- Add to the list of "normal" properties, which are

Code: Select all

define bubble.properties = {
    "bottom_left" : {
        "window_background" : Transform(bubble.frame, xzoom=1, yzoom=1),
        "window_bottom_padding" : 27,
    },
    "bottom_right" : {
        "window_background" : Transform(bubble.frame, xzoom=-1, yzoom=1),
        "window_bottom_padding" : 27,
    },
    "top_left" : {
        "window_background" : Transform(bubble.frame, xzoom=1, yzoom=-1),
        "window_top_padding" : 27,
    },
    "top_right" : {
        "window_background" : Transform(bubble.frame, xzoom=-1, yzoom=-1),
        "window_top_padding" : 27,
    },
    "thought" : {
        "window_background" : bubble.thoughtframe,
    }
}
modified properties, like:

Code: Select all

    "bottom_left_lucy" : {
        "window_background" : Transform(frame_lucy, xzoom=1, yzoom=1),
        "window_bottom_padding" : 27,
    },
    "bottom_right_lucy" : {
        "window_background" : Transform(frame_lucy, xzoom=-1, yzoom=1),
        "window_bottom_padding" : 27,
    },
    "top_left_lucy" : {
        "window_background" : Transform(frame_lucy, xzoom=1, yzoom=-1),
        "window_top_padding" : 27,
    },
    "top_right_lucy" : {
        "window_background" : Transform(frame_lucy, xzoom=-1, yzoom=-1),
        "window_top_padding" : 27,
    },
    "thought_lucy" : {
        "window_background" : thoughtframe_lucy,
    }
where frame_lucy and thoughtframe_lucy could be recolored versions of "bubble.frame" and "bubble.thoughtframe".

Then the code could be

Code: Select all

init python:
    def bub_custom(tag):
        possible = [
            '_'.join(("bottom_left", tag)),
            '_'.join(("bottom_right", tag)),
            '_'.join(("top_left", tag)),
            '_'.join(("top_right", tag)),
            '_'.join(("thought", tag))
            ]
        actual = []
        for i in possible:
            if i in bubble.properties:
                actual.append(i)
        if actual:
            return actual
        return ["bottom_left", "bottom_right", "top_left", "top_right", "thought"]

define bubble.properties_callback = bub_custom
This function constructs keys like "bottom_left_lucy" (for image tag "lucy") and checks if some of those keys exist in "bubble.properties". If yes, then bubbles for that character would use modifies properties. If there is no key of that kind, then the default properties would be used.

Therefore if you only want to use "bottom left" bubble for "lucy", you can set "bubble.properties" like this (adding one custom property for "lucy" bubbles):

Code: Select all

define bubble.properties = {
    "bottom_left" : {
        "window_background" : Transform(bubble.frame, xzoom=1, yzoom=1),
        "window_bottom_padding" : 27,
    },
    "bottom_right" : {
        "window_background" : Transform(bubble.frame, xzoom=-1, yzoom=1),
        "window_bottom_padding" : 27,
    },
    "top_left" : {
        "window_background" : Transform(bubble.frame, xzoom=1, yzoom=-1),
        "window_top_padding" : 27,
    },
    "top_right" : {
        "window_background" : Transform(bubble.frame, xzoom=-1, yzoom=-1),
        "window_top_padding" : 27,
    },
    "thought" : {
        "window_background" : bubble.thoughtframe,
    }
    "bottom_left_lucy" : {
        "window_background" : Frame("gui/bubble_lucy.png", 55, 55, 55, 95),
        "window_bottom_padding" : 27,
    },
}
This solution is not very convenient, because you would need to add all those custom properties there, but that's the hack that comes to mind at the moment.

jeffster
Veteran
Posts: 409
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: Different colour speech bubble per character

#3 Post by jeffster »

PS. To only change the bubble color, it's possible to use the same .png and add "matrixcolor" property to Transform:

Code: Select all

...Transform(bubble.frame, xzoom=1, yzoom=1, matrixcolor=TintMatrix(tint))
where tint is a color code, e.g. "#FAA" and the like.

RewindTheGame
Regular
Posts: 62
Joined: Thu Dec 31, 2020 3:37 pm
Contact:

Re: Different colour speech bubble per character

#4 Post by RewindTheGame »

Wow, these are great answers - thank you. Something to play with tomorrow :)

Jeffster: Quite a lot of my program is "hacks" to make things happen. Luckily I've been programming for decades so making things work is my middle name (lol), but it would definitely be nice to have these features available rather than having to hammer them in...

jeffster
Veteran
Posts: 409
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: Different colour speech bubble per character

#5 Post by jeffster »

RewindTheGame wrote: Mon Mar 25, 2024 3:32 pm Wow, these are great answers - thank you. Something to play with tomorrow :)

Jeffster: Quite a lot of my program is "hacks" to make things happen. Luckily I've been programming for decades so making things work is my middle name (lol), but it would definitely be nice to have these features available rather than having to hammer them in...
Understandable... ;)
Here's a script that should make coloring bubbles easier (using matrixcolor)
viewtopic.php?t=68099

Post Reply

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot], Semrush [Bot]