Revamp the prompt system, the bootstrapper system, the starting cinematic

This commit is contained in:
Michal Pikulski
2025-10-16 19:43:19 +02:00
parent df604fbc03
commit 50448c5bd3
89 changed files with 3964 additions and 677 deletions

View File

@@ -1,10 +1,7 @@
using Input;
using Interactions;
using UnityEngine;
using System;
using AppleHills.Core.Settings;
using Core;
using UnityEngine.Serialization;
namespace PuzzleS
{
@@ -37,22 +34,52 @@ namespace PuzzleS
void Awake()
{
_interactable = GetComponent<Interactable>();
// Initialize the indicator if it exists, but ensure it's hidden initially
if (puzzleIndicator != null)
{
// The indicator should start inactive until we determine its proper state
puzzleIndicator.SetActive(false);
// Get the IPuzzlePrompt component
_indicator = puzzleIndicator.GetComponent<IPuzzlePrompt>();
if (_indicator == null)
{
// Try to find it in children if not on the root
_indicator = puzzleIndicator.GetComponentInChildren<IPuzzlePrompt>();
}
if (_indicator == null)
{
Logging.Warning($"[Puzzles] Indicator prefab for {stepData?.stepId} does not implement IPuzzlePrompt");
}
}
}
void OnEnable()
{
if (_interactable == null)
_interactable = GetComponent<Interactable>();
if (_interactable != null)
{
_interactable.interactionStarted.AddListener(OnInteractionStarted);
_interactable.interactionComplete.AddListener(OnInteractionComplete);
}
PuzzleManager.Instance?.RegisterStepBehaviour(this);
// Check if this step was already unlocked
if (stepData != null && PuzzleManager.Instance != null && PuzzleManager.Instance.IsStepUnlocked(stepData))
}
void Start()
{
// Simply register with the PuzzleManager
// The manager will handle state updates appropriately based on whether data is loaded
if (stepData != null && PuzzleManager.Instance != null)
{
UnlockStep();
PuzzleManager.Instance.RegisterStepBehaviour(this);
}
else if (stepData == null)
{
Logging.Warning($"[Puzzles] Cannot register step on {gameObject.name}: stepData is null");
}
}
@@ -63,7 +90,11 @@ namespace PuzzleS
_interactable.interactionStarted.RemoveListener(OnInteractionStarted);
_interactable.interactionComplete.RemoveListener(OnInteractionComplete);
}
PuzzleManager.Instance?.UnregisterStepBehaviour(this);
if (PuzzleManager.Instance != null && stepData != null)
{
PuzzleManager.Instance.UnregisterStepBehaviour(this);
}
}
/// <summary>
@@ -73,7 +104,7 @@ namespace PuzzleS
public void UpdateProximityState(ProximityState newState)
{
if (_currentProximityState == newState) return;
if (_indicator == null) return;
if (!_isUnlocked) return; // Don't process state changes if locked
// Determine state changes and call appropriate methods
if (newState == ProximityState.Close)
@@ -97,6 +128,9 @@ namespace PuzzleS
/// </summary>
public virtual void OnShow()
{
if (puzzleIndicator != null)
puzzleIndicator.SetActive(true);
// Delegate to indicator if available
if (IsIndicatorValid())
{
@@ -104,7 +138,6 @@ namespace PuzzleS
return;
}
// Default fallback behavior
Logging.Debug($"[Puzzles] Prompt shown for {stepData?.stepId} on {gameObject.name}");
}
@@ -113,14 +146,15 @@ namespace PuzzleS
/// </summary>
public virtual void OnHide()
{
if (puzzleIndicator != null)
puzzleIndicator.SetActive(false);
// Delegate to indicator if available
if (IsIndicatorValid())
{
_indicator.OnHide();
return;
}
// Default fallback behavior
Logging.Debug($"[Puzzles] Prompt hidden for {stepData?.stepId} on {gameObject.name}");
}
@@ -138,9 +172,6 @@ namespace PuzzleS
_indicator.ShowFar();
return;
}
// Default fallback behavior
Logging.Debug($"[Puzzles] Player entered far range of {stepData?.stepId} on {gameObject.name}");
}
/// <summary>
@@ -157,9 +188,6 @@ namespace PuzzleS
_indicator.ShowClose();
return;
}
// Default fallback behavior
Logging.Debug($"[Puzzles] Player entered close range of {stepData?.stepId} on {gameObject.name}");
}
/// <summary>
@@ -176,9 +204,6 @@ namespace PuzzleS
_indicator.HideClose();
return;
}
// Default fallback behavior
Logging.Debug($"[Puzzles] Player exited close range of {stepData?.stepId} on {gameObject.name}");
}
/// <summary>
@@ -195,9 +220,6 @@ namespace PuzzleS
_indicator.HideFar();
return;
}
// Default fallback behavior
Logging.Debug($"[Puzzles] Player exited far range of {stepData?.stepId} on {gameObject.name}");
}
/// <summary>
@@ -205,57 +227,42 @@ namespace PuzzleS
/// </summary>
public void UnlockStep()
{
if (_isUnlocked) return;
_isUnlocked = true;
Logging.Debug($"[Puzzles] Step unlocked: {stepData?.stepId} on {gameObject.name}");
// Show indicator if enabled in settings
if (puzzleIndicator != null)
// Make the indicator visible since this step is now unlocked
OnShow();
if (IsIndicatorValid())
{
// Try to get the IPuzzlePrompt component from the spawned indicator
_indicator = puzzleIndicator.GetComponent<IPuzzlePrompt>();
if (_indicator == null)
// Set the correct state based on current player distance
Transform playerTransform = GameObject.FindGameObjectWithTag("Player")?.transform;
if (playerTransform != null)
{
// Try to find it in children if not on the root
_indicator = puzzleIndicator.GetComponentInChildren<IPuzzlePrompt>();
}
if (_indicator == null)
{
Logging.Warning($"[Puzzles] Indicator prefab for {stepData?.stepId} does not implement IPuzzlePrompt");
}
else
{
// First show the indicator
_indicator.OnShow();
float distance = Vector3.Distance(transform.position, playerTransform.position);
float promptRange = AppleHills.SettingsAccess.GetPuzzlePromptRange();
// Then set the correct state based on current player distance
Transform playerTransform = GameObject.FindGameObjectWithTag("Player")?.transform;
if (playerTransform != null)
if (distance <= promptRange)
{
float distance = Vector3.Distance(transform.position, playerTransform.position);
float promptRange = AppleHills.SettingsAccess.GetPuzzlePromptRange();
if (distance <= promptRange)
{
// Player is in close range
_currentProximityState = ProximityState.Close;
_indicator.ShowClose();
}
else
{
// Player is in far range
_currentProximityState = ProximityState.Far;
_indicator.ShowFar();
}
// Player is in close range
_currentProximityState = ProximityState.Close;
_indicator.ShowClose();
}
else
{
// Default to far if player not found
// Player is in far range
_currentProximityState = ProximityState.Far;
_indicator.ShowFar();
}
}
else
{
// Default to far if player not found
_currentProximityState = ProximityState.Far;
_indicator.ShowFar();
}
}
}
@@ -264,14 +271,18 @@ namespace PuzzleS
/// </summary>
public void LockStep()
{
if (!_isUnlocked && puzzleIndicator != null)
{
// Make sure indicator is hidden if we're already locked
puzzleIndicator.SetActive(false);
return;
}
_isUnlocked = false;
Logging.Debug($"[Puzzles] Step locked: {stepData?.stepId} on {gameObject.name}");
// Hide indicator
if (IsIndicatorValid())
{
_indicator.OnHide();
}
// Hide the indicator
OnHide();
}
/// <summary>
@@ -287,7 +298,7 @@ namespace PuzzleS
/// </summary>
private void OnInteractionStarted(PlayerTouchController playerRef, FollowerController followerRef)
{
// Optionally handle started interaction (e.g. visual feedback)
// Empty - handled by Interactable
}
/// <summary>
@@ -297,12 +308,17 @@ namespace PuzzleS
private void OnInteractionComplete(bool success)
{
if (!_isUnlocked) return;
if (success)
if (success && !_isCompleted)
{
Logging.Debug($"[Puzzles] Step interacted: {stepData?.stepId} on {gameObject.name}");
_isCompleted = true;
PuzzleManager.Instance?.MarkPuzzleStepCompleted(stepData);
Destroy(puzzleIndicator);
if (puzzleIndicator != null)
{
Destroy(puzzleIndicator);
_indicator = null;
}
}
}
@@ -323,7 +339,7 @@ namespace PuzzleS
// Draw threshold circle
Gizmos.color = Color.cyan;
Gizmos.DrawWireSphere(transform.position, promptRange / 2f);
Gizmos.DrawWireSphere(transform.position, promptRange);
}
}
}