mirror of
https://git.cavemanon.xyz/Cavemanon/SnootGame.git
synced 2025-03-13 20:19:25 +01:00
cg gallery wip vol2: commenting, minor code cleanup
This commit is contained in:
parent
bd6c710380
commit
f819958d80
1 changed files with 52 additions and 32 deletions
|
@ -1,50 +1,69 @@
|
|||
init python:
|
||||
# GALLERY OBJECT
|
||||
# Handles unlockables via ren'py
|
||||
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 = []
|
||||
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
|
||||
if not unlocked:
|
||||
return NOT_UNLOCKED_COVER
|
||||
|
||||
return im.FactorScale("images/cgs/" + fname + ".png", 0.225, 0.225)
|
||||
|
||||
def add_gallery_item(image_name, unlocked = False):
|
||||
g.button(image_name)
|
||||
g.image(image_name)
|
||||
# Create an object in g:Gallery, add to galleryItems
|
||||
def addGalleryItem(imageName, unlocked = False):
|
||||
g.button(imageName)
|
||||
g.image(imageName)
|
||||
|
||||
if unlocked:
|
||||
g.unlock(image_name)
|
||||
g.unlock(imageName)
|
||||
else:
|
||||
g.condition("persistent." + image_name)
|
||||
g.condition("persistent." + imageName)
|
||||
|
||||
gallery_items.append({
|
||||
"item": image_name,
|
||||
"cg": cg(image_name, unlocked)
|
||||
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
|
||||
def loadGallery():
|
||||
from os import listdir, getcwd
|
||||
from os.path import isfile, join
|
||||
|
||||
from os import listdir, getcwd
|
||||
from os.path import isfile, join
|
||||
cgPath = "images/cgs/"
|
||||
workingDirPath = getcwd().replace("\\", "/")
|
||||
cgDirPath = workingDirPath + "/game/" + cgPath
|
||||
|
||||
cg_path = "images/cgs/"
|
||||
working_dir_path = getcwd().replace("\\", "/")
|
||||
cg_dir_path = working_dir_path + "/game/" + cg_path
|
||||
# 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)
|
||||
|
||||
for cgFile in listdir(cg_dir_path):
|
||||
if isfile(join(cg_dir_path, cgFile)):
|
||||
if (cgFile[-4:] == '.png'):
|
||||
add_gallery_item(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
|
||||
})
|
||||
|
||||
extra_spaces = gallery_cols - (len(gallery_items) % gallery_cols)
|
||||
for i in range(0, extra_spaces):
|
||||
gallery_items.append({
|
||||
"item": None,
|
||||
"cg": None
|
||||
})
|
||||
# Call to loading the gallery
|
||||
loadGallery()
|
||||
|
||||
|
||||
|
||||
|
@ -55,14 +74,15 @@ screen cg_gallery():
|
|||
use game_menu(_("Gallery"), scroll="viewport"):
|
||||
|
||||
fixed:
|
||||
$ gallery_rows = len(gallery_items) / gallery_cols
|
||||
grid gallery_cols gallery_rows:
|
||||
$ galleryRows = len(galleryItems) / GALLERY_COLS
|
||||
grid GALLERY_COLS galleryRows:
|
||||
|
||||
spacing gui.slot_spacing
|
||||
|
||||
for item in gallery_items:
|
||||
# Iterate through galleryItems and add cgs buttons
|
||||
for item in galleryItems:
|
||||
if item["item"] == None:
|
||||
# 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:
|
||||
add g.make_button(item["item"], item["cg"], xalign = 0.5, yalign = 0.5)
|
||||
|
|
Loading…
Reference in a new issue