Ren'Py Need help with a Ren'Py gallery function for my game.

Soft Whisper

Member
Game Developer
Apr 9, 2023
171
492
So I'm trying to expand the gallery feature from this asset pack ( ), but I lack the coding know-how. I was able to create multiple pages that allow the user to view more than 6 images, but I can't figure out how to keep the page number buttons highlighted when selected (like in the load or save screen). Atm the gallery.rpy looks like this and I'm missing a way to tell Ren'py the page # is selected... Any help would be appreciated.
Code:
# Instant CG and BG Gallery by Leon: https://lemmasoft.renai.us/forums/viewtopic.php?f=51&t=22465

init python:
    #list the CG gallery images here:
    gallery_thumbnails = []

    gal_rows = 3
    gal_cols = 2

    #Thumbnail size in pixels:
    thumbnail_x = 328
    thumbnail_y = 185

    gal_cells = gal_rows * gal_cols
    g_cg = Gallery()

    if not gallery.variable_mode:
        for gal_item in gallery.items:
            if (isinstance(gal_item, list)):
                gallery_thumbnails.append(gal_item[0])
                g_cg.button(gal_item[0] + " butt")

                if gallery.strict_multiple:
                    g_cg.unlock_image(*gal_item)

                else:
                    for item in gal_item:
                        g_cg.unlock_image(item)

            else:
                gallery_thumbnails.append(gal_item)
                g_cg.button(gal_item + " butt")
                g_cg.unlock_image(gal_item)
    else:
        for gal_item in gallery.items:
            if (isinstance(gal_item["image"], list)):
                gallery_thumbnails.append(gal_item["image"][0])
                g_cg.button(gal_item["image"][0] + " butt")
                g_cg.condition(gal_item["variable"])

                for item in gal_item["image"]:
                    g_cg.image(item)

            else:
                gallery_thumbnails.append(gal_item["image"])
                g_cg.button(gal_item["image"] + " butt")
                g_cg.condition(gal_item["variable"])
                g_cg.image(gal_item["image"])

    g_cg.transition = fade
    cg_page=0

init +1 python:
    #Here we create the thumbnails.
    for gal_item in gallery_thumbnails:
        renpy.image (gal_item + " butt", im.Scale(ImageReference(gal_item), thumbnail_x, thumbnail_y))

screen auto_gallery():

    tag menu
    use game_menu(_("Gallery")):
        $ current_num = cg_page + 1

        fixed:
            xpos -170
            if (len(gallery_thumbnails)>gal_cells):
                text "Page {}".format(current_num):
                    ypos 65
                    xalign 0.5
                    style "page_label_text"

            frame background None:
                xalign 0.5
                yalign 0.5
                grid gal_rows gal_cols:
                    xalign 0.5
                    yalign 0.5
                    spacing gui.slot_spacing

                    $ i = 0
                    $ next_cg_page = cg_page + 1
                    $ prev_cg_page = cg_page -1
                    if next_cg_page > int(len(gallery_thumbnails)/gal_cells):
                        $ next_cg_page = 0

                    elif prev_cg_page == -1:
                        $ prev_cg_page = 0

                    for gal_item in gallery_thumbnails:
                        $ i += 1
                        if i <= (cg_page+1)*gal_cells and i>cg_page*gal_cells:
                            add g_cg.make_button(gal_item + " butt", gal_item + " butt","gui/gallery/locked.png", xalign=0.5, yalign=0.5, idle_border=None, background=None, bottom_margin=24)
                    for j in range(i, (cg_page+1)*gal_cells): #we need this to fully fill the grid
                        null

                if (len(gallery_thumbnails)>gal_cells):
                    $ pages = ((len(gallery_thumbnails)) // gal_cells) + 1

                    hbox:
                        style_prefix "page"

                        xalign 0.5
                        yalign 0.98

                        spacing gui.page_spacing

                        imagebutton:
                            auto "gui/gallery/page_number_%s.png"
                            foreground Text(_("<"),style="pg_num_idle")
                            hover_foreground Text(_("<"),style="pg_num_hover")
                            insensitive_foreground Text(_("<"),style="pg_num_insensitive")
                            action [SetVariable('cg_page', prev_cg_page), ShowMenu("auto_gallery")]
                            sensitive cg_page != 0

                        for num in range(pages):
                            $ display_num = num + 1
                            imagebutton:
                                auto "gui/gallery/page_number_%s.png"
                                foreground Text(_("{}".format(display_num)), style="pg_num_idle")
                                hover_foreground Text(_("{}".format(display_num)), style="pg_num_hover")
                                action [SetVariable('cg_page', num), ShowMenu("auto_gallery")]

                        imagebutton:
                            auto "gui/gallery/page_number_%s.png"
                            foreground Text(_(">"),style="pg_num_idle")
                            hover_foreground Text(_(">"),style="pg_num_hover")
                            insensitive_foreground Text(_(">"),style="pg_num_insensitive")
                            action [SetVariable('cg_page', next_cg_page), ShowMenu("auto_gallery")]
                            sensitive cg_page != pages-1
More specifically, I believe my problem lies somewhere in here:

Code:
                        for num in range(pages):
                            $display_num = num + 1
                            imagebutton:
                                auto "gui/gallery/page_number_%s.png"
                                foreground Text(_("{}".format(display_num)), style="pg_num_idle")
                                hover_foreground Text(_("{}".format(display_num)), style="pg_num_hover")
                                action [SetVariable('cg_page', num), ShowMenu("auto_gallery")]
I've been trying to add something like:

Code:
selected_idle_foreground Text(_("{}".format(display_num)), style="pg_num_hover")
... To that section, but I'm getting errors anytime I try to guess what Ren'Py wants there. I don't have the programming experience for complex stuff like this.
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,979
16,236
but I can't figure out how to keep the page number buttons highlighted when selected (like in the load or save screen).
Too hot for long explanation, the code should be explicit enough.

Python:
                        for num in range(pages):
                            $display_num = num + 1
                            imagebutton:
# <---
                                if current_num == display_num:
                                    auto "gui/gallery/page_number_selected_%s.png"
                                else:
                                    auto "gui/gallery/page_number_%s.png"
# --->
                                foreground Text(_("{}".format(display_num)), style="pg_num_idle")
                                hover_foreground Text(_("{}".format(display_num)), style="pg_num_hover")
                                action [SetVariable('cg_page', num), ShowMenu("auto_gallery")]
 
  • Like
Reactions: osanaiko

Soft Whisper

Member
Game Developer
Apr 9, 2023
171
492
Thanks for the help, but because of this line:
Code:
 $display_num = num + 1
... it doesn't match the if condition. (display_num is always +1 than current_num)
It still doesn't work if I manually type (hard-coded) "hover/idle/selected" for *.png.
Code:
                                hover "gui/gallery/page_number_hover.png"
                                idle "gui/gallery/page_number_idle.png"
                                selected "gui/gallery/page_number_hover.png"
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,979
16,236
Thanks for the help, but because of this line:
Code:
 $display_num = num + 1
... it doesn't match the if condition. (display_num is always +1 than current_num)
Let's say that it's because it was a very hot day, and that you aren't seriously confusing num, that come from the for loop used to display the different page numbers, with current_num set at the start of the screen and that contain the number of the current page...
 

Soft Whisper

Member
Game Developer
Apr 9, 2023
171
492
Ah, I got confused. Added your code successfully, but the page buttons are permanently highlighted in the gallery now. There are no errors this time, but I can't see the actual numbers anymore. Should I try uploading the entire rounded gui kit for reference? This one .rpy file might not be enough to figure out what's going on here.

 
Last edited:

Soft Whisper

Member
Game Developer
Apr 9, 2023
171
492
Perhaps someone else can take a look? If it's not too much trouble... I dont see me solving this on my own.
 

The Absent

Newbie
Game Developer
May 7, 2022
25
24
Perhaps someone else can take a look? If it's not too much trouble... I dont see me solving this on my own.
Try this:

Python:
imagebutton:
    auto "gui/gallery/page_number_%s.png"
    selected_idle "gui/gallery/page_number_hover.png"
    selected_hover "gui/gallery/page_number_hover.png"
    foreground Text(_("{}".format(display_num)), style="pg_num_idle")
    hover_foreground Text(_("{}".format(display_num)), style="pg_num_hover")
    selected_idle_foreground Text(_("{}".format(display_num)), style="pg_num_hover")
    action SelectedIf(SetVariable('cg_page', num)), ShowMenu("auto_gallery")
 
  • Like
Reactions: Soft Whisper