[SOLVED] How can I set styles for different hyperlink handlers?

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
Thailandian
Regular
Posts: 30
Joined: Tue Jun 01, 2021 6:24 am
Contact:

[SOLVED] How can I set styles for different hyperlink handlers?

#1 Post by Thailandian »

I have 2 different hyperlink handlers, each of which causes the hyperlink to open a different dictionary (I mean a language dictionary - not python) at the relevant entry.

Code: Select all

def strine_hander(value):
    value = value.strip()
    global st_index
    global st_list
    for x in st_list:
        if value == x:
            st_index = st_list.index(value)
            openStrine()
config.hyperlink_handlers["st_link"] = strine_hander

def vic_handler(value):
    value = value.strip()
    global vic_index
    global vic_list
    for x in vic_list:
        if value == x:
            vic_index = vic_list.index(value)
            openVic()
config.hyperlink_handlers["vic_link"] = vic_handler
Now I would like to style each type of hyperlink differently to make it clear which dialect the idiom belongs to. Is this possible and if so, how can it be done?
Also, I'd like the different hyperlinks to have different coloured backgrounds or highlights. Is there a way to do this?

As always, thanks in advance for any help or suggestions.
Last edited by Thailandian on Thu Nov 25, 2021 11:13 am, edited 1 time in total.

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

Re: How can I set styles for different hyperlink handlers?

#2 Post by Ocelot »

You can use hyperlink_functions style property to set function used to select style object used to style hyperlink, function which handles what happens when you click it and function which handles hovering and unhovering.

Example of usage:

Code: Select all

style hyper_red is hyperlink_text:
    color '#ff0000'

style hyper_blue is hyperlink_text:
    color '#0000ff'

init python:
    config.hyperlink_handlers.update({"hred": renpy.jump, "hblue": renpy.jump})

    def hyperlink_style_selector(arg):
        # Overengineered, probably will go better with if/else if you have only two custom protocols
        protocol = arg.split(':')[0]
        styles = {
            "hred":  style.hyper_red,
            "hblue": style.hyper_blue
        }
        return styles.get(protocol, style.hyperlink_text)

init 900 python:
    # You should probably set it as style property properly in screens.rpy
    # I did it here to make it one-file change to new project
    style.say_dialogue.hyperlink_functions = (hyperlink_style_selector, hyperlink_function, None)
    # hyperlink_function is a default hyperlink action provided by RenPy


label start:
    # Following like shows example of using different styles for set protocols and default style for others
    "Hello, do you want to visit {a=hred:text1}RED{/a} room or a {a=hblue:text2}BLUE{/a} one? \n{a=jump:start}This does nothing{/a}" (interact=False)
    $ renpy.pause(hard=True)
    return

label text1:
    image bg red = Solid("#f00")
    scene bg red
    pause
    return

label text2:
    image bg blue = Solid("#f00")
    scene bg blue
    pause
    return
< < insert Rick Cook quote here > >

Thailandian
Regular
Posts: 30
Joined: Tue Jun 01, 2021 6:24 am
Contact:

Re: How can I set styles for different hyperlink handlers?

#3 Post by Thailandian »

Thanks Ocelot - that worked perfectly!

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]