mirror of
https://git.cavemanon.xyz/Cavemanon/SnootGame.git
synced 2025-03-26 11:54:49 +01:00
cg gallery wip vol3: basic pagination handler
This commit is contained in:
parent
f819958d80
commit
f4a7c84f81
1 changed files with 14 additions and 3 deletions
|
@ -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<typeof galleryItems>
|
||||
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)
|
||||
|
|
Loading…
Add table
Reference in a new issue