From d6824c511101fa76377e409a01d73bf94e2549a4 Mon Sep 17 00:00:00 2001 From: nutbuster Date: Sat, 17 Jul 2021 12:46:42 +1000 Subject: [PATCH] CG Gallery EX Remove Gallery Object Text & Correct Aspect Ratio Thumbnails Pan & Scan --- game/src/cg_gallery.rpy | 113 ++++++++++++++++++++++++---------------- 1 file changed, 68 insertions(+), 45 deletions(-) diff --git a/game/src/cg_gallery.rpy b/game/src/cg_gallery.rpy index 8afdf17..b88af48 100644 --- a/game/src/cg_gallery.rpy +++ b/game/src/cg_gallery.rpy @@ -2,21 +2,15 @@ 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) + 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 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 @@ -25,30 +19,11 @@ init python: galleryItems = [] # Make a scaled cg button - # (cg: string; ext: string; w: float; h: float; unlocked?: boolean): Displayable + # (cg: string; ext: string; w: float; h: float 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 + 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 @@ -63,24 +38,39 @@ init python: _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]) +#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']) - # 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 } + 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 +""" +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) @@ -91,10 +81,43 @@ screen cg_gallery(): 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 + 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