how to add imagebuttons to choice screen

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
decray
Newbie
Posts: 12
Joined: Tue Feb 05, 2013 5:38 am
Contact:

how to add imagebuttons to choice screen

#1 Post by decray » Fri Feb 15, 2013 2:04 am

as we know the menu statement

menu:
"dasdasdadasdas":
jump asda
"adasqwqeqweqwe":
jump dada

can provide textbuttons
but how can I add imagebuttons
for example

imagebutton idle "button/sel01_p_01.gif" hover "button/sel01_p_02.gif" selected_idle "button/sel01_p_03.gif" selected_hover "button/sel01_p_03.gif" action Jump("sel01_A")

I have tried to create a new screen

screen choice01:

window:
style "menu_window"
area(150,260,650,340)
vbox:
style "menu"
imagebutton ...
imagebutton ...

but menu statement can stop the game and disable click-to-continue while this new screen cannot

User avatar
KimiYoriBaka
Miko-Class Veteran
Posts: 636
Joined: Thu May 14, 2009 8:15 pm
Projects: Castle of Arhannia
Contact:

Re: how to add imagebuttons to choice screen

#2 Post by KimiYoriBaka » Fri Feb 15, 2013 11:20 am

if you call the new screen with the "call screen" statement, it should behave the same way. otherwise you can also use the pause statement

if you want to change the screen that comes up when you use the menu statement, go into the screens.rpy file and find the part that says "screen choice"

once you find the right screen go to this part:

Code: Select all

for caption, action, chosen in items:

                if action:

                    button:
                        action action
                        style "menu_choice_button"

                        text caption style "menu_choice"

                else:
                    text caption style "menu_caption"
and change the button into an imagebutton with whatever images you want to use.

Janto
Newbie
Posts: 21
Joined: Wed Apr 11, 2012 10:48 am
Projects: Fire in the Night
Location: Florence, Italy
Contact:

Re: how to add imagebuttons to choice screen

#3 Post by Janto » Fri Feb 15, 2013 12:24 pm

I was looking at doing something similar, so I'll join this thread if that's okay to pool experience.

Rather than just having a generic imagebutton which is applied to all items in the choice menu, is it possible to have specific image buttons for specific types of choices (so a 'Flirt' button, a 'Lie' button, etc.), and for the button to be used for each choice to be specified relatively easily when writing the menu choices?

I figure I could hack this code:

Code: Select all

screen buttons:
    modal False
    for b in buttonlist:
        imagebutton:
            xpos b[0] ypos b[1]
            auto (b[2] + "_%s.png")
            action b[3]
Which puts the content of the list 'buttonlist' on screen:

Code: Select all

    buttonlist = [[20, 430, "button_1", [SetVariable("button_1_press", True), Hide("button_1"), Jump("button_1_result")]],
                  [40, 300, "button_2", [SetVariable("button_2_press", True), Hide("button_2"), Jump("button_2_result")]]]
But I would need to set up a new screen for every choice screen then.

(I'd like to have a system where the player is initially only presented with a visual image button that symbolises the topic somehow, and the menu text only appears (for that choice) when they hover over it, but that probably should have its own thread.)

decray
Newbie
Posts: 12
Joined: Tue Feb 05, 2013 5:38 am
Contact:

Re: how to add imagebuttons to choice screen

#4 Post by decray » Fri Feb 15, 2013 12:42 pm

I haven't expected call screen to have that function
although I indeed have attempted to modify screen choice
it turns out to be useless when I encounter a more complex choice menu

Janto
Newbie
Posts: 21
Joined: Wed Apr 11, 2012 10:48 am
Projects: Fire in the Night
Location: Florence, Italy
Contact:

Re: how to add imagebuttons to choice screen

#5 Post by Janto » Sat Feb 16, 2013 6:57 am

Here's the code I used for an image-button based menu, with a screenshot of the prototype. (this method is only capable of showing one image for all menu choices at the moment, but I think I'm on track to figure that out.)

The main game code, showing the menu:

Code: Select all

# The game starts here.
label start:

scene grey
show screen bars
show screen tooltip

menu:
    "Image Map Experiment":
        call image_map_exp
    # "Event Manager Experiment.":
        # call event_manager_exp
    "Image Button Experiment": 
        call image_button_exp
    "Menu UI experiment":
        call menu_ui_exp
    "2nd UI experiment":
        call second_menu
    "End Game":
        return
        
jump start
And here's my choice screen:

Code: Select all

# Choice
#
# Screen that's used to display in-game menus.
# http://www.renpy.org/doc/html/screen_special.html#choice

screen choice:

    default tt = Tooltip("")
    
    window: 
        style "menu_window"
        hbox:
            style "menu"
            spacing 20
            
            for caption, action, chosen in items:
                if action:  
                        
                    imagebutton:
                        auto "ui/inquiry_%s.png" action action
                        hovered tt.Action (caption)
                        
                else:
                    imagebutton:
                        auto "ui/inquiry_%s.png" action action
                        hovered tt.Action (caption)
    window:                     
        vbox:
            style "say_vbox"
            text tt.value style "menu_choice"
            
    # Use the quick menu.
    use quick_menu                    
        
init -2 python:
    config.narrator_menu = True
    style.menu_window.set_parent(style.default)
    style.menu_choice.set_parent(style.button_text)
    style.menu_choice.clear()
    style.menu_choice_button.set_parent(style.button)
Because of the visual style of the menues, I've hacked how the 'caption' part of the menu is displayed, showing inside a tooltip which uses the same styles as the say screen to show the caption in the main text box.

Hope that's useful.
Attachments
UI_test_1.jpg

Post Reply

Who is online

Users browsing this forum: No registered users