diff --git a/scripts/CSharp/Common/CharacterControls/Detector.cs b/scripts/CSharp/Common/CharacterControls/Detector.cs index f714870..0f27dc8 100644 --- a/scripts/CSharp/Common/CharacterControls/Detector.cs +++ b/scripts/CSharp/Common/CharacterControls/Detector.cs @@ -14,7 +14,7 @@ public partial class Detector : Area2D [Export] private ShapeCast2D _shapeCast2D; [Export] private VariableResource _itemToTriggerResource; - private readonly List _areasInDetector = new(); + private List _areasInDetector = new(); public bool IsActive { @@ -41,12 +41,8 @@ public partial class Detector : Area2D if (!_active || !InputService.Instance.InputEnabled) return; - if (area is DetectableInteractionArea detectable) - { - ulong id = detectable.GetInstanceId(); - _areasInDetector.Add(id); - CalculateClosestInteractable(); - } + PopulateList(); + CalculateClosestInteractable(); } /// @@ -58,12 +54,23 @@ public partial class Detector : Area2D if (!_active || !InputService.Instance.InputEnabled) return; - if (area is DetectableInteractionArea detectable) + PopulateList(); + CalculateClosestInteractable(); + } + + private void PopulateList() + { + // repopulate the list of areas in the detector to account for enabled / disabled areas + var currentOverlap = GetOverlappingAreas(); + _areasInDetector = new List(); + + foreach (var area2D in currentOverlap) { - ulong id = detectable.GetInstanceId(); - if( _areasInDetector.Contains(id)) - _areasInDetector.Remove(id); - CalculateClosestInteractable(); + if (area2D is DetectableInteractionArea detectable) + { + ulong id = detectable.GetInstanceId(); + _areasInDetector.Add(id); + } } } diff --git a/scripts/CSharp/Common/CharacterControls/InteractionArea2D.cs b/scripts/CSharp/Common/CharacterControls/InteractionArea2D.cs index e2e231c..cf02ecc 100644 --- a/scripts/CSharp/Common/CharacterControls/InteractionArea2D.cs +++ b/scripts/CSharp/Common/CharacterControls/InteractionArea2D.cs @@ -1,6 +1,5 @@ using System.Linq; using Babushka.scripts.CSharp.Common.Services; -using Babushka.scripts.CSharp.Low_Code.Variables; using Godot; namespace Babushka.scripts.CSharp.Common.CharacterControls; @@ -26,7 +25,12 @@ public partial class InteractionArea2D : Node2D public bool IsActive { get => _active; - set => _active = value; + set + { + ProcessMode = value ? ProcessModeEnum.Inherit : ProcessModeEnum.Disabled; + Visible = value; + _active = value; + } } public bool IsSelectedByDetector { get; set; } = false; @@ -59,6 +63,7 @@ public partial class InteractionArea2D : Node2D foreach (var sprite in _spritesToOutline) { + GD.Print($"Highlighting outline material on {sprite.Name} Nr. {GetInstanceId()}"); sprite.Material = _outlineMaterial; } } @@ -74,6 +79,7 @@ public partial class InteractionArea2D : Node2D for (var i = 0; i < _spritesToOutline.Length; i++) { var sprite = _spritesToOutline[i]; + GD.Print($"Resetting outline material on {sprite.Name} Nr. {GetInstanceId()}"); sprite.Material = _backupMaterials[i]; } } diff --git a/scripts/CSharp/Common/Farming/FieldActivator.cs b/scripts/CSharp/Common/Farming/FieldActivator.cs index f324176..ef59846 100644 --- a/scripts/CSharp/Common/Farming/FieldActivator.cs +++ b/scripts/CSharp/Common/Farming/FieldActivator.cs @@ -32,6 +32,7 @@ public partial class FieldActivator : Node _field.UpdateFieldState(FieldState.Tilled); EmitSignal(SignalName.FieldCreated, _field); _used = true; + ToggleInteractionArea(); } } diff --git a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs index 60be591..fb16671 100644 --- a/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs +++ b/scripts/CSharp/Common/Farming/FieldBehaviour2D.cs @@ -99,25 +99,21 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable case FieldState.Empty: FieldState = FieldState.Empty; PlantingInteraction.IsActive = false; - PlantingInteraction.ProcessMode = ProcessModeEnum.Disabled; break; case FieldState.Tilled: FieldState = FieldState.Tilled; _fieldSprite.Texture = Tilled; PlantingInteraction.IsActive = true; - PlantingInteraction.ProcessMode = ProcessModeEnum.Inherit; break; case FieldState.Watered: FieldState = FieldState.Watered; _fieldSprite.Texture = Watered; PlantingInteraction.IsActive = true; - PlantingInteraction.ProcessMode = ProcessModeEnum.Inherit; break; case FieldState.Planted: FieldState = FieldState.Planted; _fieldSprite.Texture = Tilled; PlantingInteraction.IsActive = false; - PlantingInteraction.ProcessMode = ProcessModeEnum.Disabled; break; default: FieldState = FieldState.NotFound;