Merge branch 'main' into audio-overhaul
This commit is contained in:
@@ -9,6 +9,9 @@ namespace Core.SaveLoad
|
||||
|
||||
// Snapshot of the player's card collection (MVP)
|
||||
public CardCollectionState cardCollection;
|
||||
|
||||
// List of unlocked minigames by name
|
||||
public List<string> unlockedMinigames = new List<string>();
|
||||
}
|
||||
|
||||
// Minimal DTOs for card persistence
|
||||
|
||||
@@ -21,6 +21,7 @@ namespace AppleHills.Core.Settings
|
||||
[Header("Default Prefabs")]
|
||||
[SerializeField] private GameObject basePickupPrefab;
|
||||
[SerializeField] private GameObject levelSwitchMenuPrefab;
|
||||
[SerializeField] private GameObject minigameSwitchMenuPrefab;
|
||||
|
||||
[Header("Puzzle Settings")]
|
||||
[Tooltip("Default prefab for puzzle step indicators")]
|
||||
@@ -39,6 +40,7 @@ namespace AppleHills.Core.Settings
|
||||
public LayerMask InteractableLayerMask => interactableLayerMask;
|
||||
public GameObject BasePickupPrefab => basePickupPrefab;
|
||||
public GameObject LevelSwitchMenuPrefab => levelSwitchMenuPrefab;
|
||||
public GameObject MinigameSwitchMenuPrefab => minigameSwitchMenuPrefab;
|
||||
public List<CombinationRule> CombinationRules => combinationRules;
|
||||
public List<SlotItemConfig> SlotItemConfigs => slotItemConfigs;
|
||||
public GameObject DefaultPuzzleIndicatorPrefab => defaultPuzzleIndicatorPrefab;
|
||||
|
||||
@@ -46,6 +46,7 @@ namespace AppleHills.Core.Settings
|
||||
LayerMask InteractableLayerMask { get; }
|
||||
GameObject BasePickupPrefab { get; }
|
||||
GameObject LevelSwitchMenuPrefab { get; }
|
||||
GameObject MinigameSwitchMenuPrefab { get; }
|
||||
List<CombinationRule> CombinationRules { get; }
|
||||
List<SlotItemConfig> SlotItemConfigs { get; }
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ public class SoundGenerator : MonoBehaviour
|
||||
if (!playerInside && other.CompareTag("Player"))
|
||||
{
|
||||
playerInside = true;
|
||||
Logging.Debug("Player entered SoundGenerator trigger!");
|
||||
// Logging.Debug("Player entered SoundGenerator trigger!");
|
||||
if (spriteRenderer != null && enterSprite != null)
|
||||
{
|
||||
spriteRenderer.sprite = enterSprite;
|
||||
@@ -50,7 +50,7 @@ public class SoundGenerator : MonoBehaviour
|
||||
if (playerInside && other.CompareTag("Player"))
|
||||
{
|
||||
playerInside = false;
|
||||
Logging.Debug("Player exited SoundGenerator trigger!");
|
||||
// Logging.Debug("Player exited SoundGenerator trigger!");
|
||||
if (spriteRenderer != null && exitSprite != null)
|
||||
{
|
||||
spriteRenderer.sprite = exitSprite;
|
||||
|
||||
@@ -28,5 +28,10 @@ namespace Levels
|
||||
/// Icon to display for this level switch.
|
||||
/// </summary>
|
||||
public Sprite mapSprite;
|
||||
|
||||
/// <summary>
|
||||
/// Icon to display for this level switch.
|
||||
/// </summary>
|
||||
public Sprite menuSprite;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Core.SaveLoad;
|
||||
using Unity.Android.Gradle;
|
||||
|
||||
namespace Levels
|
||||
{
|
||||
@@ -41,23 +43,41 @@ namespace Levels
|
||||
_onMinigameConfirm = onMinigameConfirm;
|
||||
_onCancel = onCancel;
|
||||
_onRestart = onRestart;
|
||||
if (iconImage) iconImage.sprite = switchData?.mapSprite;
|
||||
if (levelNameText) levelNameText.text = switchData?.targetLevelSceneName ?? "";
|
||||
if(switchData != null)
|
||||
{
|
||||
if (iconImage)
|
||||
{
|
||||
iconImage.sprite = switchData.menuSprite != null
|
||||
? switchData.menuSprite
|
||||
: switchData.mapSprite;
|
||||
}
|
||||
if (levelNameText) levelNameText.text = switchData?.targetLevelSceneName ?? "";
|
||||
}
|
||||
else
|
||||
{
|
||||
Logging.LogWarning("[LevelSwitchMenu] No level data is assigned!");
|
||||
}
|
||||
if (confirmButton) confirmButton.onClick.AddListener(OnConfirmClicked);
|
||||
if (cancelButton) cancelButton.onClick.AddListener(OnCancelClicked);
|
||||
if (minigameButton)
|
||||
{
|
||||
minigameButton.onClick.AddListener(OnMinigameClicked);
|
||||
|
||||
bool minigameUnlocked = true;
|
||||
minigameButton.interactable = minigameUnlocked;
|
||||
padlockIcon.SetActive(!minigameUnlocked);
|
||||
}
|
||||
if (minigameButton) minigameButton.onClick.AddListener(OnMinigameClicked);
|
||||
if (restartButton) restartButton.onClick.AddListener(OnRestartClicked);
|
||||
if (popupConfirmMenu) popupConfirmMenu.SetActive(false);
|
||||
if (tintTargetImage) _originalTintColor = tintTargetImage.color;
|
||||
if (popupConfirmButton) popupConfirmButton.onClick.AddListener(OnPopupConfirmClicked);
|
||||
if (popupCancelButton) popupCancelButton.onClick.AddListener(OnPopupCancelClicked);
|
||||
|
||||
// --- Minigame unlock state logic ---
|
||||
if (SaveLoadManager.Instance != null)
|
||||
{
|
||||
if (SaveLoadManager.Instance.IsSaveDataLoaded)
|
||||
{
|
||||
ApplyMinigameUnlockStateIfAvailable();
|
||||
}
|
||||
else
|
||||
{
|
||||
SaveLoadManager.Instance.OnLoadCompleted += OnSaveDataLoadedHandler;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
@@ -68,6 +88,10 @@ namespace Levels
|
||||
if (restartButton) restartButton.onClick.RemoveListener(OnRestartClicked);
|
||||
if (popupConfirmButton) popupConfirmButton.onClick.RemoveListener(OnPopupConfirmClicked);
|
||||
if (popupCancelButton) popupCancelButton.onClick.RemoveListener(OnPopupCancelClicked);
|
||||
if (SaveLoadManager.Instance != null)
|
||||
{
|
||||
SaveLoadManager.Instance.OnLoadCompleted -= OnSaveDataLoadedHandler;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnConfirmClicked()
|
||||
@@ -106,5 +130,25 @@ namespace Levels
|
||||
if (popupConfirmMenu) popupConfirmMenu.SetActive(false);
|
||||
if (tintTargetImage) tintTargetImage.color = _originalTintColor;
|
||||
}
|
||||
|
||||
private void ApplyMinigameUnlockStateIfAvailable()
|
||||
{
|
||||
if (minigameButton == null || padlockIcon == null || _switchData == null)
|
||||
return;
|
||||
var data = SaveLoadManager.Instance?.currentSaveData;
|
||||
string minigameName = _switchData.targetMinigameSceneName;
|
||||
bool unlocked = data?.unlockedMinigames != null && !string.IsNullOrEmpty(minigameName) && data.unlockedMinigames.Contains(minigameName);
|
||||
minigameButton.interactable = unlocked;
|
||||
padlockIcon.SetActive(!unlocked);
|
||||
}
|
||||
|
||||
private void OnSaveDataLoadedHandler(string slot)
|
||||
{
|
||||
ApplyMinigameUnlockStateIfAvailable();
|
||||
if (SaveLoadManager.Instance != null)
|
||||
{
|
||||
SaveLoadManager.Instance.OnLoadCompleted -= OnSaveDataLoadedHandler;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
195
Assets/Scripts/Levels/MinigameSwitch.cs
Normal file
195
Assets/Scripts/Levels/MinigameSwitch.cs
Normal file
@@ -0,0 +1,195 @@
|
||||
using System;
|
||||
using AppleHills.Core.Settings;
|
||||
using Core;
|
||||
using Input;
|
||||
using Interactions;
|
||||
using System.Threading.Tasks;
|
||||
using Bootstrap;
|
||||
using PuzzleS;
|
||||
using UnityEngine;
|
||||
using Core.SaveLoad;
|
||||
|
||||
// Added for IInteractionSettings
|
||||
|
||||
namespace Levels
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles switching into minigame levels when interacted with. Applies switch data and triggers scene transitions.
|
||||
/// </summary>
|
||||
public class MinigameSwitch : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// Data for this level switch (target scene, icon, etc).
|
||||
/// </summary>
|
||||
public LevelSwitchData switchData;
|
||||
private SpriteRenderer _iconRenderer;
|
||||
private Interactable _interactable;
|
||||
|
||||
// Settings reference
|
||||
private IInteractionSettings _interactionSettings;
|
||||
|
||||
private bool _isActive = true;
|
||||
|
||||
/// <summary>
|
||||
/// Unity Awake callback. Sets up icon, interactable, and event handlers.
|
||||
/// </summary>
|
||||
void Awake()
|
||||
{
|
||||
gameObject.SetActive(false); // Start inactive
|
||||
BootCompletionService.RegisterInitAction(InitializePostBoot);
|
||||
|
||||
_isActive = true;
|
||||
if (_iconRenderer == null)
|
||||
_iconRenderer = GetComponent<SpriteRenderer>();
|
||||
_interactable = GetComponent<Interactable>();
|
||||
if (_interactable != null)
|
||||
{
|
||||
_interactable.characterArrived.AddListener(OnCharacterArrived);
|
||||
}
|
||||
// Initialize settings reference
|
||||
_interactionSettings = GameManager.GetSettingsObject<IInteractionSettings>();
|
||||
ApplySwitchData();
|
||||
|
||||
// --- Save state loading logic ---
|
||||
if (SaveLoadManager.Instance != null)
|
||||
{
|
||||
if (SaveLoadManager.Instance.IsSaveDataLoaded)
|
||||
{
|
||||
ApplySavedMinigameStateIfAvailable();
|
||||
}
|
||||
else
|
||||
{
|
||||
SaveLoadManager.Instance.OnLoadCompleted += OnSaveDataLoadedHandler;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
PuzzleManager.Instance.OnAllPuzzlesComplete -= HandleAllPuzzlesComplete;
|
||||
if (_interactable != null)
|
||||
{
|
||||
_interactable.characterArrived.RemoveListener(OnCharacterArrived);
|
||||
}
|
||||
if (SaveLoadManager.Instance != null)
|
||||
{
|
||||
SaveLoadManager.Instance.OnLoadCompleted -= OnSaveDataLoadedHandler;
|
||||
}
|
||||
}
|
||||
|
||||
// Apply saved state if present in the SaveLoadManager
|
||||
private void ApplySavedMinigameStateIfAvailable()
|
||||
{
|
||||
var data = SaveLoadManager.Instance?.currentSaveData;
|
||||
if (data?.unlockedMinigames != null && switchData != null &&
|
||||
data.unlockedMinigames.Contains(switchData.targetLevelSceneName))
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
// Event handler for when save data load completes
|
||||
private void OnSaveDataLoadedHandler(string slot)
|
||||
{
|
||||
ApplySavedMinigameStateIfAvailable();
|
||||
if (SaveLoadManager.Instance != null)
|
||||
{
|
||||
SaveLoadManager.Instance.OnLoadCompleted -= OnSaveDataLoadedHandler;
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleAllPuzzlesComplete(PuzzleS.PuzzleLevelDataSO _)
|
||||
{
|
||||
// Unlock and save
|
||||
if (switchData != null)
|
||||
{
|
||||
var unlocked = SaveLoadManager.Instance.currentSaveData.unlockedMinigames;
|
||||
string minigameName = switchData.targetLevelSceneName;
|
||||
if (!unlocked.Contains(minigameName))
|
||||
{
|
||||
unlocked.Add(minigameName);
|
||||
}
|
||||
}
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
/// <summary>
|
||||
/// Unity OnValidate callback. Ensures icon and data are up to date in editor.
|
||||
/// </summary>
|
||||
void OnValidate()
|
||||
{
|
||||
if (_iconRenderer == null)
|
||||
_iconRenderer = GetComponent<SpriteRenderer>();
|
||||
ApplySwitchData();
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Applies the switch data to the level switch (icon, name, etc).
|
||||
/// </summary>
|
||||
public void ApplySwitchData()
|
||||
{
|
||||
if (switchData != null)
|
||||
{
|
||||
if (_iconRenderer != null)
|
||||
_iconRenderer.sprite = switchData.mapSprite;
|
||||
gameObject.name = switchData.targetLevelSceneName;
|
||||
// Optionally update other fields, e.g. description
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the start of an interaction (shows confirmation menu and switches the level if confirmed).
|
||||
/// </summary>
|
||||
private void OnCharacterArrived()
|
||||
{
|
||||
if (switchData == null || string.IsNullOrEmpty(switchData.targetLevelSceneName) || !_isActive)
|
||||
return;
|
||||
|
||||
var menuPrefab = _interactionSettings?.MinigameSwitchMenuPrefab;
|
||||
if (menuPrefab == null)
|
||||
{
|
||||
Debug.LogError("MinigameSwitchMenu prefab not assigned in InteractionSettings!");
|
||||
return;
|
||||
}
|
||||
// Spawn the menu overlay (assume Canvas parent is handled in prefab setup)
|
||||
var menuGo = Instantiate(menuPrefab);
|
||||
var menu = menuGo.GetComponent<MinigameSwitchMenu>();
|
||||
if (menu == null)
|
||||
{
|
||||
Debug.LogError("MinigameSwitchMenu component missing on prefab!");
|
||||
Destroy(menuGo);
|
||||
return;
|
||||
}
|
||||
// Setup menu with data and callbacks
|
||||
menu.Setup(switchData, OnLevelSelectedWrapper, OnMenuCancel);
|
||||
_isActive = false; // Prevent re-triggering until menu is closed
|
||||
|
||||
// Switch input mode to UI only
|
||||
InputManager.Instance.SetInputMode(InputMode.UI);
|
||||
}
|
||||
|
||||
private void OnLevelSelectedWrapper()
|
||||
{
|
||||
_ = OnLevelSelected();
|
||||
}
|
||||
|
||||
private async Task OnLevelSelected()
|
||||
{
|
||||
var progress = new Progress<float>(p => Logging.Debug($"Loading progress: {p * 100:F0}%"));
|
||||
await SceneManagerService.Instance.SwitchSceneAsync(switchData.targetLevelSceneName, progress);
|
||||
}
|
||||
|
||||
private void OnMenuCancel()
|
||||
{
|
||||
_isActive = true; // Allow interaction again if cancelled
|
||||
InputManager.Instance.SetInputMode(InputMode.GameAndUI);
|
||||
}
|
||||
|
||||
private void InitializePostBoot()
|
||||
{
|
||||
PuzzleManager.Instance.OnAllPuzzlesComplete += HandleAllPuzzlesComplete;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Levels/MinigameSwitch.cs.meta
Normal file
3
Assets/Scripts/Levels/MinigameSwitch.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d9b7a2b4b1fe492aae7b0f280b4063cf
|
||||
timeCreated: 1761725126
|
||||
77
Assets/Scripts/Levels/MinigameSwitchMenu.cs
Normal file
77
Assets/Scripts/Levels/MinigameSwitchMenu.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Levels
|
||||
{
|
||||
/// <summary>
|
||||
/// UI overlay for confirming a level switch. Displays level info and handles confirm/cancel actions, and supports leaderboard view.
|
||||
/// </summary>
|
||||
public class MinigameSwitchMenu : MonoBehaviour
|
||||
{
|
||||
[Header("UI References")]
|
||||
public Image iconImage;
|
||||
public TMP_Text levelNameText;
|
||||
public Button confirmButton;
|
||||
public Button cancelButton;
|
||||
public Button leaderboardButton;
|
||||
public GameObject levelInfoContainer;
|
||||
public GameObject leaderboardContainer;
|
||||
public Button leaderboardDismissButton;
|
||||
|
||||
private Action _onLevelConfirm;
|
||||
private Action _onCancel;
|
||||
private LevelSwitchData _switchData;
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the menu with data and callbacks.
|
||||
/// </summary>
|
||||
public void Setup(LevelSwitchData switchData, Action onLevelConfirm, Action onCancel)
|
||||
{
|
||||
_switchData = switchData;
|
||||
_onLevelConfirm = onLevelConfirm;
|
||||
_onCancel = onCancel;
|
||||
if (iconImage) iconImage.sprite = switchData?.menuSprite ?? switchData?.mapSprite;
|
||||
if (levelNameText) levelNameText.text = switchData?.targetLevelSceneName ?? "";
|
||||
if (confirmButton) confirmButton.onClick.AddListener(OnConfirmClicked);
|
||||
if (cancelButton) cancelButton.onClick.AddListener(OnCancelClicked);
|
||||
if (leaderboardButton) leaderboardButton.onClick.AddListener(OnLeaderboardClicked);
|
||||
if (leaderboardDismissButton) leaderboardDismissButton.onClick.AddListener(OnLeaderboardDismissClicked);
|
||||
if (levelInfoContainer) levelInfoContainer.SetActive(true);
|
||||
if (leaderboardContainer) leaderboardContainer.SetActive(false);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (confirmButton) confirmButton.onClick.RemoveListener(OnConfirmClicked);
|
||||
if (cancelButton) cancelButton.onClick.RemoveListener(OnCancelClicked);
|
||||
if (leaderboardButton) leaderboardButton.onClick.RemoveListener(OnLeaderboardClicked);
|
||||
if (leaderboardDismissButton) leaderboardDismissButton.onClick.RemoveListener(OnLeaderboardDismissClicked);
|
||||
}
|
||||
|
||||
private void OnConfirmClicked()
|
||||
{
|
||||
_onLevelConfirm?.Invoke();
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
private void OnCancelClicked()
|
||||
{
|
||||
_onCancel?.Invoke();
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
private void OnLeaderboardClicked()
|
||||
{
|
||||
if (levelInfoContainer) levelInfoContainer.SetActive(false);
|
||||
if (leaderboardContainer) leaderboardContainer.SetActive(true);
|
||||
}
|
||||
|
||||
private void OnLeaderboardDismissClicked()
|
||||
{
|
||||
if (levelInfoContainer) levelInfoContainer.SetActive(true);
|
||||
if (leaderboardContainer) leaderboardContainer.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Levels/MinigameSwitchMenu.cs.meta
Normal file
3
Assets/Scripts/Levels/MinigameSwitchMenu.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fc21f4724bf441f7bd4c5ec7d6463d66
|
||||
timeCreated: 1761725170
|
||||
@@ -197,11 +197,11 @@ namespace UI
|
||||
// pass obeyTimescale = false so this tween runs even when Time.timeScale == 0
|
||||
Tween.Value(0f, 1f, (v) =>
|
||||
{
|
||||
Logging.Debug($"[PauseMenu] Tweening pause menu alpha: {v}");
|
||||
// Logging.Debug($"[PauseMenu] Tweening pause menu alpha: {v}");
|
||||
canvasGroup.alpha = v;
|
||||
}, transitionDuration, 0f, Tween.EaseInOut, Tween.LoopType.None, null, () =>
|
||||
{
|
||||
Logging.Debug("[PauseMenu] Finished tweening pause menu in.");
|
||||
// Logging.Debug("[PauseMenu] Finished tweening pause menu in.");
|
||||
onComplete?.Invoke();
|
||||
}, false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user