[SOLVED]"On Hide" not working for imagebuttons

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
Dark12ose
Regular
Posts: 63
Joined: Mon Oct 04, 2021 11:29 pm
Deviantart: Rosentear
Contact:

[SOLVED]"On Hide" not working for imagebuttons

#1 Post by Dark12ose »

Hello,

I am creating a custom transition for my game menu where it eases in and out from the top instead of the usual simple dissolve.

This is the custom transition.

Code: Select all

transform gamemenu_trans:
    on show:
        yoffset -200
        easein 0.5 yoffset 0
    on hide:
        easeout 0.5 yoffset -200
And this is the game menu screen:

Code: Select all

screen game_menu():
    tag menu
    modal True
    add "gui/ingameui/game menu/game_menu_bg.jpg" xalign 0.5 ypos 20 at gamemenu_trans

    hbox at gamemenu_trans:
        spacing 72
        xalign 0.5
        yalign 0.10
        xysize (1269, 191)
        box_wrap True
        box_wrap_spacing 15

        imagebutton auto "gui/ingameui/game menu/save_%s.png" focus_mask True action ShowMenu("save")

        imagebutton auto "gui/ingameui/game menu/load_%s.png" focus_mask True action ShowMenu("load")

        imagebutton auto "gui/ingameui/game menu/status_%s.png" focus_mask True action ShowMenu("pointstatus")

        imagebutton auto "gui/ingameui/game menu/gloss_%s.png" focus_mask True action ShowMenu("glossarygm")

        imagebutton auto "gui/ingameui/game menu/pref_%s.png" focus_mask True action ShowMenu("preference")

        imagebutton auto "gui/ingameui/game menu/mm_%s.png" focus_mask True action MainMenu()

        imagebutton auto "gui/ingameui/game menu/quit_%s.png" focus_mask True action Quit()
The background works perfectly fine but the imagebuttons for some reason doesn't easeout and just dissolve away instead.

I tried to remove the dissolve from the config.enter/exit_transition but when I do that BOTH of them doesn't easeout on hide.

Removing the "on hide" makes the imagebutton easeout fine but once I place the "on hide" again it stops working. Tried replace/replaced just to make sure but that didn't do anything (for understandable reason, thought I might as well try).

I tried the alternative by changing the config.enter/exit_transition itself but that was creating a whole problem on it's own and the transition also effected the preference, save/load, etc whenever I pressed the "return" so alt way is no longer an option for me.

Tried to look it up but unfortunately everything was about how to show transition when showing screens in labels...

Hopefully this is another simple solution I overlooked :|
Last edited by Dark12ose on Fri Jul 01, 2022 4:07 pm, edited 1 time in total.
Note: My mind can be all over the place while I'm writing as I think. If what you read is unclear do tell it to my face :lol:

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: "On Hide" not working for imagebuttons

#2 Post by zmook »

I copied your code and hacked it up enough to get it to run in a test game (mostly I changed the image buttons to text buttons so I didn't have to find graphics for them), and it works for me.

Speculation: you have defined a style for your hbox or imagebuttons that declares a yoffset, and it's interfering with your transition?
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

User avatar
Dark12ose
Regular
Posts: 63
Joined: Mon Oct 04, 2021 11:29 pm
Deviantart: Rosentear
Contact:

Re: "On Hide" not working for imagebuttons

#3 Post by Dark12ose »

zmook wrote: Thu Jun 02, 2022 12:40 pm I copied your code and hacked it up enough to get it to run in a test game (mostly I changed the image buttons to text buttons so I didn't have to find graphics for them), and it works for me.

Speculation: you have defined a style for your hbox or imagebuttons that declares a yoffset, and it's interfering with your transition?
No styling at all for this screen other than what you see for the hbox, which is everything you see underneath it.

I also tried it with textbutton and unfortunately "on hide" was still not working. I also tried taking the hbox stylings and/or hbox itself off just in case and still no go. Strange that the textbuttons works for you and not for me.

I also tried it in Ren'py default UI but still doesn't work.
Note: My mind can be all over the place while I'm writing as I think. If what you read is unclear do tell it to my face :lol:

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

Re: "On Hide" not working for imagebuttons

#4 Post by Ocelot »

Code: Select all

    on hide:
        easeout 0.5 yoffset -200
RenPy doen't really like when you don't give start values for animations. In your case it should be fine as it is set by on show event, but try to put in yoffset 0 before interpolation and see what happens.
< < insert Rick Cook quote here > >

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: "On Hide" not working for imagebuttons

#5 Post by zmook »

Try alt-shift-I and see if there are any active transforms you don't expect?

Try commenting out everything you don't think is relevant to the problem, until you simplify down enough that it starts working? (Maybe check out a branch a branch first, so you can easily restore when you find the problem.)

The bug must be in some part of your code that you haven't posted, so maybe post more and let us look at it?
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

User avatar
Dark12ose
Regular
Posts: 63
Joined: Mon Oct 04, 2021 11:29 pm
Deviantart: Rosentear
Contact:

Re: "On Hide" not working for imagebuttons

#6 Post by Dark12ose »

Ocelot wrote: Thu Jun 02, 2022 1:22 pm RenPy doen't really like when you don't give start values for animations. In your case it should be fine as it is set by on show event, but try to put in yoffset 0 before interpolation and see what happens.
Unfortunately that didn't work :(
zmook wrote: Thu Jun 02, 2022 1:24 pm Try alt-shift-I and see if there are any active transforms you don't expect?

Try commenting out everything you don't think is relevant to the problem, until you simplify down enough that it starts working? (Maybe check out a branch a branch first, so you can easily restore when you find the problem.)

The bug must be in some part of your code that you haven't posted, so maybe post more and let us look at it?
When I pressed the alt+shift+I, I get this.
Altshifti.jpg
The "skyscape" is the name of the image I called up for scene in script and also the name of the image file.
I removed it just in case but "on hide" still doesn't work.

I did try commenting out everything one by one but still nothing. Tried it with just one imagebutton and/or one textbutton as well just in case.
I also commented out the defines/default as well but nothing.

Code: Select all

## This determines what shows up when right clicking during replay.
define config.replay_scope = { "_game_menu_screen" : "game_menu_replay" }

## The default screen right clicking will show.  Originally it was the save screen.
default _game_menu_screen = "game_menu"

## This is used when you want a sfx whenever the player brings up the game menu or exit it.
define config.enter_sound = None
define config.exit_sound = None

## Transform ###############################################################
transform gamemenu_trans:
    on show:
        yoffset -200
        easein 0.5 yoffset 0
    on hide:
        yoffset 0
        easeout 0.5 yoffset -200

############################################################################
## Game Menu
############################################################################
screen game_menu():
    tag menu
    add "gui/ingameui/game menu/game_menu_bg.jpg" xalign 0.5 ypos 20 at gamemenu_trans

    hbox at gamemenu_trans:
        spacing 72
        xalign 0.5
        yalign 0.10
        xysize (1269, 191)
        box_wrap True
        box_wrap_spacing 15

        imagebutton auto "gui/ingameui/game menu/save_%s.png" focus_mask True action ShowMenu("save")

        imagebutton auto "gui/ingameui/game menu/load_%s.png" focus_mask True action ShowMenu("load")

        imagebutton auto "gui/ingameui/game menu/status_%s.png" focus_mask True action ShowMenu("pointstatus")

        imagebutton auto "gui/ingameui/game menu/gloss_%s.png" focus_mask True action ShowMenu("glossarygm")

        imagebutton auto "gui/ingameui/game menu/pref_%s.png" focus_mask True action ShowMenu("preference")

        imagebutton auto "gui/ingameui/game menu/mm_%s.png" focus_mask True action MainMenu()

        imagebutton auto "gui/ingameui/game menu/quit_%s.png" focus_mask True action Quit()

## GAME MENU REPLAY ########################################################

screen game_menu_replay():
    tag menu
    add "gui/ingameui/game menu/game_menu_bg.jpg" xalign 0.5 ypos 20 at gamemenu_trans

    hbox at gamemenu_trans:
        spacing 72
        xalign 0.5
        yalign 0.10
        xysize (1269, 191)
        box_wrap True
        box_wrap_spacing 15

        imagebutton auto "gui/ingameui/game menu/save_%s.png" xpos 0 ypos 180 focus_mask True action ShowMenu("save")

        imagebutton auto "gui/ingameui/game menu/load_%s.png" xpos 0 ypos 180 focus_mask True action ShowMenu("load")

        imagebutton auto "gui/ingameui/game menu/status_%s.png" xpos 0 ypos 180 focus_mask True action ShowMenu("pointstatus")

        imagebutton auto "gui/ingameui/game menu/gloss_%s.png" xpos 0 ypos 180 focus_mask True action ShowMenu("glossarygm")

        imagebutton auto "gui/ingameui/game menu/pref_%s.png" xpos 0 ypos 180 focus_mask True action ShowMenu("preference")

        imagebutton auto "gui/ingameui/game menu/end_%s.png" xpos 0 ypos 180 focus_mask True action EndReplay(confirm=True)

        imagebutton auto "gui/ingameui/game menu/quit_%s.png" xpos 0 ypos 180 focus_mask True action Quit()
That's everything in my game menu.rpy.
The game_menu_replay has the same issue.
Note: My mind can be all over the place while I'm writing as I think. If what you read is unclear do tell it to my face :lol:

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

Re: "On Hide" not working for imagebuttons

#7 Post by Alex »

Dark12ose wrote: Thu Jun 02, 2022 6:56 pm ...
Didn't dig in to it therefore don't know why, but 'on hide' transform start working if menu screen was replaced by some other menu screen.
Try this sample (config.enter_transition = dissolve and config.exit_transition = dissolve are unchanged).

Code: Select all

transform my_menu_tr(t=0.5):
    on show, replace:
        yoffset - config.screen_height
        linear t yoffset 0
        
    on hide, replaced:
        #yoffset 0
        linear t yoffset - config.screen_height
        
image test_menu_bg_1:
    Solid("#c0c0c0")
    size (config.screen_width, config.screen_height)
    
image test_menu_bg_2:
    Solid("#a0a0a0")
    size (config.screen_width, config.screen_height)
    
screen empty_scr():
    tag menu
    # does nothing but changes menu screen to actual one
    timer 0.01 action ShowMenu("test_menu_1")
    
screen test_menu_1():
    tag menu
    
    add "test_menu_bg_1" at my_menu_tr
    
    vbox at my_menu_tr:
        spacing 10
        #at my_menu_tr
        align(0.5, 0.5)
        text "Screen 1"
        textbutton "Return" action Return()
        textbutton "Screen 1" action NullAction()
        textbutton "Screen 2" action ShowMenu("test_menu_2")
        textbutton "Button 3 (save)" action ShowMenu("save")
        textbutton "Button 4" action NullAction()
        
screen test_menu_2():
    tag menu
    
    add "test_menu_bg_2" at my_menu_tr
    
    vbox:
        spacing 10
        at my_menu_tr
        align(0.5, 0.5)
        text "Screen 2"
        textbutton "Return" action Return()
        textbutton "Screen 1" action ShowMenu("test_menu_1")
        textbutton "Screen 2" action NullAction()
        textbutton "Button 3 (save)" action ShowMenu("save")
        textbutton "Button 4" action NullAction()

# The game starts here.
label start:
    # this makes transform work on screen hiding
    $ _game_menu_screen = "empty_scr"
    
    # hide transform doesn't work on first screen
    # if it wasn't replaced by the other screen
    # (try to return/right click on 'test_menu_1'),
    # but it works if screen was changed
    #$ _game_menu_screen = "test_menu_1" #
    "..."
    "... ..."
    "?!"

User avatar
Dark12ose
Regular
Posts: 63
Joined: Mon Oct 04, 2021 11:29 pm
Deviantart: Rosentear
Contact:

Re: "On Hide" not working for imagebuttons

#8 Post by Dark12ose »

Alex wrote: Fri Jun 03, 2022 5:25 am Didn't dig in to it therefore don't know why, but 'on hide' transform start working if menu screen was replaced by some other menu screen.
That's very interesting and... annoying.

I did notice when changing to save/load, preference, etc "on hide" did work but at the same time the buttons duplicated itself and dissolved but that I found out it was because of define config.intra_transition = dissolve so I removed it and it was fixed. Textbutton wasn't as apparent (unless the text was huge) but the imagebuttons definitely showed.

Edit: Forgot to mention that even with the empty_scr() when right clicked on the game menu itself the "on hide" doesn't work since it never goes back to the empty_scr() and it shouldn't as it will just loop.
Hmm... so now to figure out how to do this transition if right clicked in the game menu. I know most of the time people will click another menu from the game menu but there are times when we change our mind and right click again. I know I've done that.

I'll post more once I figure out something. Thank you for the help so far everyone :D
Note: My mind can be all over the place while I'm writing as I think. If what you read is unclear do tell it to my face :lol:

User avatar
Dark12ose
Regular
Posts: 63
Joined: Mon Oct 04, 2021 11:29 pm
Deviantart: Rosentear
Contact:

Re: "On Hide" not working for imagebuttons

#9 Post by Dark12ose »

So after looking into it more there really doesn't seem to be a way to go around this other than completely disabling the game_menu keymap.

After disabling it, I created a screen with the timer like Alex did but instead set it to action Return() and have the return button on the game menu set to jump to that screen.
For example:

Code: Select all

screen gm_return():
    tag menu
    timer 0.01 action Return()
    
screen game_menu():
    imagebutton auto "gui/return_%s.png" focus_mask True action ShowMenu("gm_return")
And lastly on the quick menu have a button that opens the game menu.

When done this way everything works completely fine.
I guess in the long run I had to do something I didn't want to do but oh well. Will mark as this solved.
Note: My mind can be all over the place while I'm writing as I think. If what you read is unclear do tell it to my face :lol:

Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot]