Pop-up menu?

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
Piroshiki
Regular
Posts: 62
Joined: Mon Oct 25, 2004 2:26 pm
Location: The city of snow (Qc, CA)
Contact:

Pop-up menu?

#1 Post by Piroshiki » Wed Dec 29, 2004 3:06 pm

As I don't really like the look of a menu in the dialogue box, I've been playing around with UI functions to create some form of pop-up menu, like this. Now, that's probably one of the dumbest question ever, but... how do I jump to a label using an UI function? Looking at the tutorial, I read something about a variable returned by renpy.interact() and used in a series of if statements, but having about the ability of your average toenail when it comes to programming, everything I tried miserably failed and took me to an empty screen with only a background instead.

I also tried something involving a different window for the menus, but that window replaced the dialogue window, so I was left with only the menu window in the middle of the screen. Is there a way to use window styles instead of UI functions to display two windows at once like in the screenshot?
I'm not a meat bun ~nya

User avatar
Tage
Regular
Posts: 194
Joined: Mon Nov 01, 2004 2:18 am
Location: Memphis, TN
Contact:

#2 Post by Tage » Wed Dec 29, 2004 4:19 pm

Code: Select all

$ ui.window(xfill=800, yfill=600, xmargin=0, ymargin=0, background=Solid((0,0,0,255))) 
        $ ui.vbox(padding=10, xpos=0.5, ypos=0.5, xanchor="center", yanchor="center") 
        $ ui.text("Please choose if you want a fullscreen or window:", color=(255,255,255,255)) 
        $ ui.textbutton("Fullscreen", clicked=ui.returns("f")) 
        $ ui.textbutton("Window", clicked=ui.returns("w")) 
        $ ui.close() 
        $ choice = renpy.interact(suppress_overlay=True) 
        if choice == "f": 
            $ _preferences.fullscreen = True 
        elif choice == "w": 
            $ _preferences.fullscreen = False
This is a copy and paste of a code I posted before. Notice the "if choice" and "elif choice" at the end. "choice" is the variable name which holds the statement "renpy.interact()". Which, in actuality, is holding the String that "renpy.interact()" returns when you click one of the "ui.textbutton()"s. Notice, inside the "ui.textbuttons()" the statement "ui.return()". That's what each button returns. You set a String inside each one of them. So once they click a button, you set the answer to a variable, like "choice", and then check to see what that variable is holding with the "if" and "elif" statements. Simply, put a statement, like "jump labelName" inside each "if" and "elif" statements you make. It should work. All of this was my speculation by the way. I don't really know how it works n.n; I didn't work with ui's very much.

User avatar
PyTom
Ren'Py Creator
Posts: 15469
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

#3 Post by PyTom » Wed Dec 29, 2004 4:42 pm

There are two main ways in Ren'Py to jump to computed locations. You can use ui.jumps in python code, or the new (in 4.4) jump expression statement.

ui.jumps() is used as the clicked argument to a button, and causes control to go to the label when the button is clicked.

For example:

Code: Select all

python:
   ui.window()
   ui.vbox()

   ui.text("Are you sure you want to lick that electrical outlet?")

   ui.textbutton("Yes", clicked=ui.jumps("bad_shock"))
   ui.textbutton("No", clicked=ui.jumps.("good_idea"))

   ui.close()

   ui.interact()
Alternatively, you can express this using ui.menu and a jump expression statement. (This is probably preferred, as Ren'Py menus support the arrow keys.)

Code: Select all

python:
   ui.window()
   ui.menu([ 
     ("Are you sure you want to lick that electrical outlet?", None),
     ("Yes", "bad_shock"),
     ("No.", "good_idea")])

    rv = ui.interact()

jump expression rv
Either of these should jump to the appropriate location.

Right now, there's no good way to have both a menu and a say statement on the screen at the same time. The problem with this is that the two respond differently to (for example) mouse clicks, which can confuse the system.

Probably the best way to handle this is to fake the say statement with ui functions. If you'd like, I can supply the code to show a say box without hooking up the say behavior to it. Let me know if this would help you.

Good to see you're still alive. :-)

Piroshiki
Regular
Posts: 62
Joined: Mon Oct 25, 2004 2:26 pm
Location: The city of snow (Qc, CA)
Contact:

#4 Post by Piroshiki » Wed Dec 29, 2004 5:27 pm

Ahah, thanks! So that's why I was taken to an empty window... I was using something similar to what Tage posted, but... I had a say statement just before the renpy.interact() part <^^;; It *did* allow me to see both the menu and the dialogue box, but it also confused the system. Well, if it can't be done like that, something that could emulate the say box like you suggested would be much appreciated, please.
Last edited by Piroshiki on Thu Dec 30, 2004 4:42 pm, edited 1 time in total.
I'm not a meat bun ~nya

User avatar
PyTom
Ren'Py Creator
Posts: 15469
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

#5 Post by PyTom » Wed Dec 29, 2004 7:03 pm

Okay, here's a function that can fake up a say window.

Code: Select all

init:
 python:
  def fake_say(who, what, who_style='say_label',
                what_style='say_dialogue',
                window_style='say_window',
                who_prefix='',
                who_suffix=': ',
                what_prefix='',
                what_suffix='',
                **properties):
    """
    @param who: Who is saying the dialogue, or None if it's not being
    said by anyone.

    @param what: What is being said.

    For documentation of the various prefixes, suffixes, and styles,
    please read the documentation for Character.
    """
    
    if who is not None:
        who = who_prefix + who + who_suffix

    what = what_prefix + what + what_suffix

    ui.window(style=window_style)
    ui.vbox(padding=10)

    if who is not None:
        ui.text(who, style=who_style, **properties)

    ui.text(what, style=what_style, slow=True)
    ui.close()
When called, this function will add a new say window the screen, but not call the interact function. (And, BTW, it's ui.interact, not renpy.interact. ui.interact does some additional checking.)

For example:

Code: Select all

$ fake_say("Nanase", "Are those correct? Name %(name)s" % globals(), color=(123, 123, 123, 255))

# Menu code goes here.
Sorry, but say is right now a fairly complicated process, and it's hard to hook into it in the way that you want. In the next major version of Ren'Py, I'll add a "interact" flag to the character object, so it'll be easy to make character objects that display their window without causing an interaction to take place.

It just wasn't really something I planned for, and the correct fix is just a bit too difficult for a monkeypatch.

Piroshiki
Regular
Posts: 62
Joined: Mon Oct 25, 2004 2:26 pm
Location: The city of snow (Qc, CA)
Contact:

#6 Post by Piroshiki » Thu Dec 30, 2004 4:48 pm

Working perfectly, thanks a lot!

And, while being at it... Is there any way to change the disposition of the items in the game menu, main menu and preferences options? Say, if I want to have two lines of image buttons instead of a column of text buttons, or something like that...
I'm not a meat bun ~nya

User avatar
PyTom
Ren'Py Creator
Posts: 15469
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

#7 Post by PyTom » Thu Dec 30, 2004 5:06 pm

The main menu can be easily rewritten... IIRC, there's a section on that in newer versions of the tutorial.

The game menu is harder. There's a limited amount of support for it. (IIRC, there's a variable under library that lets you add/remove buttons from the game menu.) But you'd have to rewrite quite a bit of the library to change (for example) a textbutton to an imagebutton.

Sorry there isn't a really good answer to this. Maybe in the future I'll add more hooks into the library... But there's only so much I can do before you just have to start rewriting library.rpy yourself... and that's going to be a pain to keep up to date. :-(

Piroshiki
Regular
Posts: 62
Joined: Mon Oct 25, 2004 2:26 pm
Location: The city of snow (Qc, CA)
Contact:

#8 Post by Piroshiki » Thu Dec 30, 2004 6:06 pm

Ah, I see... I already knew about adding stuff to menus, I played around with that a little while trying to change their layout - I could change the position and content, but nothing else, and I wondered if it was possible. Seems like it would be a a pain though, so... I'll try and find something else. Thanks anyway!
I'm not a meat bun ~nya

User avatar
PyTom
Ren'Py Creator
Posts: 15469
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

#9 Post by PyTom » Thu Dec 30, 2004 6:46 pm

I should point out that if you understand the UI functions and a little bit of python, understanding the library shouldn't be _that_ hard. But there's only so much flexability I can simply provide, and then you're just programming in another language anyway.

Post Reply

Who is online

Users browsing this forum: Eyzi, Google [Bot], InkyFrog