101 lines
3.5 KiB
Plaintext
101 lines
3.5 KiB
Plaintext
init python:
|
|
|
|
# CONST PARAMS
|
|
GALLERY_COLS = 3
|
|
GALLERY_CGS_PER_PAGE = 6
|
|
PREFERRED_WIDTH = 432 #px (1920 * 0.225)
|
|
PREFERRED_HEIGHT = 243 #px (1080 * 0.225)
|
|
DEFAULT_WIDTH_SCALE_RATIO = round(float(PREFERRED_WIDTH) / float(1920), 4)
|
|
DEFAULT_HEIGHT_SCALE_RATIO = round(float(PREFERRED_HEIGHT) / float(1080), 4)
|
|
NOT_UNLOCKED_COVER = im.FactorScale("gui/gallery/unlocked_cg_button_cover.png", DEFAULT_WIDTH_SCALE_RATIO, DEFAULT_HEIGHT_SCALE_RATIO)
|
|
ACCEPTED_EXTENSIONS = ["jpg", "png"]
|
|
CG_PATHS = "images/cgs/"
|
|
|
|
# GALLERY OBJECT
|
|
# Handles unlockables via ren'py
|
|
g = Gallery()
|
|
g.transition = dissolve
|
|
g.locked_button = NOT_UNLOCKED_COVER
|
|
|
|
# GALLERY ITEMS
|
|
# Data structure that holds the data for each cg and button
|
|
# item is the key in the Gallery
|
|
# ext is the file extension
|
|
# { item: string; cg: Displayable; ext: string }[]
|
|
galleryItems = []
|
|
|
|
# Make a scaled cg button
|
|
# (cg: string; ext: string; w: float; h: float; unlocked?: boolean): Displayable
|
|
def cg(fname, ext, w, h):
|
|
scaleFactor = getBoxNormalizerRatio(w, h)
|
|
return im.FactorScale(CG_PATHS + fname + "." + ext, scaleFactor["x"], scaleFactor["y"], False)
|
|
|
|
# Create an object in g:Gallery, add to galleryItems
|
|
# (imageName: string; ext: string; w: float; h: float) -> None
|
|
def addGalleryItem(imageName, ext, w, h):
|
|
g.button(imageName)
|
|
g.image(imageName)
|
|
|
|
horizontalPan = Pan((w - 1920, h - 1080), (0, h - 1080), 30.0)
|
|
verticalPan = Pan((w - 1920, h - 1080), (w - 1920, 0), 30.0)
|
|
g.transform(horizontalPan if w > h else verticalPan) #TODO: niceify
|
|
|
|
str = "renpy.seen_image('"+imageName+"')"
|
|
g.condition(str)
|
|
|
|
galleryItems.append({
|
|
"item": imageName,
|
|
"cg": cg(imageName, ext, w, h),
|
|
"ext": ext
|
|
})
|
|
return
|
|
|
|
# Reads /images/cgs dir for all image files
|
|
# Populates g:Gallery and galleryItems
|
|
# Appends extra spaces at the end
|
|
# () -> None
|
|
def loadGallery():
|
|
|
|
list_img = renpy.list_images()
|
|
|
|
# Add each image to the gallery
|
|
for str in list_img:
|
|
_str = CG_PATHS+str+"."+ACCEPTED_EXTENSIONS[0]
|
|
if renpy.loadable(_str): #brute force
|
|
image = renpy.image_size(Image(_str))
|
|
addGalleryItem(str, ACCEPTED_EXTENSIONS[0], image[0], image[1])
|
|
return
|
|
|
|
|
|
# Returns what params to call im.FactorScale with for cg button size
|
|
# Basically the delta diff dimensions
|
|
# (w: int; h: int) -> { x: float; y: float }
|
|
def getBoxNormalizerRatio(w, h):
|
|
x = round(float(PREFERRED_WIDTH) / float(w), 4)
|
|
y = round(float(PREFERRED_HEIGHT) / float(h), 4)
|
|
|
|
return { "x": x, "y": y }
|
|
|
|
# Call to loading the gallery
|
|
loadGallery()
|
|
|
|
## CG Gallery screen ########################################################
|
|
## A screen that shows the image gallery
|
|
screen cg_gallery():
|
|
python:
|
|
items = len(galleryItems)
|
|
galleryRows = (items / GALLERY_COLS) + 1
|
|
extraSpaces = GALLERY_COLS - (items % GALLERY_COLS)
|
|
tag menu
|
|
use game_menu(_("Gallery"), scroll="viewport"):
|
|
grid GALLERY_COLS galleryRows:
|
|
spacing 8
|
|
for item in galleryItems:
|
|
# vbox:
|
|
# text item["item"] size 8
|
|
add g.make_button(item["item"], item["cg"], xalign = 0.5, yalign = 0.5)
|
|
# Add empty items to fill grid after last cg button
|
|
for i in range(0, extraSpaces):
|
|
null height 20
|
|
|