From 9f0ade7fe49032c8f49fbfd56da1486279eb48bb Mon Sep 17 00:00:00 2001 From: lazysnake Date: Thu, 17 Jun 2021 18:53:01 +0200 Subject: [PATCH] cg gallery wip vol4: pagination --- game/src/cg_gallery.rpy | 44 +++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/game/src/cg_gallery.rpy b/game/src/cg_gallery.rpy index 9e3aa79..e350eb0 100644 --- a/game/src/cg_gallery.rpy +++ b/game/src/cg_gallery.rpy @@ -14,6 +14,9 @@ init python: # { item: string; cg: Displayable; }[] galleryItems = [] + # Which page of the gallery is shown + galleryPage = 1 + # Make a scaled cg button # (cg: string, unlocked?: boolean): Displayable def cg(fname, unlocked = False): @@ -72,6 +75,16 @@ init python: end = start + GALLERY_CGS_PER_PAGE return galleryItems[start:end] + # Increments page + # (): None + def nextPage(): + galleryPage += 1 + + # Decrements page + # (): None + def prevPage(): + galleryPage -= 1 + # Call to loading the gallery loadGallery() @@ -84,16 +97,27 @@ screen cg_gallery(): use game_menu(_("Gallery"), scroll="viewport"): fixed: - $ pageItems = getGalleryPage(3) + $ pageItems = getGalleryPage(galleryPage) $ galleryRows = len(pageItems) / GALLERY_COLS - grid GALLERY_COLS galleryRows: + $ maxPage = len(galleryItems) / GALLERY_CGS_PER_PAGE + vbox: + hbox: + grid GALLERY_COLS galleryRows: - spacing gui.slot_spacing + spacing gui.slot_spacing - # Iterate through galleryItems and add cgs buttons - for item in pageItems: - if item["item"] == None: - # TODO: empty space - 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) + # Iterate through galleryItems and add cgs buttons + for item in pageItems: + if item["item"] == None: + # TODO: empty space + 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) + + hbox: + if galleryPage < maxPage: + textbutton ">" action SetVariable("galleryPage", galleryPage + 1) + + hbox: + if galleryPage > 1: + textbutton "<" action SetVariable("galleryPage", galleryPage - 1)