Re: Instant CG and BG gallery
Posted: Sun Jun 22, 2014 12:52 pm
Maybe changing the border image, so that it has a bit of transparent area on the left would fix it?
Supporting creators of visual novels and story-based games since 2003.
https://lemmasoft.renai.us/forums/
it works! Thank you!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.
But if you mean a character sprite gallery, you are probably better off using the Gallery class directly. because: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.
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.
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")]
Missing indents for "image bg"s.Code: Select all
init python: image bg hantitan = "hantitan.jpg" image bg friend = "friend.jpg"
Code: Select all
init python:
image bg hantitan = "hantitan.jpg"
image bg friend = "friend.jpg"
Oh, lol, thank youMissing indents for "image bg"s.
Add four spaces:
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
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:
I saw her solution too: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
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? @@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.
Code: Select all
init:
image cg1 = "cg1.png"
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")]
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