[SOLVED] Custom one more menu screen to display the place?

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
lyminh99
Regular
Posts: 38
Joined: Sat Jun 14, 2014 1:09 pm
Contact:

[SOLVED] Custom one more menu screen to display the place?

#1 Post by lyminh99 »

I have an idea about making menu choices that look like a place the main char want to come besides the other normal choices when they are talking. It will affect the relationship points between other heroines depend on the place the main char have chosen.

Now i can create a screen that display the place and i can use the imagebutton too. But i don't think it's efficent to create all possible screen for that, and for the Next and Previous button, i can't see the way to code it right. So i want to ask you guy if there is a way that can input the image and choice like normal menu text choice, then the previous next button can display the place in the pool we have input in it.

I have the image below to show you guy the idea more easy.

Thanks
Attachments
Choice by image.png
Last edited by lyminh99 on Thu Jul 02, 2015 4:18 am, edited 1 time in total.

User avatar
SinnyROM
Regular
Posts: 166
Joined: Mon Jul 08, 2013 12:25 am
Projects: Blue Birth
Organization: Cosmic Static Games
Contact:

Re: Custom one more menu screen to display the place?

#2 Post by SinnyROM »

Here's something I was playing with before that does something similar, but it doesn't work with the choice screen yet. If I have more time later I'll see if I can figure it out. For now I welcome anyone who wants to give their advice!

Code: Select all

screen places():
    
    ### Set page variables
    default page_curr = 1
    default page_min = 1
    default page_max = 3
    
    frame:
        xalign 0.5 yalign 0.5
        hbox:
        
            ### Simple textbuttons
            textbutton "<" action [If(page_curr > page_min, SetScreenVariable('page_curr', page_curr-1), NullAction())]
            textbutton "place "+str(page_curr) action [Jump("place"+str(page_curr))]
            textbutton ">" action  [If(page_curr < page_max, SetScreenVariable('page_curr', page_curr+1), NullAction())]

            ### With imagebuttons
            ### For page 1, place images are:
            ### "images/place_1_idle.png"
            ### "images/place_1_hover.png" etc.
            # imagebutton auto "images/arrowl_%s.png" action [If(page_curr > page_min, SetScreenVariable('page_curr', page_curr-1), NullAction())]
            # imagebutton auto "images/place_" + str(page_curr) + "_%s.png" action [Jump("place"+str(page_curr))]
            # imagebutton auto "images/arrowr_%s.png" action [If(page_curr < page_max, SetScreenVariable('page_curr', page_curr+1), NullAction())]

    ### To indicate page number
    frame:
        text "Current Page: "+str(page_curr)


label place1:
    "I choose place 1"
    return
    
label place2:
    "I think I'll go with place 2"
    return
    
label place3:
    "I rather go to place 3"
    return

User avatar
SinnyROM
Regular
Posts: 166
Joined: Mon Jul 08, 2013 12:25 am
Projects: Blue Birth
Organization: Cosmic Static Games
Contact:

Re: Custom one more menu screen to display the place?

#3 Post by SinnyROM »

Got it. This one completely replaces the choice screen, although how to make the images in the buttons show depending on the choices is another problem.
You could set the choice caption to the image filename, or have it define somewhere already with that caption name.

Code: Select all

screen choice(items):

    ### Note to self:
    ### items[page_curr] is the current choice to display
    ### it's a tuple of (caption, action, chosen)

    ### Python lists are 0-based
    default page_curr = 0
    default page_min = 0
    default page_max = len(items) -1
                        
    frame:
        xalign 0.5 yalign 0.5
        hbox:
        

            ### Simple textbuttons
            # textbutton "<" action [If(page_curr > page_min, [SetScreenVariable('page_curr', page_curr - 1)])]
            
            # if items[page_curr][1]:
            #    textbutton items[page_curr][0] action items[page_curr][1]
            #else:
            #    text items[page_curr][0]
                
            # textbutton ">" action [If(page_curr < page_max, [SetScreenVariable('page_curr', page_curr + 1)])]


            ### With imagebuttons
            ### Example: for caption "park", place thumbnail images are:
            ### "images/place_park_idle.png"
            ### "images/place_park_hover.png"
            ### etc.
            imagebutton auto "images/arrowl_%s.png" action [If(page_curr > page_min, [SetScreenVariable('page_curr', page_curr - 1)])]
            
            if items[page_curr][1]:
                imagebutton auto "images/place_" + items[page_curr][0] + "_%s.png" action items[page_curr][1]
            else:
                imagebutton auto "images/place_" + items[page_curr][0] + "_%s.png" action NullAction()

                
            imagebutton auto "images/arrowr_%s.png" action [If(page_curr < page_max, [SetScreenVariable('page_curr', page_curr + 1)])]


    ### Current caption
    frame:
        xalign 0.5 yalign 0.8
        text items[page_curr][0]
    
    ### To indicate page number
    frame:
        xalign 0.5 yalign 0.9
        text "Current Page: "+str(page_curr +1) # +1 because we like pages starting at 1

lyminh99
Regular
Posts: 38
Joined: Sat Jun 14, 2014 1:09 pm
Contact:

Re: Custom one more menu screen to display the place?

#4 Post by lyminh99 »

Thanks for your contribution, but there are definitely some problem:
- Can you call the screen out in the label? i have tried to test your code and use the call screen to call in the label start and it crashed i will give you the traceback below
- Is it possible to change the action event of caption file name in the progress of game? I want to change some events in the places, some will disappear in the next day if you didn't choose in the previous choices, if can't it will be just always the same event at one label.
- If i understand right, will all the places in the pool always display at the same time if i use your code? It will be a minor problem if i can change the label jump of the places though, but if it's possible i want it just appear in the meantime that place have a truly event, not some like " there is nothing i can do here " 's label.

Well, first of all i still have to run your screen on my machine though. :v
Attachments
traceback.txt
(1.43 KiB) Downloaded 62 times

User avatar
SinnyROM
Regular
Posts: 166
Joined: Mon Jul 08, 2013 12:25 am
Projects: Blue Birth
Organization: Cosmic Static Games
Contact:

Re: Custom one more menu screen to display the place?

#5 Post by SinnyROM »

From the traceback, you tried to call the screen choice from a label right? That implementation is only if you wanted to replace all menu choices with a place picker.

Code: Select all

label start:
    "Where to go?"

menu: # this will call the choice screen automatically 
    "park": # caption
        jump place_park
    "home":
        jump day_end

label place_park:
    "To the park!"

label day_end:
    "I'm tired, so I'll go home."
If you want to call the screen whenever you like from the script and have it sensitive to the game's events, use the places screen instead. You might have to define a global list that's similar to items to mimic the choice screen and pass it into places. Then when a place is no longer relevant you can remove it from the list.

EDIT: Updated the following code so it works:

Code: Select all

### script.rpy

# Variables
define energy = 100
define place_items = [ ("park", [SetVariable("energy", energy - 10), Jump("place1")]), ("home", Jump("place2")) ]

# The game starts here.
label start:
    jump place_select
    
label place_select:
    "I have [energy] energy."
    "Where should I go?"
    call place
    return
            
label place1:
    "Going to the park!"
    "I found a mysterious tunnel."

    # edit the place_items to remove park and add tunnel
    $ place_items = remove_place(place_items, "park")
    $ place_items = add_place(place_items, "tunnel", [SetVariable("energy", energy - 20), Jump("place3")])

    jump place_select
    
label place2:
    "I'm tired, let's go home."
    "I have [energy] energy."
    return
    
label place3:
    "Entering the tunnel - it's deeper than I thought..."
    jump place_select

Code: Select all

### screens.rpy (or places.rpy)

init python:

    # Add a place to the list
    def add_place(place_list, place_name, place_actions=[], index=0):
        #place_list.insert(index, (place_name, place_actions))  # adds it ot front of list by default
        place_list.append((place_name, place_actions))
        return place_list

    # Removes a place from the list by name
    # http://stackoverflow.com/a/22825938
    def remove_place(place_list, place_name):
        return filter(lambda x: x[0] != place_name, place_list)

label place:
    show screen places(place_items) 
    $ renpy.pause() # prevent seeing the next line

screen places(place_items):

    modal True

    ### Note to self:
    ### items[page_curr] is the current choice to display
    ### remember it's a tuple of (caption, action, chosen)

    ### Python lists are 0-based
    default page_curr = 0
    default page_min = 0
    default page_max = len(place_items) -1
                        
    frame:
        xalign 0.5 yalign 0.5
        hbox:
        
            ### Simple textbuttons
            # textbutton "<" action [If(page_curr > page_min, [SetScreenVariable('page_curr', page_curr - 1)])]
            
            # if items[page_curr][1]:
                # textbutton place_items[page_curr][0] action [Hide("places"), place_items[page_curr][1]]
            # else:
                # text place_items[page_curr][0]
                
            # textbutton ">" action [If(page_curr < page_max, [SetScreenVariable('page_curr', page_curr + 1)])]


            ### With imagebuttons
            ### Example: for caption "park", place thumbnail images are:
            ### "images/place_park_idle.png"
            ### "images/place_park_hover.png"
            ### etc.
            imagebutton auto "images/arrowl_%s.png" action [If(page_curr > page_min, [SetScreenVariable('page_curr', page_curr - 1)])]
            
            if place_items[page_curr][1]:
                imagebutton auto "images/place_" + place_items[page_curr][0] + "_%s.png" action [Hide("places"),place_items[page_curr][1]]
            else:
                imagebutton auto "images/place_" + place_items[page_curr][0] + "_%s.png" action NullAction()
                
            imagebutton auto "images/arrowr_%s.png" action [If(page_curr < page_max, [SetScreenVariable('page_curr', page_curr + 1)])]

    ### Current caption
    frame:
        xalign 0.5 yalign 0.8
        text place_items[page_curr][0]
    
    ### To indicate page number
    frame:
        xalign 0.5 yalign 0.9
        text "Current Page: "+str(page_curr +1) # +1 because we like pages starting at 1

lyminh99
Regular
Posts: 38
Joined: Sat Jun 14, 2014 1:09 pm
Contact:

Re: Custom one more menu screen to display the place?

#6 Post by lyminh99 »

Sorry, i'm too busy that can't check and test your code a few day ago, just now i have some free time to check it and it worked perfectly as i want at a rough way. Thank you very much for your hard work :).

The final thing i want to ask is can i add the effect transition like slide or dissolve to the images when we click the arrow? Just for more beautiful and animation though.

User avatar
SinnyROM
Regular
Posts: 166
Joined: Mon Jul 08, 2013 12:25 am
Projects: Blue Birth
Organization: Cosmic Static Games
Contact:

Re: Custom one more menu screen to display the place?

#7 Post by SinnyROM »

Glad it's working for you! I had to dig to find out how to perform transitions between the arrow buttons, but I found an action that does what you're looking for, in a way: With(transition).

But, these transitions deal with the entire screen, so using the slide transitions causes the arrows to move too! There's CropMove from the documentation that you can try, although I'm not sure entirely of how it works. Or maybe someone else would know a better way!

Here's the code for the full screen dissolve:

Code: Select all

            # Custom dissolve for 4 seconds
            imagebutton auto "images/arrowl_%s.png" action [If(page_curr > page_min, [SetScreenVariable('page_curr', page_curr - 1), With(Dissolve(4, alpha=True))])]

lyminh99
Regular
Posts: 38
Joined: Sat Jun 14, 2014 1:09 pm
Contact:

Re: Custom one more menu screen to display the place?

#8 Post by lyminh99 »

Ok thank you very much. :)

lyminh99
Regular
Posts: 38
Joined: Sat Jun 14, 2014 1:09 pm
Contact:

Re: Custom one more menu screen to display the place?

#9 Post by lyminh99 »

Ah, SinnyROM. Can you give a visit to this http://lemmasoft.renai.us/forums/viewto ... =8&t=32250 as well? I want to create the tooltip for the normal text choice one when we hovered the button. I think the idea is the caption of the item and one other screen have if statement with this caption's button to display a image or text for tooltip like "In this place, we have more dangerous things" when the button is hovered

Code: Select all

screen gui_tooltip:
    if (items button caption) hovered add my_picture xpos my_tt_xpos ypos my_tt_ypos
i saw your "current caption" in the above code may work the same way like the tooltips. So maybe i think you can solve this too.

Code: Select all

 ### Current caption
    frame:
        xalign 0.5 yalign 0.8
        text place_items[page_curr][0]

lyminh99
Regular
Posts: 38
Joined: Sat Jun 14, 2014 1:09 pm
Contact:

Re: Custom one more menu screen to display the place?

#10 Post by lyminh99 »

If i remove all the places it will cause the game crash. I'm just curious that if i can show an image with "there is no event, right now" that's look like the other button, just that there won't be any events happen .

I tried on the nullaction one by changing with another image link. Seem that won't work.

Code: Select all

if place_items[page_curr][1]:
                imagebutton auto "images/place_" + place_items[page_curr][0] + "_%s.png" action [Hide("places"),place_items[page_curr][1]]
            else:
                imagebutton auto "images/place_" + place_items[page_curr][0] + "_%s.png" action NullAction()

User avatar
SinnyROM
Regular
Posts: 166
Joined: Mon Jul 08, 2013 12:25 am
Projects: Blue Birth
Organization: Cosmic Static Games
Contact:

Re: Custom one more menu screen to display the place?

#11 Post by SinnyROM »

You can substitute the image in the button for the places with no action. You'll have to replace that place with the same one that has no actions, maybe using one of these methods? http://stackoverflow.com/questions/2582 ... ist-python

Code: Select all

if place_items[page_curr][1]:
                imagebutton auto "images/place_" + place_items[page_curr][0] + "_%s.png" action [Hide("places"),place_items[page_curr][1]]
            else:
                ### use no event image
                imagebutton auto "images/place_noevent_%s.png" action NullAction()

lyminh99
Regular
Posts: 38
Joined: Sat Jun 14, 2014 1:09 pm
Contact:

Re: [SOLVED] Custom one more menu screen to display the plac

#12 Post by lyminh99 »

Ok, all problem sovled :)), thanks

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Majestic-12 [Bot]