Displaying a modal screen from a quick menu button

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
trekopedia
Regular
Posts: 25
Joined: Thu Sep 14, 2017 11:38 pm
Location: Toronto, Canada
Contact:

Displaying a modal screen from a quick menu button

#1 Post by trekopedia » Wed Sep 27, 2017 2:53 pm

Hi everyone,

I'm stuck on how to implement something in Ren'py.

Here's what I am trying to accomplish: I want to add a button to the quick menu. When clicked, a modal screen should appear displaying information to the user. When the user clicks a 'Done' button, the screen clears and the game continues as it was.

I've created the screen and it works fine if I call it directly from my script (not based on any user interaction). I can display it simply enough, capture the 'done' click, and then remove the screen (basically following the approach shown in the Tutorial's code for the 'RPG Stats' screen). However, I can't figure out how to make this work from a quick menu button. The screen displays but there is no way for me to remove it (I haven't seen anything in the documentation about a callback function or anything similar that would enable my code to regain control to then provide the 'hide' instruction).

A related question: how would I go about implementing an entire screen transition *from the quick menu* that always returns to the current screen when done? For example, the existing 'Prefs' button on the quick menu displays the preferences screen and then returns control exactly as things were. How do I implement a similar capability for my own 'temporary' screens that need to return to the current screen when done. Is there a 'call'-type feature that works with the quick menu?

If possible, some actual code examples showing how the above could be accomplished would be highly appreciated -- I learn best when I can follow the actual code.

Thanks in advance!

User avatar
RicharDann
Veteran
Posts: 284
Joined: Thu Aug 31, 2017 11:47 am
Contact:

Re: Displaying a modal screen from a quick menu button

#2 Post by RicharDann » Wed Sep 27, 2017 3:31 pm

It's hard to know for sure without actually seeing your code, but, from what I understand I think what you're looking for is the Hide() screen action in the Done button, since from my experience, Return() wich is the other alternative doesn't seem to hide the screen at all if launched from the quick menu (or any other screen). An example:

Code: Select all

screen quick_menu():

    ## Ensure this appears on top of other screens.
    zorder 100

    if quick_menu:

        hbox:
            style_prefix "quick"

            xalign 0.5
            yalign 1.0

            textbutton _("Back") action Rollback()
            textbutton _("History") action ShowMenu('history')
            textbutton _("Skip") action Skip() alternate Skip(fast=True, confirm=True)
            textbutton _("Auto") action Preference("auto-forward", "toggle")
            textbutton _("Save") action ShowMenu('save')
            textbutton _("Q.Save") action QuickSave()
            textbutton _("Q.Load") action QuickLoad()
            textbutton _("Prefs") action ShowMenu('preferences')
            textbutton _("Custom") action Show('custom_screen', dissolve) #Here we add the button that launches our custom screen, with a dissolve transition

#And here is our custom screen's code
screen custom_screen():
    
    modal True #The screen has to be modal, right? So nothing below it can be clicked
    
    text "This is the Custom screen" xalign .3 yalign .2 #Some text to see if we're seeing the screen
    
    textbutton "Done" xalign .3 yalign .3 action Hide('custom_screen', dissolve) #This is the "Done" button, with the Hide() screen action, wich in this case hides the very screen where it is created.


I think this also works for your second question, since Hide() also returns control to the exact state the game was before you called the screen.

Here's the documentation on Hide and other Screen Actions:
https://www.renpy.org/doc/html/screen_actions.html#Hide
The most important step is always the next one.

User avatar
trekopedia
Regular
Posts: 25
Joined: Thu Sep 14, 2017 11:38 pm
Location: Toronto, Canada
Contact:

Re: Displaying a modal screen from a quick menu button

#3 Post by trekopedia » Wed Sep 27, 2017 3:55 pm

Ah! Thank you very much -- I did not think that I could 'hide' a screen from within that screen's definition!

I just tried it and it works perfectly. :D

Post Reply

Who is online

Users browsing this forum: Bing [Bot]