item on ground and pickup
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://cgjc4wurbgimy"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://hg7jay2kt441" path="res://scripts/CSharp/Common/Inventory/InventoryUi.cs" id="1_6wusm"]
|
||||
[ext_resource type="Script" uid="uid://b7vlkecrn0t5c" path="res://scripts/CSharp/Common/Inventory/InventoryUi.cs" id="1_6wusm"]
|
||||
[ext_resource type="Script" uid="uid://b2jhdxcrhtm2d" path="res://scripts/CSharp/Common/Inventory/InventoryTestScript.cs" id="3_exrk4"]
|
||||
[ext_resource type="Resource" uid="uid://datee0flk1e84" path="res://resources/items/pickaxe.tres" id="4_5fdxq"]
|
||||
[ext_resource type="Texture2D" uid="uid://c7wqla0mbu3np" path="res://graphics/ui/babushka_ui_tmp_inventory_select.png" id="4_tiss4"]
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://5hltxpdxmqcq"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://udhigottc8rg" path="res://scripts/CSharp/Common/Inventory/ItemOnGround.cs" id="1_mnomu"]
|
||||
[ext_resource type="PackedScene" uid="uid://ob04y3syvo0e" path="res://prefabs/interaction_area.tscn" id="2_ue6ub"]
|
||||
[ext_resource type="Script" uid="uid://c8suoi3i6kqai" path="res://scripts/CSharp/Common/Inventory/ItemOnGroundSpawnWith.cs" id="3_ue6ub"]
|
||||
[ext_resource type="Resource" uid="uid://c7viddcd3kywp" path="res://resources/items/axe.tres" id="4_sfad0"]
|
||||
|
||||
[node name="GenericItemOnGround" type="Node3D"]
|
||||
script = ExtResource("1_mnomu")
|
||||
|
||||
[node name="InteractionArea" parent="." instance=ExtResource("2_ue6ub")]
|
||||
|
||||
[node name="SpawnWithItem" type="Node" parent="."]
|
||||
script = ExtResource("3_ue6ub")
|
||||
_blueprint = ExtResource("4_sfad0")
|
||||
|
||||
[node name="ItemLabel" type="Label3D" parent="."]
|
||||
offset = Vector2(0, 55.64)
|
||||
billboard = 1
|
||||
text = "test"
|
||||
|
||||
[connection signal="Interacted" from="InteractionArea" to="." method="TryPickUp"]
|
||||
+1
-1
@@ -11,7 +11,7 @@ config_version=5
|
||||
[application]
|
||||
|
||||
config/name="Babushka"
|
||||
run/main_scene="uid://br7yq757cawts"
|
||||
run/main_scene="uid://dbxy2y85r1d8x"
|
||||
config/features=PackedStringArray("4.4", "C#", "Forward Plus")
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
[gd_scene load_steps=10 format=3 uid="uid://dbxy2y85r1d8x"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://dbd1niu3tp8y5" path="res://prefabs/Player3D.tscn" id="1_pdc5e"]
|
||||
[ext_resource type="PackedScene" uid="uid://biwd3jj65qrlh" path="res://prefabs/farming/base_field.tscn" id="2_741gk"]
|
||||
[ext_resource type="PackedScene" uid="uid://5hltxpdxmqcq" path="res://prefabs/interactions/generic_item_on_ground.tscn" id="5_sjt6k"]
|
||||
[ext_resource type="PackedScene" uid="uid://cgjc4wurbgimy" path="res://prefabs/UI/Inventory/Inventory.tscn" id="6_876p1"]
|
||||
[ext_resource type="Resource" uid="uid://cndd64batns31" path="res://resources/items/bucket.tres" id="6_nvnpb"]
|
||||
[ext_resource type="Script" uid="uid://d178x7agr603o" path="res://scripts/CSharp/Common/Farming/FieldService.cs" id="7_3rkjv"]
|
||||
|
||||
[sub_resource type="PlaneMesh" id="PlaneMesh_8yprl"]
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_8tgff"]
|
||||
albedo_color = Color(0.505882, 0.588235, 0.494118, 1)
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_t58di"]
|
||||
size = Vector3(2.01563, 0.160522, 2.00824)
|
||||
|
||||
[node name="SceneFarmVesna" type="Node3D"]
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||
transform = Transform3D(10, 0, 0, 0, 10, 0, 0, 0, 10, 0, 0, 0)
|
||||
mesh = SubResource("PlaneMesh_8yprl")
|
||||
skeleton = NodePath("")
|
||||
surface_material_override/0 = SubResource("StandardMaterial3D_8tgff")
|
||||
|
||||
[node name="StaticBody3D" type="StaticBody3D" parent="MeshInstance3D"]
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="MeshInstance3D/StaticBody3D"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.000976563, -0.0739136, -0.00112915)
|
||||
shape = SubResource("BoxShape3D_t58di")
|
||||
|
||||
[node name="Player3d" parent="." node_paths=PackedStringArray("_fieldParent") instance=ExtResource("1_pdc5e")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -5.51633, 0.725631, 3.57249)
|
||||
_fieldParent = NodePath("../FieldService")
|
||||
|
||||
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 0.618408, 0.785857, 0, -0.785857, 0.618408, -0.802612, 0, 4.73262)
|
||||
|
||||
[node name="BaseField" parent="." instance=ExtResource("2_741gk")]
|
||||
transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, 0.0574723, 0)
|
||||
visible = false
|
||||
|
||||
[node name="Inventory" parent="." instance=ExtResource("6_876p1")]
|
||||
|
||||
[node name="FieldService" type="Node3D" parent="."]
|
||||
script = ExtResource("7_3rkjv")
|
||||
|
||||
[node name="GenericItemOnGround" parent="." instance=ExtResource("5_sjt6k")]
|
||||
|
||||
[node name="SpawnWithItem" parent="GenericItemOnGround" index="1"]
|
||||
_blueprint = ExtResource("6_nvnpb")
|
||||
|
||||
[editable path="GenericItemOnGround"]
|
||||
@@ -60,4 +60,8 @@ public partial class InventoryManager : Node
|
||||
{
|
||||
return inventory.RemoveItem(inventorySlot);
|
||||
}
|
||||
public InventoryActionResult CollectItem(ItemInstance itemInstance)
|
||||
{
|
||||
return playerInventory.AddItem(itemInstance);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ public partial class InventoryUi : Control
|
||||
PopulateSlots();
|
||||
SetSlotContent();
|
||||
SetSlotSelectPosition();
|
||||
InventoryManager.Instance.playerInventory.InventoryContentsChanged += SetSlotContent;
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
@@ -88,7 +89,7 @@ public partial class InventoryUi : Control
|
||||
var destinationSlot = index;
|
||||
InventoryManager.Instance.MoveItem(_playerInventory, sourceSlot, _playerInventory, destinationSlot);
|
||||
_slotOnMouse = null;
|
||||
SetSlotContent();
|
||||
//SetSlotContent();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
using Godot;
|
||||
namespace Babushka.scripts.CSharp.Common.Inventory;
|
||||
|
||||
public partial class ItemOnGround : Node3D
|
||||
{
|
||||
private ItemInstance _itemInstance;
|
||||
|
||||
public ItemInstance itemInstance
|
||||
{
|
||||
get => _itemInstance;
|
||||
set
|
||||
{
|
||||
_itemInstance = value;
|
||||
UpdateVisuals();
|
||||
}
|
||||
}
|
||||
|
||||
public void TryPickUp()
|
||||
{
|
||||
GD.Print("Trying to pick up item");
|
||||
|
||||
var result = InventoryManager.Instance.CollectItem(itemInstance);
|
||||
if (result == InventoryActionResult.Success)
|
||||
{
|
||||
QueueFree();
|
||||
}
|
||||
else
|
||||
{
|
||||
GD.Print("Inventory is full");
|
||||
// TODO: player message
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateVisuals()
|
||||
{
|
||||
var label = GetNode<Label3D>("ItemLabel");
|
||||
if (itemInstance.blueprint != null)
|
||||
{
|
||||
label.Text = itemInstance.blueprint.name;
|
||||
}
|
||||
else
|
||||
{
|
||||
label.Text = "Error Item";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://udhigottc8rg
|
||||
@@ -0,0 +1,16 @@
|
||||
#nullable enable
|
||||
using Godot;
|
||||
namespace Babushka.scripts.CSharp.Common.Inventory;
|
||||
|
||||
public partial class ItemOnGroundSpawnWith : Node
|
||||
{
|
||||
[Export] private ItemResource? _blueprint = null;
|
||||
|
||||
public override void _EnterTree()
|
||||
{
|
||||
if(_blueprint == null) return;
|
||||
|
||||
var parent = GetParent<ItemOnGround>();
|
||||
parent.itemInstance = new ItemInstance { blueprint = _blueprint };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://c8suoi3i6kqai
|
||||
Reference in New Issue
Block a user