Ren'Py Code for gallery

Deleted member 609064

Well-Known Member
May 11, 2018
1,249
1,587
Sorry to reawaken an old thread. I used Rich's code to add a gallery, but I can't get the formatting for the gallery page correct. I haven't been able to determine what part of the code that I need to adjust to correct this. Can someone let me know how to make this adjustment? Thanks in advance.

View attachment 619575
You should tag Rich if you're hoping to get his attention. :)
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,355
15,268
Can someone let me know how to make this adjustment? Thanks in advance.
Without the code it's difficult, but it's still possible to make a guess.

The game menus are tricky, because they use the "game_menu" screen which end being partly responsible of the whole style. Therefore, if the problem is also visible in the other menus (save, load, ...), then the culprit is the "game_menu_navigation_frame" style and its xsize property, that don't let enough place for your own content.
 
  • Like
Reactions: lydcreations

lydcreations

Member
Game Developer
May 6, 2019
300
403
Without the code it's difficult, but it's still possible to make a guess.

The game menus are tricky, because they use the "game_menu" screen which end being partly responsible of the whole style. Therefore, if the problem is also visible in the other menus (save, load, ...), then the culprit is the "game_menu_navigation_frame" style and its xsize property, that don't let enough place for your own content.

Thanks for your feedback. I'll take a look at the game menu then. I wasn't sure what parts of the code would be helpful. I include my adjusted version of the 3 parts that Rich posted. I could well have messed something up as I'm still getting the hang of how the code works.

Code:
init python:
    def gallery_thumbnail(thumbnail_name):
        return im.FactorScale(thumbnail_name, 0.2)

    image_gallery = Gallery()
    image_gallery.transition = dissolve
    image_gallery.locked_button = "gallery_locked_button"

    image_gallery.button("slot01")
    image_gallery.condition('renpy.seen_image("art studio pose3")')
    image_gallery.unlock_image("art studio pose1")
    image_gallery.unlock_image("art studio pose2")
    image_gallery.unlock_image("art studio pose2a")
    image_gallery.unlock_image("art studio pose3")

    image_gallery.button("slot02")
    image_gallery.condition('renpy.seen_image("art studio1")')
    image_gallery.unlock_image("art studio pose4")
    image_gallery.unlock_image("art studio pose5")
    image_gallery.unlock_image("art studio pose7")
    image_gallery.unlock_image("art studio1")

    image_gallery.button("slot03")
    image_gallery.condition('renpy.seen_image("art studio1")')
    image_gallery.unlock_image("art studio pose4")
    image_gallery.unlock_image("art studio pose5")
    image_gallery.unlock_image("art studio pose7")
    image_gallery.unlock_image("art studio1")

    image_gallery.button("slot04")
    image_gallery.condition('renpy.seen_image("art studio1")')
    image_gallery.unlock_image("art studio pose4")
    image_gallery.unlock_image("art studio pose5")
    image_gallery.unlock_image("art studio pose7")
    image_gallery.unlock_image("art studio1")

    image_gallery.button("slot05")
    image_gallery.condition('renpy.seen_image("art studio1")')
    image_gallery.unlock_image("art studio pose4")
    image_gallery.unlock_image("art studio pose5")
    image_gallery.unlock_image("art studio pose7")
    image_gallery.unlock_image("art studio1")

    image_gallery.button("slot06")
    image_gallery.condition('renpy.seen_image("art studio1")')
    image_gallery.unlock_image("art studio pose4")
    image_gallery.unlock_image("art studio pose5")
    image_gallery.unlock_image("art studio pose7")
    image_gallery.unlock_image("art studio1")


    image_gallery_buttons_pages = [
        [
            ( "slot01", "Ch 1: Brad and Emily",     "art studio pose1.jpg" ),
            ( "slot02", "Ch 1: Parker and Becky",   "art studio pose4.jpg" ),
            ( "slot03", "Ch 2: Melanie\u2019s Bra", "art studio pose4.jpg" ),
            ( "slot04", "Ch 2: Melissa Downblouse", "art studio pose4.jpg" ),
            ( "slot05", "Ch 2: License Grab",       "art studio pose4.jpg" ),
            ( "slot06", "Ch 2: The Search, Part 1", "art studio pose4.jpg" )
        ],

    ]


screen gallery_buttons(data):
    for (name, title, thumbnail) in data:
        if name:
            vbox:
                $ the_button = image_gallery.make_button(name, gallery_thumbnail(thumbnail))
                add the_button
                if image_gallery.buttons[name].check_unlock():
                    text title
                else:
                    text ""
        else:
            text ""

screen gallery():
    default page = 1
    tag menu

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

        style_prefix "gallery"

        vbox:
            xsize 940
            ysize 500
            label "Page [page]":
                xalign 0.5
                bottom_margin 10

            grid 3 2:
                style_prefix "gallery_slot"

                xalign 0.5
                yalign 0.5

                xspacing 30
                yspacing 20

                use gallery_buttons(image_gallery_buttons_pages[page-1])

            hbox:
                style_prefix "page"

                anchor (0.5, 0.0)
                pos(0.5, 1.0)

                spacing gui.page_spacing

                if page > 1:
                    textbutton _("<") action SetScreenVariable("page", page - 1)
                else:
                    textbutton  _("<") action NullAction()

                for i in range(1, len(image_gallery_buttons_pages) + 1):
                    textbutton "[i]" action SetScreenVariable("page", i)

                if page < len(image_gallery_buttons_pages):
                    textbutton _(">") action SetScreenVariable("page", page + 1)
                else:
                    textbutton  _(">") action NullAction()

style gallery_slot_text:
    size 18
    xalign 0.5
    yalign 0.0

style gallery_button is button:
    hover_background "#fff"

style gallery_button_text:
    size 24
    bold True
    color "#fff"
    hover_color "#000"
    underline True

style gallery_button_current is button
style gallery_button_current_text is gallery_button_text:
    underline False
    hover_color "#fff"
 

lydcreations

Member
Game Developer
May 6, 2019
300
403
Rich
Not a bit - I've learned a lot by "snooping" on the code of others, so I can hardly complain...

My gallery is in two parts. In the first part, I set up a bunch of "slots" (my name for it) using PyTom's code:

Code:
init python:
    def gallery_thumbnail(thumbnail_name):
        return im.FactorScale(thumbnail_name, 0.2)

    image_gallery = Gallery()
    image_gallery.transition = dissolve
    image_gallery.locked_button = "gallery_locked_button"

    image_gallery.button("slot01")
    image_gallery.condition('renpy.seen_image("ch0b_12")')
    image_gallery.unlock_image("ch0b_09")
    image_gallery.unlock_image("ch0b_10")
    image_gallery.unlock_image("ch0b_11_movie")
    image_gallery.unlock_image("ch0b_12")

    image_gallery.button("slot02")
    image_gallery.condition('renpy.seen_image("ch0d_27")')
    image_gallery.unlock_image("ch0d_24")
    image_gallery.unlock_image("ch0d_25")
    image_gallery.unlock_image("ch0d_26_movie")
    image_gallery.unlock_image("ch0d_27")
The "condition" specifies what has to have happened for this particular gallery slot to be unlocked. All those "ch0d_27" type things are image names of mine.

If you just want them all unlocked without having to do anything, you can probably just omit that. Or maybe use
Code:
image_gallery.condition('True')
The "unlock_image" part basically tells Renpy to go ahead and show that image. As you can see, you can put a sequence of images into the gallery button.

The next part is that I set up a Python object that configured each page of my gallery. (This is still inside the Python block above):

Code:
    image_gallery_buttons_pages = [
        [
            ( "slot01", "Ch 1: Brad and Emily",     "ch0b/ch0b_09.jpg" ),
            ( "slot02", "Ch 1: Parker and Becky",   "ch0d/ch0d_24.jpg" ),
            ( "slot03", "Ch 2: Melanie\u2019s Bra", "ch1a/ch1a_03.jpg" ),
            ( "slot04", "Ch 2: Melissa Downblouse", "ch1b/ch1b_09.jpg" ),
            ( "slot05", "Ch 2: License Grab",       "ch1c/ch1c_16_0.jpg" ),
            ( "slot06", "Ch 2: The Search, Part 1", "ch1e/ch1e_09a.jpg" )
        ],
        [
            ( "slot07", "Ch 2: The Search, Part 2", "ch1e/ch1e_15.jpg" ),
            ( "slot08", "Ch 2: The Search, Part 3", "ch1e/ch1e_19a.jpg" ),
            ( "slot09", "Ch 2: The Search, Part 4", "animations/ch1e_25_00.jpg" ),
            ( "slot10", "Ch 3: A revealing time",   "ch3a/ch3a_06.jpg" ),
            ( "slot11", "Ch 3: Let\u2019s have the top", "ch3c/ch3c_07.jpg" ),
            ( "slot12", "Ch 3: And the rest",       "ch3c/ch3c_27.jpg" ),
        ],
        [
            ( "slot13", "Ch 3: Exposed",             "ch3c/ch3c_32.jpg" ),
            ( "slot14", "Ch 3: Full Search, Part 1", "ch3c/ch3c_37.jpg" ),
            ( "slot15", "Ch 3: Full Search, Part 2", "ch3c/ch3c_40.jpg" ),
            ( "slot16", "Ch 3: Dressing",           "ch3c/ch3c_46.jpg" ),
            ( "slot17", "Ch 3: Tits are tits",      "ch3d/ch3d_17.jpg" ),
            ( None,     None,                       None)
        ]
    ]
For those of you not horribly Pythonista, image_gallery_buttons_pages is an array. It has three members, each of which are also arrays, and which correspond to the gallery pages themselves. Each of those arrays contains 6 tuples (the parts in parentheses), in which the first element is the slot name, the second is the title for the gallery button and the third is the thumbnail image for the gallery button. The code requires there to be six tuples in each page, but if the buttons don't come out evenly with the number of pages, you just put None's in, as you can see for the last one.

Finally, there's the gallery screen itself:
Code:
screen gallery_buttons(data):
    for (name, title, thumbnail) in data:
        if name:
            vbox:
                $ the_button = image_gallery.make_button(name, gallery_thumbnail(thumbnail))
                add the_button
                if image_gallery.buttons[name].check_unlock():
                    text title
                else:
                    text ""
        else:
            text ""

screen gallery():
    default page = 1
    tag menu

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

        style_prefix "gallery"

        vbox:
            xsize 940
            ysize 500
            label "Page [page]":
                xalign 0.5
                bottom_margin 10

            grid 3 2:
                style_prefix "gallery_slot"

                xalign 0.5
                yalign 0.5

                xspacing 30
                yspacing 20

                use gallery_buttons(image_gallery_buttons_pages[page-1])

            hbox:
                style_prefix "page"

                anchor (0.5, 0.0)
                pos(0.5, 1.0)

                spacing gui.page_spacing

                if page > 1:
                    textbutton _("<") action SetScreenVariable("page", page - 1)
                else:
                    textbutton  _("<") action NullAction()

                for i in range(1, len(image_gallery_buttons_pages) + 1):
                    textbutton "[i]" action SetScreenVariable("page", i)

                if page < len(image_gallery_buttons_pages):
                    textbutton _(">") action SetScreenVariable("page", page + 1)
                else:
                    textbutton  _(">") action NullAction()

style gallery_slot_text:
    size 18
    xalign 0.5
    yalign 0.0

style gallery_button is button:
    hover_background "#fff"

style gallery_button_text:
    size 24
    bold True
    color "#fff"
    hover_color "#000"
    underline True

style gallery_button_current is button
style gallery_button_current_text is gallery_button_text:
    underline False
    hover_color "#fff"
gallery_buttons is a "subscreen" that will format the stuff for a single gallery button, then gallery represents the gallery screen itself, and implements the pagination and outputs the gallery buttons based on the data in image_gallery_buttons_pages.

So, there's your sample code. Adapt as you see fit. :)
Not sure how to tag someone as was suggested so that Rich would see this post, so I used the quote. Thanks for the gallery code Rich. I've tried using it with some adjustments to adapt it to my game. My version has a few issues such as formatting and it doesn't show the new background. A screen shot of the issues below and I posted the code above. If you get a chance to look at it, I would appreciate your guidance. Thanks.

gallery.png