🚧 WIP trying to make fields have outlines again
This commit is contained in:
@@ -14,7 +14,7 @@ public partial class Detector : Area2D
|
|||||||
[Export] private ShapeCast2D _shapeCast2D;
|
[Export] private ShapeCast2D _shapeCast2D;
|
||||||
[Export] private VariableResource _itemToTriggerResource;
|
[Export] private VariableResource _itemToTriggerResource;
|
||||||
|
|
||||||
private readonly List<ulong> _areasInDetector = new();
|
private List<ulong> _areasInDetector = new();
|
||||||
|
|
||||||
public bool IsActive
|
public bool IsActive
|
||||||
{
|
{
|
||||||
@@ -41,13 +41,9 @@ public partial class Detector : Area2D
|
|||||||
if (!_active || !InputService.Instance.InputEnabled)
|
if (!_active || !InputService.Instance.InputEnabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (area is DetectableInteractionArea detectable)
|
PopulateList();
|
||||||
{
|
|
||||||
ulong id = detectable.GetInstanceId();
|
|
||||||
_areasInDetector.Add(id);
|
|
||||||
CalculateClosestInteractable();
|
CalculateClosestInteractable();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called whenever this node exits an Area2D.
|
/// Called whenever this node exits an Area2D.
|
||||||
@@ -58,12 +54,23 @@ public partial class Detector : Area2D
|
|||||||
if (!_active || !InputService.Instance.InputEnabled)
|
if (!_active || !InputService.Instance.InputEnabled)
|
||||||
return;
|
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<ulong>();
|
||||||
|
|
||||||
|
foreach (var area2D in currentOverlap)
|
||||||
|
{
|
||||||
|
if (area2D is DetectableInteractionArea detectable)
|
||||||
{
|
{
|
||||||
ulong id = detectable.GetInstanceId();
|
ulong id = detectable.GetInstanceId();
|
||||||
if( _areasInDetector.Contains(id))
|
_areasInDetector.Add(id);
|
||||||
_areasInDetector.Remove(id);
|
}
|
||||||
CalculateClosestInteractable();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Babushka.scripts.CSharp.Common.Services;
|
using Babushka.scripts.CSharp.Common.Services;
|
||||||
using Babushka.scripts.CSharp.Low_Code.Variables;
|
|
||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
namespace Babushka.scripts.CSharp.Common.CharacterControls;
|
namespace Babushka.scripts.CSharp.Common.CharacterControls;
|
||||||
@@ -26,7 +25,12 @@ public partial class InteractionArea2D : Node2D
|
|||||||
public bool IsActive
|
public bool IsActive
|
||||||
{
|
{
|
||||||
get => _active;
|
get => _active;
|
||||||
set => _active = value;
|
set
|
||||||
|
{
|
||||||
|
ProcessMode = value ? ProcessModeEnum.Inherit : ProcessModeEnum.Disabled;
|
||||||
|
Visible = value;
|
||||||
|
_active = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsSelectedByDetector { get; set; } = false;
|
public bool IsSelectedByDetector { get; set; } = false;
|
||||||
@@ -59,6 +63,7 @@ public partial class InteractionArea2D : Node2D
|
|||||||
|
|
||||||
foreach (var sprite in _spritesToOutline)
|
foreach (var sprite in _spritesToOutline)
|
||||||
{
|
{
|
||||||
|
GD.Print($"Highlighting outline material on {sprite.Name} Nr. {GetInstanceId()}");
|
||||||
sprite.Material = _outlineMaterial;
|
sprite.Material = _outlineMaterial;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -74,6 +79,7 @@ public partial class InteractionArea2D : Node2D
|
|||||||
for (var i = 0; i < _spritesToOutline.Length; i++)
|
for (var i = 0; i < _spritesToOutline.Length; i++)
|
||||||
{
|
{
|
||||||
var sprite = _spritesToOutline[i];
|
var sprite = _spritesToOutline[i];
|
||||||
|
GD.Print($"Resetting outline material on {sprite.Name} Nr. {GetInstanceId()}");
|
||||||
sprite.Material = _backupMaterials[i];
|
sprite.Material = _backupMaterials[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ public partial class FieldActivator : Node
|
|||||||
_field.UpdateFieldState(FieldState.Tilled);
|
_field.UpdateFieldState(FieldState.Tilled);
|
||||||
EmitSignal(SignalName.FieldCreated, _field);
|
EmitSignal(SignalName.FieldCreated, _field);
|
||||||
_used = true;
|
_used = true;
|
||||||
|
ToggleInteractionArea();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -99,25 +99,21 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
|
|||||||
case FieldState.Empty:
|
case FieldState.Empty:
|
||||||
FieldState = FieldState.Empty;
|
FieldState = FieldState.Empty;
|
||||||
PlantingInteraction.IsActive = false;
|
PlantingInteraction.IsActive = false;
|
||||||
PlantingInteraction.ProcessMode = ProcessModeEnum.Disabled;
|
|
||||||
break;
|
break;
|
||||||
case FieldState.Tilled:
|
case FieldState.Tilled:
|
||||||
FieldState = FieldState.Tilled;
|
FieldState = FieldState.Tilled;
|
||||||
_fieldSprite.Texture = Tilled;
|
_fieldSprite.Texture = Tilled;
|
||||||
PlantingInteraction.IsActive = true;
|
PlantingInteraction.IsActive = true;
|
||||||
PlantingInteraction.ProcessMode = ProcessModeEnum.Inherit;
|
|
||||||
break;
|
break;
|
||||||
case FieldState.Watered:
|
case FieldState.Watered:
|
||||||
FieldState = FieldState.Watered;
|
FieldState = FieldState.Watered;
|
||||||
_fieldSprite.Texture = Watered;
|
_fieldSprite.Texture = Watered;
|
||||||
PlantingInteraction.IsActive = true;
|
PlantingInteraction.IsActive = true;
|
||||||
PlantingInteraction.ProcessMode = ProcessModeEnum.Inherit;
|
|
||||||
break;
|
break;
|
||||||
case FieldState.Planted:
|
case FieldState.Planted:
|
||||||
FieldState = FieldState.Planted;
|
FieldState = FieldState.Planted;
|
||||||
_fieldSprite.Texture = Tilled;
|
_fieldSprite.Texture = Tilled;
|
||||||
PlantingInteraction.IsActive = false;
|
PlantingInteraction.IsActive = false;
|
||||||
PlantingInteraction.ProcessMode = ProcessModeEnum.Disabled;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
FieldState = FieldState.NotFound;
|
FieldState = FieldState.NotFound;
|
||||||
|
|||||||
Reference in New Issue
Block a user