Add seeing mr Cement photos in the album

This commit is contained in:
Michal Pikulski
2025-12-15 15:24:17 +01:00
parent de02394198
commit f72b8f3cf5
20 changed files with 2194 additions and 230 deletions

View File

@@ -3,7 +3,7 @@ using UnityEngine;
using UnityEngine.EventSystems;
using Utils;
namespace Minigames.StatueDressup.Controllers
namespace Minigames.StatueDressup.PhotoGallery
{
/// <summary>
/// Manages enlarged photo preview display.
@@ -12,32 +12,32 @@ namespace Minigames.StatueDressup.Controllers
/// </summary>
public class PhotoEnlargeController
{
private readonly GameObject backdrop;
private readonly Transform enlargedContainer;
private readonly float animationDuration;
private readonly GameObject _backdrop;
private readonly Transform _enlargedContainer;
private readonly float _animationDuration;
private GameObject currentEnlargedPreview;
private PhotoGridItem currentSourceItem;
private GameObject _currentEnlargedPreview;
private MonoBehaviour _currentSourceItem;
/// <summary>
/// Constructor
/// </summary>
public PhotoEnlargeController(GameObject backdrop, Transform enlargedContainer, float animationDuration = 0.3f)
{
this.backdrop = backdrop;
this.enlargedContainer = enlargedContainer;
this.animationDuration = animationDuration;
this._backdrop = backdrop;
this._enlargedContainer = enlargedContainer;
this._animationDuration = animationDuration;
}
/// <summary>
/// Check if a photo is currently enlarged
/// </summary>
public bool IsPhotoEnlarged => currentEnlargedPreview != null;
public bool IsPhotoEnlarged => _currentEnlargedPreview != null;
/// <summary>
/// Enlarge a photo from a grid item
/// </summary>
public void EnlargePhoto(PhotoGridItem sourceItem, GameObject previewPrefab, Texture2D photoTexture, float enlargedScale)
public void EnlargePhoto(MonoBehaviour sourceItem, GameObject previewPrefab, Texture2D photoTexture, float enlargedScale)
{
if (sourceItem == null || previewPrefab == null || photoTexture == null)
{
@@ -46,30 +46,30 @@ namespace Minigames.StatueDressup.Controllers
}
// Don't allow multiple enlargements
if (currentEnlargedPreview != null)
if (_currentEnlargedPreview != null)
{
Logging.Warning("[PhotoEnlargeController] Photo already enlarged");
return;
}
currentSourceItem = sourceItem;
_currentSourceItem = sourceItem;
// Show backdrop
if (backdrop != null)
if (_backdrop != null)
{
backdrop.SetActive(true);
_backdrop.SetActive(true);
}
// Spawn preview clone
currentEnlargedPreview = Object.Instantiate(previewPrefab, enlargedContainer);
currentEnlargedPreview.transform.SetAsLastSibling();
_currentEnlargedPreview = Object.Instantiate(previewPrefab, _enlargedContainer);
_currentEnlargedPreview.transform.SetAsLastSibling();
// Position at source item's world position
currentEnlargedPreview.transform.position = sourceItem.transform.position;
currentEnlargedPreview.transform.localScale = sourceItem.transform.localScale;
_currentEnlargedPreview.transform.position = sourceItem.transform.position;
_currentEnlargedPreview.transform.localScale = sourceItem.transform.localScale;
// Set photo texture on preview
var previewImage = currentEnlargedPreview.GetComponent<UnityEngine.UI.Image>();
var previewImage = _currentEnlargedPreview.GetComponent<UnityEngine.UI.Image>();
if (previewImage != null)
{
// Create sprite from texture
@@ -82,10 +82,10 @@ namespace Minigames.StatueDressup.Controllers
}
// Add click handler to preview
var clickHandler = currentEnlargedPreview.GetComponent<EventTrigger>();
var clickHandler = _currentEnlargedPreview.GetComponent<EventTrigger>();
if (clickHandler == null)
{
clickHandler = currentEnlargedPreview.AddComponent<EventTrigger>();
clickHandler = _currentEnlargedPreview.AddComponent<EventTrigger>();
}
var pointerClickEntry = new EventTrigger.Entry { eventID = EventTriggerType.PointerClick };
@@ -93,8 +93,8 @@ namespace Minigames.StatueDressup.Controllers
clickHandler.triggers.Add(pointerClickEntry);
// Animate to center and scale up
TweenAnimationUtility.AnimateLocalPosition(currentEnlargedPreview.transform, Vector3.zero, animationDuration);
TweenAnimationUtility.AnimateScale(currentEnlargedPreview.transform, Vector3.one * enlargedScale, animationDuration);
TweenAnimationUtility.AnimateLocalPosition(_currentEnlargedPreview.transform, Vector3.zero, _animationDuration);
TweenAnimationUtility.AnimateScale(_currentEnlargedPreview.transform, Vector3.one * enlargedScale, _animationDuration);
// Play audio feedback
AudioManager.Instance.LoadAndPlayUIAudio("card_albumdrop_deep", false);
@@ -107,35 +107,35 @@ namespace Minigames.StatueDressup.Controllers
/// </summary>
public void ShrinkPhoto()
{
if (currentEnlargedPreview == null || currentSourceItem == null)
if (_currentEnlargedPreview == null || _currentSourceItem == null)
{
Logging.Warning("[PhotoEnlargeController] No photo to shrink");
return;
}
// Hide backdrop
if (backdrop != null)
if (_backdrop != null)
{
backdrop.SetActive(false);
_backdrop.SetActive(false);
}
// Get target position from source item
Vector3 targetWorldPos = currentSourceItem.transform.position;
Vector3 targetScale = currentSourceItem.transform.localScale;
Vector3 targetWorldPos = _currentSourceItem.transform.position;
Vector3 targetScale = _currentSourceItem.transform.localScale;
GameObject previewToDestroy = currentEnlargedPreview;
GameObject previewToDestroy = _currentEnlargedPreview;
// Animate back to source position
Pixelplacement.Tween.Position(previewToDestroy.transform, targetWorldPos, animationDuration, 0f, Pixelplacement.Tween.EaseInOut);
TweenAnimationUtility.AnimateScale(previewToDestroy.transform, targetScale, animationDuration, () =>
Pixelplacement.Tween.Position(previewToDestroy.transform, targetWorldPos, _animationDuration, 0f, Pixelplacement.Tween.EaseInOut);
TweenAnimationUtility.AnimateScale(previewToDestroy.transform, targetScale, _animationDuration, () =>
{
// Destroy preview after animation
Object.Destroy(previewToDestroy);
});
// Clear references
currentEnlargedPreview = null;
currentSourceItem = null;
_currentEnlargedPreview = null;
_currentSourceItem = null;
Logging.Debug("[PhotoEnlargeController] Photo shrunk");
}
@@ -145,18 +145,18 @@ namespace Minigames.StatueDressup.Controllers
/// </summary>
public void Cleanup()
{
if (currentEnlargedPreview != null)
if (_currentEnlargedPreview != null)
{
Object.Destroy(currentEnlargedPreview);
currentEnlargedPreview = null;
Object.Destroy(_currentEnlargedPreview);
_currentEnlargedPreview = null;
}
if (backdrop != null)
if (_backdrop != null)
{
backdrop.SetActive(false);
_backdrop.SetActive(false);
}
currentSourceItem = null;
_currentSourceItem = null;
}
}
}