parent
4f312209b3
commit
959ab68b4d
@ -0,0 +1,8 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://cgjc4wurbgimy"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://b7vlkecrn0t5c" path="res://scripts/CSharp/Common/Inventory/InventoryUI.cs" id="1_6wusm"]
|
||||
|
||||
[node name="Inventory" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 0
|
||||
script = ExtResource("1_6wusm")
|
||||
@ -0,0 +1,9 @@
|
||||
[gd_resource type="Resource" script_class="ItemResource" load_steps=2 format=3 uid="uid://c7viddcd3kywp"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cbskymrxs6ksu" path="res://scripts/CSharp/Common/Inventory/ItemResource.cs" id="1_t485b"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_t485b")
|
||||
name = "Axe Deo"
|
||||
color = Color(0.643898, 0.4587, 0.294335, 1)
|
||||
metadata/_custom_type_script = "uid://cbskymrxs6ksu"
|
||||
@ -0,0 +1,9 @@
|
||||
[gd_resource type="Resource" script_class="ItemResource" load_steps=2 format=3 uid="uid://cndd64batns31"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cbskymrxs6ksu" path="res://scripts/CSharp/Common/Inventory/ItemResource.cs" id="1_8k5aa"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_8k5aa")
|
||||
name = "Buck the Bucket"
|
||||
color = Color(0.336269, 0.489145, 0.825324, 1)
|
||||
metadata/_custom_type_script = "uid://cbskymrxs6ksu"
|
||||
@ -0,0 +1,9 @@
|
||||
[gd_resource type="Resource" script_class="ItemResource" load_steps=2 format=3 uid="uid://c5yg3lx756v4v"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cbskymrxs6ksu" path="res://scripts/CSharp/Common/Inventory/ItemResource.cs" id="1_06nef"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_06nef")
|
||||
name = "Your Mom"
|
||||
color = Color(0.751421, 0.329615, 0.570911, 1)
|
||||
metadata/_custom_type_script = "uid://cbskymrxs6ksu"
|
||||
@ -0,0 +1,9 @@
|
||||
[gd_resource type="Resource" script_class="ItemResource" load_steps=2 format=3 uid="uid://datee0flk1e84"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cbskymrxs6ksu" path="res://scripts/CSharp/Common/Inventory/ItemResource.cs" id="1_07aya"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_07aya")
|
||||
name = "Pick Axe"
|
||||
color = Color(0.226361, 0.573832, 0.480633, 1)
|
||||
metadata/_custom_type_script = "uid://cbskymrxs6ksu"
|
||||
@ -0,0 +1,47 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://mhtcm8daava5"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://cgjc4wurbgimy" path="res://prefabs/UI/Inventory/Inventory.tscn" id="1_5dyk0"]
|
||||
|
||||
[sub_resource type="BoxMesh" id="BoxMesh_5dyk0"]
|
||||
|
||||
[node name="BabushkaTestsInventory" type="Node3D"]
|
||||
|
||||
[node name="Inventory" parent="." instance=ExtResource("1_5dyk0")]
|
||||
|
||||
[node name="MockScene" type="Node3D" parent="."]
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="MockScene"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -2.52591, 0, 1.26963)
|
||||
mesh = SubResource("BoxMesh_5dyk0")
|
||||
skeleton = NodePath("../..")
|
||||
|
||||
[node name="MeshInstance3D2" type="MeshInstance3D" parent="MockScene"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.48916, 0, -0.762378)
|
||||
mesh = SubResource("BoxMesh_5dyk0")
|
||||
skeleton = NodePath("../..")
|
||||
|
||||
[node name="MeshInstance3D3" type="MeshInstance3D" parent="MockScene"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.58762, -2.38419e-07, -1.76688)
|
||||
mesh = SubResource("BoxMesh_5dyk0")
|
||||
skeleton = NodePath("../..")
|
||||
|
||||
[node name="MeshInstance3D4" type="MeshInstance3D" parent="MockScene"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.59247, -4.76837e-07, -0.0171926)
|
||||
mesh = SubResource("BoxMesh_5dyk0")
|
||||
skeleton = NodePath("../..")
|
||||
|
||||
[node name="MeshInstance3D5" type="MeshInstance3D" parent="MockScene"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.696733, -4.76837e-07, 1.49587)
|
||||
mesh = SubResource("BoxMesh_5dyk0")
|
||||
skeleton = NodePath("../..")
|
||||
|
||||
[node name="MeshInstance3D6" type="MeshInstance3D" parent="MockScene"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -4.7007, -4.76837e-07, -1.52457)
|
||||
mesh = SubResource("BoxMesh_5dyk0")
|
||||
skeleton = NodePath("../..")
|
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="MockScene"]
|
||||
transform = Transform3D(1, 0, 0, 0, 0.633826, 0.773475, 0, -0.773475, 0.633826, -0.833954, 3.04237, 2.8418)
|
||||
|
||||
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="MockScene"]
|
||||
transform = Transform3D(0.255314, 0.801032, -0.541445, -0.00609746, 0.561328, 0.827571, 0.966839, -0.207989, 0.148199, -1.99366, 2.88871, 2.87262)
|
||||
@ -0,0 +1,85 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using Godot;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Inventory;
|
||||
|
||||
public partial class InventoryInstance : Node
|
||||
{
|
||||
private List<InventorySlot> _slots = new();
|
||||
public IReadOnlyList<InventorySlot> Slots => _slots;
|
||||
|
||||
[Signal]
|
||||
public delegate void SlotAmountChangedEventHandler();
|
||||
[Signal]
|
||||
public delegate void InventoryContentsChangedEventHandler();
|
||||
|
||||
[Export]
|
||||
public int SlotAmount
|
||||
{
|
||||
get => _slots.Count;
|
||||
set
|
||||
{
|
||||
if (value < _slots.Count)
|
||||
{
|
||||
_slots.RemoveRange(value, _slots.Count - value);
|
||||
}
|
||||
else if (value > _slots.Count)
|
||||
{
|
||||
for (var i = _slots.Count; i < value; i++)
|
||||
{
|
||||
_slots.Add(new InventorySlot());
|
||||
}
|
||||
}
|
||||
EmitSignal(SignalName.SlotAmountChanged);
|
||||
}
|
||||
}
|
||||
|
||||
public InventoryActionResult AddItem(ItemInstance newItem, int inventorySlot = -1)
|
||||
{
|
||||
if (inventorySlot < 0)
|
||||
{
|
||||
inventorySlot = _slots.FindIndex(slot => slot.IsEmpty());
|
||||
}
|
||||
|
||||
if (inventorySlot < 0 || !_slots[inventorySlot].IsEmpty())
|
||||
{
|
||||
return InventoryActionResult.DestinationFull;
|
||||
}
|
||||
|
||||
if (inventorySlot >= _slots.Count)
|
||||
{
|
||||
return InventoryActionResult.DestinationDoesNotExists;
|
||||
}
|
||||
|
||||
_slots[inventorySlot].itemInstance = newItem;
|
||||
EmitSignal(SignalName.InventoryContentsChanged);
|
||||
return InventoryActionResult.Success;
|
||||
}
|
||||
|
||||
public InventoryActionResult RemoveItem(int inventorySlot, out ItemInstance? itemInstance )
|
||||
{
|
||||
if (inventorySlot < 0 || inventorySlot >= _slots.Count)
|
||||
{
|
||||
itemInstance = null;
|
||||
return InventoryActionResult.SourceDoesNotExists;
|
||||
}
|
||||
|
||||
if (_slots[inventorySlot].IsEmpty())
|
||||
{
|
||||
itemInstance = null;
|
||||
return InventoryActionResult.SourceIsEmpty;
|
||||
}
|
||||
|
||||
itemInstance = _slots[inventorySlot].itemInstance;
|
||||
_slots[inventorySlot].itemInstance = null;
|
||||
EmitSignal(SignalName.InventoryContentsChanged);
|
||||
return InventoryActionResult.Success;
|
||||
}
|
||||
|
||||
public InventoryActionResult RemoveItem(int inventorySlot)
|
||||
{
|
||||
return RemoveItem(inventorySlot, out _);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
uid://36ui8g5gu0lb
|
||||
@ -0,0 +1,63 @@
|
||||
#nullable enable
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Inventory;
|
||||
|
||||
public partial class InventoryManager : Node
|
||||
{
|
||||
public InventoryManager Instance { get; private set; }
|
||||
|
||||
public InventoryInstance playerInventory;
|
||||
|
||||
public override void _EnterTree()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
playerInventory = new InventoryInstance();
|
||||
playerInventory.SlotAmount = 30;
|
||||
}
|
||||
|
||||
public InventoryActionResult CreateItem(
|
||||
ItemResource itemBlueprint,
|
||||
InventoryInstance inventory,
|
||||
int inventorySlot = -1)
|
||||
{
|
||||
var newItem = new ItemInstance { blueprint = itemBlueprint };
|
||||
var addResult = inventory.AddItem(newItem, inventorySlot);
|
||||
return addResult;
|
||||
}
|
||||
|
||||
public InventoryActionResult MoveItem(
|
||||
InventoryInstance sourceInventory,
|
||||
int sourceSlot,
|
||||
InventoryInstance destinationInventory,
|
||||
int destinationSlot)
|
||||
{
|
||||
var remResult = sourceInventory.RemoveItem(sourceSlot, out var item);
|
||||
if (remResult != InventoryActionResult.Success) return remResult;
|
||||
|
||||
var addResult = destinationInventory.AddItem(item!, destinationSlot);
|
||||
if(addResult == InventoryActionResult.Success) return InventoryActionResult.Success;
|
||||
|
||||
sourceInventory.AddItem(item!, sourceSlot); // can not fail ... in theory
|
||||
return addResult;
|
||||
}
|
||||
|
||||
public InventoryActionResult RemoveItem(
|
||||
InventoryInstance inventory,
|
||||
int inventorySlot,
|
||||
out ItemInstance? itemInstance)
|
||||
{
|
||||
return inventory.RemoveItem(inventorySlot, out itemInstance);
|
||||
}
|
||||
|
||||
public InventoryActionResult RemoveItem(
|
||||
InventoryInstance inventory,
|
||||
int inventorySlot)
|
||||
{
|
||||
return inventory.RemoveItem(inventorySlot);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
uid://701bitgfepjc
|
||||
@ -0,0 +1,6 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class InventoryUI : Control
|
||||
{
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
uid://b7vlkecrn0t5c
|
||||
@ -0,0 +1 @@
|
||||
uid://cbskymrxs6ksu
|
||||
@ -0,0 +1 @@
|
||||
uid://csgctygxnj3bc
|
||||
Loading…
Reference in new issue