Reworked farming tools pickup animations
This commit is contained in:
@@ -684,6 +684,10 @@ z_index = 1
|
|||||||
position = Vector2(1071, 2125)
|
position = Vector2(1071, 2125)
|
||||||
_fieldParent = NodePath("../Farm visuals/FieldParent")
|
_fieldParent = NodePath("../Farm visuals/FieldParent")
|
||||||
|
|
||||||
|
[node name="CharacterBody2D" parent="YSorted/Player2d" index="0"]
|
||||||
|
_hoe = ExtResource("28_6b2nr")
|
||||||
|
_wateringCan = ExtResource("28_ipqaa")
|
||||||
|
|
||||||
[node name="Brünnen" type="Sprite2D" parent="YSorted"]
|
[node name="Brünnen" type="Sprite2D" parent="YSorted"]
|
||||||
z_index = 1
|
z_index = 1
|
||||||
y_sort_enabled = true
|
y_sort_enabled = true
|
||||||
@@ -792,6 +796,7 @@ position = Vector2(13772, 2960)
|
|||||||
shape = SubResource("RectangleShape2D_p6n74")
|
shape = SubResource("RectangleShape2D_p6n74")
|
||||||
|
|
||||||
[node name="Hoe Pickup" parent="." node_paths=PackedStringArray("_sprites") instance=ExtResource("27_klb81")]
|
[node name="Hoe Pickup" parent="." node_paths=PackedStringArray("_sprites") instance=ExtResource("27_klb81")]
|
||||||
|
visible = false
|
||||||
position = Vector2(7728, 2000)
|
position = Vector2(7728, 2000)
|
||||||
rotation = 3.3074
|
rotation = 3.3074
|
||||||
_sprites = NodePath("SpriteSwitcher2d")
|
_sprites = NodePath("SpriteSwitcher2d")
|
||||||
@@ -806,6 +811,7 @@ shape = SubResource("CircleShape2D_kxdmn")
|
|||||||
scale = Vector2(0.5, 0.5)
|
scale = Vector2(0.5, 0.5)
|
||||||
|
|
||||||
[node name="Watercan Pickup" parent="." node_paths=PackedStringArray("_sprites") instance=ExtResource("27_klb81")]
|
[node name="Watercan Pickup" parent="." node_paths=PackedStringArray("_sprites") instance=ExtResource("27_klb81")]
|
||||||
|
visible = false
|
||||||
position = Vector2(8400, 2024)
|
position = Vector2(8400, 2024)
|
||||||
_sprites = NodePath("ActiveInactive")
|
_sprites = NodePath("ActiveInactive")
|
||||||
_id = 1
|
_id = 1
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Babushka.scripts.CSharp.Common.Inventory;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
namespace Babushka.scripts.CSharp.Common.CharacterControls;
|
namespace Babushka.scripts.CSharp.Common.CharacterControls;
|
||||||
@@ -9,6 +10,8 @@ public partial class Player2D : CharacterBody2D
|
|||||||
[Export] private float _speed = 100f;
|
[Export] private float _speed = 100f;
|
||||||
[Export] private AnimatedSprite2D _sprite;
|
[Export] private AnimatedSprite2D _sprite;
|
||||||
[Export] private SceneTree.GroupCallFlags _fieldFlags;
|
[Export] private SceneTree.GroupCallFlags _fieldFlags;
|
||||||
|
[Export] private ItemResource _hoe;
|
||||||
|
[Export] private ItemResource _wateringCan;
|
||||||
|
|
||||||
// -1 means no tool.
|
// -1 means no tool.
|
||||||
private int _toolID = -1;
|
private int _toolID = -1;
|
||||||
@@ -18,7 +21,48 @@ public partial class Player2D : CharacterBody2D
|
|||||||
private bool _pickupAnimationInProgress;
|
private bool _pickupAnimationInProgress;
|
||||||
private bool _farmingAnimationInProgress;
|
private bool _farmingAnimationInProgress;
|
||||||
private Vector2 _lastDirection = Vector2.Zero;
|
private Vector2 _lastDirection = Vector2.Zero;
|
||||||
|
private InventoryManager _inventoryManager;
|
||||||
|
private InventoryInstance _inventoryInstance;
|
||||||
|
|
||||||
|
public override void _Ready()
|
||||||
|
{
|
||||||
|
_inventoryManager = InventoryManager.Instance;
|
||||||
|
_inventoryInstance = _inventoryManager.playerInventory;
|
||||||
|
_inventoryManager.SlotIndexChanged += HandleInventorySelectedSlotIndexChanged;
|
||||||
|
_inventoryInstance.InventoryContentsChanged += HandleNewItemInInventory;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandleNewItemInInventory()
|
||||||
|
{
|
||||||
|
// for future Kathi: this does not, in fact, check if an item has been added only, but triggers on every content change!
|
||||||
|
PlayPickUpAnimation();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandleInventorySelectedSlotIndexChanged(int newIndex)
|
||||||
|
{
|
||||||
|
InventorySlot currentSlot = InventoryManager.Instance.GetCurrentSelectedSlot();
|
||||||
|
ItemInstance? currentItem = currentSlot.itemInstance;
|
||||||
|
|
||||||
|
if (currentItem == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (currentItem.blueprint == _hoe)
|
||||||
|
{
|
||||||
|
ActivateTool(true, 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentItem.blueprint == _wateringCan)
|
||||||
|
{
|
||||||
|
ActivateTool(true, 1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ActivateTool(false, 0);
|
||||||
|
ActivateTool(false, 1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public override void _Process(double delta)
|
public override void _Process(double delta)
|
||||||
{
|
{
|
||||||
anyActionPressed = false;
|
anyActionPressed = false;
|
||||||
@@ -99,7 +143,6 @@ public partial class Player2D : CharacterBody2D
|
|||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
_toolID = id;
|
_toolID = id;
|
||||||
PlayPickUpAnimation();
|
|
||||||
}
|
}
|
||||||
else _toolID = -1;
|
else _toolID = -1;
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ public partial class InventoryManager : Node
|
|||||||
[Signal]
|
[Signal]
|
||||||
public delegate void SlotIndexChangedEventHandler(int newIndex);
|
public delegate void SlotIndexChangedEventHandler(int newIndex);
|
||||||
|
|
||||||
|
|
||||||
public static InventoryManager Instance { get; private set; } = null!;
|
public static InventoryManager Instance { get; private set; } = null!;
|
||||||
public int CurrentSelectedSlotIndex
|
public int CurrentSelectedSlotIndex
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user