SnootGame/game/src/cg_gallery.rpy

236 lines
7.5 KiB
Plaintext
Raw Normal View History

2022-11-07 01:07:43 +00:00
init 2 python:
2021-07-17 06:37:32 +00:00
2022-11-07 01:07:43 +00:00
import json
2022-10-27 06:25:15 +00:00
2021-07-17 06:37:32 +00:00
# CONST PARAMS
2022-11-09 05:44:28 +00:00
GALLERY_COLS = 4
2021-07-17 06:37:32 +00:00
PREFERRED_WIDTH = 432 #px (1920 * 0.225)
PREFERRED_HEIGHT = 243 #px (1080 * 0.225)
2021-08-07 09:51:40 +00:00
PREFERRED_ASPECT_RATIO = 16.0/9.0 # 1.7777..
2021-07-17 06:37:32 +00:00
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)
2022-11-17 07:56:53 +00:00
CG_PATHS = []
2021-08-07 09:51:40 +00:00
#path: folder, name: shows up in gallery, eval: runs eval() on string
"""
Data structure that holds the data for each cg and button
2023-01-01 23:49:56 +00:00
item is name, cg is the image definition
{ item: str; cg: Displayable; }
2021-08-07 09:51:40 +00:00
(reference in this init python, actually used in screens)
"""
2023-01-01 23:49:56 +00:00
gallery_dic = {}
2021-07-17 06:37:32 +00:00
2023-01-01 23:49:56 +00:00
# Makes a scaled down cg button
def cg_(fname, w):
2022-10-27 06:25:15 +00:00
scale = PREFERRED_WIDTH / w
2022-11-07 01:07:43 +00:00
if type(fname) is str:
image = im.FactorScale(fname, scale, scale, True)
return image
else:
return Transform(fname, zoom=scale)
2023-01-01 23:49:56 +00:00
# For testing purposes, unlocks all images in the gallery (And by extension the bonus chapters)
def unlock_all():
for key in gallery_dic.keys():
for image in gallery_dic[key]:
renpy.mark_image_seen(image["item"])
2021-07-17 06:37:32 +00:00
# Reads /images/cgs dir for all image files
2021-08-07 09:51:40 +00:00
# Populates galleryItems
2021-07-17 06:37:32 +00:00
# () -> None
2022-11-07 01:07:43 +00:00
def jsonloadandpop():
2023-01-01 23:49:56 +00:00
2022-12-29 20:17:44 +00:00
fp = renpy.open_file('src/gallery_dataset.json')
2022-11-07 01:07:43 +00:00
data = json.load(fp)
list_img = renpy.list_images()
2023-01-01 23:49:56 +00:00
for tab in data['tabs']:
2022-11-07 01:07:43 +00:00
2023-01-01 23:49:56 +00:00
tab_name = _(tab['tab_name'])
2022-11-07 01:07:43 +00:00
_eval = None
2023-01-01 23:49:56 +00:00
if 'eval' in tab.keys():
_eval = tab['eval']
2022-11-07 01:07:43 +00:00
2023-01-01 23:49:56 +00:00
CG_PATHS.append({'name': tab_name, 'eval': _eval})
2022-11-07 01:07:43 +00:00
gallery_dic[tab_name] = []
#gallery_dataset
2023-01-01 23:49:56 +00:00
if 'items' in tab.keys():
for image in tab['items']:
name = image["name"]
cg = image["image"]
2022-11-07 01:07:43 +00:00
rcg = renpy.get_registered_image(cg)
item = {
"item": name,
2023-01-02 06:21:45 +00:00
"image": rcg,
2023-01-01 23:49:56 +00:00
"cg": cg_(rcg, 1920),
2022-11-07 01:07:43 +00:00
}
2023-01-01 23:49:56 +00:00
2022-11-07 01:07:43 +00:00
gallery_dic[tab_name].append(item)
2023-01-01 23:49:56 +00:00
2022-11-07 01:07:43 +00:00
pass
jsonloadandpop()
2022-12-29 20:17:44 +00:00
gallery_dic['Animations'] = [{
"item": 'fang tail',
2023-01-02 06:21:45 +00:00
"image": 'images/animations/fang tail thumbnail.webp',
2023-01-01 01:36:22 +00:00
"cg": 'images/animations/fang tail thumbnail.webp',
2022-12-29 20:17:44 +00:00
}]
renpy.image("fang tail", Movie(loop=True,play='images/animations/fang tail.webm')) # Since we are hard-coding might as well.
2022-10-27 06:25:15 +00:00
pass
2023-01-01 23:49:56 +00:00
# Bullshit for the scrollbar to reset back to the beggining. Bless the renpy Discord :pray:
default adjust = ui.adjustment()
2021-08-07 09:51:40 +00:00
"""
CG Gallery screen - A screen that shows the image gallery
2023-01-01 23:49:56 +00:00
Built-in Gallery Object has terrible defaults, so I just wrote my own stuff
2021-08-07 09:51:40 +00:00
"""
2023-01-01 23:49:56 +00:00
screen cg_gallery(origin = 'CG'):
2021-08-07 09:51:40 +00:00
if main_menu:
key "game_menu" action ShowMenu("main_menu")
2023-01-01 23:49:56 +00:00
# Bg for frame
2021-08-07 09:51:40 +00:00
add gui.main_menu_background
2023-01-01 23:49:56 +00:00
# Frame
2021-08-07 09:51:40 +00:00
add gui.game_menu_background
tag menu
python:
2023-01-01 23:49:56 +00:00
empty_spaces = gallery_rows = item_counter = 0
2021-08-07 09:51:40 +00:00
gallery_items = gallery_dic[origin]
items = len(gallery_items)
gallery_rows = (items / GALLERY_COLS) + 1
empty_spaces = GALLERY_COLS - (items % GALLERY_COLS)
2023-01-01 23:49:56 +00:00
vbox id "vbx":
2021-08-07 09:51:40 +00:00
transform:
zoom 0.95
hbox:
style_prefix "navigation"
xalign 0.5
spacing gui.navigation_spacing
for cp in CG_PATHS:
if cp['name'] == origin:
textbutton _(cp['name']) text_color gui.selected_color text_xalign 0.5
else:
if cp['eval'] is None:
2023-01-01 23:49:56 +00:00
textbutton _(cp['name']) text_color gui.idle_color text_hover_color gui.hover_color activate_sound "audio/ui/uiClick.wav" action (ShowMenu('cg_gallery', cp['name']),SetField(adjust, 'value', 0)) text_xalign 0.5
2021-08-07 09:51:40 +00:00
elif eval(cp['eval']):
2023-01-01 23:49:56 +00:00
textbutton _(cp['name']) text_color gui.idle_color text_hover_color gui.hover_color activate_sound "audio/ui/uiClick.wav" action (ShowMenu('cg_gallery', cp['name']),SetField(adjust, 'value', 0)) text_xalign 0.5
2021-08-07 09:51:40 +00:00
else:
textbutton _(cp['name']) text_xalign 0.5
2021-10-09 09:26:33 +00:00
2023-01-01 23:49:56 +00:00
textbutton _("Return") activate_sound "audio/ui/uiBack.wav" action ShowMenu('main_menu') text_xalign 0.5
2021-08-07 09:51:40 +00:00
transform:
zoom 0.95
xcenter 0.525
ycenter 0.525
2022-10-27 06:25:15 +00:00
vpgrid id "vpg":
2023-01-01 23:49:56 +00:00
if gallery_rows>=4:
scrollbars "vertical"
2021-08-07 09:51:40 +00:00
mousewheel True
draggable True
pagekeys True
xfill True
2023-01-01 23:49:56 +00:00
yadjustment adjust
2021-08-07 09:51:40 +00:00
2022-10-27 06:25:15 +00:00
xcenter 0.5
spacing 20
2021-08-07 09:51:40 +00:00
2022-10-27 06:25:15 +00:00
cols GALLERY_COLS
2021-08-07 09:51:40 +00:00
2022-10-27 06:25:15 +00:00
for item in gallery_items:
2023-01-01 23:49:56 +00:00
use flag_button(item, origin)
2022-10-27 06:25:15 +00:00
for i in range(0, empty_spaces):
null height 20
2021-08-07 09:51:40 +00:00
"""
if/else flow control & extra parameters for Buttons
"""
2023-01-01 23:49:56 +00:00
screen flag_button(item, origin):
$ flag = renpy.seen_image(item['item'])
2021-08-07 09:51:40 +00:00
if flag:
button:
2023-01-01 23:49:56 +00:00
if item in gallery_dic['Animations']:
action ShowMenu('view_movie', item, ShowMenu('cg_gallery', origin))
2021-08-07 09:51:40 +00:00
else:
2023-01-01 23:49:56 +00:00
action ShowMenu('view_image', item, ShowMenu('cg_gallery',origin))
2021-08-07 09:51:40 +00:00
xcenter 0.5 ycenter 0.5
vbox:
2022-12-29 20:17:44 +00:00
yminimum PREFERRED_HEIGHT xminimum PREFERRED_WIDTH
2021-08-07 09:51:40 +00:00
add item["cg"] fit 'contain' xcenter 0.5 ycenter 0.5 size (PREFERRED_WIDTH, PREFERRED_HEIGHT)
else:
vbox:
ymaximum PREFERRED_HEIGHT
xcenter 0.5 ycenter 0.5
add NOT_UNLOCKED_COVER
screen view_movie(item, _origin):
tag menu
2022-11-16 16:55:40 +00:00
key "game_menu" action [Hide('view_movie'), _origin ]
key "button_alternate" action [Hide('view_movie'), _origin ]
add item['item']
2023-01-01 23:49:56 +00:00
if renpy.variant("small"):
hbox:
style_prefix "quick"
xalign 0.5
yalign 0.975
2022-11-30 00:40:46 +00:00
use quick_buttons("gui/button/uioptionbuttons/template_idle.png",
[
[ "Return", _origin ]
] )
2021-08-07 09:51:40 +00:00
"""
view_image, Loads the image in fullscreen with viewport control.
"""
2023-01-01 23:49:56 +00:00
screen view_image(item, _origin):
2021-07-17 06:37:32 +00:00
tag menu
2023-01-01 23:49:56 +00:00
key "game_menu" action (Hide('view_image'), _origin)
key "button_alternate" action (Hide('view_image'), _origin)
2021-08-07 09:51:40 +00:00
viewport id "vie":
#Ren'Py isn't smart enough to not edgescroll while pressed,
#so we'll have to disable this for mobile
if renpy.variant("pc"):
edgescroll (300, 1800)
draggable True
arrowkeys True
pagekeys True
xfill False
yfill False
2023-01-02 06:21:45 +00:00
add item['image'] zoom 1.0 anchor (0.55, 0.55)
2023-01-01 23:49:56 +00:00
#Reuse quick buttons. Ren'Py handles touch input lazy, it doesn't have
#double finger pinch zoom, it translates taps as mouse events - have to use
#buttons
if renpy.variant("small"):
hbox:
style_prefix "quick"
xalign 0.5
yalign 0.975
2021-08-07 09:51:40 +00:00
use quick_buttons("gui/button/uioptionbuttons/template_idle.png",
[
[ "Return", _origin ]
] )
2021-07-17 06:37:32 +00:00