Update display issues with the puzzle steps
This commit is contained in:
committed by
Michal Pikulski
parent
c4f90bfa62
commit
fe2e53b2a2
@@ -34,12 +34,34 @@ namespace PuzzleS
|
|||||||
void Awake()
|
void Awake()
|
||||||
{
|
{
|
||||||
_interactable = GetComponent<Interactable>();
|
_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()
|
void OnEnable()
|
||||||
{
|
{
|
||||||
if (_interactable == null)
|
if (_interactable == null)
|
||||||
_interactable = GetComponent<Interactable>();
|
_interactable = GetComponent<Interactable>();
|
||||||
|
|
||||||
if (_interactable != null)
|
if (_interactable != null)
|
||||||
{
|
{
|
||||||
_interactable.interactionStarted.AddListener(OnInteractionStarted);
|
_interactable.interactionStarted.AddListener(OnInteractionStarted);
|
||||||
@@ -50,7 +72,7 @@ namespace PuzzleS
|
|||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
// Register with PuzzleManager, regardless of enabled/disabled state
|
// 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);
|
PuzzleManager.Instance?.RegisterStepBehaviour(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,7 +93,7 @@ namespace PuzzleS
|
|||||||
public void UpdateProximityState(ProximityState newState)
|
public void UpdateProximityState(ProximityState newState)
|
||||||
{
|
{
|
||||||
if (_currentProximityState == newState) return;
|
if (_currentProximityState == newState) return;
|
||||||
if (!_isUnlocked) return;
|
if (!_isUnlocked) return; // Don't process state changes if locked
|
||||||
|
|
||||||
// Determine state changes and call appropriate methods
|
// Determine state changes and call appropriate methods
|
||||||
if (newState == ProximityState.Close)
|
if (newState == ProximityState.Close)
|
||||||
@@ -95,6 +117,9 @@ namespace PuzzleS
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void OnShow()
|
public virtual void OnShow()
|
||||||
{
|
{
|
||||||
|
if (puzzleIndicator != null)
|
||||||
|
puzzleIndicator.SetActive(true);
|
||||||
|
|
||||||
// Delegate to indicator if available
|
// Delegate to indicator if available
|
||||||
if (IsIndicatorValid())
|
if (IsIndicatorValid())
|
||||||
{
|
{
|
||||||
@@ -102,7 +127,6 @@ namespace PuzzleS
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default fallback behavior
|
|
||||||
Logging.Debug($"[Puzzles] Prompt shown for {stepData?.stepId} on {gameObject.name}");
|
Logging.Debug($"[Puzzles] Prompt shown for {stepData?.stepId} on {gameObject.name}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,14 +135,15 @@ namespace PuzzleS
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void OnHide()
|
public virtual void OnHide()
|
||||||
{
|
{
|
||||||
|
if (puzzleIndicator != null)
|
||||||
|
puzzleIndicator.SetActive(false);
|
||||||
|
|
||||||
// Delegate to indicator if available
|
// Delegate to indicator if available
|
||||||
if (IsIndicatorValid())
|
if (IsIndicatorValid())
|
||||||
{
|
{
|
||||||
_indicator.OnHide();
|
_indicator.OnHide();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default fallback behavior
|
|
||||||
Logging.Debug($"[Puzzles] Prompt hidden for {stepData?.stepId} on {gameObject.name}");
|
Logging.Debug($"[Puzzles] Prompt hidden for {stepData?.stepId} on {gameObject.name}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,9 +161,6 @@ namespace PuzzleS
|
|||||||
_indicator.ShowFar();
|
_indicator.ShowFar();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default fallback behavior
|
|
||||||
Logging.Debug($"[Puzzles] Player entered far range of {stepData?.stepId} on {gameObject.name}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -155,9 +177,6 @@ namespace PuzzleS
|
|||||||
_indicator.ShowClose();
|
_indicator.ShowClose();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default fallback behavior
|
|
||||||
Logging.Debug($"[Puzzles] Player entered close range of {stepData?.stepId} on {gameObject.name}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -174,9 +193,6 @@ namespace PuzzleS
|
|||||||
_indicator.HideClose();
|
_indicator.HideClose();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default fallback behavior
|
|
||||||
Logging.Debug($"[Puzzles] Player exited close range of {stepData?.stepId} on {gameObject.name}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -193,9 +209,6 @@ namespace PuzzleS
|
|||||||
_indicator.HideFar();
|
_indicator.HideFar();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default fallback behavior
|
|
||||||
Logging.Debug($"[Puzzles] Player exited far range of {stepData?.stepId} on {gameObject.name}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -208,54 +221,37 @@ namespace PuzzleS
|
|||||||
_isUnlocked = true;
|
_isUnlocked = true;
|
||||||
Logging.Debug($"[Puzzles] Step unlocked: {stepData?.stepId} on {gameObject.name}");
|
Logging.Debug($"[Puzzles] Step unlocked: {stepData?.stepId} on {gameObject.name}");
|
||||||
|
|
||||||
// Show indicator if available
|
// Make the indicator visible since this step is now unlocked
|
||||||
if (puzzleIndicator != null)
|
OnShow();
|
||||||
|
|
||||||
|
if (IsIndicatorValid())
|
||||||
{
|
{
|
||||||
// Try to get the IPuzzlePrompt component from the spawned indicator
|
// Set the correct state based on current player distance
|
||||||
_indicator = puzzleIndicator.GetComponent<IPuzzlePrompt>();
|
Transform playerTransform = GameObject.FindGameObjectWithTag("Player")?.transform;
|
||||||
|
if (playerTransform != null)
|
||||||
if (_indicator == null)
|
|
||||||
{
|
{
|
||||||
// Try to find it in children if not on the root
|
float distance = Vector3.Distance(transform.position, playerTransform.position);
|
||||||
_indicator = puzzleIndicator.GetComponentInChildren<IPuzzlePrompt>();
|
float promptRange = AppleHills.SettingsAccess.GetPuzzlePromptRange();
|
||||||
}
|
|
||||||
|
|
||||||
if (_indicator == null)
|
|
||||||
{
|
|
||||||
Logging.Warning($"[Puzzles] Indicator prefab for {stepData?.stepId} does not implement IPuzzlePrompt");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// First show the indicator
|
|
||||||
_indicator.OnShow();
|
|
||||||
|
|
||||||
// Then set the correct state based on current player distance
|
if (distance <= promptRange)
|
||||||
Transform playerTransform = GameObject.FindGameObjectWithTag("Player")?.transform;
|
|
||||||
if (playerTransform != null)
|
|
||||||
{
|
{
|
||||||
float distance = Vector3.Distance(transform.position, playerTransform.position);
|
// Player is in close range
|
||||||
float promptRange = AppleHills.SettingsAccess.GetPuzzlePromptRange();
|
_currentProximityState = ProximityState.Close;
|
||||||
|
_indicator.ShowClose();
|
||||||
if (distance <= promptRange)
|
|
||||||
{
|
|
||||||
// Player is in close range
|
|
||||||
_currentProximityState = ProximityState.Close;
|
|
||||||
_indicator.ShowClose();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Player is in far range
|
|
||||||
_currentProximityState = ProximityState.Far;
|
|
||||||
_indicator.ShowFar();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Default to far if player not found
|
// Player is in far range
|
||||||
_currentProximityState = ProximityState.Far;
|
_currentProximityState = ProximityState.Far;
|
||||||
_indicator.ShowFar();
|
_indicator.ShowFar();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Default to far if player not found
|
||||||
|
_currentProximityState = ProximityState.Far;
|
||||||
|
_indicator.ShowFar();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,16 +260,18 @@ namespace PuzzleS
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void LockStep()
|
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;
|
_isUnlocked = false;
|
||||||
Logging.Debug($"[Puzzles] Step locked: {stepData?.stepId} on {gameObject.name}");
|
Logging.Debug($"[Puzzles] Step locked: {stepData?.stepId} on {gameObject.name}");
|
||||||
|
|
||||||
// Hide indicator
|
// Hide the indicator
|
||||||
if (IsIndicatorValid())
|
OnHide();
|
||||||
{
|
|
||||||
_indicator.OnHide();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -289,7 +287,7 @@ namespace PuzzleS
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void OnInteractionStarted(PlayerTouchController playerRef, FollowerController followerRef)
|
private void OnInteractionStarted(PlayerTouchController playerRef, FollowerController followerRef)
|
||||||
{
|
{
|
||||||
// Optionally handle started interaction (e.g. visual feedback)
|
// Empty - handled by Interactable
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -29,14 +29,12 @@ namespace PuzzleS
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Steps that should be unlocked at level start (no dependencies)
|
/// Steps that should be unlocked at level start (no dependencies)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[HideInInspector]
|
|
||||||
public List<PuzzleStepSO> initialSteps = new List<PuzzleStepSO>();
|
public List<PuzzleStepSO> initialSteps = new List<PuzzleStepSO>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Pre-processed dependency data built at edit time.
|
/// Pre-processed dependency data built at edit time.
|
||||||
/// Maps step IDs to arrays of dependency step IDs (which steps are required by each step)
|
/// Maps step IDs to arrays of dependency step IDs (which steps are required by each step)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[HideInInspector]
|
|
||||||
public Dictionary<string, string[]> stepDependencies = new Dictionary<string, string[]>();
|
public Dictionary<string, string[]> stepDependencies = new Dictionary<string, string[]>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user