Update display issues with the puzzle steps

This commit is contained in:
Michal Pikulski
2025-10-15 16:33:19 +02:00
parent 9de50c42bc
commit 17feef7945
2 changed files with 59 additions and 63 deletions

View File

@@ -34,12 +34,34 @@ 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);
@@ -50,7 +72,7 @@ namespace PuzzleS
void Start()
{
// Register with PuzzleManager, regardless of enabled/disabled state
// This happens in Start instead of OnEnable to ensure PuzzleManager has loaded level data
// PuzzleManager will call UnlockStep or LockStep based on current puzzle state
PuzzleManager.Instance?.RegisterStepBehaviour(this);
}
@@ -71,7 +93,7 @@ namespace PuzzleS
public void UpdateProximityState(ProximityState newState)
{
if (_currentProximityState == newState) return;
if (!_isUnlocked) return;
if (!_isUnlocked) return; // Don't process state changes if locked
// Determine state changes and call appropriate methods
if (newState == ProximityState.Close)
@@ -95,6 +117,9 @@ namespace PuzzleS
/// </summary>
public virtual void OnShow()
{
if (puzzleIndicator != null)
puzzleIndicator.SetActive(true);
// Delegate to indicator if available
if (IsIndicatorValid())
{
@@ -102,7 +127,6 @@ namespace PuzzleS
return;
}
// Default fallback behavior
Logging.Debug($"[Puzzles] Prompt shown for {stepData?.stepId} on {gameObject.name}");
}
@@ -111,14 +135,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}");
}
@@ -136,9 +161,6 @@ namespace PuzzleS
_indicator.ShowFar();
return;
}
// Default fallback behavior
Logging.Debug($"[Puzzles] Player entered far range of {stepData?.stepId} on {gameObject.name}");
}
/// <summary>
@@ -155,9 +177,6 @@ namespace PuzzleS
_indicator.ShowClose();
return;
}
// Default fallback behavior
Logging.Debug($"[Puzzles] Player entered close range of {stepData?.stepId} on {gameObject.name}");
}
/// <summary>
@@ -174,9 +193,6 @@ namespace PuzzleS
_indicator.HideClose();
return;
}
// Default fallback behavior
Logging.Debug($"[Puzzles] Player exited close range of {stepData?.stepId} on {gameObject.name}");
}
/// <summary>
@@ -193,9 +209,6 @@ namespace PuzzleS
_indicator.HideFar();
return;
}
// Default fallback behavior
Logging.Debug($"[Puzzles] Player exited far range of {stepData?.stepId} on {gameObject.name}");
}
/// <summary>
@@ -208,54 +221,37 @@ namespace PuzzleS
_isUnlocked = true;
Logging.Debug($"[Puzzles] Step unlocked: {stepData?.stepId} on {gameObject.name}");
// Show indicator if available
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,16 +260,18 @@ namespace PuzzleS
/// </summary>
public void LockStep()
{
if (!_isUnlocked) return;
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>
@@ -289,7 +287,7 @@ namespace PuzzleS
/// </summary>
private void OnInteractionStarted(PlayerTouchController playerRef, FollowerController followerRef)
{
// Optionally handle started interaction (e.g. visual feedback)
// Empty - handled by Interactable
}
/// <summary>

View File

@@ -29,14 +29,12 @@ namespace PuzzleS
/// <summary>
/// Steps that should be unlocked at level start (no dependencies)
/// </summary>
[HideInInspector]
public List<PuzzleStepSO> initialSteps = new List<PuzzleStepSO>();
/// <summary>
/// Pre-processed dependency data built at edit time.
/// Maps step IDs to arrays of dependency step IDs (which steps are required by each step)
/// </summary>
[HideInInspector]
public Dictionary<string, string[]> stepDependencies = new Dictionary<string, string[]>();
/// <summary>