Activate a screen when hover dialogue

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
User avatar
SubnormalGang
Newbie
Posts: 24
Joined: Tue Mar 01, 2022 5:38 pm
Projects: △ DELTA
Organization: Subnormal Gang
Deviantart: Drosull
itch: noigs.itch.io
Location: Spain
Discord: Drösull#1908
Contact:

Activate a screen when hover dialogue

#1 Post by SubnormalGang » Thu Mar 03, 2022 8:49 am

Hello. I have a question.

I want to have a function when you hover some text with the mouse in the dialogue, a screen gets activated, in my case, to put some explanation.
I got a function that works perfectly that PastryIRL gave me. Basically creates a new tag that make the function possible, but it replace the {a} tag hyperlink function, making the url visible like another "explanation".

I would like to know If it's possible to not get rid of the {a} tag, or if there could be other solution, like other way to call the url from clicking the text.

The code:

Code: Select all

init 1 python:

    def call_lore(argument):
        if argument is None:
            renpy.hide_screen("lore_screen")
            renpy.restart_interaction()
        else:
            renpy.show_screen("lore_screen", txt=argument)
            renpy.restart_interaction()

    def return_hyperlink_style(argument):
        return style.hyperlink_text

    def lore_tag(tag, argument, contents):

        return [(renpy.TEXT_TAG, u"a={}".format(argument)),
            ] + contents + [
                (renpy.TEXT_TAG, u"/a"),
            ]

    config.custom_text_tags["lore"] = lore_tag

style default hyperlink_functions (return_hyperlink_style, None, call_lore)

screen lore_screen(txt):
    zorder 25
  
    frame:
        xpos 320
        ypos 846
        
        xpadding 15
        ypadding 15
        yanchor 1.0
        xmaximum 400
        text txt xalign 0.5 text_align 0.5 size 18

label start:
        "{lore=Peter}Hello{/lore}"
        return
I'll put 2 pictures, the mouse is not visible, but it hovers the texts, and click have no effect.
Attachments
Captura de pantalla 2022-03-03 084613.png
Captura de pantalla 2022-03-03 084723.png
Beyond the Imagination ヾ( ˃ᴗ˂ )◞


DELTA WEB ITCH.IO (ESP/ENG)

ILLUSTRATION COMMISSIONS OPEN!!

Become our Patreon
Follow Drosull!!
Pixiv
CHECK ALL HIS MEDIA ON HIS CARRD!

User avatar
Ocelot
Eileen-Class Veteran
Posts: 1883
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Activate a screen when hover dialogue

#2 Post by Ocelot » Thu Mar 03, 2022 9:47 am

Code: Select all

init -100 python:

    # A function that does nothing. Used to make link unclickable
    def sink_data(arg):
        pass

    # Function to handle hovering over link
    def hyperlink_hover_handler(arg):
        if arg is None:
            renpy.hide_screen("lore_screen")
            renpy.restart_interaction()
            return
        # correct format of link argument is protocol:data
        # extract both
        protocol, data = arg.split(':')
        # Check if we have a correct protocol and show lore screen only for it
        if protocol == "lore":
            renpy.show_screen("lore_screen", txt=data)
            renpy.restart_interaction()

    # Tell default click handler to use our 'do nothing' function for lore links
    config.hyperlink_handlers['lore'] = sink_data

init 900 python:
    # Add hover handler to the hyperlink funtions
    # hyperlink_styler and hyperlink_function are default ones, which usually shouldn't change
    style.say_dialogue.hyperlink_functions = (hyperlink_styler, hyperlink_function, hyperlink_hover_handler)

screen lore_screen(txt):
    zorder 25
    frame:
        xpadding 15
        ypadding 15
        xmaximum 400
        text txt xalign 0.5 text_align 0.5 size 18

label start:
        # That how you can use it.
        "{a=lore:Peter}Hello{/a}"
        return
If you wish, you can still have the [lore] tag, which will transform itself into [ a ] tag.
In addition, if you ever want to have different styles for lore links and other applications of [ a ] tag, check out this thread:
viewtopic.php?f=8&t=63595&p=548313#p548313
< < insert Rick Cook quote here > >

User avatar
SubnormalGang
Newbie
Posts: 24
Joined: Tue Mar 01, 2022 5:38 pm
Projects: △ DELTA
Organization: Subnormal Gang
Deviantart: Drosull
itch: noigs.itch.io
Location: Spain
Discord: Drösull#1908
Contact:

Re: Activate a screen when hover dialogue

#3 Post by SubnormalGang » Thu Mar 03, 2022 11:23 am

EDIT: THIS DOES NOT WORK, THE ORIGINAL UP IS THE ONE THAT WORKS
Ok, I tried to do something more with it.

Code: Select all

    #This goes in the -100 python block
    #If you try to click on a a:lore tag, It won't do nothing
    #But if it is a:link, Is should open the link
    def sink_data(arg):
        if arg == "a:lore":
            pass
        if arg is "a:link":
            OpenURL(lore) #doesn't work lmao
        pass
It actually works, but I don't know how to open the url.

Edit: Ok, I managed to make it work as I wanted.

Code: Select all

    #This goes in the -100 python block
    def sink_data(arg):
        if arg == "a:lore":     #If you try to click on a a:lore tag, It won't do nothing at clicking
            pass
       else:     #But if it is just {a=www.google.com}, It will open the link
            OpenURL()
        pass
        


I was trying to make a a:link tag or something, and this came up hehe
Last edited by SubnormalGang on Thu Mar 03, 2022 12:22 pm, edited 2 times in total.
Beyond the Imagination ヾ( ˃ᴗ˂ )◞


DELTA WEB ITCH.IO (ESP/ENG)

ILLUSTRATION COMMISSIONS OPEN!!

Become our Patreon
Follow Drosull!!
Pixiv
CHECK ALL HIS MEDIA ON HIS CARRD!

User avatar
Ocelot
Eileen-Class Veteran
Posts: 1883
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Activate a screen when hover dialogue

#4 Post by Ocelot » Thu Mar 03, 2022 11:33 am

First of all, default hyperlink handler already handles separation of protocol and data. Only what is after the colon is passed to concrete handler.
This is the whole reason I didn't override default hyperlink_function and included it in the hyperlink_functions style: to let all default protocols and everything added by usual way of defining new protocols to work.
If you want to handle other protocols, you need to register handling function by config.hyperlink_handlers['protocol'] = handling_function, where protocol is what you write before :, and handling_function is a function which will be passed everything after :.

You can read about default handlers here: https://www.renpy.org/doc/html/text.html#text-tag-a
< < insert Rick Cook quote here > >

User avatar
SubnormalGang
Newbie
Posts: 24
Joined: Tue Mar 01, 2022 5:38 pm
Projects: △ DELTA
Organization: Subnormal Gang
Deviantart: Drosull
itch: noigs.itch.io
Location: Spain
Discord: Drösull#1908
Contact:

Re: Activate a screen when hover dialogue

#5 Post by SubnormalGang » Thu Mar 03, 2022 11:41 am

Thanks for your help man!

Edit: Happens that the abomination I made doesn't work properly, and somehow I didn't realized properly. It was working and your original code wasn't, but don't know what happened and now mine gets an error when I click the one that just should hover (but still open the link in the other case) and your original works properly. So forget my last post hehe. Thank you again!
Beyond the Imagination ヾ( ˃ᴗ˂ )◞


DELTA WEB ITCH.IO (ESP/ENG)

ILLUSTRATION COMMISSIONS OPEN!!

Become our Patreon
Follow Drosull!!
Pixiv
CHECK ALL HIS MEDIA ON HIS CARRD!

Post Reply

Who is online

Users browsing this forum: No registered users