100 lines
3.2 KiB
Plaintext
100 lines
3.2 KiB
Plaintext
init python:
|
|
# GALLERY OBJECT
|
|
# Handles unlockables via ren'py
|
|
g = Gallery()
|
|
|
|
# CONST PARAMS
|
|
GALLERY_COLS = 3
|
|
GALLERY_CGS_PER_PAGE = 6
|
|
NOT_UNLOCKED_COVER = im.FactorScale("gui/gallery/unlocked_cg_button_cover.png", 0.225, 0.225)
|
|
|
|
# GALLERY ITEMS
|
|
# Data structure that holds the data for each cg and button
|
|
# item is the key in the Gallery
|
|
# { item: string; cg: Displayable; }[]
|
|
galleryItems = []
|
|
|
|
# Make a scaled cg button
|
|
# (cg: string, unlocked?: boolean): Displayable
|
|
def cg(fname, unlocked = False):
|
|
if not unlocked:
|
|
return NOT_UNLOCKED_COVER
|
|
|
|
return im.FactorScale("images/cgs/" + fname + ".png", 0.225, 0.225)
|
|
|
|
# Create an object in g:Gallery, add to galleryItems
|
|
# (imageName: string; unlocked?: boolean): None
|
|
def addGalleryItem(imageName, unlocked = False):
|
|
g.button(imageName)
|
|
g.image(imageName)
|
|
|
|
if unlocked:
|
|
g.unlock(imageName)
|
|
else:
|
|
g.condition("persistent." + imageName)
|
|
|
|
galleryItems.append({
|
|
"item": imageName,
|
|
"cg": cg(imageName, unlocked)
|
|
})
|
|
|
|
# Reads /images/cgs dir for all .png files
|
|
# Populates g:Gallery and galleryItems
|
|
# Appends extra spaces at the end
|
|
# (): None
|
|
def loadGallery():
|
|
from os import listdir, getcwd
|
|
from os.path import isfile, join
|
|
|
|
cgPath = "images/cgs/"
|
|
workingDirPath = getcwd().replace("\\", "/")
|
|
cgDirPath = workingDirPath + "/game/" + cgPath
|
|
|
|
# Add each .png to the gallery
|
|
# TODO: make case insensitive
|
|
for cgFile in listdir(cgDirPath):
|
|
if isfile(join(cgDirPath, cgFile)):
|
|
if (cgFile[-4:] == '.png'):
|
|
addGalleryItem(cgFile[0:-4], True)
|
|
|
|
# Add empty items to fill grid after last cg button
|
|
extraSpaces = GALLERY_COLS - (len(galleryItems) % GALLERY_COLS)
|
|
for i in range(0, extraSpaces):
|
|
galleryItems.append({
|
|
"item": None,
|
|
"cg": None
|
|
})
|
|
|
|
# Returns the pageth slice from galleryItems
|
|
# (page: int): Partial<typeof galleryItems>
|
|
def getGalleryPage(page):
|
|
start = (page - 1) * GALLERY_CGS_PER_PAGE
|
|
end = start + GALLERY_CGS_PER_PAGE
|
|
return galleryItems[start:end]
|
|
|
|
# Call to loading the gallery
|
|
loadGallery()
|
|
|
|
|
|
|
|
## CG Gallery screen ########################################################
|
|
## A screen that shows the image gallery
|
|
screen cg_gallery():
|
|
tag menu
|
|
use game_menu(_("Gallery"), scroll="viewport"):
|
|
|
|
fixed:
|
|
$ pageItems = getGalleryPage(3)
|
|
$ galleryRows = len(pageItems) / GALLERY_COLS
|
|
grid GALLERY_COLS galleryRows:
|
|
|
|
spacing gui.slot_spacing
|
|
|
|
# Iterate through galleryItems and add cgs buttons
|
|
for item in pageItems:
|
|
if item["item"] == None:
|
|
# TODO: empty space
|
|
add g.make_button(pageItems[0]["item"], pageItems[0]["cg"], xalign = 0.5, yalign = 0.5)
|
|
else:
|
|
add g.make_button(item["item"], item["cg"], xalign = 0.5, yalign = 0.5)
|