Files
tgcc/core/game_menu/photo_gallery.gd
2026-06-30 20:01:13 +00:00

31 lines
859 B
GDScript

extends Control
@export var photo_scene: PackedScene
@onready var grid_container: GridContainer = $%PhotoGrid
func _ready() -> void:
CollectionManager.on_photo_saved.connect(_create_photo_thumbnail)
load_gallery()
func load_gallery() -> void:
for child in grid_container.get_children():
child.queue_free()
var saved_photos = CollectionManager.saved_photos
for file_path in saved_photos:
if FileAccess.file_exists(file_path):
_create_photo_thumbnail(file_path)
if is_inside_tree():
await get_tree().process_frame
func _create_photo_thumbnail(file_path: String) -> void:
var image = Image.load_from_file(file_path)
if image:
var photo: Photo = photo_scene.instantiate()
var texture = ImageTexture.create_from_image(image)
photo.setup(texture)
grid_container.add_child(photo)
photo.custom_minimum_size = Vector2(132,154)