Rewrite how unlocking works
This commit is contained in:
parent
83e4d77249
commit
5cb9c4785c
|
@ -1,10 +1,4 @@
|
||||||
default persistent.cggallery = []
|
|
||||||
|
|
||||||
init python:
|
init python:
|
||||||
# GALLERY OBJECT
|
|
||||||
# Handles unlockables via ren'py
|
|
||||||
g = Gallery()
|
|
||||||
g.transition = dissolve
|
|
||||||
|
|
||||||
# CONST PARAMS
|
# CONST PARAMS
|
||||||
GALLERY_COLS = 3
|
GALLERY_COLS = 3
|
||||||
|
@ -15,6 +9,13 @@ init python:
|
||||||
DEFAULT_HEIGHT_SCALE_RATIO = round(float(PREFERRED_HEIGHT) / float(1080), 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)
|
NOT_UNLOCKED_COVER = im.FactorScale("gui/gallery/unlocked_cg_button_cover.png", DEFAULT_WIDTH_SCALE_RATIO, DEFAULT_HEIGHT_SCALE_RATIO)
|
||||||
ACCEPTED_EXTENSIONS = ["jpg", "png"]
|
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
|
# GALLERY ITEMS
|
||||||
# Data structure that holds the data for each cg and button
|
# Data structure that holds the data for each cg and button
|
||||||
|
@ -23,35 +24,11 @@ init python:
|
||||||
# { item: string; cg: Displayable; ext: string }[]
|
# { item: string; cg: Displayable; ext: string }[]
|
||||||
galleryItems = []
|
galleryItems = []
|
||||||
|
|
||||||
# Global function to unlock a cg
|
|
||||||
# fname should be a key used in galleryItems
|
|
||||||
# (fname: string) -> None
|
|
||||||
def unlockCg(fname):
|
|
||||||
unlocked = fname in persistent.cggallery
|
|
||||||
if unlocked:
|
|
||||||
return
|
|
||||||
|
|
||||||
# Save to renpy persistent data
|
|
||||||
tmp = list(persistent.cggallery).copy()
|
|
||||||
tmp.append(fname)
|
|
||||||
persistent.cggallery = tmp
|
|
||||||
renpy.persistent.save()
|
|
||||||
# TODO: fix unlocking without game reset
|
|
||||||
|
|
||||||
# Rebuild the gallery
|
|
||||||
for i in range(0, len(galleryItems) - 1):
|
|
||||||
if fname == str(galleryItems[i]["item"]):
|
|
||||||
loadGallery()
|
|
||||||
return
|
|
||||||
|
|
||||||
# Make a scaled cg button
|
# Make a scaled cg button
|
||||||
# (cg: string; ext: string; w: float; h: float; unlocked?: boolean): Displayable
|
# (cg: string; ext: string; w: float; h: float; unlocked?: boolean): Displayable
|
||||||
def cg(fname, ext, w, h, unlocked = False):
|
def cg(fname, ext, w, h):
|
||||||
if not unlocked:
|
|
||||||
return NOT_UNLOCKED_COVER
|
|
||||||
|
|
||||||
scaleFactor = getBoxNormalizerRatio(w, h)
|
scaleFactor = getBoxNormalizerRatio(w, h)
|
||||||
return im.FactorScale("images/cgs/" + fname + "." + ext, scaleFactor["x"], scaleFactor["y"], False)
|
return im.FactorScale(CG_PATHS + fname + "." + ext, scaleFactor["x"], scaleFactor["y"], False)
|
||||||
|
|
||||||
# Create an object in g:Gallery, add to galleryItems
|
# Create an object in g:Gallery, add to galleryItems
|
||||||
# (imageName: string; ext: string; w: float; h: float; unlocked?: boolean) -> None
|
# (imageName: string; ext: string; w: float; h: float; unlocked?: boolean) -> None
|
||||||
|
@ -63,19 +40,15 @@ init python:
|
||||||
verticalPan = Pan((w - 1920, h - 1080), (w - 1920, 0), 30.0)
|
verticalPan = Pan((w - 1920, h - 1080), (w - 1920, 0), 30.0)
|
||||||
g.transform(horizontalPan if w > h else verticalPan) #TODO: niceify
|
g.transform(horizontalPan if w > h else verticalPan) #TODO: niceify
|
||||||
|
|
||||||
if unlocked:
|
str = "renpy.seen_image('"+imageName+"')"
|
||||||
g.unlock(imageName)
|
g.condition(str)
|
||||||
g.condition("True")
|
|
||||||
else:
|
|
||||||
g.condition("False")
|
|
||||||
|
|
||||||
galleryItems.append({
|
galleryItems.append({
|
||||||
"item": imageName,
|
"item": imageName,
|
||||||
"cg": cg(imageName, ext, w, h, unlocked),
|
"cg": cg(imageName, ext, w, h),
|
||||||
"ext": ext
|
"ext": ext
|
||||||
})
|
})
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
# Reads /images/cgs dir for all image files
|
# Reads /images/cgs dir for all image files
|
||||||
# Populates g:Gallery and galleryItems
|
# Populates g:Gallery and galleryItems
|
||||||
|
@ -83,35 +56,16 @@ init python:
|
||||||
# () -> None
|
# () -> None
|
||||||
def loadGallery():
|
def loadGallery():
|
||||||
|
|
||||||
cgPath = "images/cgs/"
|
|
||||||
lazy_counter = 0
|
|
||||||
|
|
||||||
# Reset gallery
|
|
||||||
galleryItems = []
|
|
||||||
g = Gallery()
|
|
||||||
g.transition = dissolve
|
|
||||||
|
|
||||||
list_img = renpy.list_images()
|
list_img = renpy.list_images()
|
||||||
|
|
||||||
# Add each image to the gallery
|
# Add each image to the gallery
|
||||||
for str in list_img:
|
for str in list_img:
|
||||||
_str = cgPath+str+"."+ACCEPTED_EXTENSIONS[0]
|
_str = CG_PATHS+str+"."+ACCEPTED_EXTENSIONS[0]
|
||||||
if renpy.loadable(_str): #brute force
|
if renpy.loadable(_str): #brute force
|
||||||
unlocked = renpy.seen_image(str)
|
unlocked = renpy.seen_image(str)
|
||||||
image = renpy.image_size(Image(_str))
|
image = renpy.image_size(Image(_str))
|
||||||
addGalleryItem(str, ACCEPTED_EXTENSIONS[0], image[0], image[1], unlocked)
|
addGalleryItem(str, ACCEPTED_EXTENSIONS[0], image[0], image[1], unlocked)
|
||||||
lazy_counter += 1
|
|
||||||
|
|
||||||
|
|
||||||
return
|
return
|
||||||
# this is bugged, sees galleryItems as a local variable? weird python variable scope bug
|
|
||||||
extraSpaces = GALLERY_CGS_PER_PAGE - (lazy_counter % GALLERY_CGS_PER_PAGE)
|
|
||||||
for i in range(1, extraSpaces):
|
|
||||||
galleryItems.append({
|
|
||||||
"item": None,
|
|
||||||
"cg": None,
|
|
||||||
"ext": None
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
# Returns what params to call im.FactorScale with for cg button size
|
# Returns what params to call im.FactorScale with for cg button size
|
||||||
|
@ -126,9 +80,6 @@ init python:
|
||||||
# Call to loading the gallery
|
# Call to loading the gallery
|
||||||
loadGallery()
|
loadGallery()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## CG Gallery screen ########################################################
|
## CG Gallery screen ########################################################
|
||||||
## A screen that shows the image gallery
|
## A screen that shows the image gallery
|
||||||
screen cg_gallery():
|
screen cg_gallery():
|
||||||
|
@ -139,9 +90,10 @@ screen cg_gallery():
|
||||||
tag menu
|
tag menu
|
||||||
use game_menu(_("Gallery"), scroll="viewport"):
|
use game_menu(_("Gallery"), scroll="viewport"):
|
||||||
grid GALLERY_COLS galleryRows:
|
grid GALLERY_COLS galleryRows:
|
||||||
spacing 20
|
spacing 8
|
||||||
for item in galleryItems:
|
for item in galleryItems:
|
||||||
#very slow but once cached, it's 'OK', not ideal
|
# vbox:
|
||||||
|
# text item["item"] size 8
|
||||||
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)
|
||||||
# Add empty items to fill grid after last cg button
|
# Add empty items to fill grid after last cg button
|
||||||
for i in range(0, extraSpaces):
|
for i in range(0, extraSpaces):
|
||||||
|
|
Loading…
Reference in New Issue