how to create personal gallery in Gallery menu (Solved)

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
salventus
Newbie
Posts: 20
Joined: Fri Jun 20, 2014 12:16 am
Contact:

how to create personal gallery in Gallery menu (Solved)

#1 Post by salventus »

so i copied this

Code: Select all

init python:
    
    gallery_cg_items = ["cg01"]

    gal_rows = 2
    gal_cols = 2

    thumbnail_x = 200
    thumbnail_y = 150
    
    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:

    for gal_item in gallery_cg_items:
        renpy.image (gal_item + " butt", im.Scale(ImageReference(gal_item), thumbnail_x, thumbnail_y))
        
screen cg_gallery:
    tag menu
    use navigation
    frame background None xpos 10:
        grid gal_rows gal_cols:
            ypos 10
            $ 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("gallocked.jpg", thumbnail_x, thumbnail_y), 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
        frame:
            yalign 0.97
            vbox:
                if len(gallery_cg_items)>gal_cells:
                    textbutton _("Next Page") action [SetVariable('cg_page', next_cg_page), ShowMenu("cg_gallery")]

and it works perfectly. but i only get one page gallery.
What should i add to the code to get a gallery with each label containing gallery of spesific character like this picture shown?
Attachments
testes.png
Last edited by salventus on Sun Jul 06, 2014 6:55 am, edited 1 time in total.

User avatar
kisa
Veteran
Posts: 384
Joined: Sat Aug 27, 2011 7:08 pm
Completed: Brother Rose, Dogs Alone
Projects: So many projects, I can't name them.
Deviantart: tsubasafan135
Skype: Discord: Kisaofbishies#6680
itch: kisa
Contact:

Re: how to create personal gallery in Gallery menu

#2 Post by kisa »

I don't have your answer. But, where did you copy it to? I'm curious for my own usage.
I'm offering commissions!
viewtopic.php?f=62&t=41656

User avatar
Zetsubou-kyoju
Newbie
Posts: 3
Joined: Sun Jun 22, 2014 4:13 pm
Contact:

Re: how to create personal gallery in Gallery menu

#3 Post by Zetsubou-kyoju »

Surely a condition and variables, but I'm also curious to find out how.

User avatar
Chaotic
Regular
Posts: 30
Joined: Fri Feb 22, 2013 7:32 pm
Location: England, UK
Contact:

Re: how to create personal gallery in Gallery menu

#4 Post by Chaotic »

Though I'm not entirely sure (since I've never made a gallery), maybe this would be of help:
http://www.renpy.org/doc/html/rooms.html#image-gallery

salventus
Newbie
Posts: 20
Joined: Fri Jun 20, 2014 12:16 am
Contact:

Re: how to create personal gallery in Gallery menu

#5 Post by salventus »

@kisa: i found that code from tutorial in ren'py cookbook. Check that out! :D
@zetsubou-kyoju: yeaah i'm also curious but haven't understand enough what variables i should input @_@
@chaotic: Thank you! :D im gonna check that out

User avatar
ArachneJericho
Regular
Posts: 196
Joined: Sun Jun 22, 2014 2:04 am
Projects: Kaguya Hime
Tumblr: mousedeerproductions
Location: Seattle, WA, USA
Contact:

Re: how to create personal gallery in Gallery menu

#6 Post by ArachneJericho »

I have been thinking about this.

Step 1: Encapsulate the gallery display code in a function that will accept a gallery object and list of gallery items. That's everything including the first frame: under screen cg_gallery.

Step 2: Create Gallery objects for each character, listing their backgrounds.

Step 3: Create separate gallery screens for each character, and use the function from Step 1.

Step 4: Create a character gallery navigation screen menu where each item's action switches to the character's screen, and use it in all the character gallery screens defined in step 3.

Alternatively, skip Step 1 and copy the code into each gallery screen defined in Step 3, but that seems not a good way to do things. Encapsulating things in functions requires calling special renpy methods inside a python block, and calling the function would require same.

I think I can get a working version of this but it will take a few hours tomorrow. It's an interesting problem to solve.


User avatar
ArachneJericho
Regular
Posts: 196
Joined: Sun Jun 22, 2014 2:04 am
Projects: Kaguya Hime
Tumblr: mousedeerproductions
Location: Seattle, WA, USA
Contact:

Re: how to create personal gallery in Gallery menu

#8 Post by ArachneJericho »

Zetsubou-kyoju wrote:Maybe this link could help: http://lemmasoft.renai.us/forums/viewto ... =8&t=15237
That does help! Sweet, I didn't know you could use a screen with parameters.

User avatar
ArachneJericho
Regular
Posts: 196
Joined: Sun Jun 22, 2014 2:04 am
Projects: Kaguya Hime
Tumblr: mousedeerproductions
Location: Seattle, WA, USA
Contact:

Re: how to create personal gallery in Gallery menu

#9 Post by ArachneJericho »

Required quite a bit of refactoring and moving code around. Here's the scaffolding of what I did.

There are two characters: White Rabbit, and Cheshire Cat. Gallery is 1x1 to easily test pagination.

Code: Select all

##############################################################################
# Character gallery
#
init:
    image cemetary = im.Image("images/cemetary.jpg")
    image livingroom = im.Image("images/living-room.jpg")
    image menua = im.Image("menu1.jpg")
    image menub = im.Image("menu2.jpg")

init python:
    class GalleryGroup:
        def __init__(self, items):
            self.gallery = Gallery()
            self.gallery.transition = fade

            self.page = 0

            self.items = items
            for gal_item in self.items:
                self.gallery.button(gal_item + " butt")
                self.gallery.condition("True")
                self.gallery.image(gal_item)

                renpy.image (gal_item + " butt", 
                             im.Scale(ImageReference(gal_item), 
                             thumbnail_x, thumbnail_y))

    gal_rows = 1
    gal_cols = 1

    thumbnail_x = 200
    thumbnail_y = 150
    
    gal_cells = gal_rows * gal_cols
    
    white_rabbit_gal = GalleryGroup(["cemetary", "livingroom"])
    cheshire_cat_gal = GalleryGroup(["menua", "menub"])
    
screen cg_gallery_template:
    frame background None xpos 10:
        grid gal_rows gal_cols:
            ypos 10
            $ i = 0
            $ cg_page = mygal.page
            $ next_cg_page = mygal.page + 1
            if next_cg_page > int(len(mygal.items)/gal_cells):
                $ next_cg_page = 0
            for gal_item in mygal.items:
                $ i += 1
                if i <= (cg_page+1)*gal_cells and i>cg_page*gal_cells:
                    add mygal.gallery.make_button(gal_item + " butt", gal_item + " butt", im.Scale("textbox.png", thumbnail_x, thumbnail_y), 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
        frame:
            yalign 0.80
            vbox:
                if len(mygal.items)>gal_cells:
                    textbutton _("Next Page") action [SetField(mygal, 'page', next_cg_page), ShowMenu(name)]

screen cg_gallery_menu:
    frame:
        yalign 0.70

        has hbox

        textbutton _("White Rabbit") action ShowMenu("white_rabbit_gallery")
        textbutton _("Cheshire Cat") action ShowMenu("cheshire_cat_gallery")

screen white_rabbit_gallery:
    tag menu
    use navigation
    use cg_gallery_menu
    use cg_gallery_template(name="white_rabbit_gallery", mygal=white_rabbit_gal)

screen cheshire_cat_gallery:
    tag menu
    use navigation
    use cg_gallery_menu
    use cg_gallery_template(name="cheshire_cat_gallery", mygal=cheshire_cat_gal)
And then somewhere in my main menu I had

Code: Select all

        textbutton _("CG Gallery") action ShowMenu("white_rabbit_gallery")
Attachments
screenshot0005.png

salventus
Newbie
Posts: 20
Joined: Fri Jun 20, 2014 12:16 am
Contact:

Re: how to create personal gallery in Gallery menu

#10 Post by salventus »

sorry for my late response ._.

@zetsubou-kyoju:
Thanks for the reference! will definitely check and try it.
@ArachneJericho:
Required quite a bit of refactoring and moving code around. Here's the scaffolding of what I did.

There are two characters: White Rabbit, and Cheshire Cat. Gallery is 1x1 to easily test pagination.
Thanks a bunch too for everything, especially for your effort on coding around! :D :D :D . First i need to understand your code then try it myself! :9

Post Reply

Who is online

Users browsing this forum: Google [Bot]