🐛 Fixed field interaction bug
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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")
|
||||
|
||||
+2
-2
@@ -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"
|
||||
|
||||
|
||||
@@ -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"]
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -9,15 +9,16 @@ 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,5 +1,6 @@
|
||||
using System.Linq;
|
||||
using Babushka.scripts.CSharp.Common.Services;
|
||||
using Babushka.scripts.CSharp.Low_Code.Variables;
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.CharacterControls;
|
||||
@@ -7,6 +8,7 @@ namespace Babushka.scripts.CSharp.Common.CharacterControls;
|
||||
public partial class InteractionArea2D : Node2D
|
||||
{
|
||||
[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