Setup scene for the statue nonsense
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using Core;
|
||||
using Core.Lifecycle;
|
||||
using Minigames.StatueDressup.Data;
|
||||
using Minigames.StatueDressup.DragDrop;
|
||||
using UI.DragAndDrop.Core;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
@@ -10,13 +12,16 @@ namespace Minigames.StatueDressup.Controllers
|
||||
/// <summary>
|
||||
/// Manages the side menu with decoration items and pagination
|
||||
/// </summary>
|
||||
public class DecorationMenuController : MonoBehaviour
|
||||
public class DecorationMenuController : ManagedBehaviour
|
||||
{
|
||||
[Header("References")]
|
||||
[SerializeField] private DecorationItem itemPrefab;
|
||||
[SerializeField] private Transform itemsContainer;
|
||||
[SerializeField] private Button nextPageButton;
|
||||
[SerializeField] private Button previousPageButton;
|
||||
[SerializeField] private RectTransform statueArea; // For overlap detection
|
||||
[SerializeField] private Transform statueParent; // Parent for placed decorations
|
||||
[SerializeField] private StatueDecorationController statueController; // Controller for registration
|
||||
|
||||
[Header("Configuration")]
|
||||
[SerializeField] private List<DecorationData> allDecorations = new List<DecorationData>();
|
||||
@@ -25,22 +30,40 @@ namespace Minigames.StatueDressup.Controllers
|
||||
[Header("Layout")]
|
||||
[SerializeField] private GridLayoutGroup gridLayout;
|
||||
|
||||
private int _currentPage = 0;
|
||||
private int _totalPages = 0;
|
||||
private int _currentPage;
|
||||
private int _totalPages;
|
||||
private List<DecorationItem> _spawnedItems = new List<DecorationItem>();
|
||||
private Dictionary<DecorationItem, DecorationData> _itemDataMapping = new Dictionary<DecorationItem, DecorationData>();
|
||||
private AppleHills.Core.Settings.IStatueDressupSettings _settings;
|
||||
|
||||
// Properties
|
||||
public int CurrentPage => _currentPage;
|
||||
public int TotalPages => _totalPages;
|
||||
|
||||
private void Start()
|
||||
/// <summary>
|
||||
/// Early initialization - get settings reference
|
||||
/// </summary>
|
||||
internal override void OnManagedAwake()
|
||||
{
|
||||
Initialize();
|
||||
base.OnManagedAwake();
|
||||
|
||||
// Get settings early
|
||||
_settings = GameManager.GetSettingsObject<AppleHills.Core.Settings.IStatueDressupSettings>();
|
||||
|
||||
// Override itemsPerPage with settings value if available
|
||||
if (_settings != null)
|
||||
{
|
||||
itemsPerPage = _settings.ItemsPerPage;
|
||||
}
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
/// <summary>
|
||||
/// Main initialization after all managers are ready
|
||||
/// </summary>
|
||||
internal override void OnManagedStart()
|
||||
{
|
||||
base.OnManagedStart();
|
||||
|
||||
Logging.Debug($"[DecorationMenuController] Initializing with {allDecorations.Count} decorations");
|
||||
|
||||
// Calculate total pages
|
||||
@@ -105,6 +128,12 @@ namespace Minigames.StatueDressup.Controllers
|
||||
DecorationItem item = Instantiate(itemPrefab, itemsContainer);
|
||||
item.SetDecorationData(data);
|
||||
|
||||
// Set statue references for overlap detection
|
||||
item.SetStatueArea(statueArea);
|
||||
item.SetStatueParent(statueParent);
|
||||
item.SetMenuParent(itemsContainer);
|
||||
item.SetController(statueController);
|
||||
|
||||
// Store original position for return animation
|
||||
if (item.RectTransform != null)
|
||||
{
|
||||
@@ -132,9 +161,6 @@ namespace Minigames.StatueDressup.Controllers
|
||||
{
|
||||
Logging.Debug($"[DecorationMenuController] Item picked up: {item.Data?.DecorationName}");
|
||||
|
||||
// Spawn replacement in menu slot
|
||||
// This ensures menu always shows available items
|
||||
DecorationData data = _itemDataMapping[item];
|
||||
// We'll spawn replacement only if item is actually placed, not on pickup
|
||||
}
|
||||
}
|
||||
@@ -146,10 +172,10 @@ namespace Minigames.StatueDressup.Controllers
|
||||
{
|
||||
if (draggable is DecorationItem item && _itemDataMapping.ContainsKey(item))
|
||||
{
|
||||
Logging.Debug($"[DecorationMenuController] Item dropped: {item.Data?.DecorationName}, slot={item.CurrentSlot?.name}");
|
||||
Logging.Debug($"[DecorationMenuController] Item dropped: {item.Data?.DecorationName}, isPlacedOnStatue={item.IsPlacedOnStatue}");
|
||||
|
||||
// If item was placed on statue, spawn replacement in menu
|
||||
if (item.CurrentSlot != null && !item.IsInMenu)
|
||||
if (item.IsPlacedOnStatue && !item.IsInMenu)
|
||||
{
|
||||
DecorationData data = _itemDataMapping[item];
|
||||
|
||||
@@ -226,8 +252,13 @@ namespace Minigames.StatueDressup.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
/// <summary>
|
||||
/// Cleanup when menu controller is destroyed
|
||||
/// </summary>
|
||||
internal override void OnManagedDestroy()
|
||||
{
|
||||
base.OnManagedDestroy();
|
||||
|
||||
// Cleanup button listeners
|
||||
if (nextPageButton != null)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using Core;
|
||||
using Core.Lifecycle;
|
||||
using Minigames.StatueDressup.DragDrop;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
@@ -8,11 +9,13 @@ namespace Minigames.StatueDressup.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Main controller for the Mr. Cement statue decoration minigame
|
||||
/// Uses overlap-based placement instead of slots
|
||||
/// </summary>
|
||||
public class StatueDecorationController : MonoBehaviour
|
||||
public class StatueDecorationController : ManagedBehaviour
|
||||
{
|
||||
[Header("References")]
|
||||
[SerializeField] private StatueDecorationSlot[] statueSlots;
|
||||
[SerializeField] private RectTransform statueArea; // Statue area for overlap detection
|
||||
[SerializeField] private Transform statueParent; // Parent for placed decorations
|
||||
[SerializeField] private DecorationMenuController menuController;
|
||||
[SerializeField] private Button takePhotoButton;
|
||||
[SerializeField] private GameObject statue;
|
||||
@@ -24,16 +27,28 @@ namespace Minigames.StatueDressup.Controllers
|
||||
[SerializeField] private RectTransform photoArea; // Area to capture
|
||||
[SerializeField] private string photoSaveKey = "MrCementStatuePhoto";
|
||||
|
||||
private Dictionary<StatueDecorationSlot, DecorationItem> _placedDecorations = new Dictionary<StatueDecorationSlot, DecorationItem>();
|
||||
private bool _minigameCompleted = false;
|
||||
private List<DecorationItem> _placedDecorations = new List<DecorationItem>();
|
||||
private bool _minigameCompleted;
|
||||
private AppleHills.Core.Settings.IStatueDressupSettings _settings;
|
||||
|
||||
private void Start()
|
||||
/// <summary>
|
||||
/// Early initialization - get settings reference
|
||||
/// </summary>
|
||||
internal override void OnManagedAwake()
|
||||
{
|
||||
Initialize();
|
||||
base.OnManagedAwake();
|
||||
|
||||
// Get settings early
|
||||
_settings = GameManager.GetSettingsObject<AppleHills.Core.Settings.IStatueDressupSettings>();
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
/// <summary>
|
||||
/// Main initialization after all managers are ready
|
||||
/// </summary>
|
||||
internal override void OnManagedStart()
|
||||
{
|
||||
base.OnManagedStart();
|
||||
|
||||
Logging.Debug("[StatueDecorationController] Initializing minigame");
|
||||
|
||||
// Setup photo button
|
||||
@@ -42,13 +57,12 @@ namespace Minigames.StatueDressup.Controllers
|
||||
takePhotoButton.onClick.AddListener(OnTakePhoto);
|
||||
}
|
||||
|
||||
// Subscribe to slot occupation events
|
||||
foreach (var slot in statueSlots)
|
||||
// Subscribe to menu controller for tracking placed items
|
||||
// Items will manage their own placement via overlap detection
|
||||
if (menuController != null)
|
||||
{
|
||||
if (slot != null)
|
||||
{
|
||||
slot.OnOccupied += HandleDecorationPlaced;
|
||||
}
|
||||
// Menu controller will handle spawning replacements
|
||||
Logging.Debug("[StatueDecorationController] Menu controller connected");
|
||||
}
|
||||
|
||||
// Load saved state if exists
|
||||
@@ -56,21 +70,32 @@ namespace Minigames.StatueDressup.Controllers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle decoration placed in slot
|
||||
/// Register a decoration as placed on statue
|
||||
/// </summary>
|
||||
private void HandleDecorationPlaced(DraggableObject draggable)
|
||||
public void RegisterDecoration(DecorationItem decoration)
|
||||
{
|
||||
if (draggable is DecorationItem decoration)
|
||||
if (decoration != null && !_placedDecorations.Contains(decoration))
|
||||
{
|
||||
var slot = decoration.CurrentSlot as StatueDecorationSlot;
|
||||
if (slot != null)
|
||||
{
|
||||
_placedDecorations[slot] = decoration;
|
||||
Logging.Debug($"[StatueDecorationController] Decoration placed: {decoration.Data?.DecorationName} in slot {slot.name}");
|
||||
|
||||
// Auto-save state
|
||||
SaveStatueState();
|
||||
}
|
||||
_placedDecorations.Add(decoration);
|
||||
Logging.Debug($"[StatueDecorationController] Decoration placed: {decoration.Data?.DecorationName}");
|
||||
|
||||
// Auto-save state
|
||||
SaveStatueState();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unregister a decoration (when removed)
|
||||
/// </summary>
|
||||
public void UnregisterDecoration(DecorationItem decoration)
|
||||
{
|
||||
if (decoration != null && _placedDecorations.Contains(decoration))
|
||||
{
|
||||
_placedDecorations.Remove(decoration);
|
||||
Logging.Debug($"[StatueDecorationController] Decoration removed: {decoration.Data?.DecorationName}");
|
||||
|
||||
// Auto-save state
|
||||
SaveStatueState();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,11 +180,11 @@ namespace Minigames.StatueDressup.Controllers
|
||||
Logging.Debug($"[StatueDecorationController] Capturing area: {width}x{height} at ({min.x}, {min.y})");
|
||||
|
||||
// Capture the specified area
|
||||
Texture2D screenshot = new Texture2D(width, height, TextureFormat.RGB24, false);
|
||||
screenshot.ReadPixels(new Rect(min.x, min.y, width, height), 0, 0);
|
||||
screenshot.Apply();
|
||||
Texture2D areaScreenshot = new Texture2D(width, height, TextureFormat.RGB24, false);
|
||||
areaScreenshot.ReadPixels(new Rect(min.x, min.y, width, height), 0, 0);
|
||||
areaScreenshot.Apply();
|
||||
|
||||
return screenshot;
|
||||
return areaScreenshot;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -171,7 +196,8 @@ namespace Minigames.StatueDressup.Controllers
|
||||
// For now, save to PlayerPrefs as base64
|
||||
byte[] bytes = photo.EncodeToPNG();
|
||||
string base64 = System.Convert.ToBase64String(bytes);
|
||||
PlayerPrefs.SetString(photoSaveKey, base64);
|
||||
string saveKey = _settings?.PhotoSaveKey ?? photoSaveKey;
|
||||
PlayerPrefs.SetString(saveKey, base64);
|
||||
PlayerPrefs.Save();
|
||||
|
||||
Logging.Debug("[StatueDecorationController] Photo saved to album");
|
||||
@@ -228,10 +254,18 @@ namespace Minigames.StatueDressup.Controllers
|
||||
/// </summary>
|
||||
private void SaveStatueState()
|
||||
{
|
||||
// TODO: Implement save system
|
||||
// Save slot ID -> decoration ID mapping
|
||||
// Check if persistence is enabled
|
||||
if (_settings == null || !_settings.EnableStatePersistence)
|
||||
{
|
||||
Logging.Debug("[StatueDecorationController] State persistence disabled");
|
||||
return;
|
||||
}
|
||||
|
||||
Logging.Debug("[StatueDecorationController] State saved (TODO: implement persistence)");
|
||||
// TODO: Implement save system
|
||||
// Save decoration ID + position + rotation for each placed item
|
||||
// Respect MaxSavedDecorations limit
|
||||
|
||||
Logging.Debug($"[StatueDecorationController] State saved to {_settings.StateSaveKey} (TODO: implement persistence)");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -239,28 +273,31 @@ namespace Minigames.StatueDressup.Controllers
|
||||
/// </summary>
|
||||
private void LoadStatueState()
|
||||
{
|
||||
// TODO: Implement load system
|
||||
// Restore decorations to slots
|
||||
// Check if persistence is enabled
|
||||
if (_settings == null || !_settings.EnableStatePersistence)
|
||||
{
|
||||
Logging.Debug("[StatueDecorationController] State persistence disabled");
|
||||
return;
|
||||
}
|
||||
|
||||
Logging.Debug("[StatueDecorationController] State loaded (TODO: implement persistence)");
|
||||
// TODO: Implement load system
|
||||
// Restore decorations from saved state
|
||||
|
||||
Logging.Debug($"[StatueDecorationController] State loaded from {_settings.StateSaveKey} (TODO: implement persistence)");
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
/// <summary>
|
||||
/// Cleanup when controller is destroyed
|
||||
/// </summary>
|
||||
internal override void OnManagedDestroy()
|
||||
{
|
||||
base.OnManagedDestroy();
|
||||
|
||||
// Cleanup button listener
|
||||
if (takePhotoButton != null)
|
||||
{
|
||||
takePhotoButton.onClick.RemoveListener(OnTakePhoto);
|
||||
}
|
||||
|
||||
// Cleanup slot listeners
|
||||
foreach (var slot in statueSlots)
|
||||
{
|
||||
if (slot != null)
|
||||
{
|
||||
slot.OnOccupied -= HandleDecorationPlaced;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user