using Core; using UnityEngine; using UnityEngine.UI; using UnityEngine.EventSystems; namespace Minigames.StatueDressup.Controllers { /// /// Individual photo thumbnail in the gallery grid. /// Handles click to show enlarged view. /// public class PhotoGridItem : MonoBehaviour, IPointerClickHandler { [Header("References")] [SerializeField] private Image thumbnailImage; [SerializeField] private GameObject loadingIndicator; private string photoId; private StatuePhotoGalleryController galleryController; /// /// Initialize grid item with photo ID /// public void Initialize(string newPhotoId, StatuePhotoGalleryController controller) { this.photoId = newPhotoId; galleryController = controller; // Show loading state if (loadingIndicator != null) loadingIndicator.SetActive(true); if (thumbnailImage != null) thumbnailImage.enabled = false; } /// /// Set the thumbnail texture /// public void SetThumbnail(Texture2D thumbnail) { if (thumbnail == null) { Logging.Warning($"[PhotoGridItem] Null thumbnail for photo: {photoId}"); return; } // Create sprite from thumbnail Sprite thumbnailSprite = Sprite.Create( thumbnail, new Rect(0, 0, thumbnail.width, thumbnail.height), new Vector2(0.5f, 0.5f) ); if (thumbnailImage != null) { thumbnailImage.sprite = thumbnailSprite; thumbnailImage.enabled = true; } // Hide loading indicator if (loadingIndicator != null) loadingIndicator.SetActive(false); } /// /// Handle click to enlarge/shrink photo /// public void OnPointerClick(PointerEventData eventData) { if (galleryController != null && !string.IsNullOrEmpty(photoId)) { Logging.Debug($"[PhotoGridItem] Clicked: {photoId}"); galleryController.OnGridItemClicked(this, photoId); } } } }