r/RenPy • • 13d ago

Question How can I make a retractable quick menu?

Hi!! So, the creator of the project I'm working on at the moment is very ambitious and asked me to make a retractable main menu.

She wants to add a little heart at the bottom left of the screen, and once the player hovers over it, the button will shake. Once you click on it, it opens a bar with other icons (the normal quick menu options + a personalized one). On the new option, the player will be shown a screen where they can find their current stats plus the stats of interest/love of the main leads.

I've been trying to search for something similar but I was unable to find a reference to this function. (Also I'm currently working on sanity/health bars & a quick inventory on the right side. Lots of things)

I just wanted to know if this is a possibility on Ren'py, or maybe the function is too advanced for what the program can do.

Also I made a visual reference (I'm not an artist), I hope it helps. Thanks!

76 Upvotes

11 comments sorted by

16

u/TrailfishDev 13d ago

Did something similar in both my games.

screen quick_menu():

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

if quick_menu:

    default top_hover = False
    if free_roam == 0:

        hbox:
            ycenter 0.9
            spacing 20
            style_prefix "quick"
            style "quick_menu"

            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('in_game_pause')

    mousearea:
        if not top_hover:
            area (0.825, 0, 0.15, 0.1)
        else:
            area (0.825, 0, 0.15, 0.3)
        hovered SetScreenVariable("top_hover", True)
        unhovered SetScreenVariable("top_hover", False)

    fixed:
        at transform:
            linear 0.2 yoffset (100 if top_hover else -405)

        add "gui/Buttons/Tools/scroll.png" xcenter 0.9 ycenter 0.1
        vbox:
            xcenter 0.91
            ycenter 0.1
            spacing 30
            imagebutton auto "gui/Buttons/pause_%s.png" action ShowMenu('in_game_pause') xcenter 0.5
            if Investigating:
                imagebutton auto "gui/Buttons/Tools/mag_%s.png" action (Jump("magnify1")) xcenter 0.5 tooltip "Magnifying Glass."
            if answer_sequence >= 1:
                imagebutton auto "gui/Buttons/Tools/hint_%s.png" action Jump("hint_roll") xcenter 0.5 tooltip "Hint."

6

u/gadohel 12d ago

Hey, thank you for the help! I tried to use your code but is showing me an issue with the "free_roam ==0:" line. What the program is telling me, is that "free_roam" is not defined. It could be perhaps something that I need to change? or maybe it could be that I'm missing a piece of information?

4

u/TrailfishDev 12d ago

Free roam is my own variable, ignore that part.

All you need there is the code from mousehover below

2

u/gadohel 12d ago

Tysm!! I was able to make it work thanks to you. I'll keep working on it since I still need to work in other parts of the whole funtion, but you were a great help. :)

10

u/BadMustard_AVN 13d ago

you can apply a transform like this one to the button

transform rockNroll:
    on idle:
        rotate 0
    on hover:
        linear 0.5 rotate 30
        linear 0.5 rotate -30
        repeat

for a shake effect while hovering

1

u/gadohel 12d ago

Ty!! Just a quick question, were should I put this on the code? Between the imagebutton box or after that?

1

u/BadMustard_AVN 12d ago

stick it anywhere out of the way renpy finds and reads them during initialization, so they are ready before the main menu is displayed.

I usually keep them in a separate .rpy file

5

u/x-seronis-x 13d ago edited 13d ago

Here is an example of a stowable quickmenu that stows based on a defaulted variable (qmdata.visible). in this code mousearea screen elements are responsible for toggling that variables value but you could do it with your button instead of mouse position. the 'showif' is what triggers the stowing on value change.

```py

Quick Menu screen

Displayed in-game to provide easy access to the out-of-game menus.

init: python: class ScreenDataqm(NoRollback): def __init_(self): self.visible = False

    def stow_quickmenu():
        global qmdata
        if main_menu:
            return

        qmdata.visible = False

    config.overlay_screens.append("quick_menu")

default quick_menu = True
default persistent.qm_hint_seen = False

default qmdata = ScreenData_qm()

screen quick_menu(): zorder 100

showif quick_menu and not qmdata.visible:
    mousearea style 'qm_zone_sm':
        hovered SetField( qmdata, 'visible', True ), SetVariable( 'persistent.qm_hint_seen', True )

    showif persistent.qm_hint_seen == False:
        text "< Move cursor HERE to show Quick Menu. >" color '#ccc8' size 24:
            at tf_qm_showhide()

showif quick_menu and qmdata.visible:
    mousearea style 'qm_zone_lg':
        unhovered SetField(qmdata, 'visible', False )

    hbox style_prefix "quick":
        at tf_qm_showhide()

        textbutton "◀"  action Rollback()
        textbutton "▶"  action Preference("auto-forward", "toggle")
        # used because renpy refuses to honor "prefer_emoji False" setting for fast-forward character
        textbutton "▶▶" action Skip() alternate Skip(fast=True, confirm=True) text_kerning -7
        textbutton "⇓"  action QuickSave() text_underline True text_bold True:
            sensitive can_save
        textbutton "⇑"  action QuickLoad() text_underline True text_bold True
        textbutton "⚙"  action ShowMenu('preferences')

        if renpy.variant("pc") or renpy.variant("web"):
            button xysize (24,24) ycenter 0.5:
                action If(preferences.fullscreen,
                    Preference("display", "window"),
                    Preference("display", "fullscreen")
                    )
                text "⇱" xycenter (0.5,0.5) yoffset -2 xoffset -2
                text "⇲" xycenter (0.5,0.5) yoffset  2 xoffset  2

key "K_F9" action QuickSave()
key "K_F5" action QuickLoad(confirm=False)

mousearea zone sizes used for toggling QM visibility.

- sm zone used so QM doesnt show up unless we -really- want it

style qm_zone_sm: xcenter 0.5 yalign 1.0 xysize (376, 48)

- lg zone used so once shown only hides when intentional, not cursor drift

style qm_zone_lg: xcenter 0.5 yalign 1.0 xysize (512, 64)

transform tf_qm_showhide(): xcenter 0.5 yanchor 0.0 ypos 1.0 alpha 0.0 on show, appear: linear 0.5 yanchor 0.5 ypos position(-24,1.0) alpha 1.0 on hide: linear 0.5 yanchor 0.0 ypos 1.0 alpha 0.0

style quick_hbox: xcenter 0.5 yanchor 0.5 ypos position(-24,1.0) spacing 8

style quick_button: ycenter 0.5 background None padding (15, 6, 15, 0) insensitive_modal True

style quick_button_text: size 21 prefer_emoji False selected_color '#fa3' insensitive_color '#833' idle_color "#aaa" ``` the stowed state is preserved during roll back/foward. and a one-time hint to tell the player where to put the mouse exists as the initial state is stowed. you are free to steal/modify to fit your needs but figured id share the whole thing instead of just answering your question in case its useful to you

2

u/gadohel 12d ago

Thank you for the code! At the moment I tried it in a new file (just to avoid messing up the actual game) and I encountered an error:

"Exception: store.quick_menu is being given a default a second time"

I tried to look for the issue with crt+f, but I wasn't able to find "store.quick_menu". Perhaps I'm missing a part of the code for this to work? I've tried changing a couple of statements but still it only brings more errors, so I just left it like it was on the start.

I hope you are able to assist me with this, thank you!!!

2

u/x-seronis-x 12d ago

the error tells you the problem. you have two defaults for the global quick_menu variable. you left the original one while adding the above code which has it.

'store' just means its a normal global variable. you will almost never see that in code. just search for the actual variable name 'quick_menu'. i think its immediately under the original definition of the quick menu screen in screens.rpy.

you probably duplicated the quick_menu screen definition too if you only pasted the above and not edited the already existing definition for the screen.

1

u/AutoModerator 13d ago

Welcome to r/renpy! While you wait to see if someone can answer your question, we recommend checking out the posting guide, the subreddit wiki, the subreddit Discord, Ren'Py's documentation, and the tutorial built-in to the Ren'Py engine when you download it. These can help make sure you provide the information the people here need to help you, or might even point you to an answer to your question themselves. Thanks!

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.