Character Gallery based on "Help"

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Post Reply
Message
Author
trajano
Regular
Posts: 60
Joined: Sun Jun 16, 2019 7:59 pm
Github: trajano
Contact:

Character Gallery based on "Help"

#1 Post by trajano » Sun Jun 16, 2019 8:12 pm

This cookbook entry assumes you know how to make a basic gallery as noted in https://www.renpy.org/doc/html/rooms.ht ... ry#Gallery

i.e. you understand

Code: Select all

init python:

    # Step 1. Create the gallery object.
    g = Gallery()

    # Step 2. Add buttons and images to the gallery.

    # A button with an image that is always unlocked.
    g.button("coulson shooting")
    g.image("coulson shooting")
This takes a copy of the "Help" screens from the default RenPy project and converts into a Character Gallery, where instead of the devices, we specify the character names. I start out with a new file called `gallery.rpy`(this should look familiar to the help() screen in screens.rpy)

Code: Select all

screen gallery:

    tag menu

    default character = "coulson"

    use game_menu(_("Gallery"), scroll="viewport"):

        style_prefix "character_gallery"

        vbox:
            spacing 23

            hbox:

### CHANGE THIS TO MATCH WHAT YOU NEED 

                textbutton _("Phil Coulson") action SetScreenVariable("character", "coulson")
                textbutton _("Agent May") action SetScreenVariable("character", "may")
                textbutton _("Daisy") action SetScreenVariable("character", "daisy")

            if character == "coulson":
                use gallery_coulson
            elif character == "may":
                use gallery_may
            elif character == "daisy":
                use gallery_daisy

### CHANGE THIS TO MATCH WHAT YOU NEED END

style character_gallery_button is gui_button
style character_gallery_button_text is gui_button_text
style character_gallery_label is gui_label
style character_gallery_label_text is gui_label_text
style character_gallery_text is gui_text

style character_gallery_button:
    properties gui.button_properties("character_gallery_button")
    xmargin 12

style character_gallery_button_text:
    properties gui.button_text_properties("character_gallery_button")

style character_gallery_label:
    xsize 375
    right_padding 30

style character_gallery_label_text:
    size gui.text_size
    xalign 1.0
    text_align 1.0

For each gallery use this as an example

Code: Select all

screen gallery_coulson():
    style_prefix "character_gallery"

### ADJUST THIS GRID ACCORDING TO THE AMOUNT OF ROWS YOU WANT
    grid 3 1:

        xfill True

        # Call make_button to show a particular button.
        add g.make_button("coulson shooting", "coulson shooting thumbnail", xalign=0.5, yalign=0.5)
        add g.make_button("coulson riding lola", "coulson riding lola thumbnail", xalign=0.5, yalign=0.5)
        null

To have a proper sized thumbnail, use the following technique so you don't need to resize your image.

Code: Select all

image coulson shooting thumbnail: 
     "coulson shooting"
     zoom 0.2

Post Reply

Who is online

Users browsing this forum: No registered users