[Solved] Tooltip showing the values of all objects in a for loop

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
Adrian_DVL
Regular
Posts: 141
Joined: Fri Mar 15, 2019 8:46 am
Completed: Clockwork Poison
Projects: Melodic Dates, Clockwork Poison: Salvation
Contact:

[Solved] Tooltip showing the values of all objects in a for loop

#1 Post by Adrian_DVL »

Hi!

I have a screen that has a for loop which shows a list of the objects of a class. Simplifying it, it's something like this:

Code: Select all

screen screen():
	default st = Tooltip("sys/no.png")
	...
	for item in sorted_store:
       	...
            $ spic = obj.pic
            $ shpic = obj.hpic
            $ stt = obj.tt	# <-- This is the image that I want to show when the object is hovered
            imagebutton:
                idle spic
                hover shpic
                xpos xt ypos yt
                action [SetVariable("obj", obj), obj_use]
                hovered st.Action("[stt]")
            add st.value xpos xt-100 ypos yt-100
This way, all the tooltip images of ALL the objects are displayed at the same time when I hover the object, even when I'm not hovering any other object but one.
Any idea on why this is happening and how can I do so that only the tooltip for the object that I'm hovering is displayed?
Last edited by Adrian_DVL on Fri Mar 27, 2020 5:38 pm, edited 1 time in total.


Adrian_DVL
Regular
Posts: 141
Joined: Fri Mar 15, 2019 8:46 am
Completed: Clockwork Poison
Projects: Melodic Dates, Clockwork Poison: Salvation
Contact:

Re: Tooltip showing the values of all objects in a for loop

#3 Post by Adrian_DVL »

Alex wrote: Fri Mar 27, 2020 3:14 pm Try it like https://www.renpy.org/doc/html/screen_a ... l#tooltips
I must admit it really is much more simple, so thank you! Unfortunately, it does the same with a difference: now if I hover an object, the tooltip image for THAT object is displayed next to EVERY object over and over again.

User avatar
Alex
Lemma-Class Veteran
Posts: 3094
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Tooltip showing the values of all objects in a for loop

#4 Post by Alex »

What's the actual code you are using?
Did you placed imagebuttons inside a vbox?
How big are images used for imagebuttons - any chance they are overlap each other?
Try to set 'focus_mask' property for imagebuttons - https://www.renpy.org/doc/html/style_pr ... properties

Also check - viewtopic.php?f=8&t=58416&p=526651#p526622

Adrian_DVL
Regular
Posts: 141
Joined: Fri Mar 15, 2019 8:46 am
Completed: Clockwork Poison
Projects: Melodic Dates, Clockwork Poison: Salvation
Contact:

Re: Tooltip showing the values of all objects in a for loop

#5 Post by Adrian_DVL »

Alex wrote: Fri Mar 27, 2020 4:36 pm Did you placed imagebuttons inside a vbox?
Nope.
Alex wrote: Fri Mar 27, 2020 4:36 pm How big are images used for imagebuttons - any chance they are overlap each other?
They're 80x80. They don't overlap each other at all. In fact, my problem is exactly the opposite: I can see them all, each one 100 pixels to the left and up from the object, but all of them at the same time.
Alex wrote: Fri Mar 27, 2020 4:36 pm Try to set 'focus_mask' property for imagebuttons - https://www.renpy.org/doc/html/style_pr ... properties
There's no point in doing that. I want the tooltip image to show no matter where exactly the player hovers the object.
Alex wrote: Fri Mar 27, 2020 4:36 pm What's the actual code you are using?
This is the screen:

Code: Select all

screen store():
    modal True
    add "sys/store_store.png" pos (122, 76) at faders
    $ it = 0
    $ xt = 0
    $ yt = 210
    imagebutton:
        idle "sys/gohome.png"
        hover "sys/hgohome.png"
        pos (137, 91)
        action [ (SetVariable('store_page', 0)), (Hide("store")) ]
        at faders
    $ sorted_store = sorted(shop.stock, key=attrgetter('spe'), reverse=True)
    $ next_store_page = store_page + 1
    $ prev_store_page = store_page - 1
    if next_store_page > int(len(shop.stock)/12):
        $ next_store_page = 0
    if prev_store_page > int(len(shop.stock)/12):
        $ prev_store_page = 0
    for item in sorted_store:
        if it+1 <= (store_page+1)*12 and it+1>store_page*12:
            $ xt += 172
            if it%2==0:
                $ yt += 67
                $ xt = 151
            $ spic = item.pic
            $ shpic = item.hpic
            $ stt = item.tt
            image "sys/item_store.png" xpos xt ypos yt at storebuttons
            imagebutton:
                idle spic
                hover shpic
                xpos xt ypos yt
                at storebuttons
                action [SetVariable("item", item), item_buy]
                tooltip stt
            $ tooltip = GetTooltip()
            if tooltip:
                add [tooltip] xpos xt-100 ypos yt-100
            if item.spe:
                text "[item.name]" xpos xt+115 ypos yt+8 xanchor 0.5 size 15 font "BRLNSR.ttf" color ("#a3a5ff") at storebuttons
            else:
                text "[item.name]" xpos xt+115 ypos yt+8 xanchor 0.5 size 15 font "BRLNSR.ttf" at storebuttons
            if item.spe:
                text "[item.cost]cl" xpos xt+115 ypos yt+36 xanchor 0.5 size 15 font "BRLNSR.ttf" color ("#a3a5ff") at storebuttons
            else:
                text "[item.cost]$" xpos xt+115 ypos yt+36 xanchor 0.5 size 15 font "BRLNSR.ttf" color ("#cfff75") at storebuttons
As you can see, I'm using the new tooltip thing and not the legacy one, but same result.
These are the two classes involved:

Code: Select all

class Item(renpy.store.object):
        def __init__(self, name, pic, hpic, cost, tt, spe):
            self.name = name        # Item name
            self.pic = pic          # Image
            self.hpic = hpic        # Hover image
            self.cost = cost        # Price
            self.tt = tt            # Tooltip
            self.spe = spe          # If the item is not placed in inventory


class Shop(renpy.store.object):
        def __init__(self):
            self.stock = []
        def add(self, item):
            shop.stock.append(item)
        def drop(self, item):
            self.stock.remove(item)
        def buy(self, item):
            global money
            global clef
            if item.spe:
                if clef >= item.cost:
                    self.stock.remove(item)
                    renpy.sound.play("audio/buy.mp3")
                    clef -= item.cost
                    renpy.notify("- {0}cl.".format(item.cost))
                elif clef < item.cost:
                    renpy.notify("Not enough clef!")
            else:
                if money >= item.cost and len(inventory.items) < 12:
                    inventory.items.append(item)
                    self.stock.remove(item)
                    renpy.sound.play("audio/buy.mp3")
                    money -= item.cost
                    renpy.notify("- {0}$".format(item.cost))
                elif money < item.cost:
                    renpy.notify("Not enough money!")
                elif len(inventory.items) >= 12:
                    renpy.notify("Inventory full!")

User avatar
Alex
Lemma-Class Veteran
Posts: 3094
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Tooltip showing the values of all objects in a for loop

#6 Post by Alex »

Adrian_DVL wrote: Fri Mar 27, 2020 4:54 pm ...
You check

Code: Select all

if tooltip:
for each button, but no matter what button you hovering they all set the same variable 'tooltip', so condition became true for all buttons. In code sample tooltip was showing once and not for each textbutton.

Try the solution gas gave - viewtopic.php?f=8&t=58416&p=526651#p526622

Code: Select all

            imagebutton:
                idle spic
                hover shpic
                xpos xt ypos yt
                at storebuttons
                action [SetVariable("item", item), item_buy]
                hovered Show("ex_tooltip", tt_img = item.tt, tt_x = xt - 100, tt_y = yt - 100) 
                unhovered Hide("ex_tooltip")

Code: Select all

screen ex_tooltip(tt_img, tt_x, tt_y):
    add tt_img pos(tt_x, tt_y)
edit: oops
Last edited by Alex on Sat Mar 28, 2020 3:44 am, edited 1 time in total.

Adrian_DVL
Regular
Posts: 141
Joined: Fri Mar 15, 2019 8:46 am
Completed: Clockwork Poison
Projects: Melodic Dates, Clockwork Poison: Salvation
Contact:

Re: Tooltip showing the values of all objects in a for loop

#7 Post by Adrian_DVL »

Alex wrote: Fri Mar 27, 2020 5:27 pm
Adrian_DVL wrote: Fri Mar 27, 2020 4:54 pm ...
You check

Code: Select all

if tooltip:
for each button, but no matter what button you hovering they all set the same variable 'tooltip', so condition became true for all buttons. In code sample tooltip was showing once and not for each textbutton.

Try the solution gas gave - viewtopic.php?f=8&t=58416&p=526651#p526622

Code: Select all

            imagebutton:
                idle spic
                hover shpic
                xpos xt ypos yt
                at storebuttons
                action [SetVariable("item", item), item_buy]
                hovered Show("ex_tooltip", tt_img = item.tt, tt_x = xt - 100, tt_y = yt - 100) 
                unhovered Hide("ex_tooltip")

Code: Select all

screen ex_tooltip(tt_img):
    add tt_img pos(tt_x, tt_y)
And it finally worked! Thank you very much, you've helped me! Just for the record: you forgot to pass tt_x and tt_y parameters in your ex_tooltip screen, but for the rest it works as a charm. Thanks!

Post Reply

Who is online

Users browsing this forum: No registered users