From a477f9ef4fab8f13a8cf6b0cce2375c8ffbb780e Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Sat, 24 May 2025 21:47:25 +0200 Subject: [PATCH] Implemented field creation and wateringcan fill up animation --- prefabs/Player2D.tscn | 3 +- scenes/Babushka_scene_farm_outside_2d.tscn | 101 ++---------------- .../CharacterControls/InteractionArea2D.cs | 2 +- .../Common/CharacterControls/Player2D.cs | 43 ++++---- .../CSharp/Common/Farming/VesnaBehaviour2D.cs | 3 + .../Common/Inventory/InventoryManager.cs | 7 +- .../CSharp/Common/Inventory/ItemOnGround.cs | 2 - 7 files changed, 40 insertions(+), 121 deletions(-) diff --git a/prefabs/Player2D.tscn b/prefabs/Player2D.tscn index e7ea1f1..cf953b0 100644 --- a/prefabs/Player2D.tscn +++ b/prefabs/Player2D.tscn @@ -3496,10 +3496,11 @@ animations = [{ "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 script = ExtResource("1_yl84k") _farmingControls = NodePath("FarmingControls") +_player2d = NodePath("CharacterBody2D") [node name="CharacterBody2D" type="CharacterBody2D" parent="." node_paths=PackedStringArray("_sprite") groups=["PlantGrowing"]] position = Vector2(0, 374) diff --git a/scenes/Babushka_scene_farm_outside_2d.tscn b/scenes/Babushka_scene_farm_outside_2d.tscn index d8020ea..3afb1bf 100644 --- a/scenes/Babushka_scene_farm_outside_2d.tscn +++ b/scenes/Babushka_scene_farm_outside_2d.tscn @@ -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="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="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="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="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"] shader = ExtResource("13_7p0hq") @@ -128,15 +125,7 @@ size = Vector2(14208, 1176) [sub_resource type="RectangleShape2D" id="RectangleShape2D_p6n74"] resource_local_to_scene = true -size = Vector2(7048, 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 +size = Vector2(5415, 1192) [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")] z_index = 1 -position = Vector2(1071, 2125) +position = Vector2(550, 2125) _fieldParent = NodePath("../Farm visuals/FieldParent") _hoe = ExtResource("28_6b2nr") _wateringCan = ExtResource("28_ipqaa") @@ -710,7 +699,7 @@ position = Vector2(80, -368) shape = SubResource("CircleShape2D_p6n74") [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"] _blueprint = ExtResource("26_ipqaa") @@ -737,7 +726,7 @@ _blueprint = ExtResource("28_6b2nr") shape = SubResource("CircleShape2D_ipqaa") [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"] _blueprint = ExtResource("29_wtdui") @@ -746,7 +735,7 @@ _blueprint = ExtResource("29_wtdui") shape = SubResource("CircleShape2D_ipqaa") [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"] _blueprint = ExtResource("27_ipqaa") @@ -785,81 +774,16 @@ metadata/_custom_type_script = "uid://dhxtdhfqx3bte" [node name="Area2D" type="Area2D" parent="YSorted/Farm visuals/FieldParent"] position = Vector2(-48, -16) collision_mask = 5 +collision_priority = 10.0 [node name="CollisionShape2D" type="CollisionShape2D" parent="YSorted/Farm visuals/FieldParent/Area2D"] -position = Vector2(1536, 2964) +position = Vector2(1536, 2949) shape = SubResource("RectangleShape2D_2nee2") [node name="CollisionShape2D2" type="CollisionShape2D" parent="YSorted/Farm visuals/FieldParent/Area2D"] -position = Vector2(13772, 2960) +position = Vector2(12955.5, 2960) 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")] follow_viewport_enabled = false @@ -876,13 +800,9 @@ size_flags_horizontal = 4 size_flags_vertical = 8 _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="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="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/BrĂ¼nnen/InteractionArea"] @@ -896,7 +816,4 @@ _inventoryOpenedOffset = -600.0 [editable path="YSorted/ScytheGenericPickup/InteractionArea2"] [editable path="YSorted/ShovelGenericPickup"] [editable path="YSorted/ShovelGenericPickup/InteractionArea2"] -[editable path="Hoe Pickup"] -[editable path="Watercan Pickup"] -[editable path="Watercan Pickup/ActiveInactive"] [editable path="CanvasLayer"] diff --git a/scripts/CSharp/Common/CharacterControls/InteractionArea2D.cs b/scripts/CSharp/Common/CharacterControls/InteractionArea2D.cs index 93920b0..057a24f 100644 --- a/scripts/CSharp/Common/CharacterControls/InteractionArea2D.cs +++ b/scripts/CSharp/Common/CharacterControls/InteractionArea2D.cs @@ -8,7 +8,7 @@ public partial class InteractionArea2D : Node2D [Export] private Label _label; [Export] private SpriteSwitcher2D _sprites; // TODO: remove [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 InteractedEventHandler(); diff --git a/scripts/CSharp/Common/CharacterControls/Player2D.cs b/scripts/CSharp/Common/CharacterControls/Player2D.cs index b190b2f..2027e07 100644 --- a/scripts/CSharp/Common/CharacterControls/Player2D.cs +++ b/scripts/CSharp/Common/CharacterControls/Player2D.cs @@ -15,9 +15,7 @@ public partial class Player2D : CharacterBody2D private int _toolID = -1; private string _toolString; private bool anyActionPressed; - private bool _wateringInProgress; - private bool _pickupAnimationInProgress; - private bool _farmingAnimationInProgress; + private bool _canHandleInput = true; private Vector2 _lastDirection = Vector2.Zero; private InventoryManager _inventoryManager; @@ -36,8 +34,8 @@ public partial class Player2D : CharacterBody2D public override void _Process(double delta) { anyActionPressed = false; - - if (_pickupAnimationInProgress || _wateringInProgress || _farmingAnimationInProgress) + + if (!_canHandleInput) return; if (Input.IsActionPressed("move_right")) @@ -135,47 +133,46 @@ public partial class Player2D : CharacterBody2D /// public void PlayWateringAnimation() { - if (_toolID == 1 && !_wateringInProgress) + if (_toolID == 1 && _canHandleInput) { _sprite.Animation = "diagonal wateringcan"; _sprite.Play(); - _wateringInProgress = true; - Task.Run(DelayedWateringCanReset); + _canHandleInput = false; + Task.Run(DelayedInputHandlerReset); } } - private async Task DelayedWateringCanReset() + private async Task DelayedInputHandlerReset() { await Task.Delay(1000); - _wateringInProgress = false; + _canHandleInput = true; } public void PlayPickUpAnimation() { _sprite.Animation = "side pickup"; _sprite.Play(); - _pickupAnimationInProgress = true; - Task.Run(DelayedPickUpReset); - } - - private async Task DelayedPickUpReset() - { - await Task.Delay(1000); - _pickupAnimationInProgress = false; + _canHandleInput = false; + Task.Run(DelayedInputHandlerReset); } public void PlayFarmingAnimation() { _sprite.Animation = "diagonal farming"; _sprite.Play(); - _farmingAnimationInProgress = true; - Task.Run(DelayedFarmingReset); + _canHandleInput = false; + Task.Run(DelayedInputHandlerReset); } - private async Task DelayedFarmingReset() + + public void PlayWateringCanFillupAnimation() { - await Task.Delay(1000); - _farmingAnimationInProgress = false; + _sprite.Animation = "back interact"; + _sprite.Play(); + _canHandleInput = false; + _lastDirection = Vector2.Up; + Task.Run(DelayedInputHandlerReset); } + } diff --git a/scripts/CSharp/Common/Farming/VesnaBehaviour2D.cs b/scripts/CSharp/Common/Farming/VesnaBehaviour2D.cs index ca3164b..c3068e3 100644 --- a/scripts/CSharp/Common/Farming/VesnaBehaviour2D.cs +++ b/scripts/CSharp/Common/Farming/VesnaBehaviour2D.cs @@ -1,3 +1,4 @@ +using Babushka.scripts.CSharp.Common.CharacterControls; using Babushka.scripts.CSharp.Common.Inventory; using Godot; @@ -8,6 +9,7 @@ public partial class VesnaBehaviour2D : Node [ExportGroup("Farming")] [Export] private FieldService2D _fieldParent; [Export] private FarmingControls2D _farmingControls; + [Export] private Player2D _player2d; [Export] private ItemResource _hoe; [Export] private ItemResource _wateringCan; @@ -61,6 +63,7 @@ public partial class VesnaBehaviour2D : Node if (toolId == 1) { _farmingControls.FillWateringCan(true); + _player2d.PlayWateringCanFillupAnimation(); } } diff --git a/scripts/CSharp/Common/Inventory/InventoryManager.cs b/scripts/CSharp/Common/Inventory/InventoryManager.cs index 24b3ac1..86778da 100644 --- a/scripts/CSharp/Common/Inventory/InventoryManager.cs +++ b/scripts/CSharp/Common/Inventory/InventoryManager.cs @@ -15,8 +15,11 @@ public partial class InventoryManager : Node get => _currentSelectedSlotIndex; set { - _currentSelectedSlotIndex = value; - EmitSignalSlotIndexChanged(_currentSelectedSlotIndex); + if (value >= 0 && value <= 8) + { + _currentSelectedSlotIndex = value; + EmitSignalSlotIndexChanged(_currentSelectedSlotIndex); + } } } diff --git a/scripts/CSharp/Common/Inventory/ItemOnGround.cs b/scripts/CSharp/Common/Inventory/ItemOnGround.cs index d9c7cbe..22769a7 100644 --- a/scripts/CSharp/Common/Inventory/ItemOnGround.cs +++ b/scripts/CSharp/Common/Inventory/ItemOnGround.cs @@ -23,8 +23,6 @@ public partial class ItemOnGround : Node3D public void TryPickUp() { - GD.Print("Trying to pick up item"); - var result = InventoryManager.Instance.CollectItem(itemInstance.Clone()); if (result == InventoryActionResult.Success) {