Renpy mousetooltip won't show up on screen

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
abysswatcher
Regular
Posts: 42
Joined: Sun Apr 12, 2020 11:50 pm
Projects: To-Live:The Struggle
Organization: Youyu de Shijie(憂鬱的世界)
Github: LuYifeng112
itch: https://luyifeng.itc
Location: New Zealand
Contact:

Renpy mousetooltip won't show up on screen

#1 Post by abysswatcher »

I used this renpy mousetooltip from the renpy cookbook:

Code: Select all

init -1500 python:

    class MouseTooltip(Tooltip, renpy.Displayable):
        """A Tooltip whose x/y position follows the mouse's."""
        action = Action

        def __init__(self, default, padding=None, *args, **kwargs):
            super(renpy.Displayable, self).__init__(*args, **kwargs)

            self.default = default
            self.value = default

            self.padding = padding or {}
            self.pad_x = padding.get('x', 0)
            self.pad_y = padding.get('y', 0)

            self.x = 0
            self.y = 0

            self._redraw = False
 
        @property
        def redraw(self):
            return self._redraw

        @redraw.setter
        def redraw(self, new_value):
            self._redraw = new_value
            renpy.redraw(self, 0)

        def render(self, width, height, st, at):
            # Only Text() displayables have a size method
            try:
                w, h = self.value.size()

            except AttributeError:
                child_render = renpy.render(self.value, width, height, st, at)
                w, h = child_render.get_size()

            render = renpy.Render(w, h)
            render.place(self.value, x=self.x + self.pad_x, y=self.y + self.pad_y)
            return render

        def event(self, ev, x, y, st):
            self.x = x
            self.y = y

            if self.redraw:
                renpy.redraw(self, 0) 

            # Pass the event to our child
            return self.value.event(ev, x, y, st)
When I tried to apply this to my map screen as shown below with the imagebuttons, the tooltip does not appear at all. What could be the reason this happens? I have experimented solutions on a simple screen in a new project and they always work yet they never work here in my main project.

Code: Select all

screen guo_map():
    tag menu
    use TL_keyfocus
    viewport:
        xysize (config.screen_width, config.screen_height)
        child_size (4040, 2230)
        window:
            style "gm_root"
            add "maps/GUO_map.png"
        if persistent._map_audio == True and persistent._map_ocean_SFX == True:
            mousearea: # For dyanmic sounds
                focus_mask "GUO_FOCUS_OP"
                hovered [ Play("sound", "sounds/map/ambient_seaside.ogg", loop=True)]
                unhovered [Stop("sound",fadeout=2.5)]
        xinitial 2300
        yinitial 500
        draggable True
        edgescroll (350, 350)
        use tooltip
        for q in TL_GUO_loc:
            $ nx = q.x +5
            $ ny = q.y -12
            if q.IsActive:
                for n in TL_GUO:
                    if n.ID == q.ID:
                        $ act = SetVariable('nation', n)
                button:
                    xpos nx
                    ypos ny
                    sensitive GuoPlace.CitySensitive == True
                    keyboard_focus True
                    if persistent.romanized:
                        if persistent.romanization == "Modern-Standard":
                            text RomanizedMap.get(q.name) style "MapText" at ambient
                        elif persistent.romanization == "Modern-Pinyin":
                            text RomanizedPinyinMap.get(q.name) style "MapTextRomanized" at ambient
                        else:
                            text RomanizedMap.get(q.name) style "MapText" at ambient
                    else:
                        text q.name style "MapText" at ambient
                    action [act, Stop("sound", fadeout=4.5), Show('guo')]
                if not q.Port and not q.Capital:
                    #add "gui/map_bullet.png" xpos q.x ypos q.y
                    imagebutton:
                        idle "gui/map_bullet.png"
                        hover "gui/map_bullet.png"
                        xpos q.x 
                        ypos q.y
                        hovered [SetField(mtt, 'redraw', True), mtt.Action(Text("City"))]
                        unhovered SetField(mtt, 'redraw', False)
                        action NullAction()
                if q.Port and not q.Capital:
                    #add "gui/map_port.png" xpos q.x ypos q.y
                    imagebutton:
                        idle "gui/map_port.png"
                        hover "gui/map_port.png"
                        xpos q.x 
                        ypos q.y
                        hovered [SetField(mtt, 'redraw', True), mtt.Action(Text("Port City", color="#FFFFFF"))]
                        unhovered SetField(mtt, 'redraw', False)
                        action NullAction()
                if q.Capital and not q.Port:
                    #add "gui/map_bullet_capital.png" xpos q.x ypos q.y
                    imagebutton:
                        idle  "gui/map_bullet_capital.png"
                        hover  "gui/map_bullet_capital.png"
                        xpos q.x 
                        ypos q.y
                        hovered [SetField(mtt, 'redraw', True), mtt.Action(Text("Capital City"))]
                        unhovered SetField(mtt, 'redraw', False)
                        action NullAction()
                if q.Capital and q.Port:
                    #add "gui/map_bullet_capital.png" xpos q.x ypos q.y
                    imagebutton:
                        idle  "gui/map_bullet_capital.png"
                        hover  "gui/map_bullet_capital.png"
                        xpos q.x 
                        ypos q.y
                        hovered [SetField(mtt, 'redraw', True), mtt.Action(Text("Capital Port City", size=40))]
                        unhovered SetField(mtt, 'redraw', False)
                        action NullAction()
    on "show":
        action Play("notify", "sounds/menu/select_flip.ogg", loop=False)
    on "hide":
        action Stop("music", fadeout=2.5)
The goal of the revolution is to achieve the people's rights, but during the course of the revolution, we must stress military power - and the two are mutually contradictory.
-Sun Yat-sen
"Become a Visual Novel writer they said, it will be fun" (little did they know they were right)

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3794
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Renpy mousetooltip won't show up on screen

#2 Post by Imperf3kt »

Which version of renpy are you using?
There was an issue with 7.3.5 that got a fix. viewtopic.php?f=51&t=47205#p533067

Or are you using the prerelease renpy 7.4?
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

abysswatcher
Regular
Posts: 42
Joined: Sun Apr 12, 2020 11:50 pm
Projects: To-Live:The Struggle
Organization: Youyu de Shijie(憂鬱的世界)
Github: LuYifeng112
itch: https://luyifeng.itc
Location: New Zealand
Contact:

Re: Renpy mousetooltip won't show up on screen

#3 Post by abysswatcher »

Imperf3kt wrote: Mon Nov 02, 2020 10:39 pm Which version of renpy are you using?
There was an issue with 7.3.5 that got a fix. viewtopic.php?f=51&t=47205#p533067

Or are you using the prerelease renpy 7.4?
Well, I did use that fix and I'm on ver 7.3.5. I don't know why tooltips in the screen doesn't show them up. Its strange and frankly mind-boggling.
The goal of the revolution is to achieve the people's rights, but during the course of the revolution, we must stress military power - and the two are mutually contradictory.
-Sun Yat-sen
"Become a Visual Novel writer they said, it will be fun" (little did they know they were right)

Post Reply

Who is online

Users browsing this forum: No registered users