WIP: Fixes #3 - Image Gallery #14
@ -1,50 +1,69 @@
|
|||||||
init python:
|
init python:
|
||||||
|
# GALLERY OBJECT
|
||||||
|
# Handles unlockables via ren'py
|
||||||
g = Gallery()
|
g = Gallery()
|
||||||
|
|
||||||
|
# CONST PARAMS
|
||||||
|
GALLERY_COLS = 3
|
||||||
|
NOT_UNLOCKED_COVER = im.FactorScale("gui/gallery/unlocked_cg_button_cover.png", 0.225, 0.225)
|
||||||
|
|
||||||
gallery_cols = 3
|
# GALLERY ITEMS
|
||||||
gallery_items = []
|
# Data structure that holds the data for each cg and button
|
||||||
not_unlocked_cover = im.FactorScale("gui/gallery/unlocked_cg_button_cover.png", 0.225, 0.225)
|
# 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):
|
def cg(fname, unlocked = False):
|
||||||
#if not unlocked:
|
if not unlocked:
|
||||||
# return not_unlocked_cover
|
return NOT_UNLOCKED_COVER
|
||||||
|
|
||||||
return im.FactorScale("images/cgs/" + fname + ".png", 0.225, 0.225)
|
return im.FactorScale("images/cgs/" + fname + ".png", 0.225, 0.225)
|
||||||
|
|
||||||
def add_gallery_item(image_name, unlocked = False):
|
# Create an object in g:Gallery, add to galleryItems
|
||||||
g.button(image_name)
|
def addGalleryItem(imageName, unlocked = False):
|
||||||
g.image(image_name)
|
g.button(imageName)
|
||||||
|
g.image(imageName)
|
||||||
|
|
||||||
if unlocked:
|
if unlocked:
|
||||||
g.unlock(image_name)
|
g.unlock(imageName)
|
||||||
else:
|
else:
|
||||||
g.condition("persistent." + image_name)
|
g.condition("persistent." + imageName)
|
||||||
|
|
||||||
gallery_items.append({
|
galleryItems.append({
|
||||||
"item": image_name,
|
"item": imageName,
|
||||||
"cg": cg(image_name, unlocked)
|
"cg": cg(imageName, unlocked)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
# Reads /images/cgs dir for all .png files
|
||||||
|
# Populates g:Gallery and galleryItems
|
||||||
|
# Appends extra spaces at the end
|
||||||
|
def loadGallery():
|
||||||
|
from os import listdir, getcwd
|
||||||
|
from os.path import isfile, join
|
||||||
|
|
||||||
from os import listdir, getcwd
|
cgPath = "images/cgs/"
|
||||||
from os.path import isfile, join
|
workingDirPath = getcwd().replace("\\", "/")
|
||||||
|
cgDirPath = workingDirPath + "/game/" + cgPath
|
||||||
|
|
||||||
cg_path = "images/cgs/"
|
# Add each .png to the gallery
|
||||||
working_dir_path = getcwd().replace("\\", "/")
|
# TODO: make case insensitive
|
||||||
cg_dir_path = working_dir_path + "/game/" + cg_path
|
for cgFile in listdir(cgDirPath):
|
||||||
|
if isfile(join(cgDirPath, cgFile)):
|
||||||
|
if (cgFile[-4:] == '.png'):
|
||||||
|
addGalleryItem(cgFile[0:-4], True)
|
||||||
|
|
||||||
for cgFile in listdir(cg_dir_path):
|
# Add empty items to fill grid after last cg button
|
||||||
if isfile(join(cg_dir_path, cgFile)):
|
extraSpaces = GALLERY_COLS - (len(galleryItems) % GALLERY_COLS)
|
||||||
if (cgFile[-4:] == '.png'):
|
for i in range(0, extraSpaces):
|
||||||
add_gallery_item(cgFile[0:-4], True)
|
galleryItems.append({
|
||||||
|
"item": None,
|
||||||
|
"cg": None
|
||||||
|
})
|
||||||
|
|
||||||
extra_spaces = gallery_cols - (len(gallery_items) % gallery_cols)
|
# Call to loading the gallery
|
||||||
for i in range(0, extra_spaces):
|
loadGallery()
|
||||||
gallery_items.append({
|
|
||||||
"item": None,
|
|
||||||
"cg": None
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -55,14 +74,15 @@ screen cg_gallery():
|
|||||||
use game_menu(_("Gallery"), scroll="viewport"):
|
use game_menu(_("Gallery"), scroll="viewport"):
|
||||||
|
|
||||||
fixed:
|
fixed:
|
||||||
$ gallery_rows = len(gallery_items) / gallery_cols
|
$ galleryRows = len(galleryItems) / GALLERY_COLS
|
||||||
grid gallery_cols gallery_rows:
|
grid GALLERY_COLS galleryRows:
|
||||||
|
|
||||||
spacing gui.slot_spacing
|
spacing gui.slot_spacing
|
||||||
|
|
||||||
for item in gallery_items:
|
# Iterate through galleryItems and add cgs buttons
|
||||||
|
for item in galleryItems:
|
||||||
if item["item"] == None:
|
if item["item"] == None:
|
||||||
# TODO: empty space
|
# TODO: empty space
|
||||||
add g.make_button(gallery_items[0]["item"], gallery_items[0]["cg"], xalign = 0.5, yalign = 0.5)
|
add g.make_button(galleryItems[0]["item"], galleryItems[0]["cg"], xalign = 0.5, yalign = 0.5)
|
||||||
else:
|
else:
|
||||||
add g.make_button(item["item"], item["cg"], xalign = 0.5, yalign = 0.5)
|
add g.make_button(item["item"], item["cg"], xalign = 0.5, yalign = 0.5)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user