From 17feef79456c50d1382624ba6c4a77ae5b72bf0b Mon Sep 17 00:00:00 2001 From: Michal Pikulski Date: Wed, 15 Oct 2025 16:33:19 +0200 Subject: [PATCH] Update display issues with the puzzle steps --- .../Scripts/PuzzleS/ObjectiveStepBehaviour.cs | 120 +++++++++--------- Assets/Scripts/PuzzleS/PuzzleLevelDataSO.cs | 2 - 2 files changed, 59 insertions(+), 63 deletions(-) diff --git a/Assets/Scripts/PuzzleS/ObjectiveStepBehaviour.cs b/Assets/Scripts/PuzzleS/ObjectiveStepBehaviour.cs index e4687273..a86b69b2 100644 --- a/Assets/Scripts/PuzzleS/ObjectiveStepBehaviour.cs +++ b/Assets/Scripts/PuzzleS/ObjectiveStepBehaviour.cs @@ -34,12 +34,34 @@ namespace PuzzleS void Awake() { _interactable = GetComponent(); + + // 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(); + + if (_indicator == null) + { + // Try to find it in children if not on the root + _indicator = puzzleIndicator.GetComponentInChildren(); + } + + if (_indicator == null) + { + Logging.Warning($"[Puzzles] Indicator prefab for {stepData?.stepId} does not implement IPuzzlePrompt"); + } + } } void OnEnable() { if (_interactable == null) _interactable = GetComponent(); + 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 /// 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 /// 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}"); } /// @@ -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}"); } /// @@ -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}"); } /// @@ -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}"); } /// @@ -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(); - - 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(); - } - - 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 /// 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(); } /// @@ -289,7 +287,7 @@ namespace PuzzleS /// private void OnInteractionStarted(PlayerTouchController playerRef, FollowerController followerRef) { - // Optionally handle started interaction (e.g. visual feedback) + // Empty - handled by Interactable } /// diff --git a/Assets/Scripts/PuzzleS/PuzzleLevelDataSO.cs b/Assets/Scripts/PuzzleS/PuzzleLevelDataSO.cs index b5757cb3..086a8a13 100644 --- a/Assets/Scripts/PuzzleS/PuzzleLevelDataSO.cs +++ b/Assets/Scripts/PuzzleS/PuzzleLevelDataSO.cs @@ -29,14 +29,12 @@ namespace PuzzleS /// /// Steps that should be unlocked at level start (no dependencies) /// - [HideInInspector] public List initialSteps = new List(); /// /// Pre-processed dependency data built at edit time. /// Maps step IDs to arrays of dependency step IDs (which steps are required by each step) /// - [HideInInspector] public Dictionary stepDependencies = new Dictionary(); ///