Finalized work
This commit is contained in:
@@ -49,6 +49,12 @@ namespace Minigames.StatueDressup.Controllers
|
||||
{
|
||||
Logging.Error("[DecorationMenuController] Failed to load StatueDressupSettings!");
|
||||
}
|
||||
|
||||
// Ensure outline starts hidden (do this early so it's ready for saved decorations)
|
||||
if (statueOutline != null)
|
||||
{
|
||||
statueOutline.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -64,12 +70,6 @@ namespace Minigames.StatueDressup.Controllers
|
||||
return;
|
||||
}
|
||||
|
||||
// Ensure outline starts hidden
|
||||
if (statueOutline != null)
|
||||
{
|
||||
statueOutline.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
var allDecorations = _settings.AllDecorations;
|
||||
int itemsPerPage = _settings.ItemsPerPage;
|
||||
|
||||
@@ -185,14 +185,16 @@ namespace Minigames.StatueDressup.Controllers
|
||||
// Get outline RectTransform for overlap detection
|
||||
RectTransform outlineRect = statueOutline != null ? statueOutline.rectTransform : null;
|
||||
|
||||
// Initialize with references
|
||||
// Initialize with references including outline callbacks
|
||||
instance.Initialize(
|
||||
data,
|
||||
outlineRect,
|
||||
statueController.StatueParent,
|
||||
statueController,
|
||||
_settings,
|
||||
OnDraggableFinished
|
||||
OnDraggableFinished,
|
||||
ShowStatueOutline, // Show outline when picking up from statue
|
||||
HideStatueOutline // Hide outline when drag ends
|
||||
);
|
||||
|
||||
// Position at cursor (in local space)
|
||||
@@ -220,19 +222,24 @@ namespace Minigames.StatueDressup.Controllers
|
||||
/// <summary>
|
||||
/// Show the statue outline to indicate valid drop area
|
||||
/// </summary>
|
||||
private void ShowStatueOutline()
|
||||
public void ShowStatueOutline()
|
||||
{
|
||||
Logging.Debug($"[DecorationMenuController] ShowStatueOutline called - statueOutline is null: {statueOutline == null}");
|
||||
if (statueOutline != null)
|
||||
{
|
||||
statueOutline.gameObject.SetActive(true);
|
||||
Logging.Debug("[DecorationMenuController] Statue outline shown");
|
||||
}
|
||||
else
|
||||
{
|
||||
Logging.Warning("[DecorationMenuController] Cannot show outline - statueOutline is null!");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hide the statue outline after drag ends
|
||||
/// </summary>
|
||||
private void HideStatueOutline()
|
||||
public void HideStatueOutline()
|
||||
{
|
||||
if (statueOutline != null)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Core;
|
||||
using Core.Lifecycle;
|
||||
using Minigames.StatueDressup.Data;
|
||||
@@ -420,11 +421,25 @@ namespace Minigames.StatueDressup.Controllers
|
||||
// Spawn decoration instance
|
||||
DecorationDraggableInstance instance = Instantiate(draggablePrefab, statueParent);
|
||||
|
||||
// Get canvas parent for drag context (used when picking up)
|
||||
Transform canvasParent = statueParent.parent; // Typically the canvas or draggable container
|
||||
|
||||
// Create callbacks for outline show/hide
|
||||
Logging.Debug($"[StatueDecorationController] MenuController is null: {menuController == null}");
|
||||
System.Action showOutlineCallback = menuController != null ? (System.Action)menuController.ShowStatueOutline : null;
|
||||
System.Action hideOutlineCallback = menuController != null ? (System.Action)menuController.HideStatueOutline : null;
|
||||
Logging.Debug($"[StatueDecorationController] Show outline callback is null: {showOutlineCallback == null}");
|
||||
|
||||
// Initialize in "placed" state (skip drag logic)
|
||||
instance.InitializeAsPlaced(
|
||||
decorationData,
|
||||
this,
|
||||
_settings
|
||||
_settings,
|
||||
statueArea, // Pass statue outline for overlap detection
|
||||
canvasParent, // Pass canvas parent for reparenting during pickup
|
||||
showOutlineCallback, // Show outline when picking up
|
||||
hideOutlineCallback, // Hide outline when drag ends
|
||||
hideOutlineCallback // Also use hide callback for onFinished
|
||||
);
|
||||
|
||||
// Apply saved transform
|
||||
@@ -480,6 +495,13 @@ namespace Minigames.StatueDressup.Controllers
|
||||
// openGalleryButton.onClick.RemoveListener(OnOpenGallery);
|
||||
// }
|
||||
}
|
||||
|
||||
public async void ExitToAppleHills()
|
||||
{
|
||||
// Replace with the actual scene name as set in Build Settings
|
||||
var progress = new Progress<float>(p => Logging.Debug($"Loading progress: {p * 100:F0}%"));
|
||||
await SceneManagerService.Instance.SwitchSceneAsync("AppleHillsOverworld", progress);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,8 +12,9 @@ namespace Minigames.StatueDressup.DragDrop
|
||||
/// Draggable instance of a decoration that can be placed on the statue.
|
||||
/// Created dynamically when dragging from menu or picking up from statue.
|
||||
/// Destroyed if dropped outside statue area.
|
||||
/// Supports tapping and dragging when placed on statue.
|
||||
/// </summary>
|
||||
public class DecorationDraggableInstance : MonoBehaviour
|
||||
public class DecorationDraggableInstance : MonoBehaviour, IPointerClickHandler, IBeginDragHandler, IDragHandler, IEndDragHandler
|
||||
{
|
||||
[Header("References")]
|
||||
[SerializeField] private Image decorationImage;
|
||||
@@ -22,15 +23,19 @@ namespace Minigames.StatueDressup.DragDrop
|
||||
private DecorationData _decorationData;
|
||||
private RectTransform _rectTransform;
|
||||
private Canvas _canvas;
|
||||
private Transform _canvasParent; // Parent transform for dragging (usually canvas or draggable container)
|
||||
private RectTransform _statueOutline;
|
||||
private Transform _statueParent;
|
||||
private StatueDecorationController _controller;
|
||||
private AppleHills.Core.Settings.IStatueDressupSettings _settings;
|
||||
private System.Action _onFinishedCallback;
|
||||
private System.Action _onShowOutlineCallback;
|
||||
private System.Action _onHideOutlineCallback;
|
||||
|
||||
private bool _isDragging;
|
||||
private bool _isPlacedOnStatue;
|
||||
private Vector3 _dragOffset;
|
||||
private bool _dragStarted; // Track if drag actually started (vs just a click)
|
||||
|
||||
// Properties
|
||||
public DecorationData Data => _decorationData;
|
||||
@@ -41,10 +46,22 @@ namespace Minigames.StatueDressup.DragDrop
|
||||
_rectTransform = GetComponent<RectTransform>();
|
||||
_canvas = GetComponentInParent<Canvas>();
|
||||
|
||||
// Store initial parent for dragging context
|
||||
if (transform.parent != null)
|
||||
{
|
||||
_canvasParent = transform.parent;
|
||||
}
|
||||
|
||||
if (canvasGroup == null)
|
||||
{
|
||||
canvasGroup = gameObject.AddComponent<CanvasGroup>();
|
||||
}
|
||||
|
||||
// Ensure the decoration image can receive raycasts
|
||||
if (decorationImage != null)
|
||||
{
|
||||
decorationImage.raycastTarget = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -52,7 +69,7 @@ namespace Minigames.StatueDressup.DragDrop
|
||||
/// </summary>
|
||||
public void Initialize(DecorationData data, RectTransform statueOutline, Transform statueParent,
|
||||
StatueDecorationController controller, AppleHills.Core.Settings.IStatueDressupSettings settings,
|
||||
System.Action onFinishedCallback)
|
||||
System.Action onFinishedCallback, System.Action onShowOutline = null, System.Action onHideOutline = null)
|
||||
{
|
||||
_decorationData = data;
|
||||
_statueOutline = statueOutline;
|
||||
@@ -60,6 +77,8 @@ namespace Minigames.StatueDressup.DragDrop
|
||||
_controller = controller;
|
||||
_settings = settings;
|
||||
_onFinishedCallback = onFinishedCallback;
|
||||
_onShowOutlineCallback = onShowOutline;
|
||||
_onHideOutlineCallback = onHideOutline;
|
||||
|
||||
// Set sprite
|
||||
if (decorationImage != null && data != null && data.DecorationSprite != null)
|
||||
@@ -81,7 +100,9 @@ namespace Minigames.StatueDressup.DragDrop
|
||||
/// Skips drag logic and sets up as if already placed on statue
|
||||
/// </summary>
|
||||
public void InitializeAsPlaced(DecorationData data, StatueDecorationController controller,
|
||||
AppleHills.Core.Settings.IStatueDressupSettings settings)
|
||||
AppleHills.Core.Settings.IStatueDressupSettings settings, RectTransform statueOutline = null,
|
||||
Transform canvasParent = null, System.Action onShowOutline = null, System.Action onHideOutline = null,
|
||||
System.Action onFinished = null)
|
||||
{
|
||||
_decorationData = data;
|
||||
_controller = controller;
|
||||
@@ -89,6 +110,23 @@ namespace Minigames.StatueDressup.DragDrop
|
||||
_isPlacedOnStatue = true;
|
||||
_isDragging = false;
|
||||
|
||||
// Store references needed for pickup
|
||||
_statueOutline = statueOutline;
|
||||
_statueParent = transform.parent; // Already parented to statue when this is called
|
||||
if (canvasParent != null)
|
||||
{
|
||||
_canvasParent = canvasParent;
|
||||
}
|
||||
|
||||
// Store outline callbacks for when picking up from statue
|
||||
_onShowOutlineCallback = onShowOutline;
|
||||
_onHideOutlineCallback = onHideOutline;
|
||||
_onFinishedCallback = onFinished;
|
||||
|
||||
Logging.Debug($"[DecorationDraggableInstance] InitializeAsPlaced - Show outline callback is null: {_onShowOutlineCallback == null}");
|
||||
Logging.Debug($"[DecorationDraggableInstance] InitializeAsPlaced - Hide outline callback is null: {_onHideOutlineCallback == null}");
|
||||
Logging.Debug($"[DecorationDraggableInstance] InitializeAsPlaced - Finished callback is null: {_onFinishedCallback == null}");
|
||||
|
||||
// Set sprite
|
||||
if (decorationImage != null && data != null && data.DecorationSprite != null)
|
||||
{
|
||||
@@ -101,7 +139,7 @@ namespace Minigames.StatueDressup.DragDrop
|
||||
_rectTransform.sizeDelta = data.AuthoredSize;
|
||||
}
|
||||
|
||||
// Make non-interactive for placed state (can be made interactive later if needed)
|
||||
// Make interactive so it can be picked up
|
||||
if (canvasGroup != null)
|
||||
{
|
||||
canvasGroup.blocksRaycasts = true;
|
||||
@@ -250,8 +288,11 @@ namespace Minigames.StatueDressup.DragDrop
|
||||
/// <summary>
|
||||
/// Allow picking up from statue for repositioning
|
||||
/// </summary>
|
||||
public void StartDragFromStatue(Vector3 pointerPosition)
|
||||
public void StartDragFromStatue(PointerEventData eventData)
|
||||
{
|
||||
Logging.Debug($"[DecorationDraggableInstance] StartDragFromStatue called for: {_decorationData?.DecorationName}");
|
||||
Logging.Debug($"[DecorationDraggableInstance] Show outline callback is null: {_onShowOutlineCallback == null}");
|
||||
|
||||
if (_controller != null)
|
||||
{
|
||||
_controller.UnregisterDecoration(this);
|
||||
@@ -260,17 +301,87 @@ namespace Minigames.StatueDressup.DragDrop
|
||||
_isPlacedOnStatue = false;
|
||||
_isDragging = true;
|
||||
|
||||
// Calculate offset
|
||||
// Show statue outline when picking up from statue
|
||||
if (_onShowOutlineCallback != null)
|
||||
{
|
||||
Logging.Debug("[DecorationDraggableInstance] Invoking show outline callback");
|
||||
_onShowOutlineCallback.Invoke();
|
||||
}
|
||||
else
|
||||
{
|
||||
Logging.Warning("[DecorationDraggableInstance] Show outline callback is null - cannot show outline!");
|
||||
}
|
||||
|
||||
// Reparent to canvas for dragging (so coordinates work correctly)
|
||||
if (_canvasParent != null && transform.parent != _canvasParent)
|
||||
{
|
||||
// Store world position before reparenting
|
||||
Vector3 worldPos = transform.position;
|
||||
transform.SetParent(_canvasParent, false);
|
||||
transform.position = worldPos; // Restore world position
|
||||
}
|
||||
|
||||
// Calculate offset using proper camera
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(
|
||||
_canvas.transform as RectTransform,
|
||||
pointerPosition,
|
||||
null,
|
||||
eventData.position,
|
||||
eventData.pressEventCamera,
|
||||
out Vector2 localPoint);
|
||||
|
||||
_dragOffset = _rectTransform.localPosition - (Vector3)localPoint;
|
||||
|
||||
Logging.Debug($"[DecorationDraggableInstance] Started drag from statue: {_decorationData?.DecorationName}");
|
||||
}
|
||||
|
||||
#region Pointer Event Handlers
|
||||
|
||||
/// <summary>
|
||||
/// Handle pointer click - only when placed on statue
|
||||
/// </summary>
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
// Only handle clicks when placed on statue and not currently dragging
|
||||
if (!_isPlacedOnStatue || _dragStarted) return;
|
||||
|
||||
Logging.Debug($"[DecorationDraggableInstance] Decoration tapped: {_decorationData?.DecorationName}");
|
||||
|
||||
// Future: Open detail view, play sound effect, show info popup, etc.
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle drag start - only when placed on statue
|
||||
/// </summary>
|
||||
public void OnBeginDrag(PointerEventData eventData)
|
||||
{
|
||||
// Only handle drag from statue if already placed
|
||||
if (!_isPlacedOnStatue) return;
|
||||
|
||||
_dragStarted = true;
|
||||
StartDragFromStatue(eventData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle drag continuation
|
||||
/// </summary>
|
||||
public void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
if (!_isDragging) return;
|
||||
|
||||
ContinueDrag(eventData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle drag end
|
||||
/// </summary>
|
||||
public void OnEndDrag(PointerEventData eventData)
|
||||
{
|
||||
if (!_isDragging) return;
|
||||
|
||||
_dragStarted = false;
|
||||
EndDrag(eventData);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -103,7 +103,8 @@ namespace UI
|
||||
public GameObject eagleEye;
|
||||
public GameObject ramaSjangButton;
|
||||
public GameObject scrabBookButton;
|
||||
|
||||
public GameObject pauseButton;
|
||||
|
||||
[HideInInspector] public Image cinematicSprites;
|
||||
[HideInInspector] public Image cinematicBackgroundSprites;
|
||||
[HideInInspector] public GameObject currentCinematicPlayer;
|
||||
@@ -235,9 +236,12 @@ namespace UI
|
||||
case "Quarry":
|
||||
currentUIMode = UIMode.Puzzle;
|
||||
break;
|
||||
case "DivingForPictures" or "CardQualityControl" or "BirdPoop" or "StatueDecoration":
|
||||
case "DivingForPictures" or "CardQualityControl" or "BirdPoop":
|
||||
currentUIMode = UIMode.Minigame;
|
||||
break;
|
||||
case "StatueDecoration":
|
||||
currentUIMode = UIMode.HideAll;
|
||||
break;
|
||||
}
|
||||
|
||||
ShowAllHud();
|
||||
@@ -336,6 +340,10 @@ namespace UI
|
||||
}
|
||||
break;
|
||||
case UIMode.HideAll:
|
||||
eagleEye.SetActive(false);
|
||||
ramaSjangButton.SetActive(false);
|
||||
scrabBookButton.SetActive(false);
|
||||
pauseButton.SetActive(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user