124 lines
3.9 KiB
Plaintext
124 lines
3.9 KiB
Plaintext
init python:
|
|
|
|
# CONST PARAMS
|
|
GALLERY_COLS = 3
|
|
PREFERRED_WIDTH = 432 #px (1920 * 0.225)
|
|
PREFERRED_HEIGHT = 243 #px (1080 * 0.225)
|
|
PREFERRED_ASPECT_RATIO = 16.0/9.0 # 1.7777..
|
|
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 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
|
|
def cg(fname, ext, w, h):
|
|
wh = {'x': w, 'y': h}
|
|
scaleFactor = box_ratio(wh)
|
|
return im.FactorScale(fname, scaleFactor["x"], scaleFactor["y"], False)
|
|
|
|
# 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])
|
|
|
|
# Create an object in g:Gallery, add to galleryItems
|
|
# (imageName: string; ext: string; w: float; h: float) -> None
|
|
galleryItems.append({
|
|
"item": str,
|
|
"fn": _str,
|
|
"cg": cg(_str, ACCEPTED_EXTENSIONS[0], image[0], image[1]),
|
|
"ext": ACCEPTED_EXTENSIONS[0]
|
|
})
|
|
return
|
|
|
|
# (xy) -> { x: float; y: float }
|
|
# Biggest value gets % diff to preferred_ variable
|
|
def box_ratio(xy):
|
|
cent = 0
|
|
if xy['x'] > xy['y']:
|
|
cent = PREFERRED_WIDTH * 100.0 / float(xy['x'])
|
|
else:
|
|
cent = PREFERRED_HEIGHT * 100.0 / float(xy['y'])
|
|
|
|
cent /= 100.0
|
|
xy['x'] = cent
|
|
xy['y'] = cent
|
|
return xy
|
|
|
|
# Call to loading the gallery
|
|
loadGallery()
|
|
|
|
"""
|
|
CG Gallery screen - A screen that shows the image gallery
|
|
Basically Gallery Object has terrible defaults, so I just wrote my own stuff
|
|
"""
|
|
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:
|
|
use flag_button(item)
|
|
|
|
for i in range(0, extraSpaces):
|
|
null height 20
|
|
|
|
"""
|
|
if/else for buttons
|
|
"""
|
|
screen flag_button(item):
|
|
python:
|
|
flag = renpy.seen_image(item['item'])
|
|
if flag:
|
|
button:
|
|
action ShowMenu('view_image', item['fn'], ShowMenu('cg_gallery'))
|
|
xcenter 0.5 ycenter 0.5
|
|
|
|
vbox:
|
|
text item["item"] xalign 0.5
|
|
add item["cg"] fit 'contain' xcenter 0.5 ycenter 0.5 size (PREFERRED_WIDTH, PREFERRED_HEIGHT)
|
|
#action view_image(item["item"])
|
|
else:
|
|
vbox:
|
|
xcenter 0.5 ycenter 0.5
|
|
text "? ? ?" xalign 0.5
|
|
add NOT_UNLOCKED_COVER
|
|
|
|
"""
|
|
view_image, loads the image in fullscreen with viewport controls
|
|
"""
|
|
screen view_image(fn, origin):
|
|
tag menu
|
|
key "game_menu" action origin
|
|
viewport:
|
|
#Ren'Py is isn't smart enough to not edgescroll while pressed, so we'll have to disable this for mobile
|
|
edgescroll (300, 800)
|
|
draggable True
|
|
arrowkeys True
|
|
pagekeys True
|
|
#edgescroll 1.0
|
|
add fn
|