Setup scene for the statue nonsense

This commit is contained in:
Michal Pikulski
2025-11-24 13:43:42 +01:00
parent e9a6f35ef5
commit 6a41fd3340
50 changed files with 3391 additions and 214 deletions

View File

@@ -1,4 +1,5 @@
using Core;
using Minigames.StatueDressup.Controllers;
using Minigames.StatueDressup.Data;
using Minigames.StatueDressup.Utils;
using UI.DragAndDrop.Core;
@@ -8,7 +9,8 @@ using UnityEngine.UI;
namespace Minigames.StatueDressup.DragDrop
{
/// <summary>
/// Individual decoration item that can be dragged from menu to statue slots
/// Individual decoration item that can be dragged from menu to statue
/// Uses overlap detection instead of slot-based placement
/// </summary>
public class DecorationItem : DraggableObject
{
@@ -16,20 +18,38 @@ namespace Minigames.StatueDressup.DragDrop
[SerializeField] private DecorationData decorationData;
[SerializeField] private Image decorationImage;
[Header("Placement")]
[SerializeField] private RectTransform statueArea; // Reference to statue area for overlap check
private Vector2 _iconSize;
private Vector2 _authoredSize;
private Vector2 _originalMenuPosition;
private Vector2 _placedPosition; // Position when placed on statue
private bool _isInMenu = true;
private bool _isPlacedOnStatue = false;
private Transform _menuParent; // Original parent in menu
private Transform _statueParent; // Parent when placed on statue
private StatueDecorationController _controller; // Controller for registration
private AppleHills.Core.Settings.IStatueDressupSettings _settings; // Settings reference
// Properties
public DecorationData Data => decorationData;
public DecorationCategory Category => decorationData?.Category ?? DecorationCategory.Hats;
public bool IsInMenu => _isInMenu;
public bool IsPlacedOnStatue => _isPlacedOnStatue;
protected override void Initialize()
{
base.Initialize();
// Get settings
_settings = GameManager.GetSettingsObject<AppleHills.Core.Settings.IStatueDressupSettings>();
// Store menu parent
_menuParent = transform.parent;
// Find statue parent (will be set by controller)
// statueParent will be assigned externally
if (decorationData != null)
{
_iconSize = decorationData.IconSize;
@@ -83,35 +103,136 @@ namespace Minigames.StatueDressup.DragDrop
}
}
/// <summary>
/// Set statue area reference for overlap detection
/// </summary>
public void SetStatueArea(RectTransform statue)
{
statueArea = statue;
}
/// <summary>
/// Set statue parent for placing items
/// </summary>
public void SetStatueParent(Transform parent)
{
_statueParent = parent;
}
/// <summary>
/// Set controller for registration callbacks
/// </summary>
public void SetController(StatueDecorationController controller)
{
_controller = controller;
}
protected override void OnDragStartedHook()
{
Logging.Debug($"[DecorationItem] OnDragStarted: {decorationData?.DecorationName}");
// If picking up from statue, allow re-positioning
if (_isPlacedOnStatue)
{
_isPlacedOnStatue = false;
Logging.Debug($"[DecorationItem] Picking up from statue for re-positioning");
}
// Scale to authored size when dragging starts
if (RectTransform != null)
{
TweenAnimationUtility.AnimateScale(transform, Vector3.one, 0.2f);
// Animate size delta to authored size
// Smoothly transition from icon size to authored size
RectTransform.sizeDelta = _authoredSize;
float duration = _settings?.DragScaleTransitionDuration ?? 0.2f;
TweenAnimationUtility.AnimateScale(transform, Vector3.one, duration);
}
}
protected override void OnDragEndedHook()
{
Logging.Debug($"[DecorationItem] OnDragEnded: {decorationData?.DecorationName}, currentSlot={CurrentSlot?.name}");
Logging.Debug($"[DecorationItem] OnDragEnded: {decorationData?.DecorationName}");
// If not placed in a slot, return to menu
if (CurrentSlot == null)
// Check if overlapping with statue
if (IsOverlappingStatue())
{
ReturnToMenu();
PlaceOnStatue();
}
else
{
_isInMenu = false;
ReturnToMenu();
}
}
/// <summary>
/// Check if item overlaps with statue area
/// </summary>
private bool IsOverlappingStatue()
{
if (statueArea == null || RectTransform == null)
{
Logging.Warning($"[DecorationItem] Cannot check overlap - statueArea or RectTransform is null");
return false;
}
// Get bounds of this item in world space
Rect itemRect = GetWorldRect(RectTransform);
Rect statueRect = GetWorldRect(statueArea);
// Check for any overlap
bool overlaps = itemRect.Overlaps(statueRect);
Logging.Debug($"[DecorationItem] Overlap check: {decorationData?.DecorationName}, overlaps={overlaps}");
Logging.Debug($"[DecorationItem] Item rect: {itemRect}, Statue rect: {statueRect}");
return overlaps;
}
/// <summary>
/// Get world space rect for a RectTransform
/// </summary>
private Rect GetWorldRect(RectTransform rectTransform)
{
Vector3[] corners = new Vector3[4];
rectTransform.GetWorldCorners(corners);
Vector3 bottomLeft = corners[0];
Vector3 topRight = corners[2];
return new Rect(bottomLeft.x, bottomLeft.y, topRight.x - bottomLeft.x, topRight.y - bottomLeft.y);
}
/// <summary>
/// Place item on statue at current position
/// </summary>
private void PlaceOnStatue()
{
Logging.Debug($"[DecorationItem] Placing on statue: {decorationData?.DecorationName}");
_isInMenu = false;
_isPlacedOnStatue = true;
// Store current position
if (RectTransform != null)
{
_placedPosition = RectTransform.anchoredPosition;
}
// Move to statue parent if specified
if (_statueParent != null && transform.parent != _statueParent)
{
transform.SetParent(_statueParent, true); // Keep world position
}
// Register with controller
if (_controller != null)
{
_controller.RegisterDecoration(this);
}
// Keep authored size
// Position is already set by drag
}
/// <summary>
/// Return item to menu with animation
/// </summary>
@@ -119,21 +240,34 @@ namespace Minigames.StatueDressup.DragDrop
{
Logging.Debug($"[DecorationItem] Returning to menu: {decorationData?.DecorationName}");
// Unregister from controller if was placed on statue
if (_isPlacedOnStatue && _controller != null)
{
_controller.UnregisterDecoration(this);
}
_isInMenu = true;
_isPlacedOnStatue = false;
// Return to menu parent
if (_menuParent != null && transform.parent != _menuParent)
{
transform.SetParent(_menuParent, false); // Use local positioning
}
if (RectTransform != null)
{
// Animate back to icon size
RectTransform.sizeDelta = _iconSize;
TweenAnimationUtility.AnimateScale(transform, Vector3.one, 0.2f);
float scaleDuration = _settings?.DragScaleTransitionDuration ?? 0.2f;
TweenAnimationUtility.AnimateScale(transform, Vector3.one, scaleDuration);
// Animate back to original position
TweenAnimationUtility.AnimateAnchoredPosition(RectTransform, _originalMenuPosition, 0.3f);
float returnDuration = _settings?.ReturnToMenuDuration ?? 0.3f;
TweenAnimationUtility.AnimateAnchoredPosition(RectTransform, _originalMenuPosition, returnDuration);
}
}
/// <summary>
/// Set original menu position (called by menu controller)
/// </summary>
@@ -141,6 +275,14 @@ namespace Minigames.StatueDressup.DragDrop
{
_originalMenuPosition = position;
}
/// <summary>
/// Set menu parent (called by menu controller)
/// </summary>
public void SetMenuParent(Transform parent)
{
_menuParent = parent;
}
}
}

View File

@@ -13,7 +13,6 @@ namespace Minigames.StatueDressup.DragDrop
public class StatueDecorationSlot : DraggableSlot, IPointerEnterHandler, IPointerExitHandler
{
[Header("Slot Configuration")]
[SerializeField] private DecorationCategory allowedCategory;
[SerializeField] private bool isPermanent = true; // Can't remove once placed
[Header("Glow Effect")]
@@ -23,9 +22,7 @@ namespace Minigames.StatueDressup.DragDrop
private bool _isGlowing;
private Pixelplacement.TweenSystem.TweenBase _glowTween;
// Properties
public DecorationCategory AllowedCategory => allowedCategory;
public bool IsPermanent => isPermanent;
private void Start()
@@ -43,7 +40,7 @@ namespace Minigames.StatueDressup.DragDrop
if (eventData.pointerDrag != null)
{
var decoration = eventData.pointerDrag.GetComponent<DecorationItem>();
if (decoration != null && decoration.Category == allowedCategory && !IsOccupied)
if (decoration != null && !IsOccupied)
{
StartGlow();
}
@@ -100,19 +97,7 @@ namespace Minigames.StatueDressup.DragDrop
public new bool CanAccept(DraggableObject draggable)
{
// First check base conditions
if (!base.CanAccept(draggable))
return false;
// Then check category matching
if (draggable is DecorationItem decoration)
{
bool matches = decoration.Category == allowedCategory;
Logging.Debug($"[StatueDecorationSlot] CanAccept: {decoration.Data?.DecorationName}, " +
$"category={decoration.Category}, allowed={allowedCategory}, matches={matches}");
return matches;
}
return false;
return base.CanAccept(draggable);
}
private void OnDisable()