🐛 Fixed field interaction bug
This commit is contained in:
@@ -8,16 +8,17 @@ namespace Babushka.scripts.CSharp.Common.CharacterControls;
|
||||
public partial class DetectableInteractionArea : Area2D
|
||||
{
|
||||
[Export] public InteractionArea2D interactionArea2D;
|
||||
|
||||
|
||||
public void InteractionAreaSelectionChanged(Variant instanceID)
|
||||
{
|
||||
if (instanceID.AsString() == GetInstanceId().ToString())
|
||||
{
|
||||
GD.Print("InteractionArea: Selected.");
|
||||
interactionArea2D.HighlightInteractable();
|
||||
}
|
||||
else
|
||||
{
|
||||
GD.Print("InteractionArea: Not Selected.");
|
||||
interactionArea2D.ResetHighlight();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
using System.Linq;
|
||||
using Babushka.scripts.CSharp.Common.Services;
|
||||
using Babushka.scripts.CSharp.Low_Code.Variables;
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.CharacterControls;
|
||||
|
||||
public partial class InteractionArea2D : Node2D
|
||||
{
|
||||
[ExportGroup("Settings")]
|
||||
[ExportGroup("Settings")]
|
||||
[Export] private VariableListener _selectionChangeListener;
|
||||
[Export] private Area2D _area;
|
||||
[Export] private Label _label;
|
||||
[Export] private bool _active = true;
|
||||
@@ -29,6 +31,7 @@ public partial class InteractionArea2D : Node2D
|
||||
{
|
||||
ProcessMode = value ? ProcessModeEnum.Inherit : ProcessModeEnum.Disabled;
|
||||
Visible = value;
|
||||
_selectionChangeListener.ProcessMode = value ? ProcessModeEnum.Inherit : ProcessModeEnum.Disabled;
|
||||
_active = value;
|
||||
}
|
||||
}
|
||||
@@ -50,6 +53,7 @@ public partial class InteractionArea2D : Node2D
|
||||
|
||||
public void HighlightInteractable()
|
||||
{
|
||||
GD.Print($"InteractionArea: Trying to highlight interactable. Current state: Active {_active}, Input Enabled {InputService.Instance.InputEnabled}, show label: {_showLabel} and use outline {_useOutline}.");
|
||||
IsSelectedByDetector = true;
|
||||
|
||||
if (!_active || !InputService.Instance.InputEnabled)
|
||||
@@ -63,13 +67,13 @@ public partial class InteractionArea2D : Node2D
|
||||
|
||||
foreach (var sprite in _spritesToOutline)
|
||||
{
|
||||
GD.Print($"Highlighting outline material on {sprite.Name} Nr. {GetInstanceId()}");
|
||||
sprite.Material = _outlineMaterial;
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetHighlight()
|
||||
{
|
||||
GD.Print($"InteractionArea: Resetting interactable. Current state: show label: {_showLabel} and use outline {_useOutline}.");
|
||||
IsSelectedByDetector = false;
|
||||
_label.Hide();
|
||||
|
||||
@@ -79,7 +83,6 @@ 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];
|
||||
}
|
||||
}
|
||||
@@ -105,18 +108,11 @@ public partial class InteractionArea2D : Node2D
|
||||
|
||||
private void TryInteract()
|
||||
{
|
||||
GD.Print("InteractionArea: Trying to interact.");
|
||||
if (_area.HasOverlappingAreas())
|
||||
{
|
||||
_label.Hide();
|
||||
|
||||
if (_useOutline)
|
||||
{
|
||||
for (var i = 0; i < _spritesToOutline.Length; i++)
|
||||
{
|
||||
var sprite = _spritesToOutline[i];
|
||||
sprite.Material = _backupMaterials[i];
|
||||
}
|
||||
}
|
||||
GD.Print("InteractionArea: Interacting.");
|
||||
ResetHighlight();
|
||||
Interact();
|
||||
}
|
||||
}
|
||||
@@ -135,6 +131,7 @@ public partial class InteractionArea2D : Node2D
|
||||
|
||||
public void ToggleActive()
|
||||
{
|
||||
GD.Print("InteractionArea: Toggled active state");
|
||||
_active = !_active;
|
||||
_label.Hide();
|
||||
}
|
||||
|
||||
@@ -63,6 +63,9 @@ public partial class VariableListener : Node
|
||||
/// </summary>
|
||||
public void EventPayloadChanged(Variant payload, Variant oldPayload)
|
||||
{
|
||||
if (ProcessMode == ProcessModeEnum.Disabled)
|
||||
return;
|
||||
|
||||
if(_showLog)
|
||||
GD.Print($"Calling Event Payload Changed Signals on: " + Name);
|
||||
EmitSignal(SignalName.PayloadChanged, payload, oldPayload);
|
||||
|
||||
Reference in New Issue
Block a user