Ren'Py How to keep hover quick menu visible after pressing the "Back" button?

Sedid

Member
Donor
Game Developer
Nov 27, 2018
270
617
Hi,

I have a quick menu that disappears when you don't hover over it and reappears when you hover over it.

My problem:

I want the "Back" button to keep the quick menu visible after it's pressed (e.g., when navigating back). I've tried various solutions, but nothing has worked so far.

For the fade effect, I use a transform, plus a mousearea, with hovered/unhovered quick menu.

Has anyone ever done this? Is there a simple solution?

You don't have permission to view the spoiler content. Log in or register now.

Thanks,

Sedid
 
Last edited:

Winterfire

Conversation Conqueror
Respected User
Game Developer
Sep 27, 2018
6,169
8,901
Did you take the code from somewhere? If you wrote it, you should easily figure out you can throw a boolean in there to prevent the disappearing function to trigger temporarily. Maybe behind a timer that eventually turns it back on if you haven't interacted with the back button for long enough.
 

Sedid

Member
Donor
Game Developer
Nov 27, 2018
270
617
Basically, I want the quick menu to be hidden (as it is now), EXCEPT when you hover over it with the mouse or press the back button. The hovering effect is done, but I'm having trouble with the back button. No matter what I tried, the quick menu always disappear when I click on Back (which I don't want).

I generate a few codes with AI, like here, and sometimes I try to solve the problem myself and other times with AI, but here nothing works, hence my post.
 

Sedid

Member
Donor
Game Developer
Nov 27, 2018
270
617
Alright, so

I have a file quick menu.rpy:

Code:
transform true_smooth_fade:
    alpha 0.0
    on show:
        easeout 0.35 alpha 1.0
    on hide:
        easein 0.55 alpha 0.0
    on replaced:
        alpha 1.0

screen quick_menu():
    zorder 100
    default quick_showing = False


    mousearea:
        xysize (1920, 90)
        yalign 1.0
        hovered Show("quick_menu_display")  # show quick menu
        unhovered Hide("quick_menu_display")  # hide quick menu

And in screens.rpy, I have this:

Code:
screen quick_menu_display():
    zorder 100
    modal False
 
    hbox at true_smooth_fade:
        style_prefix "quick"
        xalign 0.5
        yalign 0.98
        spacing 0

        #textbutton _("Back") action Rollback()
        textbutton _("History") action ShowMenu("history")
        textbutton _("Options") action ShowMenu('preferences')
        textbutton _("Auto") action Preference("auto-forward", "toggle")
        textbutton _("Quick Save") action QuickSave()
        textbutton _("Load") action ShowMenu('load')
        textbutton _("Save") action ShowMenu('save')

## This code ensures that the quick_menu screen is displayed in-game, whenever
## the player has not explicitly hidden the interface.
init python:
    config.overlay_screens.append("quick_menu")

default quick_menu = True
In screens.rpy, I also have this, but it's not really related:


Code:
screen quick_menu():
    variant "touch"

    zorder 100

    if quick_menu:

        hbox:
            style_prefix "quick"

            xalign 0.5
            yalign 1.0

            textbutton _("Back") action Rollback()
            textbutton _("Skip") action Skip() alternate Skip(fast=True, confirm=True)
            textbutton _("Auto") action Preference("auto-forward", "toggle")
            textbutton _("Menu") action ShowMenu()
 
Last edited:

Mattock

Member
May 27, 2018
114
96
Hi,
I think you got most covered...only the variable is in the wrong "location"; your:
default quick_showing = False
is a "screen"-variable...
the (RenPy-default):
default quick_menu = True
is a "store"-variable, but as you want to use Rollback this will never be of any help...
I would use a "persistent"-variable (in fact I would use 2)
something along this
Python:
init python:
    if persistent.quick_explained is None:
        persistent.quick_explained = False
    if persistent.show_quick is None:
        persistent.show_quick = True
    if persistent.quick_explained:# == True
        persistent.show_quick = False
you can skip the "quick_explained", but as most RenPy-players expect a quick-menu to be there,
I'd say it's worth to at least explain once that its normally being hidden...e.g.
Python:
label start:
    "dev" "I hide the quick-menu, blah!"
    $ persistent.quick_explained = True
Now what to do with it...
1st don't touch the screen.rpy from RenPy-SDK, make your own .rpy (e.g. myscreens.rpy), this way changing from one to another RenPy-version becomes much more easy in the future!
2nd we want to get rid of the original quick-menu, and now we're back to RenPy's store-var
default quick_menu = True
just do e.g. in myscreens.rpy
Python:
init 3:
    quick_menu = False
not too nice, but should do...
then your screens
Python:
screen quick_menu_display():
    zorder 100
    modal False

    if persistent.show_quick:# == True
        hbox at true_smooth_fade:
            style_prefix "quick"
            xalign 0.5
            yalign 0.98
            spacing 0

            textbutton _("Back") action Rollback()###TODO LATER!
            textbutton _("History") action ShowMenu("history")
            #[...]

###and your activator
screen qm_activator():
    zorder 100
    modal False#should be said, tho it's by default False, irrc

    mousearea:
        xysize (1920, 90)
        yalign 1.0
        hovered SetField( persistent, "show_quick", True )# show quick menu
        unhovered SetField( persistent, "show_quick", False )# hide quick menu

###and putting both in overlay
init python:
    config.overlay_screens.append( "quick_menu_display" )
    config.overlay_screens.append( "qm_activator" )
you already have all that!
and that was the easy part;)

you want the qm still visible when you do a Rollback(btw. why?)
well most easy is if player clicks on your "Back"-button...you see the###TODO?
we change to:
Code:
textbutton _( "Back" ) action [ SetField( persistent, "show_quick", True ), Rollback() ]###done1
problem is...when player moves the mouse out of the mousearea the unhovered action is being done and your qm is being hidden again...
but maybe this is what you want?
else we would need another variable to set...
AND player still could press "PageUp" on his keyboard...do you want to show your quickmenu on every Rollback-event?(even when the mouse is not inside the mousearea?)

(I think I've seen something like a Rollback-callback, but I my mind may be playing tricks too...you still could re-define the "keyboard"-action, but that sounds like overkill too...)
hmm, this got more complicated than I thought at first...
maybe describe more what you want(?)
(or some1else has a better idea)
greets Mattock

(ignored transformation and stuff, and all written "on-the-fly"! beware of typo's!)


EDIT: IF this works to your liking: don't forget to make a
Python:
screen quick_menu_display():
    variant "touch"
    #[...]
#and
screen qm_activator():
    variant "touch"
    #[...]
#too!!! else those never will get a quick-menu!!!
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
12,418
19,946
I want the "Back" button to keep the quick menu visible after it's pressed (e.g., when navigating back).
Said otherwise, you want Ren'Py to revert to its state during the previous interaction... A state that include, "the quick menu is not displayed", as well as, "the mouse is not in 'this' area".
Plus, mousearea is triggered when the mouse enter or leave the area, something that do not happen here, since the mouse is already inside the area.

I works with "skip", because the current state ("the quick menu is displayed" and "the mouse is in 'this' area") is propagated to the next interaction. But it cannot works in the other way, because both are sent back to their opposite.


Python:
screen quick_menu_display():
    zorder 100
    modal False

    if persistent.show_quick:# == True
The idea is interesting but, as I said above, the rollback will hide the "quick_menu_display" screen. Therefore, it's not here that the persistent flag must be used.

A possiblity could be :
Python:
init python:
   #  No need to keep the state when the game was closed, it's a persistent value only 
   # to escape from the rollback.
   persistent.showQuickMenu = False

screen quick_menu():
    zorder 100

    #  Force the display of the screen *if* the persistent flag is raised *and* the screen 
    # isn't already displayed.
    if store.persistent.showQuickMenu and not renpy.get_screen( "quick_menu_display" ):
        $ renpy.run( Show( "quick_menu_display" ) )

    mousearea:
        xysize (1920, 90)
        yalign 1.0
        #  Raise the flag when entering the area.
        hovered [ Show("quick_menu_display"), SetVariable( "persistent.showQuickMenu ", True ) ]
        #  Lower it when leaving the area.
        unhovered [ Hide("quick_menu_display"), SetVariable( "persistent.showQuickMenu ", False) ]
But the fact is that it display the "quick_menu_display" screen before the game is even started, despite the flag being lowered... :confused:
Once the game is started everything works as intended, including the screen being hidden when a menu is opened. But this is not just an anecdotal issue, the screen shouldn't been shown before the game starts, period.

I kind of remember that there's a way to know if the game is started or not. Adding it to the if should solve the issue, but right now I don't remember how to get the information.
Alternatively adding an "if in menu state" to the condition should also works. But it's the same, it's near midnight here, and I don't fucking remember what is the variable name to get the information.
 

Mattock

Member
May 27, 2018
114
96
couldn't sleep before trying this...
I do know some ways to determine the state of RenPy, but imho for this it's just not needed(?)
well I blame it on the late hour (OR I'm still WRONG...?...)
mebbe you didn't see, I put both screens into "overlay"
(I'm still unhappy that I don't do it in ONE screen, but...one step after another...)

I'm also more a fan of camel-toes, and the 2nd persitent-var is senseless!
(@dev: you still should explain to the players that the quick-menu is being hidden(imho))

not sure if my MOD-frame does something else(I don't think so), but I'm here on my last modded game(RenPy 8.0.3)
and to me it works as I had (kinda) expected it...

leave (RenPy-)screens.rpy untouched! and do e.g. in myscreens.rpy:
(I left out the transform! you do that better than me)
Python:
###da control-var (initially show QM)
init python:
    if persistent.showQuickMenu is None:
        persistent.showQuickMenu = True

###the activator...now doubling QM
init 3 screen quick_menu():
    zorder 100
    modal False
    mousearea:
        xysize (1920, 90)
        yalign 1.0
        hovered SetField( persistent, "showQuickMenu", True )
        unhovered SetField( persistent, "showQuickMenu", False )

screen quick_menu_display():
    zorder 100
    modal False
    if persistent.showQuickMenu:
        hbox:# at true_smooth_fade:#skipping transform...you do that!
            style_prefix "quick"
            xalign 0.5
            yalign 0.98##yalign 1.0
            spacing 0#+
            textbutton _("Back") action Rollback()###following is roughly what I do as QM...
            textbutton _("History") action ShowMenu('history')
            textbutton _("Skip") action Skip()# alternate Skip(fast=True, confirm=True)
            textbutton _("F.Skip") action 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')

###and putting BOTH in overlay
init python:
    if "quick_menu" not in config.overlay_screens:#watch this! LOL, sry
        config.overlay_screens.append( "quick_menu" )
    if "quick_menu_display" not in config.overlay_screens:
        config.overlay_screens.append( "quick_menu_display" )
on 1st use QM is showing after loading a game (not before, and not in any "menu"-state)
later QM was always "hidden" until mouse moved down, and while mouse stayed in designated mousearea the QM was always shown on many Rollback...

I'm somewhat unsure about my machine now...
opinions?