Added Inventory System

This commit is contained in:
2026-08-29 23:24:04 +01:00
parent 00f9448329
commit 7df4adec93
60 changed files with 4283 additions and 2 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,105 @@
{
"Version": 1,
"WorkspaceRootPath": "D:\\GameDev\\GodotTutorials\\",
"Documents": [
{
"AbsoluteMoniker": "D:0:0:{7E42B83A-A25D-4FD2-A8FC-BC16565A2C33}|Tutorials.csproj|d:\\gamedev\\godottutorials\\inventory\\csharp\\inventoryslot.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{7E42B83A-A25D-4FD2-A8FC-BC16565A2C33}|Tutorials.csproj|solutionrelative:inventory\\csharp\\inventoryslot.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
},
{
"AbsoluteMoniker": "D:0:0:{7E42B83A-A25D-4FD2-A8FC-BC16565A2C33}|Tutorials.csproj|d:\\gamedev\\godottutorials\\inventory\\csharp\\inventorycontroller.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{7E42B83A-A25D-4FD2-A8FC-BC16565A2C33}|Tutorials.csproj|solutionrelative:inventory\\csharp\\inventorycontroller.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
},
{
"AbsoluteMoniker": "D:0:0:{7E42B83A-A25D-4FD2-A8FC-BC16565A2C33}|Tutorials.csproj|d:\\gamedev\\godottutorials\\inventory\\csharp\\inventoryslotdata.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{7E42B83A-A25D-4FD2-A8FC-BC16565A2C33}|Tutorials.csproj|solutionrelative:inventory\\csharp\\inventoryslotdata.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
},
{
"AbsoluteMoniker": "D:0:0:{7E42B83A-A25D-4FD2-A8FC-BC16565A2C33}|Tutorials.csproj|d:\\gamedev\\godottutorials\\inventory\\csharp\\inventory.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{7E42B83A-A25D-4FD2-A8FC-BC16565A2C33}|Tutorials.csproj|solutionrelative:inventory\\csharp\\inventory.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
},
{
"AbsoluteMoniker": "D:0:0:{7E42B83A-A25D-4FD2-A8FC-BC16565A2C33}|Tutorials.csproj|d:\\gamedev\\godottutorials\\inventory\\csharp\\itemdata.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{7E42B83A-A25D-4FD2-A8FC-BC16565A2C33}|Tutorials.csproj|solutionrelative:inventory\\csharp\\itemdata.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
}
],
"DocumentGroupContainers": [
{
"Orientation": 0,
"VerticalTabListWidth": 256,
"DocumentGroups": [
{
"DockedWidth": 200,
"SelectedChildIndex": 2,
"Children": [
{
"$type": "Document",
"DocumentIndex": 1,
"Title": "InventoryController.cs",
"DocumentMoniker": "D:\\GameDev\\GodotTutorials\\Inventory\\CSharp\\InventoryController.cs",
"RelativeDocumentMoniker": "Inventory\\CSharp\\InventoryController.cs",
"ToolTip": "D:\\GameDev\\GodotTutorials\\Inventory\\CSharp\\InventoryController.cs",
"RelativeToolTip": "Inventory\\CSharp\\InventoryController.cs",
"ViewState": "AgIAAAAAAAAAAAAAAAAAAAwAAAAlAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2026-08-29T16:55:52.325Z",
"EditorCaption": ""
},
{
"$type": "Document",
"DocumentIndex": 2,
"Title": "InventorySlotData.cs",
"DocumentMoniker": "D:\\GameDev\\GodotTutorials\\Inventory\\CSharp\\InventorySlotData.cs",
"RelativeDocumentMoniker": "Inventory\\CSharp\\InventorySlotData.cs",
"ToolTip": "D:\\GameDev\\GodotTutorials\\Inventory\\CSharp\\InventorySlotData.cs",
"RelativeToolTip": "Inventory\\CSharp\\InventorySlotData.cs",
"ViewState": "AgIAAAAAAAAAAAAAAAAAAAIAAAAOAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2026-08-29T16:31:20.262Z",
"EditorCaption": ""
},
{
"$type": "Document",
"DocumentIndex": 0,
"Title": "InventorySlot.cs",
"DocumentMoniker": "D:\\GameDev\\GodotTutorials\\Inventory\\CSharp\\InventorySlot.cs",
"RelativeDocumentMoniker": "Inventory\\CSharp\\InventorySlot.cs",
"ToolTip": "D:\\GameDev\\GodotTutorials\\Inventory\\CSharp\\InventorySlot.cs",
"RelativeToolTip": "Inventory\\CSharp\\InventorySlot.cs",
"ViewState": "AgIAAC0AAAAAAAAAAAAmwD8AAAApAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2026-08-29T16:14:15.781Z",
"EditorCaption": ""
},
{
"$type": "Document",
"DocumentIndex": 3,
"Title": "Inventory.cs",
"DocumentMoniker": "D:\\GameDev\\GodotTutorials\\Inventory\\CSharp\\Inventory.cs",
"RelativeDocumentMoniker": "Inventory\\CSharp\\Inventory.cs",
"ToolTip": "D:\\GameDev\\GodotTutorials\\Inventory\\CSharp\\Inventory.cs",
"RelativeToolTip": "Inventory\\CSharp\\Inventory.cs",
"ViewState": "AgIAAC0AAAAAAAAAAAAIwDUAAAABAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2026-08-29T15:55:05.207Z",
"EditorCaption": ""
},
{
"$type": "Document",
"DocumentIndex": 4,
"Title": "ItemData.cs",
"DocumentMoniker": "D:\\GameDev\\GodotTutorials\\Inventory\\CSharp\\ItemData.cs",
"RelativeDocumentMoniker": "Inventory\\CSharp\\ItemData.cs",
"ToolTip": "D:\\GameDev\\GodotTutorials\\Inventory\\CSharp\\ItemData.cs",
"RelativeToolTip": "Inventory\\CSharp\\ItemData.cs",
"ViewState": "AgIAAAAAAAAAAAAAAAAAAAkAAAAxAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2026-08-29T15:43:48.537Z",
"EditorCaption": ""
}
]
}
]
}
]
}
+105
View File
@@ -0,0 +1,105 @@
{
"Version": 1,
"WorkspaceRootPath": "D:\\GameDev\\GodotTutorials\\",
"Documents": [
{
"AbsoluteMoniker": "D:0:0:{7E42B83A-A25D-4FD2-A8FC-BC16565A2C33}|Tutorials.csproj|d:\\gamedev\\godottutorials\\inventory\\csharp\\inventorycontroller.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{7E42B83A-A25D-4FD2-A8FC-BC16565A2C33}|Tutorials.csproj|solutionrelative:inventory\\csharp\\inventorycontroller.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
},
{
"AbsoluteMoniker": "D:0:0:{7E42B83A-A25D-4FD2-A8FC-BC16565A2C33}|Tutorials.csproj|d:\\gamedev\\godottutorials\\inventory\\csharp\\inventory.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{7E42B83A-A25D-4FD2-A8FC-BC16565A2C33}|Tutorials.csproj|solutionrelative:inventory\\csharp\\inventory.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
},
{
"AbsoluteMoniker": "D:0:0:{7E42B83A-A25D-4FD2-A8FC-BC16565A2C33}|Tutorials.csproj|d:\\gamedev\\godottutorials\\inventory\\csharp\\inventoryslotdata.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{7E42B83A-A25D-4FD2-A8FC-BC16565A2C33}|Tutorials.csproj|solutionrelative:inventory\\csharp\\inventoryslotdata.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
},
{
"AbsoluteMoniker": "D:0:0:{7E42B83A-A25D-4FD2-A8FC-BC16565A2C33}|Tutorials.csproj|d:\\gamedev\\godottutorials\\inventory\\csharp\\inventoryslot.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{7E42B83A-A25D-4FD2-A8FC-BC16565A2C33}|Tutorials.csproj|solutionrelative:inventory\\csharp\\inventoryslot.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
},
{
"AbsoluteMoniker": "D:0:0:{7E42B83A-A25D-4FD2-A8FC-BC16565A2C33}|Tutorials.csproj|d:\\gamedev\\godottutorials\\inventory\\csharp\\itemdata.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{7E42B83A-A25D-4FD2-A8FC-BC16565A2C33}|Tutorials.csproj|solutionrelative:inventory\\csharp\\itemdata.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
}
],
"DocumentGroupContainers": [
{
"Orientation": 0,
"VerticalTabListWidth": 256,
"DocumentGroups": [
{
"DockedWidth": 200,
"SelectedChildIndex": 0,
"Children": [
{
"$type": "Document",
"DocumentIndex": 0,
"Title": "InventoryController.cs",
"DocumentMoniker": "D:\\GameDev\\GodotTutorials\\Inventory\\CSharp\\InventoryController.cs",
"RelativeDocumentMoniker": "Inventory\\CSharp\\InventoryController.cs",
"ToolTip": "D:\\GameDev\\GodotTutorials\\Inventory\\CSharp\\InventoryController.cs",
"RelativeToolTip": "Inventory\\CSharp\\InventoryController.cs",
"ViewState": "AgIAAAAAAAAAAAAAAAAAAAgAAAA/AAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2026-08-29T16:55:52.325Z",
"EditorCaption": ""
},
{
"$type": "Document",
"DocumentIndex": 2,
"Title": "InventorySlotData.cs",
"DocumentMoniker": "D:\\GameDev\\GodotTutorials\\Inventory\\CSharp\\InventorySlotData.cs",
"RelativeDocumentMoniker": "Inventory\\CSharp\\InventorySlotData.cs",
"ToolTip": "D:\\GameDev\\GodotTutorials\\Inventory\\CSharp\\InventorySlotData.cs",
"RelativeToolTip": "Inventory\\CSharp\\InventorySlotData.cs",
"ViewState": "AgIAAAAAAAAAAAAAAAAAAAcAAAABAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2026-08-29T16:31:20.262Z",
"EditorCaption": ""
},
{
"$type": "Document",
"DocumentIndex": 3,
"Title": "InventorySlot.cs",
"DocumentMoniker": "D:\\GameDev\\GodotTutorials\\Inventory\\CSharp\\InventorySlot.cs",
"RelativeDocumentMoniker": "Inventory\\CSharp\\InventorySlot.cs",
"ToolTip": "D:\\GameDev\\GodotTutorials\\Inventory\\CSharp\\InventorySlot.cs",
"RelativeToolTip": "Inventory\\CSharp\\InventorySlot.cs",
"ViewState": "AgIAAAAAAAAAAAAAAAAAAEMAAAACAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2026-08-29T16:14:15.781Z",
"EditorCaption": ""
},
{
"$type": "Document",
"DocumentIndex": 1,
"Title": "Inventory.cs",
"DocumentMoniker": "D:\\GameDev\\GodotTutorials\\Inventory\\CSharp\\Inventory.cs",
"RelativeDocumentMoniker": "Inventory\\CSharp\\Inventory.cs",
"ToolTip": "D:\\GameDev\\GodotTutorials\\Inventory\\CSharp\\Inventory.cs",
"RelativeToolTip": "Inventory\\CSharp\\Inventory.cs",
"ViewState": "AgIAAAAAAAAAAAAAAAAAAAgAAAAuAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2026-08-29T15:55:05.207Z",
"EditorCaption": ""
},
{
"$type": "Document",
"DocumentIndex": 4,
"Title": "ItemData.cs",
"DocumentMoniker": "D:\\GameDev\\GodotTutorials\\Inventory\\CSharp\\ItemData.cs",
"RelativeDocumentMoniker": "Inventory\\CSharp\\ItemData.cs",
"ToolTip": "D:\\GameDev\\GodotTutorials\\Inventory\\CSharp\\ItemData.cs",
"RelativeToolTip": "Inventory\\CSharp\\ItemData.cs",
"ViewState": "AgIAAAAAAAAAAAAAAAAAAAkAAAAxAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2026-08-29T15:43:48.537Z",
"EditorCaption": ""
}
]
}
]
}
]
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 1006 KiB

+40
View File
@@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cy0inxl8hyq24"
path="res://.godot/imported/2026-08-29_18.12.06.png-2be8e6961eb5ac9d609f2c3c4a96dff2.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://2026-08-29_18.12.06.png"
dest_files=["res://.godot/imported/2026-08-29_18.12.06.png-2be8e6961eb5ac9d609f2c3c4a96dff2.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
Binary file not shown.

After

Width:  |  Height:  |  Size: 223 B

@@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://c1ek2u18es0nv"
path="res://.godot/imported/EnemyHpBar1.png-337250efa6b6b3b4816681e44f5be87c.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://CustomNodes/Textures/EnemyHpBar1.png"
dest_files=["res://.godot/imported/EnemyHpBar1.png-337250efa6b6b3b4816681e44f5be87c.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
Binary file not shown.

After

Width:  |  Height:  |  Size: 182 B

@@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bqpbjtq8yun7h"
path="res://.godot/imported/EnemyHpBar2.png-5fe79bf54d5b0a4740ae6a0561317282.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://CustomNodes/Textures/EnemyHpBar2.png"
dest_files=["res://.godot/imported/EnemyHpBar2.png-5fe79bf54d5b0a4740ae6a0561317282.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 254 B

+40
View File
@@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://c5p7tjjms7cqy"
path="res://.godot/imported/EnemyIcon.png-c6f31e49e156bc09e83287eda140a44f.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://CustomNodes/Textures/EnemyIcon.png"
dest_files=["res://.godot/imported/EnemyIcon.png-c6f31e49e156bc09e83287eda140a44f.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 220 B

+40
View File
@@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://wfheyedrar4v"
path="res://.godot/imported/enemy.png-8b9c087cc390fd19156dbccef25a4019.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://CustomNodes/Textures/enemy.png"
dest_files=["res://.godot/imported/enemy.png-8b9c087cc390fd19156dbccef25a4019.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
+10
View File
@@ -0,0 +1,10 @@
using Godot;
using System;
using System.Linq;
[GlobalClass]
public partial class Inventory : Resource
{
[Export] public int Size = 36;
[Export] public InventorySlotData[] Slots;
}
+1
View File
@@ -0,0 +1 @@
uid://7dsydoyjsley
+18
View File
@@ -0,0 +1,18 @@
using Godot;
public partial class InventoryController : Control
{
[Export] public Inventory Inventory;
public override void _Ready()
{
var inventorySlots = GetTree().GetNodesInGroup("inventory_slots_cs");
for (int i = 0; i < inventorySlots.Count; i++)
{
var slot = (InventorySlot)inventorySlots[i];
slot.InitializeSlot(i, Inventory);
}
}
}
@@ -0,0 +1 @@
uid://rcwsi83u3a2d
+74
View File
@@ -0,0 +1,74 @@
using Godot;
using Godot.Collections;
using System;
using System.Linq;
public partial class InventorySlot : Panel
{
[Export] public TextureRect IconRect;
[Export] public Label CountLabel;
public InventorySlotData SlotData;
public int SlotIndex;
public Inventory Inventory;
// Refresh the current slot with the data of it's inventory slot
public void Refresh()
{
if (SlotIndex < Inventory.Slots.Count())
{
SlotData = Inventory.Slots[SlotIndex];
}
if (SlotData == null)
{
IconRect.Texture = null;
CountLabel.Text = "";
}
else
{
IconRect.Texture = SlotData.Item.Icon;
CountLabel.Text = (SlotData.Count > 1) ? SlotData.Count.ToString() : "";
}
}
// Handle Item being dragged elsewhere
public override Variant _GetDragData(Vector2 atPosition)
{
if (SlotData == null)
return default;
// Create a preview of the item being dragged
var preview = new TextureRect { Texture = SlotData.Item.Icon, CustomMinimumSize = new Vector2(32f, 32f) };
SetDragPreview(preview);
var data = new Dictionary { { "from_slot", SlotIndex } };
return data;
}
// Can we drop the item where we are?
public override bool _CanDropData(Vector2 atPosition, Variant data)
{
return data.VariantType == Variant.Type.Dictionary
&& ((Dictionary)data).ContainsKey("from_slot");
}
public override void _DropData(Vector2 atPosition, Variant data)
{
int fromIndex = (int)((Dictionary)data)["from_slot"];
// Swap the 2 indexes
(Inventory.Slots[SlotIndex], Inventory.Slots[fromIndex]) = (Inventory.Slots[fromIndex], Inventory.Slots[SlotIndex]);
// Call the refresh method for all objects that belong in the inventory_slots group
GetTree().CallGroup("inventory_slots_cs", InventorySlot.MethodName.Refresh);
}
public void InitializeSlot(int slotIndex, Inventory inventory)
{
SlotIndex = slotIndex;
Inventory = inventory;
Refresh();
}
}
+1
View File
@@ -0,0 +1 @@
uid://6px2tco0hdyp
+8
View File
@@ -0,0 +1,8 @@
using Godot;
[GlobalClass]
public partial class InventorySlotData : Resource
{
[Export] public ItemData Item;
[Export] public int Count;
}
@@ -0,0 +1 @@
uid://c61uo84g0gp1v
+11
View File
@@ -0,0 +1,11 @@
using Godot;
using System;
[GlobalClass]
public partial class ItemData : Resource
{
[Export] public string Id { get; set; }
[Export] public string DisplayName { get; set; }
[Export] public Texture2D Icon { get; set; }
[Export] public int MaxStack { get; set; } = 64;
}
+1
View File
@@ -0,0 +1 @@
uid://b8yemi4n7cqls
+5
View File
@@ -0,0 +1,5 @@
extends Resource
class_name InventoryGD
@export var size: int = 36
@export var slots : Array[InventorySlotDataGD] = [] # Data regarding what's in each slot
+1
View File
@@ -0,0 +1 @@
uid://dila5f4tuiun1
@@ -0,0 +1,5 @@
extends Resource
class_name InventorySlotDataGD
@export var item: ItemDataGD
@export var count: int
@@ -0,0 +1 @@
uid://mv6k4s5wf52h
+64
View File
@@ -0,0 +1,64 @@
extends Panel
class_name InventorySlotGD
@onready var icon_rect: TextureRect = $Icon
@onready var count_label: Label = $CountLabel
@export var slot_data : InventorySlotDataGD # Slot data as defined in the InventoryGD class
@export var slot_index: int
@export var main_inventory: InventoryGD
# Refresh the current slot with the data of it's inventory slot
func refresh():
if (slot_index < main_inventory.slots.size()):
slot_data = main_inventory.slots[slot_index]
if slot_data == null:
icon_rect.texture = null
count_label.text = ""
else:
icon_rect.texture = slot_data.item.icon
count_label.text = str(slot_data.count) if slot_data.count > 1 else ""
# Handle Item being dragged elsewhere
func _get_drag_data(at_position: Vector2) -> Variant:
if slot_data == null:
return null
# Create a preview of the item being dragged
var preview = TextureRect.new()
preview.texture = slot_data.item.icon
preview.custom_minimum_size = Vector2(32,32)
set_drag_preview(preview)
var data = { "from_slot": slot_index, "payload": slot_data }
return data
func _can_drop_data(at_position: Vector2, data: Variant) -> bool:
return typeof(data) == TYPE_DICTIONARY and data.has("from_slot")
# Can we drop the item where we are?
func _drop_data(_pos, data):
var from_index = data.from_slot
# Swap the 2 indexes
var temp = main_inventory.slots[slot_index]
main_inventory.slots[slot_index] = main_inventory.slots[from_index]
main_inventory.slots[from_index] = temp
# Call the refresh method for all objects that belong in the inventory_slots group
get_tree().call_group("inventory_slots", "refresh")
func initialize_slot(index: int, inventory: InventoryGD):
slot_index = index
main_inventory = inventory
if index < main_inventory.slots.size():
var inventory_slot = main_inventory.slots[slot_index]
if inventory_slot != null :
slot_data = inventory_slot
refresh()
@@ -0,0 +1 @@
uid://b0uy0my40tjsv
+7
View File
@@ -0,0 +1,7 @@
extends Resource
class_name ItemDataGD
@export var id: String
@export var display_name: String
@export var icon: Texture2D
@export var max_stack: int = 64
+1
View File
@@ -0,0 +1 @@
uid://b8cygu5gimsgi
+11
View File
@@ -0,0 +1,11 @@
[gd_resource type="Resource" script_class="ItemData" format=3 uid="uid://d0w7bxo6cotsc"]
[ext_resource type="Texture2D" uid="uid://bgam5s5hw83cf" path="res://Inventory/Textures/Apple.png" id="1_5kwn6"]
[ext_resource type="Script" uid="uid://b8yemi4n7cqls" path="res://Inventory/CSharp/ItemData.cs" id="1_bou2a"]
[resource]
script = ExtResource("1_bou2a")
Id = "1"
DisplayName = "Apple"
Icon = ExtResource("1_5kwn6")
metadata/_custom_type_script = "uid://b8yemi4n7cqls"
+45
View File
@@ -0,0 +1,45 @@
[gd_resource type="Resource" script_class="InventoryGD" format=3 uid="uid://d378a606v8xdt"]
[ext_resource type="Script" uid="uid://dila5f4tuiun1" path="res://Inventory/GDScript/InventoryGD.gd" id="1_8jwj0"]
[ext_resource type="Script" uid="uid://mv6k4s5wf52h" path="res://Inventory/GDScript/InventorySlotDataGD.gd" id="2_yctcd"]
[ext_resource type="Resource" uid="uid://cqyo3lbguv5hg" path="res://Inventory/Resources/GDItemApple.tres" id="3_yctcd"]
[ext_resource type="Script" uid="uid://b8cygu5gimsgi" path="res://Inventory/GDScript/ItemDataGD.gd" id="4_ev12v"]
[sub_resource type="Resource" id="Resource_7tu70"]
script = ExtResource("2_yctcd")
item = ExtResource("3_yctcd")
count = 24
metadata/_custom_type_script = "uid://mv6k4s5wf52h"
[sub_resource type="Resource" id="Resource_mrqgh"]
script = ExtResource("2_yctcd")
item = ExtResource("3_yctcd")
count = 14
metadata/_custom_type_script = "uid://mv6k4s5wf52h"
[sub_resource type="Resource" id="Resource_jwwx0"]
script = ExtResource("2_yctcd")
item = ExtResource("3_yctcd")
count = 14
metadata/_custom_type_script = "uid://mv6k4s5wf52h"
[sub_resource type="CompressedTexture2D" id="CompressedTexture2D_7tu70"]
load_path = "res://.godot/imported/Apple.png-d164bb800f362dfbf6df55c5ab1627cc.ctex"
[sub_resource type="Resource" id="Resource_3eq5k"]
script = ExtResource("4_ev12v")
id = "1"
display_name = "Apple"
icon = SubResource("CompressedTexture2D_7tu70")
metadata/_custom_type_script = "uid://b8cygu5gimsgi"
[sub_resource type="Resource" id="Resource_1cv4e"]
script = ExtResource("2_yctcd")
item = SubResource("Resource_3eq5k")
count = 14
metadata/_custom_type_script = "uid://mv6k4s5wf52h"
[resource]
script = ExtResource("1_8jwj0")
slots = Array[ExtResource("2_yctcd")]([SubResource("Resource_7tu70"), null, null, SubResource("Resource_mrqgh"), null, SubResource("Resource_jwwx0"), null, null, null, null, null, null, null, null, null, SubResource("Resource_1cv4e"), null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null])
metadata/_custom_type_script = "uid://dila5f4tuiun1"
+11
View File
@@ -0,0 +1,11 @@
[gd_resource type="Resource" script_class="ItemDataGD" format=3 uid="uid://cqyo3lbguv5hg"]
[ext_resource type="Texture2D" uid="uid://bgam5s5hw83cf" path="res://Inventory/Textures/Apple.png" id="1_b3dgm"]
[ext_resource type="Script" uid="uid://b8cygu5gimsgi" path="res://Inventory/GDScript/ItemDataGD.gd" id="1_sdqjv"]
[resource]
script = ExtResource("1_sdqjv")
id = "1"
display_name = "Apple"
icon = ExtResource("1_b3dgm")
metadata/_custom_type_script = "uid://b8cygu5gimsgi"
+22
View File
@@ -0,0 +1,22 @@
[gd_resource type="Resource" script_class="Inventory" format=3 uid="uid://bdnml67fnkqw2"]
[ext_resource type="Script" uid="uid://7dsydoyjsley" path="res://Inventory/CSharp/Inventory.cs" id="1_0mvht"]
[ext_resource type="Resource" uid="uid://d0w7bxo6cotsc" path="res://Inventory/Resources/CSharpItemApple.tres" id="1_twj40"]
[ext_resource type="Script" uid="uid://c61uo84g0gp1v" path="res://Inventory/CSharp/InventorySlotData.cs" id="2_55fp8"]
[sub_resource type="Resource" id="Resource_qjyhv"]
script = ExtResource("2_55fp8")
Item = ExtResource("1_twj40")
Count = 32
metadata/_custom_type_script = "uid://c61uo84g0gp1v"
[sub_resource type="Resource" id="Resource_6dau2"]
script = ExtResource("2_55fp8")
Item = ExtResource("1_twj40")
Count = 12
metadata/_custom_type_script = "uid://c61uo84g0gp1v"
[resource]
script = ExtResource("1_0mvht")
Slots = Array[Resource]([null, null, null, null, SubResource("Resource_qjyhv"), null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, SubResource("Resource_6dau2"), null, null, null, null, null, null, null, null, null])
metadata/_custom_type_script = "uid://7dsydoyjsley"
File diff suppressed because it is too large Load Diff
Binary file not shown.

After

Width:  |  Height:  |  Size: 296 B

+40
View File
@@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bgam5s5hw83cf"
path="res://.godot/imported/Apple.png-d164bb800f362dfbf6df55c5ab1627cc.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Inventory/Textures/Apple.png"
dest_files=["res://.godot/imported/Apple.png-d164bb800f362dfbf6df55c5ab1627cc.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
File diff suppressed because it is too large Load Diff
+13
View File
@@ -0,0 +1,13 @@
extends Control
class_name InventoryControllerGD
@export var inventory : InventoryGD
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
# Obtain all InventorySlot objects and initialize with an index
var inventory_slots = get_tree().get_nodes_in_group("inventory_slots")
for i in inventory_slots.size():
var slot = inventory_slots[i]
slot.initialize_slot(i, inventory)
+1
View File
@@ -0,0 +1 @@
uid://badvl1uwl3bpa
+15
View File
@@ -0,0 +1,15 @@
using Godot;
using System;
public partial class TestScript : Control
{
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
}
}
+1
View File
@@ -0,0 +1 @@
uid://ci8owg3kuimrf
+1 -1
View File
@@ -1,4 +1,4 @@
<Project Sdk="Godot.NET.Sdk/4.6.0">
<Project Sdk="Godot.NET.Sdk/4.7.2">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework Condition=" '$(GodotTargetPlatform)' == 'android' ">net9.0</TargetFramework>
+7
View File
@@ -0,0 +1,7 @@
<Project Sdk="Godot.NET.Sdk/4.6.0">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework Condition=" '$(GodotTargetPlatform)' == 'android' ">net9.0</TargetFramework>
<EnableDynamicLoading>true</EnableDynamicLoading>
</PropertyGroup>
</Project>
+7
View File
@@ -0,0 +1,7 @@
<Project Sdk="Godot.NET.Sdk/4.6.2">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework Condition=" '$(GodotTargetPlatform)' == 'android' ">net9.0</TargetFramework>
<EnableDynamicLoading>true</EnableDynamicLoading>
</PropertyGroup>
</Project>
+6
View File
@@ -18,6 +18,8 @@ dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.cte
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
@@ -25,6 +27,10 @@ mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
+6 -1
View File
@@ -16,9 +16,14 @@ compatibility/default_parent_skeleton_in_mesh_instance_3d=true
config/name="Tutorials"
run/main_scene="uid://c2e6p1udf2nyi"
config/features=PackedStringArray("4.6", "C#")
config/features=PackedStringArray("4.7", "C#")
config/icon="res://icon.svg"
[display]
window/size/viewport_width=1265
window/size/viewport_height=712
[dotnet]
project/assembly_name="Tutorials"