From f4a7c84f81d1e6ce71d0fbd94dd1ce9304f5bfa9 Mon Sep 17 00:00:00 2001 From: lazysnake Date: Thu, 17 Jun 2021 18:36:25 +0200 Subject: [PATCH] cg gallery wip vol3: basic pagination handler --- game/src/cg_gallery.rpy | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/game/src/cg_gallery.rpy b/game/src/cg_gallery.rpy index be192ff..9e3aa79 100644 --- a/game/src/cg_gallery.rpy +++ b/game/src/cg_gallery.rpy @@ -5,6 +5,7 @@ init python: # CONST PARAMS GALLERY_COLS = 3 + GALLERY_CGS_PER_PAGE = 6 NOT_UNLOCKED_COVER = im.FactorScale("gui/gallery/unlocked_cg_button_cover.png", 0.225, 0.225) # GALLERY ITEMS @@ -22,6 +23,7 @@ init python: return im.FactorScale("images/cgs/" + fname + ".png", 0.225, 0.225) # Create an object in g:Gallery, add to galleryItems + # (imageName: string; unlocked?: boolean): None def addGalleryItem(imageName, unlocked = False): g.button(imageName) g.image(imageName) @@ -39,6 +41,7 @@ init python: # Reads /images/cgs dir for all .png files # Populates g:Gallery and galleryItems # Appends extra spaces at the end + # (): None def loadGallery(): from os import listdir, getcwd from os.path import isfile, join @@ -62,6 +65,13 @@ init python: "cg": None }) + # Returns the pageth slice from galleryItems + # (page: int): Partial + def getGalleryPage(page): + start = (page - 1) * GALLERY_CGS_PER_PAGE + end = start + GALLERY_CGS_PER_PAGE + return galleryItems[start:end] + # Call to loading the gallery loadGallery() @@ -74,15 +84,16 @@ screen cg_gallery(): use game_menu(_("Gallery"), scroll="viewport"): fixed: - $ galleryRows = len(galleryItems) / GALLERY_COLS + $ pageItems = getGalleryPage(3) + $ galleryRows = len(pageItems) / GALLERY_COLS grid GALLERY_COLS galleryRows: spacing gui.slot_spacing # Iterate through galleryItems and add cgs buttons - for item in galleryItems: + for item in pageItems: if item["item"] == None: # TODO: empty space - add g.make_button(galleryItems[0]["item"], galleryItems[0]["cg"], xalign = 0.5, yalign = 0.5) + add g.make_button(pageItems[0]["item"], pageItems[0]["cg"], xalign = 0.5, yalign = 0.5) else: add g.make_button(item["item"], item["cg"], xalign = 0.5, yalign = 0.5)