Page 1 of 1

Different colour speech bubble per character

Posted: Mon Mar 25, 2024 9:20 am
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 :)

Re: Different colour speech bubble per character

Posted: Mon Mar 25, 2024 1:27 pm
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.

Re: Different colour speech bubble per character

Posted: Mon Mar 25, 2024 1:54 pm
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.

Re: Different colour speech bubble per character

Posted: Mon Mar 25, 2024 3:32 pm
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...

Re: Different colour speech bubble per character

Posted: Mon Mar 25, 2024 5:19 pm
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