mirror of
https://git.cavemanon.xyz/Cavemanon/SnootGame.git
synced 2025-04-02 08:41:45 +02: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
|
# CONST PARAMS
|
||||||
GALLERY_COLS = 3
|
GALLERY_COLS = 3
|
||||||
|
GALLERY_CGS_PER_PAGE = 6
|
||||||
NOT_UNLOCKED_COVER = im.FactorScale("gui/gallery/unlocked_cg_button_cover.png", 0.225, 0.225)
|
NOT_UNLOCKED_COVER = im.FactorScale("gui/gallery/unlocked_cg_button_cover.png", 0.225, 0.225)
|
||||||
|
|
||||||
# GALLERY ITEMS
|
# GALLERY ITEMS
|
||||||
|
@ -22,6 +23,7 @@ init python:
|
||||||
return im.FactorScale("images/cgs/" + fname + ".png", 0.225, 0.225)
|
return im.FactorScale("images/cgs/" + fname + ".png", 0.225, 0.225)
|
||||||
|
|
||||||
# Create an object in g:Gallery, add to galleryItems
|
# Create an object in g:Gallery, add to galleryItems
|
||||||
|
# (imageName: string; unlocked?: boolean): None
|
||||||
def addGalleryItem(imageName, unlocked = False):
|
def addGalleryItem(imageName, unlocked = False):
|
||||||
g.button(imageName)
|
g.button(imageName)
|
||||||
g.image(imageName)
|
g.image(imageName)
|
||||||
|
@ -39,6 +41,7 @@ init python:
|
||||||
# Reads /images/cgs dir for all .png files
|
# Reads /images/cgs dir for all .png files
|
||||||
# Populates g:Gallery and galleryItems
|
# Populates g:Gallery and galleryItems
|
||||||
# Appends extra spaces at the end
|
# Appends extra spaces at the end
|
||||||
|
# (): None
|
||||||
def loadGallery():
|
def loadGallery():
|
||||||
from os import listdir, getcwd
|
from os import listdir, getcwd
|
||||||
from os.path import isfile, join
|
from os.path import isfile, join
|
||||||
|
@ -62,6 +65,13 @@ init python:
|
||||||
"cg": None
|
"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
|
# Call to loading the gallery
|
||||||
loadGallery()
|
loadGallery()
|
||||||
|
|
||||||
|
@ -74,15 +84,16 @@ screen cg_gallery():
|
||||||
use game_menu(_("Gallery"), scroll="viewport"):
|
use game_menu(_("Gallery"), scroll="viewport"):
|
||||||
|
|
||||||
fixed:
|
fixed:
|
||||||
$ galleryRows = len(galleryItems) / GALLERY_COLS
|
$ pageItems = getGalleryPage(3)
|
||||||
|
$ galleryRows = len(pageItems) / GALLERY_COLS
|
||||||
grid GALLERY_COLS galleryRows:
|
grid GALLERY_COLS galleryRows:
|
||||||
|
|
||||||
spacing gui.slot_spacing
|
spacing gui.slot_spacing
|
||||||
|
|
||||||
# Iterate through galleryItems and add cgs buttons
|
# Iterate through galleryItems and add cgs buttons
|
||||||
for item in galleryItems:
|
for item in pageItems:
|
||||||
if item["item"] == None:
|
if item["item"] == None:
|
||||||
# TODO: empty space
|
# 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:
|
else:
|
||||||
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)
|
||||||
|
|
Loading…
Add table
Reference in a new issue