From a98c842ee0ffdea771de8aefb0d7645b7ef7dd60 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Tue, 16 Dec 2025 13:04:40 +0100 Subject: [PATCH] :bug: Fixed field interaction bug --- prefabs/farm/base_field.tscn | 4 +--- prefabs/interactions/interaction_area_2d.tscn | 3 ++- project.godot | 4 ++-- scenes/Babushka_scene_farm_outside_2d.tscn | 8 ++----- scenes/Babushka_scene_indoor_common_room.tscn | 2 +- .../DetectableInteractionArea.cs | 3 ++- .../CharacterControls/InteractionArea2D.cs | 23 ++++++++----------- .../Low Code/Variables/VariableListener.cs | 3 +++ 8 files changed, 23 insertions(+), 27 deletions(-) diff --git a/prefabs/farm/base_field.tscn b/prefabs/farm/base_field.tscn index be59b32..a0d879b 100644 --- a/prefabs/farm/base_field.tscn +++ b/prefabs/farm/base_field.tscn @@ -38,7 +38,7 @@ z_index = 1 scale = Vector2(1.3499999, 1.5) texture = ExtResource("9_wx561") -[node name="FieldBehaviour" type="Sprite2D" parent="." node_paths=PackedStringArray("_fieldIndex", "_saveIdHolder", "_fieldSprite", "_maskSprite", "_outlineSprite", "PlantingInteraction", "FieldInteractionArea", "PlantingPlaceholder", "_wateringParticles")] +[node name="FieldBehaviour" type="Sprite2D" parent="." node_paths=PackedStringArray("_fieldIndex", "_saveIdHolder", "_fieldSprite", "_maskSprite", "_outlineSprite", "PlantingInteraction", "PlantingPlaceholder", "_wateringParticles")] visible = false z_index = -1 y_sort_enabled = true @@ -56,7 +56,6 @@ _maskTexture = Array[Texture2D]([ExtResource("2_w8caw"), ExtResource("3_c014y"), Tilled = ExtResource("5_wx561") Watered = ExtResource("6_7m4xq") PlantingInteraction = NodePath("InteractionArea") -FieldInteractionArea = NodePath("InteractionArea") PlantingPlaceholder = NodePath("PlantPlaceholder") ItemRepository = ExtResource("7_w8caw") _wateringParticles = NodePath("../pouring water vfx") @@ -79,7 +78,6 @@ position = Vector2(-28.88889, -57) scale = Vector2(1.1111112, 1) _active = false _spritesToOutline = [NodePath("../../OutlineSprite")] -_showLabel = false [node name="PlantCreationEventRaiser" type="Node" parent="."] script = ExtResource("9_teirr") diff --git a/prefabs/interactions/interaction_area_2d.tscn b/prefabs/interactions/interaction_area_2d.tscn index 8880a38..36e121c 100644 --- a/prefabs/interactions/interaction_area_2d.tscn +++ b/prefabs/interactions/interaction_area_2d.tscn @@ -13,8 +13,9 @@ radius = 150.0 [sub_resource type="Theme" id="Theme_5ajrf"] default_font_size = 30 -[node name="InteractionArea" type="Node2D" node_paths=PackedStringArray("_area", "_label")] +[node name="InteractionArea" type="Node2D" node_paths=PackedStringArray("_selectionChangeListener", "_area", "_label")] script = ExtResource("1_5ajrf") +_selectionChangeListener = NodePath("SelectionListener") _area = NodePath("Area2D") _label = NodePath("Area2D/CanvasLayer/MarginContainer/Label") _outlineMaterial = ExtResource("2_qoey7") diff --git a/project.godot b/project.godot index 362fd84..994ee6f 100644 --- a/project.godot +++ b/project.godot @@ -187,8 +187,8 @@ directories/tres_directory={ [display] -window/size/viewport_width=1980 -window/size/viewport_height=1020 +window/size/viewport_width=1920 +window/size/viewport_height=1080 window/stretch/mode="viewport" window/stretch/aspect="keep_height" diff --git a/scenes/Babushka_scene_farm_outside_2d.tscn b/scenes/Babushka_scene_farm_outside_2d.tscn index dc38873..33291b3 100644 --- a/scenes/Babushka_scene_farm_outside_2d.tscn +++ b/scenes/Babushka_scene_farm_outside_2d.tscn @@ -1001,9 +1001,7 @@ metadata/SaveID = "5a823507-8107-40ce-8b32-6d0f81a3c44e" [node name="SpawnWithItem" parent="YSorted/CanGenericPickup" index="0"] _blueprint = ExtResource("28_ipqaa") -[node name="PickupInteractionArea" parent="YSorted/CanGenericPickup" index="3" node_paths=PackedStringArray("_spritesToOutline")] -_outlineMaterial = null -_spritesToOutline = [] +[node name="PickupInteractionArea" parent="YSorted/CanGenericPickup" index="3"] metadata/SaveID = "0c006f5c-c472-4f89-908b-d8f34503ba37" [node name="CollisionShape3D" parent="YSorted/CanGenericPickup/PickupInteractionArea/Area2D" index="0"] @@ -1019,9 +1017,7 @@ metadata/SaveID = "e13886b1-2131-4072-bc06-7d8abb19357b" [node name="SpawnWithItem" parent="YSorted/RakeGenericPickup" index="0"] _blueprint = ExtResource("28_6b2nr") -[node name="PickupInteractionArea" parent="YSorted/RakeGenericPickup" index="3" node_paths=PackedStringArray("_spritesToOutline")] -_outlineMaterial = null -_spritesToOutline = [] +[node name="PickupInteractionArea" parent="YSorted/RakeGenericPickup" index="3"] metadata/SaveID = "c148aa78-114b-4770-a040-8498483edb1d" [node name="CollisionShape3D" parent="YSorted/RakeGenericPickup/PickupInteractionArea/Area2D" index="0"] diff --git a/scenes/Babushka_scene_indoor_common_room.tscn b/scenes/Babushka_scene_indoor_common_room.tscn index aade251..4ef6b46 100644 --- a/scenes/Babushka_scene_indoor_common_room.tscn +++ b/scenes/Babushka_scene_indoor_common_room.tscn @@ -357,7 +357,7 @@ region_enabled = true region_rect = Rect2(1156, 1185, 940, 189) [node name="Katze" type="Sprite2D" parent="BackWall/Bench"] -z_index = -10 +z_index = 10 position = Vector2(61, -87) scale = Vector2(2, 2) texture = ExtResource("15_sndxu") diff --git a/scripts/CSharp/Common/CharacterControls/DetectableInteractionArea.cs b/scripts/CSharp/Common/CharacterControls/DetectableInteractionArea.cs index 0f42034..0202e10 100644 --- a/scripts/CSharp/Common/CharacterControls/DetectableInteractionArea.cs +++ b/scripts/CSharp/Common/CharacterControls/DetectableInteractionArea.cs @@ -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(); } } diff --git a/scripts/CSharp/Common/CharacterControls/InteractionArea2D.cs b/scripts/CSharp/Common/CharacterControls/InteractionArea2D.cs index cf02ecc..31093af 100644 --- a/scripts/CSharp/Common/CharacterControls/InteractionArea2D.cs +++ b/scripts/CSharp/Common/CharacterControls/InteractionArea2D.cs @@ -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(); } diff --git a/scripts/CSharp/Low Code/Variables/VariableListener.cs b/scripts/CSharp/Low Code/Variables/VariableListener.cs index 2576015..90573a9 100644 --- a/scripts/CSharp/Low Code/Variables/VariableListener.cs +++ b/scripts/CSharp/Low Code/Variables/VariableListener.cs @@ -63,6 +63,9 @@ public partial class VariableListener : Node /// 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);