Compare commits
4 Commits
e99b574d1f
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 7d1187d218 | |||
| 54b07cccad | |||
| fb0c14c3f1 | |||
| fb362e10ad |
@@ -4,11 +4,12 @@ importer="scene"
|
|||||||
importer_version=1
|
importer_version=1
|
||||||
type="PackedScene"
|
type="PackedScene"
|
||||||
uid="uid://b3kyrsoobmkhp"
|
uid="uid://b3kyrsoobmkhp"
|
||||||
valid=false
|
path="res://.godot/imported/best_house_blender.blend-ac89c74aef2f275bdf4b4baadee17c0c.scn"
|
||||||
|
|
||||||
[deps]
|
[deps]
|
||||||
|
|
||||||
source_file="res://art/mockups/3d/best_house_blender.blend"
|
source_file="res://art/mockups/3d/best_house_blender.blend"
|
||||||
|
dest_files=["res://.godot/imported/best_house_blender.blend-ac89c74aef2f275bdf4b4baadee17c0c.scn"]
|
||||||
|
|
||||||
[params]
|
[params]
|
||||||
|
|
||||||
|
|||||||
@@ -41,4 +41,22 @@ label_settings = SubResource("LabelSettings_7emux")
|
|||||||
horizontal_alignment = 1
|
horizontal_alignment = 1
|
||||||
vertical_alignment = 1
|
vertical_alignment = 1
|
||||||
|
|
||||||
|
[node name="AmountLabel" type="Label" parent="."]
|
||||||
|
layout_mode = 1
|
||||||
|
anchors_preset = -1
|
||||||
|
anchor_left = 1.0
|
||||||
|
anchor_top = 1.0
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
offset_left = -409.0
|
||||||
|
offset_top = -329.0
|
||||||
|
offset_right = -10.0
|
||||||
|
offset_bottom = -10.0
|
||||||
|
grow_horizontal = 0
|
||||||
|
grow_vertical = 0
|
||||||
|
theme_override_colors/font_color = Color(0, 0, 0, 1)
|
||||||
|
text = "999"
|
||||||
|
horizontal_alignment = 2
|
||||||
|
vertical_alignment = 2
|
||||||
|
|
||||||
[connection signal="gui_input" from="." to="." method="_on_gui_input"]
|
[connection signal="gui_input" from="." to="." method="_on_gui_input"]
|
||||||
|
|||||||
@@ -6,4 +6,5 @@
|
|||||||
script = ExtResource("1_t485b")
|
script = ExtResource("1_t485b")
|
||||||
name = "Axe Deo"
|
name = "Axe Deo"
|
||||||
color = Color(0.643898, 0.4587, 0.294335, 1)
|
color = Color(0.643898, 0.4587, 0.294335, 1)
|
||||||
|
maxStack = 1
|
||||||
metadata/_custom_type_script = "uid://cbskymrxs6ksu"
|
metadata/_custom_type_script = "uid://cbskymrxs6ksu"
|
||||||
|
|||||||
@@ -6,4 +6,5 @@
|
|||||||
script = ExtResource("1_8k5aa")
|
script = ExtResource("1_8k5aa")
|
||||||
name = "Buck the Bucket"
|
name = "Buck the Bucket"
|
||||||
color = Color(0.336269, 0.489145, 0.825324, 1)
|
color = Color(0.336269, 0.489145, 0.825324, 1)
|
||||||
|
maxStack = 1
|
||||||
metadata/_custom_type_script = "uid://cbskymrxs6ksu"
|
metadata/_custom_type_script = "uid://cbskymrxs6ksu"
|
||||||
|
|||||||
@@ -6,4 +6,5 @@
|
|||||||
script = ExtResource("1_06nef")
|
script = ExtResource("1_06nef")
|
||||||
name = "Your Mom"
|
name = "Your Mom"
|
||||||
color = Color(0.751421, 0.329615, 0.570911, 1)
|
color = Color(0.751421, 0.329615, 0.570911, 1)
|
||||||
|
maxStack = 1
|
||||||
metadata/_custom_type_script = "uid://cbskymrxs6ksu"
|
metadata/_custom_type_script = "uid://cbskymrxs6ksu"
|
||||||
|
|||||||
@@ -6,4 +6,5 @@
|
|||||||
script = ExtResource("1_07aya")
|
script = ExtResource("1_07aya")
|
||||||
name = "Pick Axe"
|
name = "Pick Axe"
|
||||||
color = Color(0.589014, 0.823353, 0.998475, 1)
|
color = Color(0.589014, 0.823353, 0.998475, 1)
|
||||||
|
maxStack = 1
|
||||||
metadata/_custom_type_script = "uid://cbskymrxs6ksu"
|
metadata/_custom_type_script = "uid://cbskymrxs6ksu"
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
[gd_resource type="Resource" script_class="ItemResource" load_steps=2 format=3 uid="uid://d1uuxp1lp4aro"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://cbskymrxs6ksu" path="res://scripts/CSharp/Common/Inventory/ItemResource.cs" id="1_dustj"]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
script = ExtResource("1_dustj")
|
||||||
|
name = "Tomato Seed"
|
||||||
|
color = Color(0.135039, 0.307214, 0.333128, 1)
|
||||||
|
maxStack = 20
|
||||||
|
metadata/_custom_type_script = "uid://cbskymrxs6ksu"
|
||||||
@@ -5,9 +5,9 @@
|
|||||||
[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://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="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="Resource" uid="uid://cndd64batns31" path="res://resources/items/bucket.tres" id="6_nvnpb"]
|
||||||
[ext_resource type="Script" uid="uid://cywyym5l7ymhr" path="res://scripts/CSharp/Common/Farming/FieldService.cs" id="7_3rkjv"]
|
[ext_resource type="Script" uid="uid://d17si23dtlg72" path="res://scripts/CSharp/Common/Farming/FieldService.cs" id="7_3rkjv"]
|
||||||
[ext_resource type="Resource" uid="uid://c5yg3lx756v4v" path="res://resources/items/hoe.tres" id="7_hv2km"]
|
[ext_resource type="Resource" uid="uid://c5yg3lx756v4v" path="res://resources/items/hoe.tres" id="7_hv2km"]
|
||||||
[ext_resource type="Resource" uid="uid://datee0flk1e84" path="res://resources/items/pickaxe.tres" id="8_hae25"]
|
[ext_resource type="Resource" uid="uid://d1uuxp1lp4aro" path="res://resources/items/tomato_seed.tres" id="8_hv2km"]
|
||||||
|
|
||||||
[sub_resource type="PlaneMesh" id="PlaneMesh_8yprl"]
|
[sub_resource type="PlaneMesh" id="PlaneMesh_8yprl"]
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 6.1678, -4.76837e-07, -3.9497
|
|||||||
_infiniteSupply = true
|
_infiniteSupply = true
|
||||||
|
|
||||||
[node name="SpawnWithItem" parent="GenericItemOnGround4" index="1"]
|
[node name="SpawnWithItem" parent="GenericItemOnGround4" index="1"]
|
||||||
_blueprint = ExtResource("8_hae25")
|
_blueprint = ExtResource("8_hv2km")
|
||||||
|
|
||||||
[editable path="GenericItemOnGround"]
|
[editable path="GenericItemOnGround"]
|
||||||
[editable path="GenericItemOnGround2"]
|
[editable path="GenericItemOnGround2"]
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://xm0um640aes7
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://12hleqx8amr8
|
||||||
@@ -12,6 +12,7 @@ public partial class InventoryInstance : Node
|
|||||||
|
|
||||||
[Signal]
|
[Signal]
|
||||||
public delegate void SlotAmountChangedEventHandler();
|
public delegate void SlotAmountChangedEventHandler();
|
||||||
|
|
||||||
[Signal]
|
[Signal]
|
||||||
public delegate void InventoryContentsChangedEventHandler();
|
public delegate void InventoryContentsChangedEventHandler();
|
||||||
|
|
||||||
@@ -32,33 +33,65 @@ public partial class InventoryInstance : Node
|
|||||||
_slots.Add(new InventorySlot());
|
_slots.Add(new InventorySlot());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EmitSignal(SignalName.SlotAmountChanged);
|
EmitSignal(SignalName.SlotAmountChanged);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public InventoryActionResult AddItem(ItemInstance newItem, int inventorySlot = -1)
|
public InventoryActionResult AddItem(ItemInstance newItem)
|
||||||
{
|
{
|
||||||
if (inventorySlot < 0)
|
var result = AddItemAndStackRecursive(newItem, 0);
|
||||||
{
|
EmitSignal(SignalName.InventoryContentsChanged);
|
||||||
inventorySlot = _slots.FindIndex(slot => slot.IsEmpty());
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inventorySlot < 0 || !_slots[inventorySlot].IsEmpty())
|
private InventoryActionResult AddItemAndStackRecursive(ItemInstance newItem, int slotSearch)
|
||||||
|
{
|
||||||
|
if (newItem.blueprint == null || newItem.amount == 0)
|
||||||
|
return InventoryActionResult.SourceDoesNotExists;
|
||||||
|
|
||||||
|
var slotIndex = -1;
|
||||||
|
// find stackable slot
|
||||||
|
for (var i = slotSearch; i < _slots.Count; i++)
|
||||||
|
{
|
||||||
|
if (_slots[i].itemInstance?.blueprint == newItem.blueprint)
|
||||||
|
{
|
||||||
|
slotIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (slotIndex < 0)
|
||||||
|
{
|
||||||
|
// find empty slot
|
||||||
|
for (var i = slotSearch; i < _slots.Count; i++)
|
||||||
|
{
|
||||||
|
if (_slots[i].IsEmpty())
|
||||||
|
{
|
||||||
|
slotIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (slotIndex < 0)
|
||||||
{
|
{
|
||||||
return InventoryActionResult.DestinationFull;
|
return InventoryActionResult.DestinationFull;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inventorySlot >= _slots.Count)
|
var itemInstance = _slots[slotIndex].itemInstance ?? new ItemInstance { blueprint = newItem.blueprint, amount = 0 };
|
||||||
{
|
var maxStack = itemInstance!.blueprint.maxStack;
|
||||||
return InventoryActionResult.DestinationDoesNotExists;
|
var freeOnStack = maxStack - itemInstance.amount;
|
||||||
|
var moveAmount = Math.Min(freeOnStack, newItem.amount);
|
||||||
|
itemInstance.amount += moveAmount;
|
||||||
|
newItem.amount -= moveAmount;
|
||||||
|
_slots[slotIndex].itemInstance = itemInstance;
|
||||||
|
return newItem.amount <= 0
|
||||||
|
? InventoryActionResult.Success
|
||||||
|
: AddItemAndStackRecursive(newItem, slotIndex + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
_slots[inventorySlot].itemInstance = newItem;
|
public InventoryActionResult RemoveItem(int inventorySlot, out ItemInstance? itemInstance)
|
||||||
EmitSignal(SignalName.InventoryContentsChanged);
|
|
||||||
return InventoryActionResult.Success;
|
|
||||||
}
|
|
||||||
|
|
||||||
public InventoryActionResult RemoveItem(int inventorySlot, out ItemInstance? itemInstance )
|
|
||||||
{
|
{
|
||||||
if (inventorySlot < 0 || inventorySlot >= _slots.Count)
|
if (inventorySlot < 0 || inventorySlot >= _slots.Count)
|
||||||
{
|
{
|
||||||
@@ -82,4 +115,17 @@ public partial class InventoryInstance : Node
|
|||||||
{
|
{
|
||||||
return RemoveItem(inventorySlot, out _);
|
return RemoveItem(inventorySlot, out _);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public InventoryActionResult AddItemToSlot(ItemInstance itemInstance, int destinationSlot)
|
||||||
|
{
|
||||||
|
if (destinationSlot < 0 || destinationSlot >= _slots.Count)
|
||||||
|
return InventoryActionResult.DestinationDoesNotExists;
|
||||||
|
|
||||||
|
if (!_slots[destinationSlot].IsEmpty())
|
||||||
|
return InventoryActionResult.DestinationFull;
|
||||||
|
|
||||||
|
_slots[destinationSlot].itemInstance = itemInstance;
|
||||||
|
EmitSignal(SignalName.InventoryContentsChanged);
|
||||||
|
return InventoryActionResult.Success;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -23,11 +23,13 @@ public partial class InventoryManager : Node
|
|||||||
public InventoryActionResult CreateItem(
|
public InventoryActionResult CreateItem(
|
||||||
ItemResource itemBlueprint,
|
ItemResource itemBlueprint,
|
||||||
InventoryInstance inventory,
|
InventoryInstance inventory,
|
||||||
|
int amount = 1,
|
||||||
int inventorySlot = -1)
|
int inventorySlot = -1)
|
||||||
{
|
{
|
||||||
var newItem = new ItemInstance { blueprint = itemBlueprint };
|
var newItem = new ItemInstance { blueprint = itemBlueprint, amount = amount };
|
||||||
var addResult = inventory.AddItem(newItem, inventorySlot);
|
return inventorySlot < 0
|
||||||
return addResult;
|
? inventory.AddItem(newItem)
|
||||||
|
: inventory.AddItemToSlot(newItem, inventorySlot);
|
||||||
}
|
}
|
||||||
|
|
||||||
public InventoryActionResult MoveItem(
|
public InventoryActionResult MoveItem(
|
||||||
@@ -39,10 +41,11 @@ public partial class InventoryManager : Node
|
|||||||
var remResult = sourceInventory.RemoveItem(sourceSlot, out var item);
|
var remResult = sourceInventory.RemoveItem(sourceSlot, out var item);
|
||||||
if (remResult != InventoryActionResult.Success) return remResult;
|
if (remResult != InventoryActionResult.Success) return remResult;
|
||||||
|
|
||||||
var addResult = destinationInventory.AddItem(item!, destinationSlot);
|
var addResult = destinationInventory.AddItemToSlot(item!, destinationSlot);
|
||||||
if(addResult == InventoryActionResult.Success) return InventoryActionResult.Success;
|
if (addResult == InventoryActionResult.Success) return InventoryActionResult.Success;
|
||||||
|
|
||||||
sourceInventory.AddItem(item!, sourceSlot); // can not fail ... in theory
|
// if adding in the destination failed, re-add the item into the source
|
||||||
|
sourceInventory.AddItemToSlot(item!, sourceSlot); // can not fail ... in theory
|
||||||
return addResult;
|
return addResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,6 +63,7 @@ public partial class InventoryManager : Node
|
|||||||
{
|
{
|
||||||
return inventory.RemoveItem(inventorySlot);
|
return inventory.RemoveItem(inventorySlot);
|
||||||
}
|
}
|
||||||
|
|
||||||
public InventoryActionResult CollectItem(ItemInstance itemInstance)
|
public InventoryActionResult CollectItem(ItemInstance itemInstance)
|
||||||
{
|
{
|
||||||
return playerInventory.AddItem(itemInstance);
|
return playerInventory.AddItem(itemInstance);
|
||||||
|
|||||||
@@ -43,6 +43,12 @@ public partial class InventoryUi : Control
|
|||||||
uiSlot!.nameLabel.Text = inventorySlot.itemInstance?.blueprint.name ?? "";
|
uiSlot!.nameLabel.Text = inventorySlot.itemInstance?.blueprint.name ?? "";
|
||||||
uiSlot!.nameLabel.LabelSettings = uiSlot!.nameLabel.LabelSettings.Duplicate() as LabelSettings;
|
uiSlot!.nameLabel.LabelSettings = uiSlot!.nameLabel.LabelSettings.Duplicate() as LabelSettings;
|
||||||
uiSlot!.nameLabel.LabelSettings!.FontColor = inventorySlot.itemInstance?.blueprint.color ?? Colors.White;
|
uiSlot!.nameLabel.LabelSettings!.FontColor = inventorySlot.itemInstance?.blueprint.color ?? Colors.White;
|
||||||
|
|
||||||
|
var amountText = inventorySlot.itemInstance != null &&
|
||||||
|
inventorySlot.itemInstance.amount != 1
|
||||||
|
? inventorySlot.itemInstance.amount.ToString()
|
||||||
|
: "";
|
||||||
|
uiSlot!.amountLabel.Text = amountText;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,6 +105,7 @@ public partial class InventoryUi : Control
|
|||||||
{
|
{
|
||||||
InputInventoryOpenClose();
|
InputInventoryOpenClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Input.IsActionJustPressed("ui_inventory_disadvance"))
|
if (Input.IsActionJustPressed("ui_inventory_disadvance"))
|
||||||
{
|
{
|
||||||
_selectedSlot++;
|
_selectedSlot++;
|
||||||
@@ -106,7 +113,8 @@ public partial class InventoryUi : Control
|
|||||||
_selectedSlot = 0;
|
_selectedSlot = 0;
|
||||||
SetSlotSelectPosition();
|
SetSlotSelectPosition();
|
||||||
}
|
}
|
||||||
if(Input.IsActionJustPressed("ui_inventory_advance"))
|
|
||||||
|
if (Input.IsActionJustPressed("ui_inventory_advance"))
|
||||||
{
|
{
|
||||||
_selectedSlot--;
|
_selectedSlot--;
|
||||||
if (_selectedSlot < 0)
|
if (_selectedSlot < 0)
|
||||||
|
|||||||
@@ -3,4 +3,14 @@
|
|||||||
public class ItemInstance
|
public class ItemInstance
|
||||||
{
|
{
|
||||||
public ItemResource blueprint;
|
public ItemResource blueprint;
|
||||||
|
public int amount = 1;
|
||||||
|
|
||||||
|
public ItemInstance Clone()
|
||||||
|
{
|
||||||
|
return new ItemInstance
|
||||||
|
{
|
||||||
|
blueprint = blueprint,
|
||||||
|
amount = amount
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public partial class ItemOnGround : Node3D
|
|||||||
{
|
{
|
||||||
GD.Print("Trying to pick up item");
|
GD.Print("Trying to pick up item");
|
||||||
|
|
||||||
var result = InventoryManager.Instance.CollectItem(itemInstance);
|
var result = InventoryManager.Instance.CollectItem(itemInstance.Clone());
|
||||||
if (result == InventoryActionResult.Success)
|
if (result == InventoryActionResult.Success)
|
||||||
{
|
{
|
||||||
if (!_infiniteSupply)
|
if (!_infiniteSupply)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
namespace Babushka.scripts.CSharp.Common.Inventory;
|
namespace Babushka.scripts.CSharp.Common.Inventory;
|
||||||
|
|
||||||
[GlobalClass]
|
[GlobalClass]
|
||||||
public partial class ItemResource: Resource
|
public partial class ItemResource : Resource
|
||||||
{
|
{
|
||||||
[Export]
|
[Export]
|
||||||
public string name;
|
public string name;
|
||||||
@@ -10,9 +10,13 @@ public partial class ItemResource: Resource
|
|||||||
[Export]
|
[Export]
|
||||||
public Color color;
|
public Color color;
|
||||||
|
|
||||||
|
[Export]
|
||||||
|
public int maxStack;
|
||||||
|
|
||||||
public ItemResource()
|
public ItemResource()
|
||||||
{
|
{
|
||||||
name = "";
|
name = "";
|
||||||
color = Colors.Red;
|
color = Colors.Red;
|
||||||
|
maxStack = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,12 +7,14 @@ public partial class SlotUi : Control
|
|||||||
{
|
{
|
||||||
public Label nameLabel;
|
public Label nameLabel;
|
||||||
public int index;
|
public int index;
|
||||||
|
public Label amountLabel;
|
||||||
|
|
||||||
[Signal] public delegate void ClickedEventHandler(int index);
|
[Signal] public delegate void ClickedEventHandler(int index);
|
||||||
|
|
||||||
public override void _EnterTree()
|
public override void _EnterTree()
|
||||||
{
|
{
|
||||||
nameLabel = GetNode<Label>("NameLabel");
|
nameLabel = GetNode<Label>("NameLabel");
|
||||||
|
amountLabel = GetNode<Label>("AmountLabel");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void _on_gui_input(InputEvent ev)
|
public void _on_gui_input(InputEvent ev)
|
||||||
|
|||||||
Reference in New Issue
Block a user