diff --git a/prefabs/characters/Vesna.tscn b/prefabs/characters/Vesna.tscn
index 3ec6385..0c92a50 100644
--- a/prefabs/characters/Vesna.tscn
+++ b/prefabs/characters/Vesna.tscn
@@ -2173,7 +2173,7 @@ script = ExtResource("472_kduih")
_wateringCanFillStateNode = NodePath("../WateringCanFillState")
[node name="DetectionCross" parent="CharacterBody2D" instance=ExtResource("466_e04c3")]
-position = Vector2(0, -371)
+position = Vector2(0, -260)
[node name="FarmingControls" type="Node2D" parent="." node_paths=PackedStringArray("_movingPlayer")]
script = ExtResource("817_6nrw3")
diff --git a/prefabs/farm/animals/duck.tscn b/prefabs/farm/animals/duck.tscn
index b503a3d..c9b269c 100644
--- a/prefabs/farm/animals/duck.tscn
+++ b/prefabs/farm/animals/duck.tscn
@@ -1,8 +1,7 @@
-[gd_scene load_steps=25 format=3 uid="uid://muuxxgvx33fp"]
+[gd_scene load_steps=24 format=3 uid="uid://muuxxgvx33fp"]
[ext_resource type="Script" uid="uid://7m1rt7agb6rm" path="res://scripts/CSharp/Common/Temp/MVPDuck.cs" id="1_54k4r"]
[ext_resource type="Texture2D" uid="uid://hvchk6t0xe7j" path="res://art/animals/Ente.png" id="1_cgxhx"]
-[ext_resource type="Resource" uid="uid://tt3d166mntmi" path="res://resources/low code/farming/var_sceneNameProvider.tres" id="2_fdf3t"]
[ext_resource type="AudioStream" uid="uid://qv0aubjeyi0u" path="res://audio/sfx/Animals/SFX_Duck_Quack_01.wav" id="3_kjie1"]
[ext_resource type="Script" uid="uid://cfnrd5k1k0gxw" path="res://scripts/CSharp/Common/AudioPlayer2D.cs" id="3_rdn2q"]
[ext_resource type="AudioStream" uid="uid://da84l8e44scwh" path="res://audio/sfx/Animals/SFX_Duck_Quack_02.wav" id="4_54k4r"]
@@ -143,7 +142,6 @@ viewport_path = NodePath("SubViewport")
z_index = 1
y_sort_enabled = true
script = ExtResource("1_54k4r")
-_sceneKeyProvider = ExtResource("2_fdf3t")
_transferDelayMs = 1000
_animationPlayer = NodePath("AnimationPlayer")
diff --git a/prefabs/farm/base_field.tscn b/prefabs/farm/base_field.tscn
index f7d7083..be59b32 100644
--- a/prefabs/farm/base_field.tscn
+++ b/prefabs/farm/base_field.tscn
@@ -74,6 +74,7 @@ texture = ExtResource("5_wx561")
y_sort_enabled = true
[node name="InteractionArea" parent="FieldBehaviour" node_paths=PackedStringArray("_spritesToOutline") instance=ExtResource("7_2eegd")]
+process_mode = 4
position = Vector2(-28.88889, -57)
scale = Vector2(1.1111112, 1)
_active = false
diff --git a/prefabs/interactions/detection_cross.tscn b/prefabs/interactions/detection_cross.tscn
index c7b7f7a..3dfe0e2 100644
--- a/prefabs/interactions/detection_cross.tscn
+++ b/prefabs/interactions/detection_cross.tscn
@@ -2,19 +2,20 @@
[ext_resource type="Script" uid="uid://ccc6m6c5khd2x" path="res://scripts/CSharp/Common/CharacterControls/DetectionCross.cs" id="1_va8tx"]
[ext_resource type="PackedScene" uid="uid://dugr6ff1g7hi0" path="res://prefabs/interactions/detector.tscn" id="2_8hh05"]
-[ext_resource type="Script" uid="uid://b4n0nlu4ckqga" path="res://scripts/CSharp/Common/CharacterControls/RaycastDetector.cs" id="2_va8tx"]
-[node name="DetectionCross" type="Node2D" node_paths=PackedStringArray("_collider", "_detector")]
-position = Vector2(0, 1)
+[sub_resource type="RectangleShape2D" id="RectangleShape2D_va8tx"]
+
+[node name="DetectionCross" type="Node2D" node_paths=PackedStringArray("_collider", "_shapeCast2D")]
script = ExtResource("1_va8tx")
_collider = NodePath("detector")
-_detector = NodePath("Raycast")
+_shapeCast2D = NodePath("ShapeCast2D")
_xOffset = 200.0
_yOffset = 200.0
-[node name="Raycast" type="RayCast2D" parent="."]
-target_position = Vector2(222, -168)
-collide_with_areas = true
-script = ExtResource("2_va8tx")
+[node name="detector" parent="." node_paths=PackedStringArray("_shapeCast2D") instance=ExtResource("2_8hh05")]
+_shapeCast2D = NodePath("../ShapeCast2D")
-[node name="detector" parent="." instance=ExtResource("2_8hh05")]
+[node name="ShapeCast2D" type="ShapeCast2D" parent="."]
+shape = SubResource("RectangleShape2D_va8tx")
+target_position = Vector2(200, 0)
+collide_with_areas = true
diff --git a/prefabs/interactions/detector.tscn b/prefabs/interactions/detector.tscn
index 74721b6..33c4be5 100644
--- a/prefabs/interactions/detector.tscn
+++ b/prefabs/interactions/detector.tscn
@@ -1,13 +1,15 @@
-[gd_scene load_steps=3 format=3 uid="uid://dugr6ff1g7hi0"]
+[gd_scene load_steps=4 format=3 uid="uid://dugr6ff1g7hi0"]
[ext_resource type="Script" uid="uid://c3pd60biootsx" path="res://scripts/CSharp/Common/CharacterControls/Detector.cs" id="1_6pib0"]
+[ext_resource type="Resource" uid="uid://clwqh3w5aqi5e" path="res://resources/low code/interactables/var_interactableToTrigger.tres" id="2_3fanv"]
[sub_resource type="CircleShape2D" id="CircleShape2D_6pib0"]
-radius = 200.0
+radius = 300.0
[node name="detector" type="Area2D"]
collision_layer = 4
script = ExtResource("1_6pib0")
+_itemToTriggerResource = ExtResource("2_3fanv")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("CircleShape2D_6pib0")
diff --git a/prefabs/interactions/interaction_area_2d.tscn b/prefabs/interactions/interaction_area_2d.tscn
index 73bbc94..8880a38 100644
--- a/prefabs/interactions/interaction_area_2d.tscn
+++ b/prefabs/interactions/interaction_area_2d.tscn
@@ -1,9 +1,10 @@
-[gd_scene load_steps=7 format=3 uid="uid://cqc72e4hq6bcd"]
+[gd_scene load_steps=8 format=3 uid="uid://cqc72e4hq6bcd"]
[ext_resource type="Script" uid="uid://ckp413wrub5fm" path="res://scripts/CSharp/Common/CharacterControls/InteractionArea2D.cs" id="1_5ajrf"]
[ext_resource type="Resource" uid="uid://clwqh3w5aqi5e" path="res://resources/low code/interactables/var_interactableToTrigger.tres" id="2_o1drf"]
[ext_resource type="Material" uid="uid://blch5kdhkbj75" path="res://art/materials/simple_interactable_outline.tres" id="2_qoey7"]
[ext_resource type="Script" uid="uid://cp2q4k62sjo6h" path="res://scripts/CSharp/Common/CharacterControls/DetectableInteractionArea.cs" id="3_2wrrq"]
+[ext_resource type="Script" uid="uid://pqemey80frcq" path="res://scripts/CSharp/Low Code/Variables/VariableListener.cs" id="4_gj2nu"]
[sub_resource type="CircleShape2D" id="CircleShape2D_npluf"]
resource_local_to_scene = true
@@ -14,7 +15,6 @@ default_font_size = 30
[node name="InteractionArea" type="Node2D" node_paths=PackedStringArray("_area", "_label")]
script = ExtResource("1_5ajrf")
-_interactableToTrigger = ExtResource("2_o1drf")
_area = NodePath("Area2D")
_label = NodePath("Area2D/CanvasLayer/MarginContainer/Label")
_outlineMaterial = ExtResource("2_qoey7")
@@ -54,5 +54,8 @@ text = "[E]"
horizontal_alignment = 2
vertical_alignment = 2
-[connection signal="area_entered" from="Area2D" to="." method="OnPlayerEntered"]
-[connection signal="area_exited" from="Area2D" to="." method="OnPlayerExited"]
+[node name="SelectionListener" type="Node" parent="."]
+script = ExtResource("4_gj2nu")
+_variableResources = Array[Object]([ExtResource("2_o1drf")])
+
+[connection signal="NewEventPayload" from="SelectionListener" to="Area2D" method="InteractionAreaSelectionChanged"]
diff --git a/scenes/Babushka_scene_farm_outside_2d.tscn b/scenes/Babushka_scene_farm_outside_2d.tscn
index be2050a..dc38873 100644
--- a/scenes/Babushka_scene_farm_outside_2d.tscn
+++ b/scenes/Babushka_scene_farm_outside_2d.tscn
@@ -985,7 +985,8 @@ collision_mask = 4
position = Vector2(145.5, -224)
shape = SubResource("RectangleShape2D_0sfl7")
-[node name="InteractionArea" parent="YSorted/Well" instance=ExtResource("27_klb81")]
+[node name="InteractionArea" parent="YSorted/Well" node_paths=PackedStringArray("_spritesToOutline") instance=ExtResource("27_klb81")]
+_spritesToOutline = [NodePath("..")]
_id = 1
metadata/SaveID = "b8f7b7fe-e057-4974-ba12-9134722998de"
@@ -2313,9 +2314,8 @@ position = Vector2(3183, 2369)
offset = Vector2(1, -50)
region_rect = Rect2(207, 1184, 149, 142)
-[node name="InteractionArea" parent="YSorted/trash/trashObject2" index="0" node_paths=PackedStringArray("_spritesToOutline")]
+[node name="InteractionArea" parent="YSorted/trash/trashObject2" index="0"]
position = Vector2(-9, -46)
-_spritesToOutline = []
metadata/SaveID = "549bbcf4-ea57-4b8f-80b1-b13ca648559b"
[node name="trashObject3" parent="YSorted/trash" instance=ExtResource("53_ycj14")]
@@ -2325,9 +2325,8 @@ position = Vector2(4724, 3519)
offset = Vector2(1, -50)
region_rect = Rect2(400, 1053, 163, 141)
-[node name="InteractionArea" parent="YSorted/trash/trashObject3" index="0" node_paths=PackedStringArray("_spritesToOutline")]
+[node name="InteractionArea" parent="YSorted/trash/trashObject3" index="0"]
position = Vector2(-13, -53)
-_spritesToOutline = []
metadata/SaveID = "29874314-50c1-4a21-9494-18f936d6e097"
[node name="trashObject4" parent="YSorted/trash" instance=ExtResource("53_ycj14")]
@@ -2337,9 +2336,8 @@ position = Vector2(5385, 3391)
offset = Vector2(1, -50)
region_rect = Rect2(1048, 1092, 348, 106)
-[node name="InteractionArea" parent="YSorted/trash/trashObject4" index="0" node_paths=PackedStringArray("_spritesToOutline")]
+[node name="InteractionArea" parent="YSorted/trash/trashObject4" index="0"]
position = Vector2(0, -59)
-_spritesToOutline = []
metadata/SaveID = "7ccaa831-5526-40ed-8ca3-31ba2ad929a6"
[node name="trashObject5" parent="YSorted/trash" instance=ExtResource("53_ycj14")]
@@ -2376,9 +2374,8 @@ rotation = 1.77025
offset = Vector2(0, 0)
region_rect = Rect2(1048, 1092, 348, 106)
-[node name="InteractionArea" parent="YSorted/trash/trashObject9" index="0" node_paths=PackedStringArray("_spritesToOutline")]
+[node name="InteractionArea" parent="YSorted/trash/trashObject9" index="0"]
position = Vector2(22.40873, 25.05658)
-_spritesToOutline = []
metadata/SaveID = "7bf227d6-3844-41e9-a9cd-524052aced3b"
[node name="CanvasLayer" parent="." instance=ExtResource("32_2nee2")]
diff --git a/scripts/CSharp/Common/CharacterControls/DetectableInteractionArea.cs b/scripts/CSharp/Common/CharacterControls/DetectableInteractionArea.cs
index e630f62..0f42034 100644
--- a/scripts/CSharp/Common/CharacterControls/DetectableInteractionArea.cs
+++ b/scripts/CSharp/Common/CharacterControls/DetectableInteractionArea.cs
@@ -9,14 +9,16 @@ public partial class DetectableInteractionArea : Area2D
{
[Export] public InteractionArea2D interactionArea2D;
- public void Detected()
+
+ public void InteractionAreaSelectionChanged(Variant instanceID)
{
- GD.Print("Detected " + interactionArea2D.GetParent().Name);
- interactionArea2D.IsSelectedByDetector = true;
- }
-
- public void NoLongerDetected()
- {
- interactionArea2D.IsSelectedByDetector = false;
+ if (instanceID.AsString() == GetInstanceId().ToString())
+ {
+ interactionArea2D.HighlightInteractable();
+ }
+ else
+ {
+ interactionArea2D.ResetHighlight();
+ }
}
}
\ No newline at end of file
diff --git a/scripts/CSharp/Common/CharacterControls/DetectionCross.cs b/scripts/CSharp/Common/CharacterControls/DetectionCross.cs
index 2930303..70010ab 100644
--- a/scripts/CSharp/Common/CharacterControls/DetectionCross.cs
+++ b/scripts/CSharp/Common/CharacterControls/DetectionCross.cs
@@ -8,7 +8,7 @@ namespace Babushka.scripts.CSharp.Common.CharacterControls;
public partial class DetectionCross : Node2D
{
[Export] private Detector _collider;
- [Export] private RaycastDetector _detector;
+ [Export] private ShapeCast2D _shapeCast2D;
[Export] private float _xOffset;
[Export] private float _yOffset;
@@ -20,6 +20,6 @@ public partial class DetectionCross : Node2D
{
Vector2 newPos = new Vector2(direction.X * _xOffset, direction.Y * _yOffset);
_collider.Position = newPos;
- _detector.TargetPosition = newPos;
+ _shapeCast2D.TargetPosition = newPos;
}
}
\ No newline at end of file
diff --git a/scripts/CSharp/Common/CharacterControls/Detector.cs b/scripts/CSharp/Common/CharacterControls/Detector.cs
index 3aba858..f714870 100644
--- a/scripts/CSharp/Common/CharacterControls/Detector.cs
+++ b/scripts/CSharp/Common/CharacterControls/Detector.cs
@@ -1,6 +1,7 @@
+using System.Collections.Generic;
using Babushka.scripts.CSharp.Common.Services;
+using Babushka.scripts.CSharp.Low_Code.Variables;
using Godot;
-using Godot.Collections;
namespace Babushka.scripts.CSharp.Common.CharacterControls;
@@ -9,18 +10,11 @@ namespace Babushka.scripts.CSharp.Common.CharacterControls;
///
public partial class Detector : Area2D
{
-
[Export] private bool _active = true;
-
- ///
- /// Called when entering an interactionArea node.
- ///
- [Signal] public delegate void InteractableEnteredEventHandler();
+ [Export] private ShapeCast2D _shapeCast2D;
+ [Export] private VariableResource _itemToTriggerResource;
- ///
- /// Called when exiting an interactionArea node.
- ///
- [Signal] public delegate void InteractableExitedEventHandler();
+ private readonly List _areasInDetector = new();
public bool IsActive
{
@@ -47,9 +41,11 @@ public partial class Detector : Area2D
if (!_active || !InputService.Instance.InputEnabled)
return;
- if (area is DetectableInteractionArea interactionArea2D)
+ if (area is DetectableInteractionArea detectable)
{
- EmitSignal(SignalName.InteractableEntered);
+ ulong id = detectable.GetInstanceId();
+ _areasInDetector.Add(id);
+ CalculateClosestInteractable();
}
}
@@ -62,10 +58,35 @@ public partial class Detector : Area2D
if (!_active || !InputService.Instance.InputEnabled)
return;
- if (area is DetectableInteractionArea interactionArea2D)
+ if (area is DetectableInteractionArea detectable)
{
-
- EmitSignal(SignalName.InteractableExited);
+ ulong id = detectable.GetInstanceId();
+ if( _areasInDetector.Contains(id))
+ _areasInDetector.Remove(id);
+ CalculateClosestInteractable();
}
}
+
+ private void CalculateClosestInteractable()
+ {
+ GD.Print($"Areas in detector: {_areasInDetector.Count}");
+ float smallestDistance = float.MaxValue;
+ string closestInteractable = null;
+ foreach (var area in _areasInDetector)
+ {
+ Area2D? area2D = InstanceFromId(area) as Area2D;
+ if(area2D == null)
+ continue;
+
+ float distance = area2D.GlobalPosition.DistanceSquaredTo(ToGlobal(_shapeCast2D.TargetPosition));
+ if (distance < smallestDistance)
+ {
+ closestInteractable = area.ToString();
+ smallestDistance = distance;
+ }
+ }
+ GD.Print($"Closest interactable: {closestInteractable}");
+ _itemToTriggerResource.Payload = closestInteractable;
+ }
+
}
\ No newline at end of file
diff --git a/scripts/CSharp/Common/CharacterControls/InteractionArea2D.cs b/scripts/CSharp/Common/CharacterControls/InteractionArea2D.cs
index 83b9d03..41ec0b6 100644
--- a/scripts/CSharp/Common/CharacterControls/InteractionArea2D.cs
+++ b/scripts/CSharp/Common/CharacterControls/InteractionArea2D.cs
@@ -43,10 +43,10 @@ public partial class InteractionArea2D : Node2D
_backupMaterials = _spritesToOutline.Select(s => s.Material).ToArray();
}
}
-
+
+/*
public void OnPlayerEntered(Node2D player)
{
- GD.Print("OnPlayerEntered: " + this.GetParent().Name);
if (!_active || !InputService.Instance.InputEnabled)
return;
@@ -59,13 +59,28 @@ public partial class InteractionArea2D : Node2D
if (!IsSelectedByDetector)
return;
+ ActivateOutline();
+ }
+ */
+
+ public void HighlightInteractable()
+ {
+ if (!_active || !InputService.Instance.InputEnabled)
+ return;
+
+ if (_showLabel)
+ _label.Show();
+
+ if (!_useOutline)
+ return;
+
foreach (var sprite in _spritesToOutline)
{
sprite.Material = _outlineMaterial;
}
}
- public void OnPlayerExited(Node2D player)
+ public void ResetHighlight()
{
_label.Hide();
@@ -78,6 +93,13 @@ public partial class InteractionArea2D : Node2D
sprite.Material = _backupMaterials[i];
}
}
+
+/*
+ public void OnPlayerExited(Node2D player)
+ {
+
+ }
+ */
public override void _Input(InputEvent @event)
{
@@ -134,4 +156,5 @@ public partial class InteractionArea2D : Node2D
_label.Hide();
}
+
}
\ No newline at end of file
diff --git a/scripts/CSharp/Common/CharacterControls/RaycastDetector.cs b/scripts/CSharp/Common/CharacterControls/RaycastDetector.cs
deleted file mode 100644
index 773527e..0000000
--- a/scripts/CSharp/Common/CharacterControls/RaycastDetector.cs
+++ /dev/null
@@ -1,41 +0,0 @@
-using Godot;
-
-namespace Babushka.scripts.CSharp.Common.CharacterControls;
-
-public partial class RaycastDetector : RayCast2D
-{
- [Export] private bool _active = true;
-
- private DetectableInteractionArea? _lastDetected;
-
- public bool IsActive
- {
- get => _active;
- set
- {
- Visible = value;
- _active = value;
- }
- }
-
- public override void _PhysicsProcess(double delta)
- {
- if (!_active)
- return;
-
- if (IsColliding())
- {
- if (GetCollider() is DetectableInteractionArea interactionArea)
- {
- if (_lastDetected != null && _lastDetected != interactionArea)
- {
- _lastDetected.NoLongerDetected();
- }
-
- GD.Print("Colliding with: " + interactionArea.GetParent().Name);
- _lastDetected = interactionArea;
- interactionArea.Detected();
- }
- }
- }
-}
\ No newline at end of file
diff --git a/scripts/CSharp/Common/CharacterControls/RaycastDetector.cs.uid b/scripts/CSharp/Common/CharacterControls/RaycastDetector.cs.uid
deleted file mode 100644
index 6b83bca..0000000
--- a/scripts/CSharp/Common/CharacterControls/RaycastDetector.cs.uid
+++ /dev/null
@@ -1 +0,0 @@
-uid://b4n0nlu4ckqga