Page 7 of 11

Re: Instant CG and BG gallery

Posted: Sun Jun 22, 2014 12:52 pm
by leon
Maybe changing the border image, so that it has a bit of transparent area on the left would fix it?

Re: Instant CG and BG gallery

Posted: Thu Jun 26, 2014 4:10 am
by salventus
The error indicates that "bg cave" and "bg meadow" images aren't defined. Double check for typos and try adding "init" in front of the image definition. You can also download the code and first get that to work with your images, then work from there.
it works! Thank you! :D

ohyeah, i still don't understand how to separate a gallery for each character like in this picture.

if i wanna add like this, what variable do i need to input or add in the instant code of CG/BG gallery?

Re: Instant CG and BG gallery

Posted: Sun Jul 06, 2014 4:09 pm
by leon
Sorry for the late reply.

If you mean a CG gallery for each character:
leon wrote:Just create a gallery for each character. The example has galleries for CGs and BGs, which are essentially the same, so just copy that for each character.

For the character selection you'll want to create a special screen with character names (you can show this screen on it's own or include it into other screens using "use"). To make the buttons there are many ways - Button, Imagebutton, Textbutton and Imagemap. Check out the Screen Language documentation.
But if you mean a character sprite gallery, you are probably better off using the Gallery class directly. because:
leon wrote:I haven't included a character gallery, because sprites usually include many variations/expressions, they come in different sizes and they require an extra background, so a simple copy/pastable solution wouldn't work that well.

Re: Instant CG and BG gallery

Posted: Sun Jul 06, 2014 6:31 pm
by liverpool8
Hallo.
I got a problem. I put a printscreen in attached files.
I am nub, have worked with ren'py for 3 days :)
So I dont understand how I should fix it.
Or may be I am totally wrong. Could you please explain? :)

Code: Select all

init python:
    
image bg hantitan = "hantitan.jpg"
image bg friend = "friend.jpg"
    #Galleries settings - start
    #list the BG gallery images here (if a BG includes several variations, such as night version, include only one variation here):
    gallery_bg_items = ["bg hantitan", "bg friend"]
    #how many rows and columns in the gallery screens?
    gal_rows = 1
    gal_cols = 2
    #thumbnail size in pixels:
    thumbnail_x = 267
    thumbnail_y = 150
    #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_bg = Gallery()
    for gal_item in gallery_bg_items:
        g_bg.button(gal_item + " butt")
        g_bg.image(gal_item)
        g_bg.unlock(gal_item)
        #if BGs have variations, such as night version, uncomment the lines below and include the code for each BG with variations
#        if gal_item == "bg kitchen":
#            g_bg.image("bg kitchen dining")
#            g_bg.unlock("bg kitchen dining")
    g_bg.transition = fade
    bg_page=0
    
init +1 python:
    #Here we create the thumbnails. We create a grayscale thumbnail image for BGs, but we use a special "locked" image for CGs to prevent spoilers.
    for gal_item in gallery_bg_items:
        renpy.image (gal_item + " butt", im.Scale(ImageReference(gal_item), thumbnail_x, thumbnail_y))
        renpy.image (gal_item + " butt dis", im.Grayscale(ImageReference(gal_item + " butt")))
        
screen bg_gallery:
#The BG gallery screen is more or less copy pasted from the CG screen above, I only changed "make_button" to include a grayscale thumbnail for locked items
    tag menu
    use navigation
    frame background None xpos 10:
        grid gal_rows gal_cols:
            ypos 10
            $ i = 0
            $ next_bg_page = bg_page + 1
            if next_bg_page > int(len(gallery_bg_items)/gal_cells):
                $ next_bg_page = 0
            for gal_item in gallery_bg_items:
                $ i += 1
                if i <= (bg_page+1)*gal_cells and i>bg_page*gal_cells:
                    add g_bg.make_button(gal_item + " butt", gal_item + " butt", gal_item + " butt dis", xalign=0.5, yalign=0.5, idle_border=None, background=None, bottom_margin=24)
            for j in range(i, (bg_page+1)*gal_cells):
                null
        frame:
            yalign 0.97
            vbox:
                if len(gallery_bg_items)>gal_cells:
                    textbutton _("Next Page") action [SetVariable('bg_page', next_bg_page), ShowMenu("bg_gallery")]

Re: Instant CG and BG gallery

Posted: Sun Jul 06, 2014 9:30 pm
by mjshi

Code: Select all

init python:
    
image bg hantitan = "hantitan.jpg"
image bg friend = "friend.jpg"
Missing indents for "image bg"s.

Add four spaces:

Code: Select all

init python:
    
    image bg hantitan = "hantitan.jpg"
    image bg friend = "friend.jpg"

Re: Instant CG and BG gallery

Posted: Sun Jul 06, 2014 9:54 pm
by liverpool8
Missing indents for "image bg"s.

Add four spaces:
Oh, lol, thank you :)

But now it shows new error.

Re: Instant CG and BG gallery

Posted: Sun Jul 06, 2014 9:58 pm
by PyTom
The image statement isn't allowed in a python (or init python) block. You need to move it out. So your code should begin with:

Code: Select all

image bg hantitan = "hantitan.jpg"
image bg friend = "friend.jpg"

init python:
    
    #Galleries settings - start
    #list the BG gallery images here (if a BG includes several variations, such as night version, include only one variation here):
    gallery_bg_items = ["bg hantitan", "bg friend"]
    #how many rows and columns in the gallery screens?
    gal_rows = 1
    gal_cols = 2

Re: Instant CG and BG gallery

Posted: Sun Jul 06, 2014 11:17 pm
by liverpool8

Code: Select all

The image statement isn't allowed in a python (or init python) block. You need to move it out. So your code should begin with:
Thanks! I got it. Everything is working now!
And big thank you guys for this topic! It really helps!

Re: Instant CG and BG gallery

Posted: Wed Jul 16, 2014 3:31 pm
by Ignideus
This is great! Would OP like to be credited in my game if I end up using this code?

Re: Instant CG and BG gallery

Posted: Wed Jul 16, 2014 3:54 pm
by leon
It's not required, but I don't mind.

Re: Instant CG and BG gallery

Posted: Thu Jul 17, 2014 8:54 pm
by Carrogath
Hi again Leon. We tried taking you advice and adding some transparent space around the border, but we could only fix the top and bottom margins. The left/right margins are still off. I'm attaching a screenshot so you can see.

Any advice?

Re: Instant CG and BG gallery

Posted: Sat Jul 19, 2014 12:15 pm
by leon
Is the size of the border image the same as the thumbnail size(thumbnail_x and thumbnail_y)?

If you can't fix it, please attach a sample of your code.

Re: Instant CG and BG gallery

Posted: Thu Jul 24, 2014 5:53 am
by scorlight
First of all, thank you so much for your code! It's really easy to understand
However, I have the same problem like Vmarshal (comment in page 4)
I did everything as instructed and fixed the hiccups in my code. One problem though, the images don't unlock.
I deleted saved data and persistent data and have tried playing through the VN thinking it will unlock after viewing all the images manually via VN. Still locked in the gallery. Don't know what's going on. Clicking on the 'locked images' didn't work either. Any help would be appreciated :(
I saw her solution too:
The name of the CG images in screens.rpy has to be the same name as the ACTUAL CG image files in your scripts.rpy. The reason it didn't unlock was because renpy recognized the images as separate entities due to their tags being different. By renaming my original script files with the same tags as the screens.rpy init, the CG Gallery was able to unlock on the first instance it was displayed in-game.
But I'm not sure I did the right thing. I tried to add this code at the beginning of screens.rpy but it didn't change anything, I have the same code in scripts.rpy too. Did I miss something? @@

Code: Select all

init:
image cg1 = "cg1.png"

Re: Instant CG and BG gallery

Posted: Sun Jul 27, 2014 10:02 pm
by Carrogath
Whoops. Sorry for taking so long to reply.

And, yep, it's the same size as the thumbnail (352x198). The code is a little long so I'll just attach it as a .txt file.

Re: Instant CG and BG gallery

Posted: Mon Jul 28, 2014 3:48 pm
by Kagehide
Hello i have been using your gallery for a while and i have customised the hell out of it (with minor problems).
Right now i have a problem that the cg with variations shows up as unlocked in the gallery but the variations of that cg dont show up because the game crashes.
My guess is that it might be because of how the bg gallery had the cg show up as grayscale when it has variations.
Ofcourse i realy dont want it to be grayscale so i deleted that line but now it wont show as locked.
Here is my whole gallery

Code: Select all

init python:
    #Galleries settings - start
    #list the CG gallery images here:
    gallery_cg_items = ["cg3"]
    #list the BG gallery images here (if a BG includes several variations, such as night version, include only one variation here):
    gallery_eris_items = ["cg1", "cg5"]
    gallery_deus_items = ["cg12"]
    #gallery_mer_items = ["cgm1"]
    #how many rows and columns in the gallery screens?
    gal_rows = 3
    gal_cols = 2
    #thumbnail size in pixels:
    thumbnail_x = 267
    thumbnail_y = 170
    #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) 
        #if gal_item == "cg1":
            #g_cg.image("cg2")
            #g_cg.unlock("cg2")
    g_cg.transition = fade
    cg_page=0

    g_eris = Gallery()
    for gal_item in gallery_eris_items:
        g_eris.button(gal_item + " butt")
        g_eris.image(gal_item)
        g_eris.unlock(gal_item)
        #if BGs have variations, such as night version, uncomment the lines below and include the code for each BG with variations
        if gal_item == "cg1":
            g_eris.image("cg2")
    g_eris.transition = fade
    eris_page=0
   
    g_deus = Gallery()
    for gal_item in gallery_deus_items:
        g_deus.button(gal_item + " butt")
        g_deus.image(gal_item)
        g_deus.unlock(gal_item)
        #if BGs have variations, such as night version, uncomment the lines below and include the code for each BG with variations
        if gal_item == "cg12":
            g_deus.image("cg13")
            g_deus.image("cg14")
            g_deus.image("cg15")
            g_deus.image("cg16")
            g_deus.image("cg17")
            g_deus.image("cg18")
            g_deus.image("cg19")
            g_deus.image("cg20")
    g_deus.transition = fade
    deus_page=0 

init python:
    #Here we create the thumbnails. We create a grayscale thumbnail image for BGs, but we use a special "locked" image for CGs to prevent spoilers.
    for gal_item in gallery_cg_items:
        renpy.image (gal_item + " butt", im.Scale(ImageReference(gal_item), thumbnail_x, thumbnail_y))
    for gal_item in gallery_eris_items:
        renpy.image (gal_item + " butt", im.Scale(ImageReference(gal_item), thumbnail_x, thumbnail_y))
    for gal_item in gallery_deus_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.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 background None:
            yalign 0.97
            vbox:
                textbutton _("Eris Gallery") action ShowMenu("eris_gallery")
                textbutton _("Deus Gallery") action ShowMenu ("deus_gallery")
                if len(gallery_cg_items)>gal_cells:
                    textbutton _("Next Page") action [SetVariable('cg_page', next_cg_page), ShowMenu("cg_gallery")]

screen eris_gallery:
#The BG gallery screen is more or less copy pasted from the CG screen above, I only changed "make_button" to include a grayscale thumbnail for locked items
    tag menu
    use navigation
    frame background None xpos 10:
        grid gal_rows gal_cols:
            ypos 10
            $ i = 0
            $ next_eris_page = eris_page + 1
            if next_eris_page > int(len(gallery_eris_items)/gal_cells):
                $ next_eris_page = 0
            for gal_item in gallery_eris_items:
                $ i += 1
                if i <= (eris_page+1)*gal_cells and i>eris_page*gal_cells:
                    add g_eris.make_button(gal_item + " butt", gal_item + " butt", im.Scale("gallocked.png", thumbnail_x, thumbnail_y), xalign=0.5, yalign=0.5, idle_border=None, background=None, bottom_margin=24)
            for j in range(i, (eris_page+1)*gal_cells):
                null
        frame:
            yalign 0.97
            vbox:
                textbutton _("CG Gallery") action ShowMenu("cg_gallery")
                textbutton _("Deus Gallery") action ShowMenu ("deus_gallery")
                if len(gallery_eris_items)>gal_cells:
                    textbutton _("Next Page") action [SetVariable('eris_page', next_bg_page), ShowMenu("eris_gallery")]
screen deus_gallery:
#The BG gallery screen is more or less copy pasted from the CG screen above, I only changed "make_button" to include a grayscale thumbnail for locked items
    tag menu
    use navigation
    frame background None xpos 10:
        grid gal_rows gal_cols:
            ypos 10
            $ i = 0
            $ next_deus_page = deus_page + 1
            if next_deus_page > int(len(gallery_deus_items)/gal_cells):
                $ next_deus_page = 0
            for gal_item in gallery_deus_items:
                $ i += 1
                if i <= (deus_page+1)*gal_cells and i>deus_page*gal_cells:
                    add g_deus.make_button(gal_item + " butt", gal_item + " butt", im.Scale("gallocked.png", thumbnail_x, thumbnail_y), xalign=0.5, yalign=0.5, idle_border=None, background=None, bottom_margin=24)
            for j in range(i, (deus_page+1)*gal_cells):
                null
        frame:
            yalign 0.97
            vbox:
                textbutton _("CG Gallery") action ShowMenu("cg_gallery")
                textbutton _("Eris Gallery") action ShowMenu ("eris_gallery")
                if len(gallery_deus_items)>gal_cells:
                    textbutton _("Next Page") action [SetVariable('deus_page', next_bg_page), ShowMenu("deus_gallery")]
And here is the error i get ingame when i try to go to the variations

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "renpy/common/00gallery.rpy", line 452, in show
    index = images.index((button, image))
ValueError: (0, 0) is not in list

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "renpy/common/_layout/screen_main_menu.rpym", line 29, in script
    $ ui.interact()
  File "C:\Users\Sade\Downloads\renpy-6.14.1-sdk\renpy\ast.py", line 756, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "C:\Users\Sade\Downloads\renpy-6.14.1-sdk\renpy\python.py", line 1382, in py_exec_bytecode
    exec bytecode in globals, locals
  File "renpy/common/_layout/screen_main_menu.rpym", line 29, in <module>
    $ ui.interact()
  File "C:\Users\Sade\Downloads\renpy-6.14.1-sdk\renpy\ui.py", line 264, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "C:\Users\Sade\Downloads\renpy-6.14.1-sdk\renpy\display\core.py", line 2065, in interact
    repeat, rv = self.interact_core(preloads=preloads, **kwargs)
  File "C:\Users\Sade\Downloads\renpy-6.14.1-sdk\renpy\display\core.py", line 2652, in interact_core
    rv = root_widget.event(ev, x, y, 0)
  File "C:\Users\Sade\Downloads\renpy-6.14.1-sdk\renpy\display\layout.py", line 774, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "C:\Users\Sade\Downloads\renpy-6.14.1-sdk\renpy\display\layout.py", line 774, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "C:\Users\Sade\Downloads\renpy-6.14.1-sdk\renpy\display\layout.py", line 774, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "C:\Users\Sade\Downloads\renpy-6.14.1-sdk\renpy\display\screen.py", line 345, in event
    rv = self.child.event(ev, x, y, st)
  File "C:\Users\Sade\Downloads\renpy-6.14.1-sdk\renpy\display\layout.py", line 774, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "C:\Users\Sade\Downloads\renpy-6.14.1-sdk\renpy\display\layout.py", line 180, in event
    rv = d.event(ev, x - xo, y - yo, st)
  File "C:\Users\Sade\Downloads\renpy-6.14.1-sdk\renpy\display\layout.py", line 774, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "C:\Users\Sade\Downloads\renpy-6.14.1-sdk\renpy\display\layout.py", line 180, in event
    rv = d.event(ev, x - xo, y - yo, st)
  File "C:\Users\Sade\Downloads\renpy-6.14.1-sdk\renpy\display\behavior.py", line 726, in event
    return handle_click(self.clicked)
  File "C:\Users\Sade\Downloads\renpy-6.14.1-sdk\renpy\display\behavior.py", line 669, in handle_click
    rv = run(action)
  File "C:\Users\Sade\Downloads\renpy-6.14.1-sdk\renpy\display\behavior.py", line 274, in run
    return var(*args, **kwargs)
  File "C:\Users\Sade\Downloads\renpy-6.14.1-sdk\renpy\curry.py", line 38, in __call__
    **dict(self.kwargs.items() + kwargs.items()))
  File "C:\Users\Sade\Downloads\renpy-6.14.1-sdk\renpy\game.py", line 235, in invoke_in_new_context
    return callable(*args, **kwargs)
  File "renpy/common/00gallery.rpy", line 452, in show
    index = images.index((button, image))
ValueError: (0, 0) is not in list

Windows-post2008Server-6.2.9200
Ren'Py 6.17.6.512
Heroine of Revenge Demo 2.0