Page 1 of 1

transform inside a button ?

Posted: Wed Sep 06, 2023 2:45 am
by jack_norton
I am having trouble doing something that I think can be done, but I'm not entirely sure how :)
In short: I have buttons that pops up (zooming in/out) as you hover on them. And that works fine.
But I also have a text inside those buttons that I'd like to hide (alpha 0.0) when they're not hovered, and show (alpha=1.0) when they're hovered.
I tried using an at transform clause in the button but it doesn't work (it ignores it and always displays the text with full alpha).
The code is below, ignore my custom coding stuff, the line in question is the last one (at ttext).
Am I missing something or perhaps it's not possible at all to have such behavior ? thanks!

Code: Select all

transform tsign:
    on hover:
        yoffset 50 zoom .3
        linear 0.3 yoffset 0 zoom 1.0
    on idle:
        linear 0.1 yoffset 50 zoom .3

transform ttext:
    on hover:
        alpha 0.0
        linear 0.5 alpha 1.0
    on idle:
        linear .3 alpha 0.0

screen map():
    add "map/basemap.jpg"
    for loc in map_system.list_locations(DayNight[CurTime]):
        button xcenter loc.x ypos loc.y at tsign:
            xsize 235 ysize 210 xpadding 0 ypadding 0 left_padding 8 top_padding 8
            action Return(loc.image)
            background "map/sign.png"
            add "map/%s.png" % loc.image
            text loc.name xcenter .5 ypos 45 size 36 outlines [(2,"#000")] at ttext

Re: transform inside a button ?

Posted: Wed Sep 06, 2023 6:58 am
by m_from_space
It's possible, you can use logic inside screen elements. Here is an example, make sure that you change the events inside your "ttext" transform accordingly:

Code: Select all

transform ttext:
    alpha 0.0
    on show:
        linear 0.5 alpha 1.0
    on hide:
        linear 0.3 alpha 0.0

screen map():
    default button_hovered = False
    button at tsign:
        # ...
        hovered SetScreenVariable("button_hovered", True)
        unhovered SetScreenVariable("button_hovered", False)
        showif button_hovered:
            text "Click me!" at ttext

Re: transform inside a button ?

Posted: Thu Sep 07, 2023 2:02 am
by jack_norton
Ah right, I didn't think about that! Just tried it and works, thanks a lot :)