Using Hyperlinks to Show/Hide Screens When Hovered/Unhovered

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
chip
Newbie
Posts: 3
Joined: Sat Apr 15, 2017 2:44 am
Contact:

Using Hyperlinks to Show/Hide Screens When Hovered/Unhovered

#1 Post by chip »

Hello,

I'm trying to make something like a pop-up dictionary where the meaning of a word appears in a text box over the dialogue window when the user hovers over a word in the dialogue. Now that was doable, but what I'm having trouble with is how to hide the text box when the hyperlink is idle (unhovered).

I'm using code I've found on other threads on this forum:

Code: Select all

screen defin:
    frame:
        xalign 0
        yalign 0.65
        has vbox

        text "Now defining...."
                  
init python:
    def hyperlink_styler(hi):
        return style.hyperlink_text
    def hyperlink_callback(hi):
        if hi==None:
            renpy.hide_screen("defin")
        else:    
         renpy.show_screen("defin")
         renpy.restart_interaction()
       
style default hyperlink_functions (hyperlink_styler,  None, hyperlink_callback)
And I read on the renpy documentation that
The hyperlink focus function is called with the argument of the hyperlink when the hyperlink gains focus, and with None when it loses focus. If it returns a value other than None, the interaction returns that value
which is why I tried using "None".

I also tried playing with the screen code, to no avail.

Thank you in advance!
Last edited by chip on Sun Apr 16, 2017 12:38 am, edited 1 time in total.

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

Re: Using Hyperlinks to Show/Hide Screens When Hovered

#2 Post by Imperf3kt »

Have you tried using tooltips.
I believe a solution to what you seek can be found here: viewtopic.php?f=8&t=15374#p200108
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

chip
Newbie
Posts: 3
Joined: Sat Apr 15, 2017 2:44 am
Contact:

Re: Using Hyperlinks to Show/Hide Screens When Hovered

#3 Post by chip »

Thank you for your suggestion! I tried, but I can't get the pop-up box to disappear when the hyperlink is unhovered. I tried doing this:

Code: Select all

screen defin:
    
    default tin = Tooltip(NullAction()) 
    default timo = Tooltip (tin.Action("[link]"))
    frame:
       xalign 0
       yalign 0.65
       has vbox:
        text Text(timo.value) #a failed attempt to explicitly convert timo.value, which is an action, to a text.
                                        #Still got a "cannot display <other_action......> as text" exception
                                        #Also, I realize this is wrong on so many levels because this way the 
                                        #"NullAction" will never even occur... I was just trying different things.
I think I'm unable to use the code in the link posted because:
1) I'm not using textbuttons, but hyperlinks, and I don't know if they have "hovered" and "idle" functions like buttons do.

2) Since I'm using hyperlinks, I needed to define the hyperlink_callback function, in which I call the screen. So I can't do everything from within the screen like in the posted link. I also tried to pass tin.Action("[link]") as an argument from the hyperlink_callback function to the screen, but the object "tin" was not recognized in hyperlink_callback. So I then tried to define "tin" in init blocks, and in python blocks, but it was still unrecognized in the python block which has the hyperlink_callback function.

3) I'm trying to simply have a textbox, with no buttons or anything else, that appears when I hover over the hyperlink, and disappears again when the hyperlink loses focus.

4) I'm a newbie and there's probably something I'm missing about tooltips. :D

If only there were some way to know if the hyperlink is unhovered, like "if hyperlink is_hovered == False"... I found "config.hyperlink_focus" here but I don't know how to use it or make it "not None".

philat
Eileen-Class Veteran
Posts: 1909
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Using Hyperlinks to Show/Hide Screens When Hovered/Unhov

#4 Post by philat »

This honestly looks like a bug in the hyperlink unfocus event. Could be wrong, but it just looks like hyperlink_callback(None) never runs, even though the documentation (and a quick peek at text.py) says it should.

chip
Newbie
Posts: 3
Joined: Sat Apr 15, 2017 2:44 am
Contact:

Re: Using Hyperlinks to Show/Hide Screens When Hovered/Unhov

#5 Post by chip »

I see... I hope someone can help find a solution for this. I've created a timed textbox for now to give the feeling that it disappears when you unhover, but of course it's not the same.

Post Reply

Who is online

Users browsing this forum: Google [Bot]