@scorlight: You only need to define the images once. They don't need to be in the same file as the gallery. Note that image unlocking is handled automatically by Ren'Py. Could you copy the relevant lines of the code?
@Carrogath: The code looks fine to me. Could you upload the whole thing (with images included)?
@Kagehide: Firstly check that all the images cg13-cg20 are acutally defined and there are no typos.
You'll probably also want to add unlock conditions to the buttons.
First: Your code is awesome!!!! Second: I use this in one project and it's working perfectly; but I´m use that in a new project and not working and check it often but I not find the error.
init python:
#Las opciones de galeria empiezan acá
#lista de las imagenes del CG gallery aquí:
gallery_cg_items = ["Imagen01"]
#Cuantas filas y columnas en la pantalla de la galería?
gal_rows = 1
gal_cols = 2
#thumbnail size in pixels (lo cambie):
thumbnail_x = 267
thumbnail_y = 150
#El ajuste anterior (267x150) va a funcionar bien con una relación de pantalla de 16:9. Asegúrese de ajustar, si es que está utilizando 4:3 o algo más.
#Opciones de galeria terminadas
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:
#Acá nosotros hacemos la miniatura. Una imagen en miniatura, que nosotros creamos en escalas de grises para los BGs, pero creamos una imagen especial de "bloqueado" para los CGs para prevenir spoilers.
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.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): #necesitamos esto para llenar completamente la cuadricula
null
frame:
yalign 0.97
vbox:
if len(gallery_cg_items)>gal_cells:
textbutton _("Siguiente") action [SetVariable('cg_page', next_cg_page), ShowMenu("cg_gallery")]
Some parts that is in spanish because is my lenguage, I speak a simple english.
Below I put the image with the error listed me, and in this part:
(598)init +1 python:
#Acá nosotros hacemos la miniatura. Una imagen en miniatura, que nosotros creamos en escalas de grises para los BGs, pero creamos una imagen especial de "bloqueado" para los CGs para prevenir spoilers.
for gal_item in gallery_cg_items:
(591) renpy.image (gal_item + " butt", im.Scale(ImageReference(gal_item), thumbnail_x, thumbnail_y))
Hey! I'm not sure if this thread is still being replied to, but I keep getting an in-game error message in red text: Image 'wCG' can't take parameters "butt" (perhaps you got the same wrong?) I know someone had this problem earlier on, but I couldn't find the actual solution in the replies
Cousin Leon, is there a way for you to give me the character gallery code/tutorial I really wanted to make one for my Visual Novel!!Please help!!
leon wrote:Here's a code snippet to include the CG and/or BG galleries to your games without much extra effort. Just copy paste it to screens.rpy, change the settings at the top to your liking and you'll have a working gallery.
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 sollution wouldn't work that well.
init python:
#Galleries settings - start
#list the CG gallery images here:
gallery_cg_items = ["cg1", "cg2", "cg3", "cg4", "cg5", "cg6", "cg7", "cg8", "cg9", "cg10"]
#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 kitchen", "bg road"]
#how many rows and columns in the gallery screens?
gal_rows = 3
gal_cols = 3
#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_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
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_cg_items:
renpy.image (gal_item + " butt", im.Scale(ImageReference(gal_item), thumbnail_x, thumbnail_y))
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 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:
yalign 0.97
vbox:
if len(gallery_cg_items)>gal_cells:
textbutton _("Next Page") action [SetVariable('cg_page', next_cg_page), ShowMenu("cg_gallery")]
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")]
In the attached file is a working example; credit for the included CG of a girl touching her boobs goes to azureXtwilight.
Hi Leon! This code has made my life 100x easier, so thank you for that.
I had a bit of a customization related question for you. Is there a way to have thumbnail specific images? What I mean by this is that I want every button in the menu to have the same white border that my gallocked.png has. So I thought about making unique images for each button, but then I realized that I wouldn't want that version to show up in the actual zoomed image viewing (I already have a good idea of how to sneak them into the game for the sake of unlocking, it's just a matter of not including the button image in the viewer).
Hopefully that makes sense. I guess the core of what I'm trying to say is that I get annoyed at the inconsistency of button borders in my gallery, and I wanted to know if there was a way to make everything have a border without having to view the bordered image first.
Hello and thank you for this great script! After some work I managed to make it work.
Although I have a question. My cg gallery contains transparent pictures (.png) without background. How can I add a background image when I click to open and enlarge a cg picture?
Hello! My code is working completely fine, but I was wonder if there's a way to add a white or custom border onto the unlocked CG's in the gallery just to fancy it up a bit?
Edit: Nevermind, I figured it out.
Last edited by Batensan on Mon Aug 10, 2015 2:43 pm, edited 1 time in total.
For some reason, I can't get it working, though the code should be ok. I keep getting the following error:
I'm sorry, but an uncaught exception occurred.
While running game code:
File "game/gallery.rpy", line 43, in script
init +1 python:
File "game/gallery.rpy", line 48, in <module>
renpy.image (gal_item + " butt", im.Scale(ImageReference(gal_item), thumbnail_x, thumbnail_y))
Exception: Expected an image, but got a general displayable.
-- Full Traceback ------------------------------------------------------------
Full traceback:
File "game/gallery.rpy", line 43, in script
init +1 python:
File "N:\Downloads\Programs\renpy-6.99.5-sdk\renpy\ast.py", line 797, in execute
renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
File "N:\Downloads\Programs\renpy-6.99.5-sdk\renpy\python.py", line 1448, in py_exec_bytecode
exec bytecode in globals, locals
File "game/gallery.rpy", line 48, in <module>
renpy.image (gal_item + " butt", im.Scale(ImageReference(gal_item), thumbnail_x, thumbnail_y))
File "N:\Downloads\Programs\renpy-6.99.5-sdk\renpy\display\im.py", line 668, in __init__
im = image(im)
File "N:\Downloads\Programs\renpy-6.99.5-sdk\renpy\display\im.py", line 1564, in image
return image(arg.target, loose=loose, **properties)
File "N:\Downloads\Programs\renpy-6.99.5-sdk\renpy\display\im.py", line 1579, in image
raise Exception("Expected an image, but got a general displayable.")
Exception: Expected an image, but got a general displayable.
Here's the code of the gallery, which was put in a seperate file (gallery.rpy)
Currently only BG's are to be displayed:
init python:
#Galleries settings - start
#list the CG gallery images here:
# gallery_cg_items = ["xinxin"]
#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 xinxin"]
#how many rows and columns in the gallery screens?
gal_rows = 3
gal_cols = 3
#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_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 BGs have variations, such as night version, uncomment the lines below and include the code for each BG with variations
# if gal_item == "xinxin":
# g_cg.image("funhouse1")
# g_cg.unlock("funhouse1")
# g_cg.transition = fade
# cg_page=0
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 xinxin":
g_bg.image("bg funhouse1")
g_bg.unlock("bg funhouse1")
g_bg.image("bg funhouse3")
g_bg.unlock("bg funhouse3")
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_cg_items:
# renpy.image (gal_item + " butt", im.Scale(ImageReference(gal_item), thumbnail_x, thumbnail_y))
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 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:
# yalign 0.97
# vbox:
# if len(gallery_cg_items)>gal_cells:
# textbutton _("Next Page") action [SetVariable('cg_page', next_cg_page), ShowMenu("cg_gallery")]
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")]
And in the script.rpy:
image bg xinxin = "images/gallery/xinxin/xinxin.png"
image bg funhouse1 = "images/backgrounds/funhouse_anasophie_xinxin_1.png"
image bg funhouse2 = "images/backgrounds/funhouse_anasophie_xinxin_2.png"
image bg funhouse3 = "images/backgrounds/funhouse_anasophie_xinxin_3.png"
image bg funhouse4 = "images/backgrounds/funhouse_anasophie_xinxin_4.png"
Also the BG Gallery option won't show in the main menu:
textbutton _("Start Game") action Start()
textbutton _("Load Game") action ShowMenu("load")
textbutton _("BG Gallery") action ShowMenu("bg_gallery")
textbutton _("Preferences") action ShowMenu("preferences")
textbutton _("Help") action Help()
textbutton _("Quit") action Quit(confirm=False)