✨ added InventoryListener and made field interaction area activate only when the right item (seed) is in the inventory
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
[gd_scene load_steps=14 format=3 uid="uid://b1d2e7ely6hyw"]
|
[gd_scene load_steps=17 format=3 uid="uid://b1d2e7ely6hyw"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://bdffon388rkty" path="res://scripts/CSharp/Common/Farming/FieldBehaviour2D.cs" id="1_qa01x"]
|
[ext_resource type="Script" uid="uid://bdffon388rkty" path="res://scripts/CSharp/Common/Farming/FieldBehaviour2D.cs" id="1_qa01x"]
|
||||||
[ext_resource type="Texture2D" uid="uid://cgmu3qlovdr22" path="res://art/masks/field_outline_1.png" id="2_w8caw"]
|
[ext_resource type="Texture2D" uid="uid://cgmu3qlovdr22" path="res://art/masks/field_outline_1.png" id="2_w8caw"]
|
||||||
@@ -13,10 +13,13 @@
|
|||||||
[ext_resource type="Script" uid="uid://b5dotkx17gvxg" path="res://scripts/CSharp/Low Code/Events/EventRaiser.cs" id="9_teirr"]
|
[ext_resource type="Script" uid="uid://b5dotkx17gvxg" path="res://scripts/CSharp/Low Code/Events/EventRaiser.cs" id="9_teirr"]
|
||||||
[ext_resource type="Texture2D" uid="uid://bovypw2hsn2nq" path="res://art/masks/field_outline_1_outline.png" id="9_wx561"]
|
[ext_resource type="Texture2D" uid="uid://bovypw2hsn2nq" path="res://art/masks/field_outline_1_outline.png" id="9_wx561"]
|
||||||
[ext_resource type="Resource" uid="uid://b4hawvsc7cmkn" path="res://resources/low code/farming/event_newPlantCreated.tres" id="10_wx561"]
|
[ext_resource type="Resource" uid="uid://b4hawvsc7cmkn" path="res://resources/low code/farming/event_newPlantCreated.tres" id="10_wx561"]
|
||||||
|
[ext_resource type="Script" uid="uid://3t0af586fimq" path="res://scripts/CSharp/Common/Inventory/InventoryListener.cs" id="14_w08sx"]
|
||||||
|
[ext_resource type="Resource" uid="uid://d1uuxp1lp4aro" path="res://resources/items/tomato_seed.tres" id="15_i4qwg"]
|
||||||
|
[ext_resource type="Resource" uid="uid://duq7tshxv6uhp" path="res://resources/items/beet_seed.tres" id="16_i4qwg"]
|
||||||
|
|
||||||
[node name="BaseField" type="Node2D"]
|
[node name="BaseField" type="Node2D"]
|
||||||
|
|
||||||
[node name="FieldBehaviour" type="Sprite2D" parent="." node_paths=PackedStringArray("_fieldSprite", "_maskSprite", "_outlineSprite", "PlantingInteraction", "PlantingPlaceholder")]
|
[node name="FieldBehaviour" type="Sprite2D" parent="." node_paths=PackedStringArray("_fieldSprite", "_maskSprite", "_outlineSprite", "PlantingInteraction", "PlantingPlaceholder", "FieldInteractionArea")]
|
||||||
z_index = -1
|
z_index = -1
|
||||||
scale = Vector2(0.9, 1)
|
scale = Vector2(0.9, 1)
|
||||||
script = ExtResource("1_qa01x")
|
script = ExtResource("1_qa01x")
|
||||||
@@ -30,6 +33,7 @@ Watered = ExtResource("6_7m4xq")
|
|||||||
PlantingInteraction = NodePath("../InteractionArea")
|
PlantingInteraction = NodePath("../InteractionArea")
|
||||||
PlantingPlaceholder = NodePath("PlantPlaceholder")
|
PlantingPlaceholder = NodePath("PlantPlaceholder")
|
||||||
ItemRepository = ExtResource("7_w8caw")
|
ItemRepository = ExtResource("7_w8caw")
|
||||||
|
FieldInteractionArea = NodePath("../InteractionArea")
|
||||||
|
|
||||||
[node name="MaskedField" type="Sprite2D" parent="FieldBehaviour"]
|
[node name="MaskedField" type="Sprite2D" parent="FieldBehaviour"]
|
||||||
clip_children = 1
|
clip_children = 1
|
||||||
@@ -49,11 +53,17 @@ texture = ExtResource("9_wx561")
|
|||||||
|
|
||||||
[node name="InteractionArea" parent="." node_paths=PackedStringArray("_spritesToOutline") instance=ExtResource("7_2eegd")]
|
[node name="InteractionArea" parent="." node_paths=PackedStringArray("_spritesToOutline") instance=ExtResource("7_2eegd")]
|
||||||
position = Vector2(-26, -57)
|
position = Vector2(-26, -57)
|
||||||
|
_active = false
|
||||||
_spritesToOutline = [NodePath("../FieldBehaviour/OutlineSprite")]
|
_spritesToOutline = [NodePath("../FieldBehaviour/OutlineSprite")]
|
||||||
|
|
||||||
[node name="PlantCreationEventRaiser" type="Node" parent="."]
|
[node name="PlantCreationEventRaiser" type="Node" parent="."]
|
||||||
script = ExtResource("9_teirr")
|
script = ExtResource("9_teirr")
|
||||||
_eventResources = Array[Object]([ExtResource("10_wx561")])
|
_eventResources = Array[Object]([ExtResource("10_wx561")])
|
||||||
|
|
||||||
|
[node name="InventoryListener" type="Node" parent="."]
|
||||||
|
script = ExtResource("14_w08sx")
|
||||||
|
_itemResourcesToListenFor = Array[Object]([ExtResource("15_i4qwg"), ExtResource("16_i4qwg")])
|
||||||
|
|
||||||
[connection signal="Planted" from="FieldBehaviour" to="PlantCreationEventRaiser" method="RaiseEvents"]
|
[connection signal="Planted" from="FieldBehaviour" to="PlantCreationEventRaiser" method="RaiseEvents"]
|
||||||
[connection signal="Interacted" from="InteractionArea" to="FieldBehaviour" method="Farm"]
|
[connection signal="Interacted" from="InteractionArea" to="FieldBehaviour" method="Farm"]
|
||||||
|
[connection signal="ItemInstanceActivated" from="InventoryListener" to="FieldBehaviour" method="ActivatedSeedInInventory"]
|
||||||
|
|||||||
@@ -19,15 +19,33 @@ public partial class FieldBehaviour2D : Sprite2D
|
|||||||
[Export] public InteractionArea2D PlantingInteraction;
|
[Export] public InteractionArea2D PlantingInteraction;
|
||||||
[Export] public Node2D PlantingPlaceholder;
|
[Export] public Node2D PlantingPlaceholder;
|
||||||
[Export] public ItemRepository ItemRepository;
|
[Export] public ItemRepository ItemRepository;
|
||||||
|
[Export] public InteractionArea2D FieldInteractionArea;
|
||||||
|
|
||||||
public Vector2 FieldPosition;
|
public Vector2 FieldPosition;
|
||||||
|
|
||||||
|
private bool _seedsActive;
|
||||||
|
|
||||||
[Signal] public delegate void PlantedEventHandler();
|
[Signal] public delegate void PlantedEventHandler();
|
||||||
|
|
||||||
|
private void UpdateInteractionArea()
|
||||||
|
{
|
||||||
|
// fieldstate == tilled / watered && samen im Inventar
|
||||||
|
bool canPlant = (FieldState == FieldState.Tilled || FieldState == FieldState.Watered) && _seedsActive;
|
||||||
|
// fieldstate == tilled && watering can ausgewählt
|
||||||
|
bool canWater = false;
|
||||||
|
FieldInteractionArea.IsActive = canPlant || canWater;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ActivatedSeedInInventory(bool activated)
|
||||||
|
{
|
||||||
|
_seedsActive = activated;
|
||||||
|
UpdateInteractionArea();
|
||||||
|
}
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
UpdateFieldState(FieldState);
|
UpdateFieldState(FieldState);
|
||||||
|
UpdateInteractionArea();
|
||||||
int randomIndex = new Random().Next(0, _maskTexture.Length);
|
int randomIndex = new Random().Next(0, _maskTexture.Length);
|
||||||
_maskSprite.Texture = _maskTexture[randomIndex];
|
_maskSprite.Texture = _maskTexture[randomIndex];
|
||||||
_outlineSprite.Texture = _maskOutlineTextures[randomIndex];
|
_outlineSprite.Texture = _maskOutlineTextures[randomIndex];
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
using Godot;
|
||||||
|
|
||||||
|
namespace Babushka.scripts.CSharp.Common.Inventory;
|
||||||
|
|
||||||
|
public partial class InventoryListener : Node
|
||||||
|
{
|
||||||
|
[Export] private ItemResource[] _itemResourcesToListenFor;
|
||||||
|
|
||||||
|
[Signal] public delegate void ItemInstanceActivatedEventHandler(bool activated);
|
||||||
|
|
||||||
|
public override void _Ready()
|
||||||
|
{
|
||||||
|
InventoryManager.Instance.playerInventory.InventoryContentsChanged += HandleNewItemInInventory;
|
||||||
|
InventoryManager.Instance.SlotIndexChanged += HandleNewItemInInventory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void _ExitTree()
|
||||||
|
{
|
||||||
|
InventoryManager.Instance.playerInventory.InventoryContentsChanged -= HandleNewItemInInventory;
|
||||||
|
InventoryManager.Instance.SlotIndexChanged -= HandleNewItemInInventory;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandleNewItemInInventory(int newIndex)
|
||||||
|
{
|
||||||
|
HandleNewItemInInventory();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandleNewItemInInventory()
|
||||||
|
{
|
||||||
|
int currentSlotIndex = InventoryManager.Instance.CurrentSelectedSlotIndex;
|
||||||
|
ItemInstance? instance = InventoryManager.Instance.playerInventory.Slots[currentSlotIndex].itemInstance;
|
||||||
|
if (instance != null)
|
||||||
|
{
|
||||||
|
ItemResource? item = instance.blueprint;
|
||||||
|
|
||||||
|
foreach (var res in _itemResourcesToListenFor)
|
||||||
|
{
|
||||||
|
if (item == res)
|
||||||
|
{
|
||||||
|
EmitSignal(SignalName.ItemInstanceActivated, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
EmitSignal(SignalName.ItemInstanceActivated, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://3t0af586fimq
|
||||||
Reference in New Issue
Block a user