Window show / Window hide (on keybind)

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
sculpteur
Veteran
Posts: 312
Joined: Fri Nov 17, 2017 6:40 pm
Completed: Apocalypse Lovers
Projects: Apocalypse Lovers
Organization: Awake_Production
Location: France
Discord: https://discord.gg/apocalypse-lovers
Contact:

Window show / Window hide (on keybind)

#1 Post by sculpteur »

Hello guys,

I Have a really simple obstacle I'm sure you're going to joke about but I'am strugguling against it almost all the afternoon.

I'm looking for a way to do this :

When you press a key (like "i" for exemple), you hide or show the window where the text is writen (by default) (it's the 'say' screen with the 'who, what' parameter).

When you press 'h" by default (hiding interface), you hide or show all the actif screen of the interface to only look at the scene. I'm looking to do almost the same thing but I only want to show/hide the say screen.

In the code it's simple, in a label I know how to do it with the following line : window hide / window show

But I want a key to do that, not a label.

Just to let you know, I what to do this because :
> I have mutiple screen in my interface that's why I don't what to use H
> I have customized a lot my say screen, adding new part and new button on it (like the backpack acces)

So I need a way to hide/show the text box of the say screen even if there is no text currently displaying in it.

For now I tried this, but any of this is working :
(it's not just one screen, it's all the test I've done mixed together)

Code: Select all

# screen story_inv_belt_main_window:

    # if objective_window_displayed == True:
    #     key "i"  action [ToggleVariable( "story_inv_belt_main_window_displayed" ), Call("story_inv_belt_main_window_show")]
    # else:
    #     key "i" action [ToggleVariable( "story_inv_belt_main_window_displayed" ), Call("story_inv_belt_main_window_hide")]
    # 
    # if story_inv_belt_main_window_displayed == True:
    #     key "i"  action [ToggleVariable( "story_inv_belt_main_window_displayed" ), Hide("say"())
    # else:
    #     key "i"  action [ToggleVariable( "story_inv_belt_main_window_displayed" ), Show("say"())

    # if objective_window_displayed == True:
    #     key "i" action ToggleVariable( "story_inv_belt_main_window_displayed" ), Hide("story_inv_belt_main_window")
    # else:
    #     key "i" action ToggleVariable( "story_inv_belt_main_window_displayed" ), Show("story_inv_belt_main_window")

    # if objective_window_displayed == True:
    #     key "i" action [ToggleVariable( "story_inv_belt_main_window_displayed" ), Call("story_inv_belt_main_window_show")]
    # else:
    #     key "i"  action [ToggleVariable( "story_inv_belt_main_window_displayed" ), Call("story_inv_belt_main_window_hide")]

# label story_inv_belt_main_window_show:
#     window show
# label story_inv_belt_main_window_hide:
#     window hide
Image

“He asked me to calm down, close my eyes and be quiet. He explained to me that if I was afraid, the shadow that ran barefoot in the street would feel it. I got scared seeing Jumanji on TV, so let me tell you, we didn't stay hidden for long and had to start running again.”
Jessica's Diary.

sculpteur
Veteran
Posts: 312
Joined: Fri Nov 17, 2017 6:40 pm
Completed: Apocalypse Lovers
Projects: Apocalypse Lovers
Organization: Awake_Production
Location: France
Discord: https://discord.gg/apocalypse-lovers
Contact:

Re: Window show / Window hide (on keybind)

#2 Post by sculpteur »

Anyone ? I think it's simple but I really can't figure it out. So I will take any idea ! Thanks guys
Image

“He asked me to calm down, close my eyes and be quiet. He explained to me that if I was afraid, the shadow that ran barefoot in the street would feel it. I got scared seeing Jumanji on TV, so let me tell you, we didn't stay hidden for long and had to start running again.”
Jessica's Diary.

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

Re: Window show / Window hide (on keybind)

#3 Post by Ocelot »

you can use Function(_window_hide) or Function(_window_show) actions to call Python equcalent of window show/hide statements.
https://www.renpy.org/doc/html/dialogue ... indow_hide
< < insert Rick Cook quote here > >

sculpteur
Veteran
Posts: 312
Joined: Fri Nov 17, 2017 6:40 pm
Completed: Apocalypse Lovers
Projects: Apocalypse Lovers
Organization: Awake_Production
Location: France
Discord: https://discord.gg/apocalypse-lovers
Contact:

Re: Window show / Window hide (on keybind)

#4 Post by sculpteur »

Hey, thank you. I tried this and this isn't working. But it could be a synthax matter because I don't handle python code very well so can you look at this three tries I've done, then told me why this isn't working ? Thank you in advance !

Code: Select all

    if story_inv_all_main_window_displayed == True:
        key "t"  action ToggleVariable( "story_inv_all_main_window_displayed" ), Call(Function(_window_show))
    else:
        key "t"  action ToggleVariable( "story_inv_all_main_window_displayed" ), Call(Function(_window_hide))

Code: Select all

    if story_inv_all_main_window_displayed == True:
        key "t"  action ToggleVariable( "story_inv_all_main_window_displayed" ), Function(_window_show)
    else:
        key "t"  action ToggleVariable( "story_inv_all_main_window_displayed" ), Function(_window_hide)

Code: Select all

    if story_inv_all_main_window_displayed == True:
        key "t"  action [ToggleVariable( "story_inv_all_main_window_displayed" ), Function(_window_show)]
    else:
        key "t"  action [ToggleVariable( "story_inv_all_main_window_displayed" ), Function(_window_hide)]
And just for let you know, this is include in this code :
(the other part is working perfectly for the other screen)

Code: Select all

screen quick_screen_keys_input:
    if quick_menu_displayed == True:
        key "g" action ToggleVariable( "quick_menu_displayed" ), Hide("quick_acces")
    else:
        key "g" action ToggleVariable( "quick_menu_displayed" ), Show("quick_acces")
    if objective_window_displayed == True:
        key "q" action ToggleVariable( "objective_window_displayed" ), Hide("story_menu_main")
    else:
        key "q" action ToggleVariable( "objective_window_displayed" ), Show("story_menu_main")
    if story_inv_all_main_window_displayed == True:
        key "t"  action [ToggleVariable( "story_inv_all_main_window_displayed" ), Function(_window_show)]
    else:
        key "t"  action [ToggleVariable( "story_inv_all_main_window_displayed" ), Function(_window_hide)]
Image

“He asked me to calm down, close my eyes and be quiet. He explained to me that if I was afraid, the shadow that ran barefoot in the street would feel it. I got scared seeing Jumanji on TV, so let me tell you, we didn't stay hidden for long and had to start running again.”
Jessica's Diary.

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

Re: Window show / Window hide (on keybind)

#5 Post by Ocelot »

following works for me:

Code: Select all

screen quick_keys():
    key "t"  action [ToggleVariable( "story_inv_all_main_window_displayed" ), Call("do_stuff", story_inv_all_main_window_displayed, from_current=True)]

label do_stuff(do_hide=False):
    if do_hide:
        window hide
    else:
        window show
    return
Changed to label to avoid "interaction within interaction issue".
And it works: https://streamable.com/xcd67y

I suspect you have other problems with how say screen management works.
There are three kinds of statements: ones which always make say screen appear, ones which always hide it and those which do not do anything in particular. All window statements change behavior of last statements.
For example, even if you write window show, say screen will still disappear when you call any screen.
< < insert Rick Cook quote here > >

sculpteur
Veteran
Posts: 312
Joined: Fri Nov 17, 2017 6:40 pm
Completed: Apocalypse Lovers
Projects: Apocalypse Lovers
Organization: Awake_Production
Location: France
Discord: https://discord.gg/apocalypse-lovers
Contact:

Re: Window show / Window hide (on keybind)

#6 Post by sculpteur »

Hey I tried it with your code but it didn't do anything contrary to you and your little example movie.

But the thing is, you were right when you say you suspect I have other problems with how say screen management works.

So I looked at my say() screen and think it might be the problem, so I tried to incorporate your code in it like this :

Code: Select all

screen say(who, what):
    style_prefix "say"
    window:
        id "window"

        if show_inventory:
            pass

        else:
            text what id "what"
            if who is not None:
                window:
                    style "namebox"
                    text who id "who"
    if inv_button_show:
        imagebutton:
            keysym "i"
            xpos 0.806 ypos 0.850
            insensitive "GUI_inv_butt_small_insensitive"
            idle "GUI_inv_butt_small"
            hover "GUI_inv_butt_small_hover"
            action [ToggleVariable( "show_inventory" ), Show("inventory_main_bigbag"), SensitiveIf( invbig_button_sensitive )]
        imagebutton:
            keysym "o"
            xpos 0.152 ypos 0.850
            insensitive "GUI_inv_belt_butt_small_insensitive"
            idle "GUI_inv_belt_butt_small"
            hover "GUI_inv_belt_butt_small_hover"
            action [ToggleVariable( "show_inventory" ), Show("inventory_main"), SensitiveIf( inv_button_sensitive )]


    if quick_menu_displayed == True:
        key "g" action ToggleVariable( "quick_menu_displayed" ), Hide("quick_acces")
    else:
        key "g" action ToggleVariable( "quick_menu_displayed" ), Show("quick_acces")
    if objective_window_displayed == True:
        key "q" action ToggleVariable( "objective_window_displayed" ), Hide("story_menu_main")
    else:
        key "q" action ToggleVariable( "objective_window_displayed" ), Show("story_menu_main")

    key "t"  action [ToggleVariable( "story_inv_all_main_window_displayed" ), Call("do_stuff", story_inv_all_main_window_displayed, from_current=True)]


label do_stuff(do_hide=False):
    if do_hide:
        window hide
    else:
        window show
    return

And it almost work ! But not completly sadly.

I mean, when you press the corresponding key, something do happens :

> IF the say screen is already active then : the dialog screen (say screen) hide for one second with a dissolve transition but appear again right away.
> IF the say screen is not displayed : nothing happens, like before.

I thought it might be a matter of "auto" argument like (trans=False, auto=False) so I've done this :

Code: Select all

label do_stuff(do_hide=False):
    if do_hide:
        $ _window_hide(trans=False, auto=False)
    else:
        $ _window_show(trans=False, auto=False)
    return
But saddly it does nothing ! And I don't know what to try next so, even you already helped me a lot, I will take gladly any other idea !

Thanks a lot !
Image

“He asked me to calm down, close my eyes and be quiet. He explained to me that if I was afraid, the shadow that ran barefoot in the street would feel it. I got scared seeing Jumanji on TV, so let me tell you, we didn't stay hidden for long and had to start running again.”
Jessica's Diary.

sculpteur
Veteran
Posts: 312
Joined: Fri Nov 17, 2017 6:40 pm
Completed: Apocalypse Lovers
Projects: Apocalypse Lovers
Organization: Awake_Production
Location: France
Discord: https://discord.gg/apocalypse-lovers
Contact:

Re: Window show / Window hide (on keybind)

#7 Post by sculpteur »

Oh and just for let you know, this is a screen of my interface.
Like this you might understand why my say screen code is so messy ^^

Image
Image

“He asked me to calm down, close my eyes and be quiet. He explained to me that if I was afraid, the shadow that ran barefoot in the street would feel it. I got scared seeing Jumanji on TV, so let me tell you, we didn't stay hidden for long and had to start running again.”
Jessica's Diary.

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

Re: Window show / Window hide (on keybind)

#8 Post by Ocelot »

window show/hide turns off auto argument, so it is not a problem. The problem is that say statement interaction forces say screen to appear. Likewise, scene and call screen statements hide it. I do not know, how to stop them from doing that. At least you can wrap all content of the say screen in the if statement to make screen empty and nothing appear on screen, but it is another problem for called screens.

Also: you have hide/show hotkey inside the say screen. It wouldn't work if the screen is hidden, so you cannot show screen wih it.
< < insert Rick Cook quote here > >

sculpteur
Veteran
Posts: 312
Joined: Fri Nov 17, 2017 6:40 pm
Completed: Apocalypse Lovers
Projects: Apocalypse Lovers
Organization: Awake_Production
Location: France
Discord: https://discord.gg/apocalypse-lovers
Contact:

Re: Window show / Window hide (on keybind)

#9 Post by sculpteur »

Yes, but if I don't insert your code inside the say screen this is doing nothing and I don't know why.

I've this separated screen :

Code: Select all

screen quick_screen_keys_input:


    if quick_menu_displayed == True:
        key "g" action ToggleVariable( "quick_menu_displayed" ), Hide("quick_acces")
    else:
        key "g" action ToggleVariable( "quick_menu_displayed" ), Show("quick_acces")
    if objective_window_displayed == True:
        key "q" action ToggleVariable( "objective_window_displayed" ), Hide("story_menu_main")
    else:
        key "q" action ToggleVariable( "objective_window_displayed" ), Show("story_menu_main")

    key "t"  action [ToggleVariable( "story_inv_all_main_window_displayed" ), Call("do_stuff", story_inv_all_main_window_displayed, from_current=True)]


label do_stuff(do_hide=False):
    if do_hide:
        window hide
    else:
        window show
    return
But pressing the "t" key does nothing.


At least I would like to display an empty say screen when no text is display on the say screen.

I mean, my goal in this matter is in fact really simple.

My say screen include two button on the right and on the left of the dialog box, corresponding to the 'inventory belt' and the 'inventory bag'.

And in the current state of my code the player can only open this two inventory when the say screen is active in order to be able to access the two button.

For exemple, if there is no text displayed in the say screen and the player want to consult what's inside is bag, he will have to rollback to the previous displayed text or wait for an other.

So I was looking for a way to display and empty say screen when the say screen is not active.

I know I could try to separate the two button from the say screen but I don't want to do it cause it will make me rework too many code part.
Image

“He asked me to calm down, close my eyes and be quiet. He explained to me that if I was afraid, the shadow that ran barefoot in the street would feel it. I got scared seeing Jumanji on TV, so let me tell you, we didn't stay hidden for long and had to start running again.”
Jessica's Diary.

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

Re: Window show / Window hide (on keybind)

#10 Post by Ocelot »

I was going to suggest a frame challeng and copy current say screen into new screen, deleting stuff related to displaying text, and remove everything but the text from the say screen. This would make life easier.

I still thik that nothing is showing, because you are in some statement which explicitely suppresses say screen. For example if you use call screen, say screen will not appear. Only way to ignore that is to set previous say statement to be non-interactive.
sculpteur wrote: Thu Apr 29, 2021 5:37 am I know I could try to separate the two button from the say screen but I don't want to do it cause it will make me rework too many code part.
Welcome to the wonderful world of programming, where a decision you made half a year ago can add dozens man-hours of work in the future. Getting rid of technical debt and making old code conform to the new standards is the large part of programmers work.
< < insert Rick Cook quote here > >

sculpteur
Veteran
Posts: 312
Joined: Fri Nov 17, 2017 6:40 pm
Completed: Apocalypse Lovers
Projects: Apocalypse Lovers
Organization: Awake_Production
Location: France
Discord: https://discord.gg/apocalypse-lovers
Contact:

Re: Window show / Window hide (on keybind)

#11 Post by sculpteur »

Yeah that's right. I was so tunnel vision in this that I forgot to look at the general picture.
So thank you for your time and for trying to solve this with me but now it's fine I've figured something out and it seems to be working for now !
I will do more testing but I'm almost sure I'm on the right track ! Thank man
Image

“He asked me to calm down, close my eyes and be quiet. He explained to me that if I was afraid, the shadow that ran barefoot in the street would feel it. I got scared seeing Jumanji on TV, so let me tell you, we didn't stay hidden for long and had to start running again.”
Jessica's Diary.

Post Reply

Who is online

Users browsing this forum: Bing [Bot]