Implemented field creation and wateringcan fill up animation

remotes/checkIfPRContentChanged-1749880758504311652/feature/farming_visuals
kziolkowski 8 months ago
parent b917fb5fbd
commit a477f9ef4f

@ -3496,10 +3496,11 @@ animations = [{
"speed": 15.0 "speed": 15.0
}] }]
[node name="Player2d" type="Node2D" node_paths=PackedStringArray("_farmingControls")] [node name="Player2d" type="Node2D" node_paths=PackedStringArray("_farmingControls", "_player2d")]
y_sort_enabled = true y_sort_enabled = true
script = ExtResource("1_yl84k") script = ExtResource("1_yl84k")
_farmingControls = NodePath("FarmingControls") _farmingControls = NodePath("FarmingControls")
_player2d = NodePath("CharacterBody2D")
[node name="CharacterBody2D" type="CharacterBody2D" parent="." node_paths=PackedStringArray("_sprite") groups=["PlantGrowing"]] [node name="CharacterBody2D" type="CharacterBody2D" parent="." node_paths=PackedStringArray("_sprite") groups=["PlantGrowing"]]
position = Vector2(0, 374) position = Vector2(0, 374)

@ -1,4 +1,4 @@
[gd_scene load_steps=61 format=3 uid="uid://gigb28qk8t12"] [gd_scene load_steps=56 format=3 uid="uid://gigb28qk8t12"]
[ext_resource type="PackedScene" uid="uid://c25udixd5m6l0" path="res://prefabs/Player2D.tscn" id="1_7wfwe"] [ext_resource type="PackedScene" uid="uid://c25udixd5m6l0" path="res://prefabs/Player2D.tscn" id="1_7wfwe"]
[ext_resource type="Texture2D" uid="uid://8sr11ex30n0m" path="res://art/mockups/Kenney_Backgrounds/Samples/uncolored_hills.png" id="2_7b2ri"] [ext_resource type="Texture2D" uid="uid://8sr11ex30n0m" path="res://art/mockups/Kenney_Backgrounds/Samples/uncolored_hills.png" id="2_7b2ri"]
@ -31,11 +31,8 @@
[ext_resource type="PackedScene" uid="uid://cqc72e4hq6bcd" path="res://prefabs/interaction_area_2d.tscn" id="27_klb81"] [ext_resource type="PackedScene" uid="uid://cqc72e4hq6bcd" path="res://prefabs/interaction_area_2d.tscn" id="27_klb81"]
[ext_resource type="Resource" uid="uid://dlcmqfjvgphqu" path="res://resources/items/rake.tres" id="28_6b2nr"] [ext_resource type="Resource" uid="uid://dlcmqfjvgphqu" path="res://resources/items/rake.tres" id="28_6b2nr"]
[ext_resource type="Resource" uid="uid://cndd64batns31" path="res://resources/items/wateringcan.tres" id="28_ipqaa"] [ext_resource type="Resource" uid="uid://cndd64batns31" path="res://resources/items/wateringcan.tres" id="28_ipqaa"]
[ext_resource type="PackedScene" uid="uid://ce0mc0ddijmyi" path="res://prefabs/interactions/sprite_switcher_2d.tscn" id="28_p6n74"]
[ext_resource type="Texture2D" uid="uid://x8hr8287ff2n" path="res://art/farm/farming/farmobjekte/tools atlas.png" id="29_p6n74"]
[ext_resource type="Resource" uid="uid://datee0flk1e84" path="res://resources/items/scythe.tres" id="29_wtdui"] [ext_resource type="Resource" uid="uid://datee0flk1e84" path="res://resources/items/scythe.tres" id="29_wtdui"]
[ext_resource type="PackedScene" uid="uid://cgjc4wurbgimy" path="res://prefabs/UI/Inventory/Inventory.tscn" id="32_2nee2"] [ext_resource type="PackedScene" uid="uid://cgjc4wurbgimy" path="res://prefabs/UI/Inventory/Inventory.tscn" id="32_2nee2"]
[ext_resource type="PackedScene" uid="uid://b1d2e7ely6hyw" path="res://prefabs/farm/base_field_2d.tscn" id="33_wtdui"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_xy0kg"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_xy0kg"]
shader = ExtResource("13_7p0hq") shader = ExtResource("13_7p0hq")
@ -128,15 +125,7 @@ size = Vector2(14208, 1176)
[sub_resource type="RectangleShape2D" id="RectangleShape2D_p6n74"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_p6n74"]
resource_local_to_scene = true resource_local_to_scene = true
size = Vector2(7048, 1192) size = Vector2(5415, 1192)
[sub_resource type="CircleShape2D" id="CircleShape2D_kxdmn"]
resource_local_to_scene = true
radius = 300.0
[sub_resource type="CircleShape2D" id="CircleShape2D_hukxv"]
resource_local_to_scene = true
radius = 300.0
[node name="BabushkaSceneFarmOutside2d" type="Node2D"] [node name="BabushkaSceneFarmOutside2d" type="Node2D"]
@ -682,7 +671,7 @@ y_sort_enabled = true
[node name="Vesna" parent="YSorted" node_paths=PackedStringArray("_fieldParent") instance=ExtResource("1_7wfwe")] [node name="Vesna" parent="YSorted" node_paths=PackedStringArray("_fieldParent") instance=ExtResource("1_7wfwe")]
z_index = 1 z_index = 1
position = Vector2(1071, 2125) position = Vector2(550, 2125)
_fieldParent = NodePath("../Farm visuals/FieldParent") _fieldParent = NodePath("../Farm visuals/FieldParent")
_hoe = ExtResource("28_6b2nr") _hoe = ExtResource("28_6b2nr")
_wateringCan = ExtResource("28_ipqaa") _wateringCan = ExtResource("28_ipqaa")
@ -710,7 +699,7 @@ position = Vector2(80, -368)
shape = SubResource("CircleShape2D_p6n74") shape = SubResource("CircleShape2D_p6n74")
[node name="HoeGenericPickup" parent="YSorted" instance=ExtResource("25_hukxv")] [node name="HoeGenericPickup" parent="YSorted" instance=ExtResource("25_hukxv")]
position = Vector2(4482, 1978) position = Vector2(8234, 2076)
[node name="SpawnWithItem" parent="YSorted/HoeGenericPickup" index="0"] [node name="SpawnWithItem" parent="YSorted/HoeGenericPickup" index="0"]
_blueprint = ExtResource("26_ipqaa") _blueprint = ExtResource("26_ipqaa")
@ -737,7 +726,7 @@ _blueprint = ExtResource("28_6b2nr")
shape = SubResource("CircleShape2D_ipqaa") shape = SubResource("CircleShape2D_ipqaa")
[node name="ScytheGenericPickup" parent="YSorted" instance=ExtResource("25_hukxv")] [node name="ScytheGenericPickup" parent="YSorted" instance=ExtResource("25_hukxv")]
position = Vector2(11890, 2060) position = Vector2(15642, 2158)
[node name="SpawnWithItem" parent="YSorted/ScytheGenericPickup" index="0"] [node name="SpawnWithItem" parent="YSorted/ScytheGenericPickup" index="0"]
_blueprint = ExtResource("29_wtdui") _blueprint = ExtResource("29_wtdui")
@ -746,7 +735,7 @@ _blueprint = ExtResource("29_wtdui")
shape = SubResource("CircleShape2D_ipqaa") shape = SubResource("CircleShape2D_ipqaa")
[node name="ShovelGenericPickup" parent="YSorted" instance=ExtResource("25_hukxv")] [node name="ShovelGenericPickup" parent="YSorted" instance=ExtResource("25_hukxv")]
position = Vector2(5229, 2038) position = Vector2(7593, 2038)
[node name="SpawnWithItem" parent="YSorted/ShovelGenericPickup" index="0"] [node name="SpawnWithItem" parent="YSorted/ShovelGenericPickup" index="0"]
_blueprint = ExtResource("27_ipqaa") _blueprint = ExtResource("27_ipqaa")
@ -785,81 +774,16 @@ metadata/_custom_type_script = "uid://dhxtdhfqx3bte"
[node name="Area2D" type="Area2D" parent="YSorted/Farm visuals/FieldParent"] [node name="Area2D" type="Area2D" parent="YSorted/Farm visuals/FieldParent"]
position = Vector2(-48, -16) position = Vector2(-48, -16)
collision_mask = 5 collision_mask = 5
collision_priority = 10.0
[node name="CollisionShape2D" type="CollisionShape2D" parent="YSorted/Farm visuals/FieldParent/Area2D"] [node name="CollisionShape2D" type="CollisionShape2D" parent="YSorted/Farm visuals/FieldParent/Area2D"]
position = Vector2(1536, 2964) position = Vector2(1536, 2949)
shape = SubResource("RectangleShape2D_2nee2") shape = SubResource("RectangleShape2D_2nee2")
[node name="CollisionShape2D2" type="CollisionShape2D" parent="YSorted/Farm visuals/FieldParent/Area2D"] [node name="CollisionShape2D2" type="CollisionShape2D" parent="YSorted/Farm visuals/FieldParent/Area2D"]
position = Vector2(13772, 2960) position = Vector2(12955.5, 2960)
shape = SubResource("RectangleShape2D_p6n74") shape = SubResource("RectangleShape2D_p6n74")
[node name="TestFields" type="Node" parent="YSorted"]
[node name="BaseField" parent="YSorted/TestFields" instance=ExtResource("33_wtdui")]
position = Vector2(8221, 2809)
[node name="BaseField2" parent="YSorted/TestFields" instance=ExtResource("33_wtdui")]
position = Vector2(8225, 3458)
[node name="BaseField3" parent="YSorted/TestFields" instance=ExtResource("33_wtdui")]
position = Vector2(7492, 2812)
[node name="BaseField4" parent="YSorted/TestFields" instance=ExtResource("33_wtdui")]
position = Vector2(7496, 3458)
[node name="BaseField5" parent="YSorted/TestFields" instance=ExtResource("33_wtdui")]
position = Vector2(11266, 2772)
[node name="BaseField6" parent="YSorted/TestFields" instance=ExtResource("33_wtdui")]
position = Vector2(11270, 3421)
[node name="BaseField7" parent="YSorted/TestFields" instance=ExtResource("33_wtdui")]
position = Vector2(10537, 2775)
[node name="BaseField8" parent="YSorted/TestFields" instance=ExtResource("33_wtdui")]
position = Vector2(10541, 3421)
[node name="Hoe Pickup" parent="." node_paths=PackedStringArray("_sprites") instance=ExtResource("27_klb81")]
visible = false
position = Vector2(7728, 2000)
rotation = 3.3074
_sprites = NodePath("SpriteSwitcher2d")
[node name="Area2D" parent="Hoe Pickup" index="0"]
collision_mask = 5
[node name="CollisionShape3D" parent="Hoe Pickup/Area2D" index="0"]
shape = SubResource("CircleShape2D_kxdmn")
[node name="SpriteSwitcher2d" parent="Hoe Pickup" instance=ExtResource("28_p6n74")]
scale = Vector2(0.5, 0.5)
[node name="Watercan Pickup" parent="." node_paths=PackedStringArray("_sprites") instance=ExtResource("27_klb81")]
visible = false
position = Vector2(8400, 2024)
_sprites = NodePath("ActiveInactive")
_id = 1
[node name="Area2D" parent="Watercan Pickup" index="0"]
collision_mask = 5
[node name="CollisionShape3D" parent="Watercan Pickup/Area2D" index="0"]
shape = SubResource("CircleShape2D_hukxv")
[node name="Label" parent="Watercan Pickup" index="1"]
z_index = 1
[node name="ActiveInactive" parent="Watercan Pickup" instance=ExtResource("28_p6n74")]
[node name="ActiveSprite" parent="Watercan Pickup/ActiveInactive" index="0"]
texture = ExtResource("29_p6n74")
region_rect = Rect2(-2, 1135, 421, 292)
[node name="InactiveSprite" parent="Watercan Pickup/ActiveInactive" index="1"]
texture = ExtResource("29_p6n74")
region_rect = Rect2(1, 1138, 418, 288)
[node name="CanvasLayer" parent="." instance=ExtResource("32_2nee2")] [node name="CanvasLayer" parent="." instance=ExtResource("32_2nee2")]
follow_viewport_enabled = false follow_viewport_enabled = false
@ -876,13 +800,9 @@ size_flags_horizontal = 4
size_flags_vertical = 8 size_flags_vertical = 8
_inventoryOpenedOffset = -600.0 _inventoryOpenedOffset = -600.0
[connection signal="PickedUpTool" from="YSorted/Vesna" to="Hoe Pickup" method="SetSpriteActiveState"]
[connection signal="PickedUpTool" from="YSorted/Vesna" to="Watercan Pickup" method="SetSpriteActiveState"]
[connection signal="InteractedTool" from="YSorted/Brünnen/InteractionArea" to="YSorted/Vesna" method="TryFillWateringCan"] [connection signal="InteractedTool" from="YSorted/Brünnen/InteractionArea" to="YSorted/Vesna" method="TryFillWateringCan"]
[connection signal="mouse_entered" from="YSorted/Farm visuals/FieldParent/Area2D" to="YSorted/Farm visuals/FieldParent" method="MouseEnteredAllowedArea"] [connection signal="mouse_entered" from="YSorted/Farm visuals/FieldParent/Area2D" to="YSorted/Farm visuals/FieldParent" method="MouseEnteredAllowedArea"]
[connection signal="mouse_exited" from="YSorted/Farm visuals/FieldParent/Area2D" to="YSorted/Farm visuals/FieldParent" method="MouseExitedAllowedArea"] [connection signal="mouse_exited" from="YSorted/Farm visuals/FieldParent/Area2D" to="YSorted/Farm visuals/FieldParent" method="MouseExitedAllowedArea"]
[connection signal="InteractedTool" from="Hoe Pickup" to="YSorted/Vesna" method="ActivateTool"]
[connection signal="InteractedTool" from="Watercan Pickup" to="YSorted/Vesna" method="ActivateTool"]
[editable path="YSorted/Vesna"] [editable path="YSorted/Vesna"]
[editable path="YSorted/Brünnen/InteractionArea"] [editable path="YSorted/Brünnen/InteractionArea"]
@ -896,7 +816,4 @@ _inventoryOpenedOffset = -600.0
[editable path="YSorted/ScytheGenericPickup/InteractionArea2"] [editable path="YSorted/ScytheGenericPickup/InteractionArea2"]
[editable path="YSorted/ShovelGenericPickup"] [editable path="YSorted/ShovelGenericPickup"]
[editable path="YSorted/ShovelGenericPickup/InteractionArea2"] [editable path="YSorted/ShovelGenericPickup/InteractionArea2"]
[editable path="Hoe Pickup"]
[editable path="Watercan Pickup"]
[editable path="Watercan Pickup/ActiveInactive"]
[editable path="CanvasLayer"] [editable path="CanvasLayer"]

@ -8,7 +8,7 @@ public partial class InteractionArea2D : Node2D
[Export] private Label _label; [Export] private Label _label;
[Export] private SpriteSwitcher2D _sprites; // TODO: remove [Export] private SpriteSwitcher2D _sprites; // TODO: remove
[Export] private bool _showLabel = true; [Export] private bool _showLabel = true;
[Export] private int _id; // TODO: remove [Export] private int _id = -1; // TODO: remove
[Signal] public delegate void InteractedToolEventHandler(int id); // TODO: remove [Signal] public delegate void InteractedToolEventHandler(int id); // TODO: remove
[Signal] public delegate void InteractedEventHandler(); [Signal] public delegate void InteractedEventHandler();

@ -15,9 +15,7 @@ public partial class Player2D : CharacterBody2D
private int _toolID = -1; private int _toolID = -1;
private string _toolString; private string _toolString;
private bool anyActionPressed; private bool anyActionPressed;
private bool _wateringInProgress; private bool _canHandleInput = true;
private bool _pickupAnimationInProgress;
private bool _farmingAnimationInProgress;
private Vector2 _lastDirection = Vector2.Zero; private Vector2 _lastDirection = Vector2.Zero;
private InventoryManager _inventoryManager; private InventoryManager _inventoryManager;
@ -37,7 +35,7 @@ public partial class Player2D : CharacterBody2D
{ {
anyActionPressed = false; anyActionPressed = false;
if (_pickupAnimationInProgress || _wateringInProgress || _farmingAnimationInProgress) if (!_canHandleInput)
return; return;
if (Input.IsActionPressed("move_right")) if (Input.IsActionPressed("move_right"))
@ -135,47 +133,46 @@ public partial class Player2D : CharacterBody2D
/// </summary> /// </summary>
public void PlayWateringAnimation() public void PlayWateringAnimation()
{ {
if (_toolID == 1 && !_wateringInProgress) if (_toolID == 1 && _canHandleInput)
{ {
_sprite.Animation = "diagonal wateringcan"; _sprite.Animation = "diagonal wateringcan";
_sprite.Play(); _sprite.Play();
_wateringInProgress = true; _canHandleInput = false;
Task.Run(DelayedWateringCanReset); Task.Run(DelayedInputHandlerReset);
} }
} }
private async Task DelayedWateringCanReset() private async Task DelayedInputHandlerReset()
{ {
await Task.Delay(1000); await Task.Delay(1000);
_wateringInProgress = false; _canHandleInput = true;
} }
public void PlayPickUpAnimation() public void PlayPickUpAnimation()
{ {
_sprite.Animation = "side pickup"; _sprite.Animation = "side pickup";
_sprite.Play(); _sprite.Play();
_pickupAnimationInProgress = true; _canHandleInput = false;
Task.Run(DelayedPickUpReset); Task.Run(DelayedInputHandlerReset);
}
private async Task DelayedPickUpReset()
{
await Task.Delay(1000);
_pickupAnimationInProgress = false;
} }
public void PlayFarmingAnimation() public void PlayFarmingAnimation()
{ {
_sprite.Animation = "diagonal farming"; _sprite.Animation = "diagonal farming";
_sprite.Play(); _sprite.Play();
_farmingAnimationInProgress = true; _canHandleInput = false;
Task.Run(DelayedFarmingReset); Task.Run(DelayedInputHandlerReset);
} }
private async Task DelayedFarmingReset()
public void PlayWateringCanFillupAnimation()
{ {
await Task.Delay(1000); _sprite.Animation = "back interact";
_farmingAnimationInProgress = false; _sprite.Play();
_canHandleInput = false;
_lastDirection = Vector2.Up;
Task.Run(DelayedInputHandlerReset);
} }
} }

@ -1,3 +1,4 @@
using Babushka.scripts.CSharp.Common.CharacterControls;
using Babushka.scripts.CSharp.Common.Inventory; using Babushka.scripts.CSharp.Common.Inventory;
using Godot; using Godot;
@ -8,6 +9,7 @@ public partial class VesnaBehaviour2D : Node
[ExportGroup("Farming")] [ExportGroup("Farming")]
[Export] private FieldService2D _fieldParent; [Export] private FieldService2D _fieldParent;
[Export] private FarmingControls2D _farmingControls; [Export] private FarmingControls2D _farmingControls;
[Export] private Player2D _player2d;
[Export] private ItemResource _hoe; [Export] private ItemResource _hoe;
[Export] private ItemResource _wateringCan; [Export] private ItemResource _wateringCan;
@ -61,6 +63,7 @@ public partial class VesnaBehaviour2D : Node
if (toolId == 1) if (toolId == 1)
{ {
_farmingControls.FillWateringCan(true); _farmingControls.FillWateringCan(true);
_player2d.PlayWateringCanFillupAnimation();
} }
} }

@ -14,11 +14,14 @@ public partial class InventoryManager : Node
{ {
get => _currentSelectedSlotIndex; get => _currentSelectedSlotIndex;
set set
{
if (value >= 0 && value <= 8)
{ {
_currentSelectedSlotIndex = value; _currentSelectedSlotIndex = value;
EmitSignalSlotIndexChanged(_currentSelectedSlotIndex); EmitSignalSlotIndexChanged(_currentSelectedSlotIndex);
} }
} }
}
public InventoryInstance playerInventory = new InventoryInstance(); public InventoryInstance playerInventory = new InventoryInstance();

@ -23,8 +23,6 @@ public partial class ItemOnGround : Node3D
public void TryPickUp() public void TryPickUp()
{ {
GD.Print("Trying to pick up item");
var result = InventoryManager.Instance.CollectItem(itemInstance.Clone()); var result = InventoryManager.Instance.CollectItem(itemInstance.Clone());
if (result == InventoryActionResult.Success) if (result == InventoryActionResult.Success)
{ {

Loading…
Cancel
Save