Gallery code

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
Bakaiju
Newbie
Posts: 1
Joined: Sun May 19, 2019 2:21 pm
Deviantart: Baka2niisan
Contact:

Gallery code

#1 Post by Bakaiju » Sun May 19, 2019 2:43 pm

Hi there. I've been trying over and over again, with many many different solutions that ended in failures for my gallery to get unlocked once the game is over.
I first tried with a boolean but not working, then I copy pasted codes that worked with some people but not for me. And yet, the only thing that changes are just the number of pictures.
I keep trying, the different solutions proposed to me via the Renpy Discord didn't work either.
I tested with the delete persistent but nothing changed.

Here's my code.

Code: Select all

#Galleries:
init python:
    #Galleries settings - start
    #list the CG gallery images here:
    gallery_cg_items = ["bg sc01", "bg sc02", "bg sc03", "bg sc04", "bg sc05", "bg sc06", "bg sc07", "bg sc08", "bg sc09", "bg sc10", "bg sc11", "bg sc12", "bg sc13", "bg sc14", "bg sc15", "bg sc16", "bg sc17", "bg sc18", "bg sc19", "bg sc20", "bg sc21", "bg sc22", "bg sc23", "bg sc24", "bg sc25"]
    #how many rows and columns in the gallery screens?
    gal_rows = 3
    gal_cols = 3
    #thumbnail size in pixels:
    thumbnail_x = 192
    thumbnail_y = 108
    #the setting above (267x150) will work well with 16:9 screen ratio. Make sure to adjust it, if your are using 4:3 or something else.
    #Galleries settings - end
    
    gal_cells = gal_rows * gal_cols    
    g_cg = Gallery()
    for gal_item in gallery_cg_items:
        g_cg.button(gal_item + " butt")
        g_cg.image(gal_item)
        g_cg.unlock(gal_item)
    g_cg.transition = fade
    cg_page=0

    
init +1 python:
    renpy.image ("bg sc01 butt", im.Scale("bg_encounter1.jpg", thumbnail_x, thumbnail_y))
    renpy.image ("bg sc02 butt", im.Scale("bg_encounter2.jpg", thumbnail_x, thumbnail_y))
    renpy.image ("bg sc03 butt", im.Scale("bg_Dragon.jpg", thumbnail_x, thumbnail_y))
    renpy.image ("bg sc04 butt", im.Scale("bg_Fight3.jpg", thumbnail_x, thumbnail_y))
    renpy.image ("bg sc05 butt", im.Scale("bg_Fight4.jpg", thumbnail_x, thumbnail_y))
    renpy.image ("bg sc06 butt", im.Scale("bg_What.jpg", thumbnail_x, thumbnail_y))
    renpy.image ("bg sc07 butt", im.Scale("bg_backstory1.jpg", thumbnail_x, thumbnail_y))
    renpy.image ("bg sc08 butt", im.Scale("bg_backstory2.jpg", thumbnail_x, thumbnail_y))
    renpy.image ("bg sc09 butt", im.Scale("bg_realstory1.jpg", thumbnail_x, thumbnail_y))
    renpy.image ("bg sc10 butt", im.Scale("bg_realstory2.jpg", thumbnail_x, thumbnail_y))
    renpy.image ("bg sc11 butt", im.Scale("bg_realstory3.jpg", thumbnail_x, thumbnail_y))
    renpy.image ("bg sc12 butt", im.Scale("bg_realstory4.jpg", thumbnail_x, thumbnail_y))
    renpy.image ("bg sc13 butt", im.Scale("bg_realstory5.jpg", thumbnail_x, thumbnail_y))
    renpy.image ("bg sc14 butt", im.Scale("bg_realstory6.jpg", thumbnail_x, thumbnail_y))
    renpy.image ("bg sc15 butt", im.Scale("bg_First.jpg", thumbnail_x, thumbnail_y))
    renpy.image ("bg sc16 butt", im.Scale("bg_smallchild.jpg", thumbnail_x, thumbnail_y))
    renpy.image ("bg sc17 butt", im.Scale("bg_refug.jpg", thumbnail_x, thumbnail_y))
    renpy.image ("bg sc18 butt", im.Scale("bg_antihero.jpg", thumbnail_x, thumbnail_y))
    renpy.image ("bg sc19 butt", im.Scale("bg_alliance.jpg", thumbnail_x, thumbnail_y))
    renpy.image ("bg sc20 butt", im.Scale("bg_finalbattle.jpg", thumbnail_x, thumbnail_y))
    renpy.image ("bg sc21 butt", im.Scale("bg_finale.jpg", thumbnail_x, thumbnail_y))
    renpy.image ("bg sc22 butt", im.Scale("bg_end.jpg", thumbnail_x, thumbnail_y))
    renpy.image ("bg sc23 butt", im.Scale("bg_castle.jpg", thumbnail_x, thumbnail_y))
    renpy.image ("bg sc24 butt", im.Scale("bg_throneroom.jpg", thumbnail_x, thumbnail_y))
    renpy.image ("bg sc25 butt", im.Scale("bg_balcony.jpg", thumbnail_x, thumbnail_y))
    
   
        
screen cg_gallery:
     tag menu
     use game_menu(_("Image Gallery"), scroll="viewport"):
        hbox:
            grid gal_cols gal_rows:
                spacing 35
                $ i = 0
                $ next_cg_page = cg_page + 1            
                if next_cg_page > int(len(gallery_cg_items)/gal_cells):
                    $ next_cg_page = 0
                for gal_item in gallery_cg_items:
                    $ 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", im.Scale("lock.png", thumbnail_x, thumbnail_y), xalign=0.5, yalign=0.5, idle_border=None, background=None, bottom_margin=0)
                for j in range(i, (cg_page+1)*gal_cells): #we need this to fully fill the grid
                    null
            frame:
                xpos 35
                ypos 455
                if len(gallery_cg_items)>gal_cells:
                    textbutton _("Next Page") action [SetVariable('cg_page', next_cg_page), ShowMenu("cg_gallery")] 
With this code, the gallery is locked forever. No matter how many times I finish the game.
I know when I put # in front of this line g_cg.unlock(gal_item), the gallery is unlocked forever.

I need help, I'm at wit's end.

Please help me

User avatar
Remix
Eileen-Class Veteran
Posts: 1307
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Gallery code

#2 Post by Remix » Sun May 19, 2019 2:59 pm

Bakaiju wrote:
Sun May 19, 2019 2:43 pm
I know when I put # in front of this line g_cg.unlock(gal_item), the gallery is unlocked forever.
?? Huh ??
When you comment that out it is unlocked?
So, when g_cg.unlocked is Not being called on each item, it unlocks them and when it IS being called it locks them?

Anyway, presuming you meant the other way around and that unlock() method actually works...

First:
Remove that from your current code (or comment it out)

Second:
In the label at the end of your game, add a small python bit to do the same

Code: Select all

label end_of_game:

    "That's All Folks. Hope you had fun"
    
    python:
        for gal_item in gallery_cg_items:
            # renpy.notify( "Unlocking : {}".format(gal_item) ) # uncomment to check it runs
            g_cg.unlock(gal_item)
            
    return # the game ends here
Mad Scientist Todo List:
  • Finish Improved Event Handler
  • Implement DragonBones animation as a Creator Defined Container
  • Develop Cartoon Speech Bubble dialogue
  • Finish Bitmask collision and rebound vector system
  • Develop time based building mechanic
  • Others
  • *Find a superb artist and actually write a game*

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 2690
Joined: Mon Dec 14, 2015 5:05 am
Location: Your monitor
Contact:

Re: Gallery code

#3 Post by Imperf3kt » Sun May 19, 2019 6:37 pm

Here's an alternative CG gallery, hastily modified on my phone from a project I just happened to have a copy of on hand.

Code: Select all

####################

## Gallery screen ##

####################

image cg_01 = "images/backgrounds/cg01.png"

image cg_02 = "images/backgrounds/cg02.png"

image cg_01_thumb = im.Scale("images/cg01.png", 468, 266, bilinear=True)

image cg_02_thumb = im.Scale("images/cg02.png", 468, 266, bilinear=True)

image gal_locked = "gui/locked.png"


init python:

    g = Gallery()


    g.button("cg_1")

    g.unlock_image("cg_01")

    g.transition = dissolve


    g.button("cg_2")

    g.unlock_image("cg_02")

    g.transition = dissolve


screen cg():


    tag menu


    use gallery(_("CG Gallery"))



screen cg2():


    tag menu


    use gallery(_("CG Gallery"))




screen gallery(title):

   

    add gui.gallery_menu_background

    hbox:

        xpos 980

        ypos 126

        spacing 35

       

        imagebutton:

            idle "gui/01_idle.png" 

            hover "gui/01_hover.png"

            selected "gui/01_hover.png"

            action ShowMenu("cg")


        imagebutton:

            idle "gui/02_idle.png" 

            hover "gui/02_hover.png"

            selected "gui/02_hover.png"

            action ShowMenu("cg2")

   

    fixed:

        xmaximum 1060

        ymaximum 660

        xpos 475

        ypos 280

        xfill True

        yfill True

        spacing 25


    vpgrid:

            cols 2

            xalign 0.5

            xfill True

            yfill True

            draggable False

            spacing 5


            if renpy.get_screen("cg"):


                add g.make_button("cg_1", "cg_01_thumb", "gal_locked", xalign=0.5, yalign=0.5)

                add g.make_button("cg_1", "cg_01_thumb", "gal_locked", xalign=0.5, yalign=0.5)

                add g.make_button("cg_1", "cg_01_thumb", "gal_locked", xalign=0.5, yalign=0.5)

                add g.make_button("cg_1", "cg_01_thumb", "gal_locked", xalign=0.5, yalign=0.5)


            if renpy.get_screen("cg2"):


                add g.make_button("cg_2", "cg_02_thumb", "gal_locked", xalign=0.5, yalign=0.5)

                add g.make_button("cg_2", "cg_02_thumb", "gal_locked", xalign=0.5, yalign=0.5)

                add g.make_button("cg_2", "cg_02_thumb", "gal_locked", xalign=0.5, yalign=0.5)

                add g.make_button("cg_2", "cg_02_thumb", "gal_locked", xalign=0.5, yalign=0.5)

    fixed:

        xpos 120

        ypos 980


        imagebutton:

            idle "gui/return_idle.png"

            hover "gui/return_hover.png"

            action Return()

This will require several images to use though, as the navigation is manual.

You'll also need to add

Code: Select all

define gui.gallery_menu_background = "some_image.jpg"
To gui.rpy, as this gallery uses a custom screen.

To access the gallery, a textbutton with action ShowMenu("cg") is all that is required.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Todo list:
Actually finish a project

Post Reply

Who is online

Users browsing this forum: No registered users