From b799c326e5737284f40404e6838e9a183f6a8663 Mon Sep 17 00:00:00 2001 From: Dragon20C Date: Tue, 6 May 2025 09:37:34 +0100 Subject: [PATCH 1/9] Initial loading items complete Items will load from a dictionary (in the future a Json file) --- assets/ui/inventory_ui/ExitButton.svg | 1 + assets/ui/inventory_ui/ExitButton.svg.import | 37 +++++++ resources/Items/Bandage.tres | 14 +++ resources/Items/Gernade.tres | 14 +++ resources/Items/HealthPack.tres | 14 +++ resources/Items/Rifle.tres | 14 +++ resources/item_database.tres | 18 ++++ scenes/inventory_system/slot.tscn | 36 +++++++ scenes/loader.tscn | 2 + scenes/menus/inventory_menu.tscn | 98 +++++++++++++++++++ scripts/global/manager.gd | 6 +- scripts/inventory_system/classes/inv_item.gd | 19 ++++ .../inventory_system/classes/inv_item.gd.uid | 1 + .../classes/inventory_container.gd | 74 ++++++++++++++ .../classes/inventory_container.gd.uid | 1 + .../classes/inventory_manager.gd | 11 +++ .../classes/inventory_manager.gd.uid | 1 + .../inventory_system/classes/item_database.gd | 4 + .../classes/item_database.gd.uid | 1 + .../inventory_system/classes/item_resource.gd | 8 ++ .../classes/item_resource.gd.uid | 1 + scripts/inventory_system/classes/slot.gd | 13 +++ scripts/inventory_system/classes/slot.gd.uid | 1 + scripts/menus/inventory_menu.gd | 32 ++++++ scripts/menus/inventory_menu.gd.uid | 1 + 25 files changed, 420 insertions(+), 2 deletions(-) create mode 100644 assets/ui/inventory_ui/ExitButton.svg create mode 100644 assets/ui/inventory_ui/ExitButton.svg.import create mode 100644 resources/Items/Bandage.tres create mode 100644 resources/Items/Gernade.tres create mode 100644 resources/Items/HealthPack.tres create mode 100644 resources/Items/Rifle.tres create mode 100644 resources/item_database.tres create mode 100644 scenes/inventory_system/slot.tscn create mode 100644 scenes/menus/inventory_menu.tscn create mode 100644 scripts/inventory_system/classes/inv_item.gd create mode 100644 scripts/inventory_system/classes/inv_item.gd.uid create mode 100644 scripts/inventory_system/classes/inventory_container.gd create mode 100644 scripts/inventory_system/classes/inventory_container.gd.uid create mode 100644 scripts/inventory_system/classes/inventory_manager.gd create mode 100644 scripts/inventory_system/classes/inventory_manager.gd.uid create mode 100644 scripts/inventory_system/classes/item_database.gd create mode 100644 scripts/inventory_system/classes/item_database.gd.uid create mode 100644 scripts/inventory_system/classes/item_resource.gd create mode 100644 scripts/inventory_system/classes/item_resource.gd.uid create mode 100644 scripts/inventory_system/classes/slot.gd create mode 100644 scripts/inventory_system/classes/slot.gd.uid create mode 100644 scripts/menus/inventory_menu.gd create mode 100644 scripts/menus/inventory_menu.gd.uid diff --git a/assets/ui/inventory_ui/ExitButton.svg b/assets/ui/inventory_ui/ExitButton.svg new file mode 100644 index 0000000..a9dde87 --- /dev/null +++ b/assets/ui/inventory_ui/ExitButton.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/assets/ui/inventory_ui/ExitButton.svg.import b/assets/ui/inventory_ui/ExitButton.svg.import new file mode 100644 index 0000000..ae20110 --- /dev/null +++ b/assets/ui/inventory_ui/ExitButton.svg.import @@ -0,0 +1,37 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://yorwmxguj5ob" +path="res://.godot/imported/ExitButton.svg-a9d95da04deed76cf55df31e2664f20c.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/ui/inventory_ui/ExitButton.svg" +dest_files=["res://.godot/imported/ExitButton.svg-a9d95da04deed76cf55df31e2664f20c.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=true +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +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 +svg/scale=2.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/resources/Items/Bandage.tres b/resources/Items/Bandage.tres new file mode 100644 index 0000000..1dbafdc --- /dev/null +++ b/resources/Items/Bandage.tres @@ -0,0 +1,14 @@ +[gd_resource type="Resource" script_class="Item" load_steps=3 format=3 uid="uid://cfhr0sg8bfjm4"] + +[ext_resource type="Script" uid="uid://dtx3xrtjsr0sa" path="res://scripts/inventory_system/classes/item_resource.gd" id="1_h77xr"] +[ext_resource type="Texture2D" uid="uid://b05hj6ognkfqi" path="res://assets/icon.svg" id="1_t08m0"] + +[resource] +script = ExtResource("1_h77xr") +item_name = "Bandage" +item_description = "Stops bleeding " +id = 0 +stackable = true +max_stackable = 6 +item_texture = ExtResource("1_t08m0") +metadata/_custom_type_script = "uid://dtx3xrtjsr0sa" diff --git a/resources/Items/Gernade.tres b/resources/Items/Gernade.tres new file mode 100644 index 0000000..43f7ab3 --- /dev/null +++ b/resources/Items/Gernade.tres @@ -0,0 +1,14 @@ +[gd_resource type="Resource" script_class="Item" load_steps=3 format=3 uid="uid://31es6aujwcn1"] + +[ext_resource type="Script" uid="uid://dtx3xrtjsr0sa" path="res://scripts/inventory_system/classes/item_resource.gd" id="1_2o47v"] +[ext_resource type="Texture2D" uid="uid://b05hj6ognkfqi" path="res://assets/icon.svg" id="1_vo7bo"] + +[resource] +script = ExtResource("1_2o47v") +item_name = "Gernade" +item_description = "Does explosive damage to an area" +id = 1 +stackable = true +max_stackable = 4 +item_texture = ExtResource("1_vo7bo") +metadata/_custom_type_script = "uid://dtx3xrtjsr0sa" diff --git a/resources/Items/HealthPack.tres b/resources/Items/HealthPack.tres new file mode 100644 index 0000000..f0fd641 --- /dev/null +++ b/resources/Items/HealthPack.tres @@ -0,0 +1,14 @@ +[gd_resource type="Resource" script_class="Item" load_steps=3 format=3 uid="uid://cudho7h14sjr4"] + +[ext_resource type="Script" uid="uid://dtx3xrtjsr0sa" path="res://scripts/inventory_system/classes/item_resource.gd" id="1_hjc62"] +[ext_resource type="Texture2D" uid="uid://b05hj6ognkfqi" path="res://assets/icon.svg" id="1_xtv8e"] + +[resource] +script = ExtResource("1_hjc62") +item_name = "HealthPack" +item_description = "Heals the player for a small amount but does not fix wounds" +id = 2 +stackable = false +max_stackable = 1 +item_texture = ExtResource("1_xtv8e") +metadata/_custom_type_script = "uid://dtx3xrtjsr0sa" diff --git a/resources/Items/Rifle.tres b/resources/Items/Rifle.tres new file mode 100644 index 0000000..6c20cfa --- /dev/null +++ b/resources/Items/Rifle.tres @@ -0,0 +1,14 @@ +[gd_resource type="Resource" script_class="Item" load_steps=3 format=3 uid="uid://dborkiydh6s2c"] + +[ext_resource type="Texture2D" uid="uid://b05hj6ognkfqi" path="res://assets/icon.svg" id="1_7vojk"] +[ext_resource type="Script" uid="uid://dtx3xrtjsr0sa" path="res://scripts/inventory_system/classes/item_resource.gd" id="1_stogv"] + +[resource] +script = ExtResource("1_stogv") +item_name = "Rifle" +item_description = "Fight off your enemies!" +id = 3 +stackable = false +max_stackable = 1 +item_texture = ExtResource("1_7vojk") +metadata/_custom_type_script = "uid://dtx3xrtjsr0sa" diff --git a/resources/item_database.tres b/resources/item_database.tres new file mode 100644 index 0000000..c219b0b --- /dev/null +++ b/resources/item_database.tres @@ -0,0 +1,18 @@ +[gd_resource type="Resource" script_class="ItemDatabase" load_steps=7 format=3 uid="uid://bjmr6gmi6bxog"] + +[ext_resource type="Script" uid="uid://dtx3xrtjsr0sa" path="res://scripts/inventory_system/classes/item_resource.gd" id="1_yiash"] +[ext_resource type="Script" uid="uid://drjden62jh6oe" path="res://scripts/inventory_system/classes/item_database.gd" id="2_bb8ke"] +[ext_resource type="Resource" uid="uid://cfhr0sg8bfjm4" path="res://resources/Items/Bandage.tres" id="2_vjx7s"] +[ext_resource type="Resource" uid="uid://31es6aujwcn1" path="res://resources/Items/Gernade.tres" id="3_ef8je"] +[ext_resource type="Resource" uid="uid://cudho7h14sjr4" path="res://resources/Items/HealthPack.tres" id="4_2s1r4"] +[ext_resource type="Resource" uid="uid://dborkiydh6s2c" path="res://resources/Items/Rifle.tres" id="5_3c7v2"] + +[resource] +script = ExtResource("2_bb8ke") +database = Dictionary[int, ExtResource("1_yiash")]({ +0: ExtResource("2_vjx7s"), +1: ExtResource("3_ef8je"), +2: ExtResource("4_2s1r4"), +3: ExtResource("5_3c7v2") +}) +metadata/_custom_type_script = "uid://drjden62jh6oe" diff --git a/scenes/inventory_system/slot.tscn b/scenes/inventory_system/slot.tscn new file mode 100644 index 0000000..3dde682 --- /dev/null +++ b/scenes/inventory_system/slot.tscn @@ -0,0 +1,36 @@ +[gd_scene load_steps=6 format=3 uid="uid://b7i7rt41oe7vk"] + +[ext_resource type="Texture2D" uid="uid://b4cl313lwqp7m" path="res://assets/ui/inventory_ui/InventorySlot64x64.png" id="1_65pqo"] +[ext_resource type="Script" uid="uid://6vjak2yutoxw" path="res://scripts/inventory_system/classes/slot.gd" id="1_cfmsa"] +[ext_resource type="Texture2D" uid="uid://c204tk0m0rfpn" path="res://assets/ui/inventory_ui/InventorySlotSelected64x64.png" id="3_87dan"] +[ext_resource type="Texture2D" uid="uid://ti4qvgtc55lp" path="res://assets/ui/inventory_ui/InventorySlotUsed64x64.png" id="4_7odv4"] + +[sub_resource type="StyleBoxTexture" id="StyleBoxTexture_nn0qy"] +texture = ExtResource("1_65pqo") +texture_margin_left = 10.0 +texture_margin_top = 10.0 +texture_margin_right = 10.0 +texture_margin_bottom = 10.0 + +[node name="Slot" type="PanelContainer"] +custom_minimum_size = Vector2(64, 64) +anchors_preset = -1 +anchor_right = 0.065625 +anchor_bottom = 0.116667 +offset_right = -20.0 +offset_bottom = -20.0 +theme_override_styles/panel = SubResource("StyleBoxTexture_nn0qy") +script = ExtResource("1_cfmsa") +metadata/_edit_use_anchors_ = true + +[node name="Button" type="TextureButton" parent="."] +layout_mode = 2 +texture_pressed = ExtResource("3_87dan") +texture_hover = ExtResource("4_7odv4") + +[node name="Icon" type="TextureRect" parent="."] +custom_minimum_size = Vector2(48, 48) +layout_mode = 2 +mouse_filter = 2 +expand_mode = 1 +stretch_mode = 5 diff --git a/scenes/loader.tscn b/scenes/loader.tscn index e79d4be..738b709 100644 --- a/scenes/loader.tscn +++ b/scenes/loader.tscn @@ -3,8 +3,10 @@ [node name="CanvasLayer" type="CanvasLayer"] [node name="ProgressBar" type="ProgressBar" parent="."] +visible = false anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 +mouse_filter = 2 diff --git a/scenes/menus/inventory_menu.tscn b/scenes/menus/inventory_menu.tscn new file mode 100644 index 0000000..20096bb --- /dev/null +++ b/scenes/menus/inventory_menu.tscn @@ -0,0 +1,98 @@ +[gd_scene load_steps=7 format=3 uid="uid://kwglhhfyum7a"] + +[ext_resource type="Script" uid="uid://c8126ok62de4e" path="res://scripts/menus/inventory_menu.gd" id="1_egj0w"] +[ext_resource type="Resource" uid="uid://bjmr6gmi6bxog" path="res://resources/item_database.tres" id="2_e31cf"] +[ext_resource type="Texture2D" uid="uid://dqwlq3g4qvkcb" path="res://assets/ui/panels/BLueTransparentPanel64x64.png" id="2_v0b1f"] +[ext_resource type="Texture2D" uid="uid://yorwmxguj5ob" path="res://assets/ui/inventory_ui/ExitButton.svg" id="3_xcp4r"] + +[sub_resource type="StyleBoxTexture" id="StyleBoxTexture_xcp4r"] +texture = ExtResource("2_v0b1f") +texture_margin_left = 10.0 +texture_margin_top = 10.0 +texture_margin_right = 10.0 +texture_margin_bottom = 10.0 +axis_stretch_horizontal = 1 +axis_stretch_vertical = 1 + +[sub_resource type="StyleBoxTexture" id="StyleBoxTexture_v0b1f"] +texture = ExtResource("2_v0b1f") +texture_margin_left = 10.0 +texture_margin_top = 10.0 +texture_margin_right = 10.0 +texture_margin_bottom = 10.0 +axis_stretch_horizontal = 1 +axis_stretch_vertical = 1 + +[node name="InventoryMenu" type="Control" node_paths=PackedStringArray("grid_container")] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_egj0w") +database = ExtResource("2_e31cf") +grid_container = NodePath("PanelContainer/MarginContainer/GridContainer") + +[node name="PanelContainer" type="PanelContainer" parent="."] +layout_mode = 1 +anchors_preset = -1 +anchor_left = 0.46875 +anchor_top = 0.444444 +anchor_right = 0.53125 +anchor_bottom = 0.555556 +offset_left = 20.0 +offset_top = 20.0 +offset_right = -20.0 +offset_bottom = -20.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_styles/panel = SubResource("StyleBoxTexture_xcp4r") +metadata/_edit_use_anchors_ = true + +[node name="MarginContainer" type="MarginContainer" parent="PanelContainer"] +layout_mode = 2 +theme_override_constants/margin_left = 30 +theme_override_constants/margin_top = 30 +theme_override_constants/margin_right = 30 +theme_override_constants/margin_bottom = 30 + +[node name="GridContainer" type="GridContainer" parent="PanelContainer/MarginContainer"] +layout_mode = 2 +columns = 4 + +[node name="Title" type="PanelContainer" parent="."] +layout_mode = 1 +anchors_preset = -1 +anchor_left = 0.355469 +anchor_top = 0.0388889 +anchor_right = 0.644531 +anchor_bottom = 0.130556 +grow_horizontal = 2 +theme_override_styles/panel = SubResource("StyleBoxTexture_v0b1f") +metadata/_edit_use_anchors_ = true + +[node name="Label" type="Label" parent="Title"] +layout_mode = 2 +size_flags_vertical = 1 +theme_override_font_sizes/font_size = 32 +text = "INVENTORY" +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="ExitButton" type="TextureButton" parent="."] +layout_mode = 1 +anchors_preset = -1 +anchor_left = 0.917969 +anchor_top = 0.0527778 +anchor_right = 0.967969 +anchor_bottom = 0.141667 +offset_right = 64.0 +offset_bottom = 64.0 +grow_horizontal = 0 +scale = Vector2(0.5, 0.5) +texture_normal = ExtResource("3_xcp4r") +stretch_mode = 5 +metadata/_edit_use_anchors_ = true + +[connection signal="pressed" from="ExitButton" to="." method="_on_exit_button_pressed"] diff --git a/scripts/global/manager.gd b/scripts/global/manager.gd index c5b8eab..81e4a5f 100644 --- a/scripts/global/manager.gd +++ b/scripts/global/manager.gd @@ -3,7 +3,8 @@ class_name Manager ## GameManager that handles loading and spawning scenes ## e.g Player, world scene and more. - +# temporary leaving inventory in a global script (I dont know if this is a good place or not) +var player_inventory : Array const loading_scene: String = "res://scenes/loader.tscn" ## path to the loading screen var loader: ProgressBar ## loading screen progress @@ -30,7 +31,8 @@ func _ready() -> void: add_scene("res://scenes/main/main.tscn", Keys.main) add_child(preload(loading_scene).instantiate()) loader = get_child(0).get_child(0) - spawn_scene(Keys.main) + # temporary disabled the menu to focus on working on the inventory system + #spawn_scene(Keys.main) ## adds scene path to dictionary with assignes key func add_scene(scene : String, key : Keys) -> void: diff --git a/scripts/inventory_system/classes/inv_item.gd b/scripts/inventory_system/classes/inv_item.gd new file mode 100644 index 0000000..69f4daf --- /dev/null +++ b/scripts/inventory_system/classes/inv_item.gd @@ -0,0 +1,19 @@ +extends RefCounted +class_name InvItem + + +# the top left of the item/slot +var origin : Vector2i = Vector2i(-1,-1) + +var id : int = -1 +var stackable : bool = false +var stack : int = -1 +var icon : Texture2D +var object : Node2D + +func _init(_origin : Vector2i,_id : int, item : Item) -> void: + origin = _origin + id = _id + stackable = item.stackable + stack = 1 + icon = item.item_texture diff --git a/scripts/inventory_system/classes/inv_item.gd.uid b/scripts/inventory_system/classes/inv_item.gd.uid new file mode 100644 index 0000000..38bd9b4 --- /dev/null +++ b/scripts/inventory_system/classes/inv_item.gd.uid @@ -0,0 +1 @@ +uid://c6l12gx17r28o diff --git a/scripts/inventory_system/classes/inventory_container.gd b/scripts/inventory_system/classes/inventory_container.gd new file mode 100644 index 0000000..4cfc955 --- /dev/null +++ b/scripts/inventory_system/classes/inventory_container.gd @@ -0,0 +1,74 @@ +extends RefCounted +class_name InventoryContainer + +signal slot_pressed(id : int , index : Vector2i) + +var _slots : Dictionary[Vector2i,Slot] +var _item : Dictionary[Vector2i,InvItem] +var _size : Vector2i +var _id : int +var _container : GridContainer +const _spacing : float = 64 + + +func _init(container : GridContainer,size : Vector2i) -> void: + _container = container + _size = size + +func set_id(id : int) -> void: + _id = id + +func generate_cells() -> void: + _container.columns = _size.x + var slot_pack : PackedScene = preload("res://scenes/inventory_system/slot.tscn") + + for x in range(_size.x): + for y in range(_size.y): + var slot : Slot = slot_pack.instantiate() + _container.add_child(slot) + + # setup the signals + slot.button.pressed.connect(slot_is_pressed.bind(slot)) + + # set the slots index and inv id + slot.index = Vector2i(x,y) + ## this might be useful for detecting multiple different inventories + #slot.inventory_id = _id + # set slot into the slots dict to be able to change the item sprite + _slots[slot.index] = slot + # set the index into the items dict and set it to null to indicate its empty + _item[slot.index] = null + +func slot_is_pressed(slot : Slot) -> void: + slot_pressed.emit(_id,slot.index) + +func is_cell_free(index : Vector2i) -> bool: + if not _item.has(index): + return false + + return _item[index] == null + +func add_item(inv_item : InvItem) -> bool: + var index : Vector2i = inv_item.origin + + if not is_cell_free(index): + return false + + # set item and item icon + _item[index] = inv_item + _slots[index].set_icon(inv_item.icon) + + return true + +func remove_item(inv_item : InvItem) -> void: + var index : Vector2i = inv_item.origin + _item[index] = null + _slots[index].set_icon(null) + +func load_data(items : Array[Dictionary],database : ItemDatabase) -> void: + + for item in items: + var found_item : Item = database.database[item["ID"]] + + var inv_item : InvItem = InvItem.new(item["Position"],item["ID"],found_item) + add_item(inv_item) diff --git a/scripts/inventory_system/classes/inventory_container.gd.uid b/scripts/inventory_system/classes/inventory_container.gd.uid new file mode 100644 index 0000000..8a1d857 --- /dev/null +++ b/scripts/inventory_system/classes/inventory_container.gd.uid @@ -0,0 +1 @@ +uid://4fgvjlk334rv diff --git a/scripts/inventory_system/classes/inventory_manager.gd b/scripts/inventory_system/classes/inventory_manager.gd new file mode 100644 index 0000000..fae2c76 --- /dev/null +++ b/scripts/inventory_system/classes/inventory_manager.gd @@ -0,0 +1,11 @@ +extends Node + + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + pass diff --git a/scripts/inventory_system/classes/inventory_manager.gd.uid b/scripts/inventory_system/classes/inventory_manager.gd.uid new file mode 100644 index 0000000..b3940f6 --- /dev/null +++ b/scripts/inventory_system/classes/inventory_manager.gd.uid @@ -0,0 +1 @@ +uid://bqo0ptn54lesw diff --git a/scripts/inventory_system/classes/item_database.gd b/scripts/inventory_system/classes/item_database.gd new file mode 100644 index 0000000..9379e02 --- /dev/null +++ b/scripts/inventory_system/classes/item_database.gd @@ -0,0 +1,4 @@ +extends Resource +class_name ItemDatabase + +@export var database : Dictionary[int,Item] diff --git a/scripts/inventory_system/classes/item_database.gd.uid b/scripts/inventory_system/classes/item_database.gd.uid new file mode 100644 index 0000000..62175c4 --- /dev/null +++ b/scripts/inventory_system/classes/item_database.gd.uid @@ -0,0 +1 @@ +uid://drjden62jh6oe diff --git a/scripts/inventory_system/classes/item_resource.gd b/scripts/inventory_system/classes/item_resource.gd new file mode 100644 index 0000000..5f74e92 --- /dev/null +++ b/scripts/inventory_system/classes/item_resource.gd @@ -0,0 +1,8 @@ +extends Resource +class_name Item + +@export var item_name : String +@export_multiline var item_description : String +@export var stackable : bool = false +@export var max_stackable : int = 4 +@export var item_texture : Texture2D diff --git a/scripts/inventory_system/classes/item_resource.gd.uid b/scripts/inventory_system/classes/item_resource.gd.uid new file mode 100644 index 0000000..bf719ce --- /dev/null +++ b/scripts/inventory_system/classes/item_resource.gd.uid @@ -0,0 +1 @@ +uid://dtx3xrtjsr0sa diff --git a/scripts/inventory_system/classes/slot.gd b/scripts/inventory_system/classes/slot.gd new file mode 100644 index 0000000..bd99e33 --- /dev/null +++ b/scripts/inventory_system/classes/slot.gd @@ -0,0 +1,13 @@ +extends PanelContainer +class_name Slot + +var index :Vector2i + +@onready var icon : TextureRect = get_node("Icon") +@onready var button : TextureButton = get_node("Button") + +func set_icon(texture : Texture2D) -> void: + if not icon: + return + + icon.texture = texture diff --git a/scripts/inventory_system/classes/slot.gd.uid b/scripts/inventory_system/classes/slot.gd.uid new file mode 100644 index 0000000..14b9646 --- /dev/null +++ b/scripts/inventory_system/classes/slot.gd.uid @@ -0,0 +1 @@ +uid://6vjak2yutoxw diff --git a/scripts/menus/inventory_menu.gd b/scripts/menus/inventory_menu.gd new file mode 100644 index 0000000..230d6e7 --- /dev/null +++ b/scripts/menus/inventory_menu.gd @@ -0,0 +1,32 @@ +extends MenuBase + +@export_group("Settings") +@export var database : ItemDatabase +@export var grid_container : GridContainer +@export var inventory_size : Vector2i = Vector2i(8,6) + +var inventory : InventoryContainer + +func _ready() -> void: + inventory = InventoryContainer.new(grid_container,inventory_size) + # This setting of id should be dynamic to include other external inventories e.g chests, lockers + # currently its not. + inventory.set_id(0) + inventory.generate_cells() + + # Temp for testing items in the inventory, should be a global thing + var items : Array[Dictionary] = [ + {"ID" : 0, "Position" : Vector2i(0,0)}, + {"ID" : 3, "Position" : Vector2i(4,1)}, + {"ID" : 2, "Position" : Vector2i(5,0)}, + {"ID" : 1, "Position" : Vector2i(2,4)} + ] + + inventory.load_data(items,database) + inventory.slot_pressed.connect(on_slot_pressed) + +func on_slot_pressed(id : int,index : Vector2i) -> void: + print("Inventory (%s) was pressed at (%s)" % [id, index]) + +func _on_exit_button_pressed() -> void: + menu_manager.switch_to_previous_menu() diff --git a/scripts/menus/inventory_menu.gd.uid b/scripts/menus/inventory_menu.gd.uid new file mode 100644 index 0000000..c89b67c --- /dev/null +++ b/scripts/menus/inventory_menu.gd.uid @@ -0,0 +1 @@ +uid://c8126ok62de4e From 86807b79b165972e75c731feaebd890af0e20e62 Mon Sep 17 00:00:00 2001 From: Dragon20C Date: Wed, 14 May 2025 09:38:48 +0100 Subject: [PATCH 2/9] pick up and drop items. added the ability to pick up and drop items, it also shows the player dragging the items around. --- project.godot | 1 + scenes/menus/inventory_menu.tscn | 10 +- scripts/global/inventory_manager.gd | 36 +++++++ scripts/global/inventory_manager.gd.uid | 1 + .../classes/inventory_container.gd | 9 +- scripts/menus/inventory_menu.gd | 93 +++++++++++++++---- 6 files changed, 128 insertions(+), 22 deletions(-) create mode 100644 scripts/global/inventory_manager.gd create mode 100644 scripts/global/inventory_manager.gd.uid diff --git a/project.godot b/project.godot index dfab5e5..32e8637 100644 --- a/project.godot +++ b/project.godot @@ -18,6 +18,7 @@ config/icon="res://assets/icon.svg" [autoload] GameManager="*res://scripts/global/manager.gd" +InventoryManager="*res://scripts/global/inventory_manager.gd" [display] diff --git a/scenes/menus/inventory_menu.tscn b/scenes/menus/inventory_menu.tscn index 20096bb..26424c9 100644 --- a/scenes/menus/inventory_menu.tscn +++ b/scenes/menus/inventory_menu.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=7 format=3 uid="uid://kwglhhfyum7a"] +[gd_scene load_steps=8 format=3 uid="uid://kwglhhfyum7a"] [ext_resource type="Script" uid="uid://c8126ok62de4e" path="res://scripts/menus/inventory_menu.gd" id="1_egj0w"] [ext_resource type="Resource" uid="uid://bjmr6gmi6bxog" path="res://resources/item_database.tres" id="2_e31cf"] [ext_resource type="Texture2D" uid="uid://dqwlq3g4qvkcb" path="res://assets/ui/panels/BLueTransparentPanel64x64.png" id="2_v0b1f"] [ext_resource type="Texture2D" uid="uid://yorwmxguj5ob" path="res://assets/ui/inventory_ui/ExitButton.svg" id="3_xcp4r"] +[ext_resource type="Texture2D" uid="uid://b05hj6ognkfqi" path="res://assets/icon.svg" id="5_ml676"] [sub_resource type="StyleBoxTexture" id="StyleBoxTexture_xcp4r"] texture = ExtResource("2_v0b1f") @@ -23,7 +24,7 @@ texture_margin_bottom = 10.0 axis_stretch_horizontal = 1 axis_stretch_vertical = 1 -[node name="InventoryMenu" type="Control" node_paths=PackedStringArray("grid_container")] +[node name="InventoryMenu" type="Control" node_paths=PackedStringArray("grid_container", "held_icon")] layout_mode = 3 anchors_preset = 15 anchor_right = 1.0 @@ -33,6 +34,7 @@ grow_vertical = 2 script = ExtResource("1_egj0w") database = ExtResource("2_e31cf") grid_container = NodePath("PanelContainer/MarginContainer/GridContainer") +held_icon = NodePath("HeldIcon") [node name="PanelContainer" type="PanelContainer" parent="."] layout_mode = 1 @@ -95,4 +97,8 @@ texture_normal = ExtResource("3_xcp4r") stretch_mode = 5 metadata/_edit_use_anchors_ = true +[node name="HeldIcon" type="Sprite2D" parent="."] +scale = Vector2(0.5, 0.5) +texture = ExtResource("5_ml676") + [connection signal="pressed" from="ExitButton" to="." method="_on_exit_button_pressed"] diff --git a/scripts/global/inventory_manager.gd b/scripts/global/inventory_manager.gd new file mode 100644 index 0000000..78f3d1f --- /dev/null +++ b/scripts/global/inventory_manager.gd @@ -0,0 +1,36 @@ +extends Node +## Inventory manager, handles storing the inventory in a global space + +var inventories : Dictionary[int,InventoryContainer] +var next_id : int = -1 + +## Player related +var inventory_size : Vector2i = Vector2i(8,6) +var player_inv : InventoryContainer +# this might change in the future for a better way of storing items +var player_items : Array[Dictionary] = [ + # ID is the item id, Position is the slot index, can add stack size here as well + {"ID" : 0, "Position" : Vector2i(0,0)}, + {"ID" : 3, "Position" : Vector2i(4,1)}, + {"ID" : 2, "Position" : Vector2i(5,0)}, + {"ID" : 1, "Position" : Vector2i(2,4)} + ] + +func _ready() -> void: + player_inv = InventoryContainer.new(inventory_size) + player_inv.set_id(register_inventory(player_inv)) + + +func register_inventory(inventory : InventoryContainer) -> int: + next_id += 1 + + inventories[next_id] = inventory + + return next_id + +# maybe in the future save logic could be here when an inventory is not in use +func unregister_inventory(id : int) -> void: + inventories.erase(id) + +func get_inventory(id : int) -> InventoryContainer: + return inventories.get(id) diff --git a/scripts/global/inventory_manager.gd.uid b/scripts/global/inventory_manager.gd.uid new file mode 100644 index 0000000..d342241 --- /dev/null +++ b/scripts/global/inventory_manager.gd.uid @@ -0,0 +1 @@ +uid://btf1dgftkhmmy diff --git a/scripts/inventory_system/classes/inventory_container.gd b/scripts/inventory_system/classes/inventory_container.gd index 4cfc955..d6078f2 100644 --- a/scripts/inventory_system/classes/inventory_container.gd +++ b/scripts/inventory_system/classes/inventory_container.gd @@ -11,14 +11,14 @@ var _container : GridContainer const _spacing : float = 64 -func _init(container : GridContainer,size : Vector2i) -> void: - _container = container +func _init(size : Vector2i) -> void: _size = size func set_id(id : int) -> void: _id = id -func generate_cells() -> void: +func generate_cells(container : GridContainer) -> void: + _container = container _container.columns = _size.x var slot_pack : PackedScene = preload("res://scenes/inventory_system/slot.tscn") @@ -65,6 +65,9 @@ func remove_item(inv_item : InvItem) -> void: _item[index] = null _slots[index].set_icon(null) +func get_item(index : Vector2i) -> InvItem: + return _item[index] + func load_data(items : Array[Dictionary],database : ItemDatabase) -> void: for item in items: diff --git a/scripts/menus/inventory_menu.gd b/scripts/menus/inventory_menu.gd index 230d6e7..1eb2309 100644 --- a/scripts/menus/inventory_menu.gd +++ b/scripts/menus/inventory_menu.gd @@ -4,29 +4,88 @@ extends MenuBase @export var database : ItemDatabase @export var grid_container : GridContainer @export var inventory_size : Vector2i = Vector2i(8,6) +@export var held_icon : Sprite2D + +enum states {Empty,Held,Drop,PickUp} +var current_state : states = states.Empty + +var inventories : Dictionary[int,InventoryContainer] var inventory : InventoryContainer +var held_item : InvItem +var current_id : int +var current_index : Vector2i + func _ready() -> void: - inventory = InventoryContainer.new(grid_container,inventory_size) - # This setting of id should be dynamic to include other external inventories e.g chests, lockers - # currently its not. - inventory.set_id(0) - inventory.generate_cells() - - # Temp for testing items in the inventory, should be a global thing - var items : Array[Dictionary] = [ - {"ID" : 0, "Position" : Vector2i(0,0)}, - {"ID" : 3, "Position" : Vector2i(4,1)}, - {"ID" : 2, "Position" : Vector2i(5,0)}, - {"ID" : 1, "Position" : Vector2i(2,4)} - ] - - inventory.load_data(items,database) - inventory.slot_pressed.connect(on_slot_pressed) + var player_inv : InventoryContainer = _get_inventory(0) # 0 is the players inv + player_inv.generate_cells(grid_container) + # we need to generate the cells before we can load data, might not be the right way... + player_inv.load_data(InventoryManager.player_items,database) + # connect the slot pressed signal to a function in this script + player_inv.slot_pressed.connect(on_slot_pressed) + +func _process(delta: float) -> void: + handle_state_update() func on_slot_pressed(id : int,index : Vector2i) -> void: - print("Inventory (%s) was pressed at (%s)" % [id, index]) + handle_state_transition(id,index) + #print("Inventory (%s) was pressed at (%s)" % [id, index]) func _on_exit_button_pressed() -> void: menu_manager.switch_to_previous_menu() + +## Handles logic that needs to be run constantly like moving a held item or checking if a pop up should show up +func handle_state_update() -> void: + match current_state: + states.Empty: + pass + states.Held: + held_icon.global_position = get_global_mouse_position() + states.Drop: + # grab the inventory + var inv : InventoryContainer = _get_inventory(current_id) + # empty the held_icon and reset position + held_icon.global_position = Vector2(0,0) + held_icon.texture = null + # update the held items origin index if we dont it returns to the previous index + held_item.origin = current_index + # add the item from the previous inventory + inv.add_item(held_item) + # change the state to held + current_state = states.Empty + states.PickUp: + # grab the inventory + var inv : InventoryContainer = _get_inventory(current_id) + # set the item to the held_item + held_item = inv.get_item(current_index) + # set the texture from the held item + held_icon.texture = held_item.icon + # remove the item from the previous inventory + inv.remove_item(held_item) + # change the state to held + current_state = states.Held + +## Handles the logic in each state e.g empty state you can pick up an item +func handle_state_transition(id: int, index : Vector2i) -> void: + match current_state: + states.Empty: + var inv : InventoryContainer = _get_inventory(id) + if not inv.is_cell_free(index): # Check if we should pick up the item + current_id = id + current_index = index + current_state = states.PickUp + states.Held: + var inv : InventoryContainer = _get_inventory(id) + if inv.is_cell_free(index): # Check if the cell is empty + current_id = id + current_index = index + current_state = states.Drop + states.Drop: + pass + states.PickUp: + pass + +## Helper function to make it less painful to write +func _get_inventory(id : int) -> InventoryContainer: + return InventoryManager.get_inventory(id) From c298315f4a53c86e531c8ff4d053192b17d56946 Mon Sep 17 00:00:00 2001 From: Dragon20C Date: Mon, 19 May 2025 08:33:20 +0100 Subject: [PATCH 3/9] Added items from prev inventory. --- assets/ui/inventory items/Bandage.png | Bin 0 -> 165 bytes assets/ui/inventory items/Bandage.png.import | 34 ++++++++ assets/ui/inventory items/Basic Boots.png | Bin 0 -> 133 bytes .../ui/inventory items/Basic Boots.png.import | 34 ++++++++ assets/ui/inventory items/Basic Helmet.png | Bin 0 -> 133 bytes .../inventory items/Basic Helmet.png.import | 34 ++++++++ assets/ui/inventory items/Basic Vest.png | Bin 0 -> 133 bytes .../ui/inventory items/Basic Vest.png.import | 34 ++++++++ assets/ui/inventory items/Food 1.png | Bin 0 -> 140 bytes assets/ui/inventory items/Food 1.png.import | 34 ++++++++ assets/ui/inventory items/Fuel.png | Bin 0 -> 153 bytes assets/ui/inventory items/Fuel.png.import | 34 ++++++++ .../ui/inventory items/Intermediate Boots.png | Bin 0 -> 153 bytes .../Intermediate Boots.png.import | 34 ++++++++ .../inventory items/Intermediate Helmet.png | Bin 0 -> 153 bytes .../Intermediate Helmet.png.import | 34 ++++++++ .../ui/inventory items/Intermediate Vest.png | Bin 0 -> 133 bytes .../Intermediate Vest.png.import | 34 ++++++++ assets/ui/inventory items/Med Kit.png | Bin 0 -> 297 bytes assets/ui/inventory items/Med Kit.png.import | 34 ++++++++ assets/ui/inventory items/Repair Kit.png | Bin 0 -> 295 bytes .../ui/inventory items/Repair Kit.png.import | 34 ++++++++ assets/ui/inventory items/Weapon 1.png | Bin 0 -> 133 bytes assets/ui/inventory items/Weapon 1.png.import | 34 ++++++++ .../ui/inventory_ui/overlays/Body_Overlay.png | Bin 0 -> 262 bytes .../overlays/Body_Overlay.png.import | 34 ++++++++ .../ui/inventory_ui/overlays/Boot_Overlay.png | Bin 0 -> 201 bytes .../overlays/Boot_Overlay.png.import | 34 ++++++++ .../inventory_ui/overlays/Helmet_Overlay.png | Bin 0 -> 391 bytes .../overlays/Helmet_Overlay.png.import | 34 ++++++++ .../inventory_ui/overlays/Weapon_Overlay.png | Bin 0 -> 197 bytes .../overlays/Weapon_Overlay.png.import | 34 ++++++++ resources/Items/Bandage.tres | 3 +- resources/Items/Gernade.tres | 3 +- resources/Items/HealthPack.tres | 3 +- resources/Items/Rifle.tres | 3 +- scenes/inventory_system/slot.tscn | 9 +- scenes/menus/inventory_menu.tscn | 3 +- scripts/global/inventory_manager.gd | 14 +-- .../classes/inventory_container.gd | 8 ++ scripts/inventory_system/classes/slot.gd | 11 +++ scripts/menus/inventory_menu.gd | 81 +++++++++++++----- 42 files changed, 646 insertions(+), 36 deletions(-) create mode 100644 assets/ui/inventory items/Bandage.png create mode 100644 assets/ui/inventory items/Bandage.png.import create mode 100644 assets/ui/inventory items/Basic Boots.png create mode 100644 assets/ui/inventory items/Basic Boots.png.import create mode 100644 assets/ui/inventory items/Basic Helmet.png create mode 100644 assets/ui/inventory items/Basic Helmet.png.import create mode 100644 assets/ui/inventory items/Basic Vest.png create mode 100644 assets/ui/inventory items/Basic Vest.png.import create mode 100644 assets/ui/inventory items/Food 1.png create mode 100644 assets/ui/inventory items/Food 1.png.import create mode 100644 assets/ui/inventory items/Fuel.png create mode 100644 assets/ui/inventory items/Fuel.png.import create mode 100644 assets/ui/inventory items/Intermediate Boots.png create mode 100644 assets/ui/inventory items/Intermediate Boots.png.import create mode 100644 assets/ui/inventory items/Intermediate Helmet.png create mode 100644 assets/ui/inventory items/Intermediate Helmet.png.import create mode 100644 assets/ui/inventory items/Intermediate Vest.png create mode 100644 assets/ui/inventory items/Intermediate Vest.png.import create mode 100644 assets/ui/inventory items/Med Kit.png create mode 100644 assets/ui/inventory items/Med Kit.png.import create mode 100644 assets/ui/inventory items/Repair Kit.png create mode 100644 assets/ui/inventory items/Repair Kit.png.import create mode 100644 assets/ui/inventory items/Weapon 1.png create mode 100644 assets/ui/inventory items/Weapon 1.png.import create mode 100644 assets/ui/inventory_ui/overlays/Body_Overlay.png create mode 100644 assets/ui/inventory_ui/overlays/Body_Overlay.png.import create mode 100644 assets/ui/inventory_ui/overlays/Boot_Overlay.png create mode 100644 assets/ui/inventory_ui/overlays/Boot_Overlay.png.import create mode 100644 assets/ui/inventory_ui/overlays/Helmet_Overlay.png create mode 100644 assets/ui/inventory_ui/overlays/Helmet_Overlay.png.import create mode 100644 assets/ui/inventory_ui/overlays/Weapon_Overlay.png create mode 100644 assets/ui/inventory_ui/overlays/Weapon_Overlay.png.import diff --git a/assets/ui/inventory items/Bandage.png b/assets/ui/inventory items/Bandage.png new file mode 100644 index 0000000000000000000000000000000000000000..65323ae18281c6752aaa768b8a075107e0810a5b GIT binary patch literal 165 zcmeAS@N?(olHy`uVBq!ia0vp^{22mkMm&z1CG-8AR7gv55c z$$$BuPUe}hz$7vu#JCfL8;s6=Q!-!ZbE#qDfl4-pn>yTUQ{H$Q15IJ@boFyt=akR{ E06rEmqW}N^ literal 0 HcmV?d00001 diff --git a/assets/ui/inventory items/Bandage.png.import b/assets/ui/inventory items/Bandage.png.import new file mode 100644 index 0000000..8318da4 --- /dev/null +++ b/assets/ui/inventory items/Bandage.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://b4nhgp2ncitj2" +path="res://.godot/imported/Bandage.png-5e2534f607e876d904c31a0c4462c1cb.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/ui/inventory items/Bandage.png" +dest_files=["res://.godot/imported/Bandage.png-5e2534f607e876d904c31a0c4462c1cb.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +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/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 diff --git a/assets/ui/inventory items/Basic Boots.png b/assets/ui/inventory items/Basic Boots.png new file mode 100644 index 0000000000000000000000000000000000000000..d7f975ac59d30370696e24562b4d0f0bd1741a64 GIT binary patch literal 133 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61SBU+%rFB|jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85qP=L734qNaX`iP|DNAF~q_@xgaA$fwMPDfenOtt$2BP8SZa) V5SSs)T?SOe;OXk;vd$@?2>`Y)9C!c# literal 0 HcmV?d00001 diff --git a/assets/ui/inventory items/Basic Boots.png.import b/assets/ui/inventory items/Basic Boots.png.import new file mode 100644 index 0000000..1e51eb7 --- /dev/null +++ b/assets/ui/inventory items/Basic Boots.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://3717j7851wp8" +path="res://.godot/imported/Basic Boots.png-080791d73fccb794fb1b7038d39cb6c4.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/ui/inventory items/Basic Boots.png" +dest_files=["res://.godot/imported/Basic Boots.png-080791d73fccb794fb1b7038d39cb6c4.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +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/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 diff --git a/assets/ui/inventory items/Basic Helmet.png b/assets/ui/inventory items/Basic Helmet.png new file mode 100644 index 0000000000000000000000000000000000000000..deb46bb4343e80142def856611aa2b9d88525310 GIT binary patch literal 133 zcmeAS@N?(olHy`uVBq!ia0vp^{2jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85qP=L734qNaX`iP|DNAF+?Lc`A7Yv{tA;-Qo_Bfj=5|JuARis Zu=31YHGw%=_kpSyJYD@<);T3K0RSxhA#nfz literal 0 HcmV?d00001 diff --git a/assets/ui/inventory items/Basic Helmet.png.import b/assets/ui/inventory items/Basic Helmet.png.import new file mode 100644 index 0000000..bf55575 --- /dev/null +++ b/assets/ui/inventory items/Basic Helmet.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://sa0nlf0101p6" +path="res://.godot/imported/Basic Helmet.png-dd8797f6de52a48f8c077c44b3ef09b8.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/ui/inventory items/Basic Helmet.png" +dest_files=["res://.godot/imported/Basic Helmet.png-dd8797f6de52a48f8c077c44b3ef09b8.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +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/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 diff --git a/assets/ui/inventory items/Basic Vest.png b/assets/ui/inventory items/Basic Vest.png new file mode 100644 index 0000000000000000000000000000000000000000..c1f9d7f3cac4aa6f724aa247f989e611eeebd495 GIT binary patch literal 133 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61SBU+%rFB|jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85qP=L734qNaX`iP|DNAF~q_@IU}P$fwMPDfenOtt$2C)7~+pP V2%NMLE&-}y@O1TaS?83{1OT#Y99#eZ literal 0 HcmV?d00001 diff --git a/assets/ui/inventory items/Basic Vest.png.import b/assets/ui/inventory items/Basic Vest.png.import new file mode 100644 index 0000000..78e5b2b --- /dev/null +++ b/assets/ui/inventory items/Basic Vest.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cahsastudigpq" +path="res://.godot/imported/Basic Vest.png-ff25a7a883d9219eb3bd669d34025311.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/ui/inventory items/Basic Vest.png" +dest_files=["res://.godot/imported/Basic Vest.png-ff25a7a883d9219eb3bd669d34025311.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +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/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 diff --git a/assets/ui/inventory items/Food 1.png b/assets/ui/inventory items/Food 1.png new file mode 100644 index 0000000000000000000000000000000000000000..60428236aea3ba4fa1d78a7bc6b10f30d1acec9e GIT binary patch literal 140 zcmeAS@N?(olHy`uVBq!ia0vp^{2jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85qP=L734qNaX`iP|wrFF+?MH>hX=73jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85qP=L734qNaX`iP|wrFF+?MH>hX=73JZ5U}`d k-Ir_8`Fp=25r^M0uHY_c+;*wi3aFF8)78&qol`;+0L%g|-T(jq literal 0 HcmV?d00001 diff --git a/assets/ui/inventory items/Intermediate Boots.png.import b/assets/ui/inventory items/Intermediate Boots.png.import new file mode 100644 index 0000000..a17f3c9 --- /dev/null +++ b/assets/ui/inventory items/Intermediate Boots.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://gxyb4f4nc1je" +path="res://.godot/imported/Intermediate Boots.png-194c4a27853d7c65ec7517efd8da7c61.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/ui/inventory items/Intermediate Boots.png" +dest_files=["res://.godot/imported/Intermediate Boots.png-194c4a27853d7c65ec7517efd8da7c61.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +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/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 diff --git a/assets/ui/inventory items/Intermediate Helmet.png b/assets/ui/inventory items/Intermediate Helmet.png new file mode 100644 index 0000000000000000000000000000000000000000..9385a6a348bb9ec301aecc38dffa48209e72783d GIT binary patch literal 153 zcmeAS@N?(olHy`uVBq!ia0vp^{2jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85qP=L734qNaX`iP|wrFF+?MH>hX=73jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85qP=L734qNaX`iP|DNAF+?Lc`N#kLjTI)Vq=b7{9dp?d{C7Vi YgWqa{yPdXGazIrKp00i_>zopr07~5=CIA2c literal 0 HcmV?d00001 diff --git a/assets/ui/inventory items/Intermediate Vest.png.import b/assets/ui/inventory items/Intermediate Vest.png.import new file mode 100644 index 0000000..82a81b0 --- /dev/null +++ b/assets/ui/inventory items/Intermediate Vest.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dl1kwcgaj7vm" +path="res://.godot/imported/Intermediate Vest.png-8b781821050039a41c4c942c57f523f6.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/ui/inventory items/Intermediate Vest.png" +dest_files=["res://.godot/imported/Intermediate Vest.png-8b781821050039a41c4c942c57f523f6.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +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/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 diff --git a/assets/ui/inventory items/Med Kit.png b/assets/ui/inventory items/Med Kit.png new file mode 100644 index 0000000000000000000000000000000000000000..e9c17ec3e3f9b892ebae06564ef901d0cbd3245a GIT binary patch literal 297 zcmeAS@N?(olHy`uVBq!ia0vp^{2c;n|6fW%a#ErK z%fCOr4<9&n-rlnCdYsKFPyJu$g%me@t<}r1(tn(e;zz={?y?EU!Hz9XOk1t zTV&eAAkNKxc>8{Pi5U?G{8U}FSvD|zHFUh0(inJFrHS#%AL$ukl9G}OV;(Um3;g@_ zdv>E|w}0cqlhf0A_BXWs`SZJ5fi1J@(^uAJt@Sd@kEh4q|2KW^`}7?j{)sVL8*G2z ry+Yyp-=rU>7aUSPdm%I600TopY`Dt7l)cx1K4I{5^>bP0l+XkKt5kY4 literal 0 HcmV?d00001 diff --git a/assets/ui/inventory items/Med Kit.png.import b/assets/ui/inventory items/Med Kit.png.import new file mode 100644 index 0000000..86145e2 --- /dev/null +++ b/assets/ui/inventory items/Med Kit.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://d064goqtv6tb2" +path="res://.godot/imported/Med Kit.png-dfabbc2fc6207e8a0e8d0a955e08a516.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/ui/inventory items/Med Kit.png" +dest_files=["res://.godot/imported/Med Kit.png-dfabbc2fc6207e8a0e8d0a955e08a516.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +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/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 diff --git a/assets/ui/inventory items/Repair Kit.png b/assets/ui/inventory items/Repair Kit.png new file mode 100644 index 0000000000000000000000000000000000000000..f238d2e5598dbc8fb214f210a030ff1d1bd936e3 GIT binary patch literal 295 zcmeAS@N?(olHy`uVBq!ia0vp^{23{v-M1dzMsW7S*B$EWAs_g)3fB5 zvGU>n^Y=^6Si|#FLc-3DUAjKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85qP=L734qNaX`iP|DNAF+?LcIpWREmI{+qQo_Bfj=5|Je!G)} Z;n|G%1rI)c4g;!U@O1TaS?83{1OQN*Bai?9 literal 0 HcmV?d00001 diff --git a/assets/ui/inventory items/Weapon 1.png.import b/assets/ui/inventory items/Weapon 1.png.import new file mode 100644 index 0000000..30179c8 --- /dev/null +++ b/assets/ui/inventory items/Weapon 1.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://d4l8s4nvpp7ca" +path="res://.godot/imported/Weapon 1.png-03a012ffc460c727f12ee7aecf276065.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/ui/inventory items/Weapon 1.png" +dest_files=["res://.godot/imported/Weapon 1.png-03a012ffc460c727f12ee7aecf276065.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +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/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 diff --git a/assets/ui/inventory_ui/overlays/Body_Overlay.png b/assets/ui/inventory_ui/overlays/Body_Overlay.png new file mode 100644 index 0000000000000000000000000000000000000000..76f6a6570bd2f4219a3f90a1e47754c735206984 GIT binary patch literal 262 zcmeAS@N?(olHy`uVBq!ia0vp^0zk~i!3HGN^yhQ|DaPU;cPEB*=VV?2IV|apzK#qG z8~eHcB(eheoCO|{#S9E$svykh8Km+7C^*~G#WBRff9fPgz7_=m=I>|z&i=spbMbeM zel69~NE1J&Z70OKKY41tReLgLcGt?kzH@cf%DK(D*|JJ1(=Hig6f#&d|7<*v^Y)XV=)Cuxb^JEJ#OAy0 z^mTX~JL_d=TjjE;iOd_OCGF3Z7OF7jFlVqUOEEM4&CJ)dLg?n)OU^)NGI+ZBxvXZDI;uvD#|8`O!-vI><=ZkOdwM_PZy+YB? z{zTn(p`#w&BD$-px|7rPRlV3L=>K~`)f@#$)+by3YfX5nuTYfu$oTE9Jxsn=uJ_Cg u;C{cu>6p)ppLd!s9shGm`{Rmg7paItO8*bMnC%6$iNVv=&t;ucLK6U{E=ZRE literal 0 HcmV?d00001 diff --git a/assets/ui/inventory_ui/overlays/Boot_Overlay.png.import b/assets/ui/inventory_ui/overlays/Boot_Overlay.png.import new file mode 100644 index 0000000..8cfa90a --- /dev/null +++ b/assets/ui/inventory_ui/overlays/Boot_Overlay.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://drp0q2blofo6n" +path="res://.godot/imported/Boot_Overlay.png-3531eb67daf736b39311eb77597a58c6.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/ui/inventory_ui/overlays/Boot_Overlay.png" +dest_files=["res://.godot/imported/Boot_Overlay.png-3531eb67daf736b39311eb77597a58c6.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +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/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 diff --git a/assets/ui/inventory_ui/overlays/Helmet_Overlay.png b/assets/ui/inventory_ui/overlays/Helmet_Overlay.png new file mode 100644 index 0000000000000000000000000000000000000000..dcb5b5513fd767f27a4826f595ab7179c62cecb0 GIT binary patch literal 391 zcmeAS@N?(olHy`uVBq!ia0vp^0zfRt!3HF+tk*dLq!^2X+?^QKos)S9a~60+7Beu2se&-0XOPMVpavOF7sn6_|Kv66*Z)87z?jf@Nn=5JlKJ85 z{P!2wa3nlTNLrz{zV(v;!_kJXudf-$?5gQxe4(|1Ln|XECnX>_EVZMjv#HC#z`!wc zgNof*1%^qxOTU{%=<*!kWniqCmB`@C8^9pak&-weZU=YAMp?EAR}V1@KG9F&Jt)cc zgh7OPg6}cb3s)cTG=GcyEHP`je{#kwJJybLM^{CLY>5U252iHcU5z_p+6CDZde`LS zB$Q=mTMLvo-2~d?Y%Y<*u<5MAhxgy(4Rlq`o>kB|$d{(fJRxd^qedcwaZBrDQJ-|R zCx$7i;te+q8rDd%1nglje)4>~e1KqxLH)@Zk+TX7n{8fXyiZ9;W7*j<^WpFF{ye2$ gXGG3yY;0s?DEL&N_n)ON3mA9|p00i_>zopr02pVBsQ>@~ literal 0 HcmV?d00001 diff --git a/assets/ui/inventory_ui/overlays/Helmet_Overlay.png.import b/assets/ui/inventory_ui/overlays/Helmet_Overlay.png.import new file mode 100644 index 0000000..89d582d --- /dev/null +++ b/assets/ui/inventory_ui/overlays/Helmet_Overlay.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://ce0pf5op5farq" +path="res://.godot/imported/Helmet_Overlay.png-d85e1ec47514efa7a01345a857dc2680.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/ui/inventory_ui/overlays/Helmet_Overlay.png" +dest_files=["res://.godot/imported/Helmet_Overlay.png-d85e1ec47514efa7a01345a857dc2680.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +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/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 diff --git a/assets/ui/inventory_ui/overlays/Weapon_Overlay.png b/assets/ui/inventory_ui/overlays/Weapon_Overlay.png new file mode 100644 index 0000000000000000000000000000000000000000..1eced2f6138ed97466353ca7f1b6d4c98ec560e9 GIT binary patch literal 197 zcmeAS@N?(olHy`uVBq!ia0vp^d?3uh1|;P@bT0xa#^NA%Cx&(BWL^R}Ea{HEjtmSN z`?>!lvI6;>1s;*b3=CqbAk63)r1AkM80G2W7-Hd{yk`CS|K}ap5}GclG*4VGk=5(4 zV{)?clvY`WWJaIl3>L;2Dpn3=BCC(}t&3}$e}BJ2rNDuMXW5S#G=wI*MjFmwyV-EM nY)vEcC5IF1oz+en8Za=_)`+{G6h4~ void: player_inv = InventoryContainer.new(inventory_size) - player_inv.set_id(register_inventory(player_inv)) - + register_inventory(player_inv) -func register_inventory(inventory : InventoryContainer) -> int: +## helper function for registering the inventory globally +func register_inventory(inventory : InventoryContainer) -> void: next_id += 1 inventories[next_id] = inventory - - return next_id + inventory.set_id(next_id) -# maybe in the future save logic could be here when an inventory is not in use +## helper function that removes an inventory from its id func unregister_inventory(id : int) -> void: inventories.erase(id) diff --git a/scripts/inventory_system/classes/inventory_container.gd b/scripts/inventory_system/classes/inventory_container.gd index d6078f2..9ac98bc 100644 --- a/scripts/inventory_system/classes/inventory_container.gd +++ b/scripts/inventory_system/classes/inventory_container.gd @@ -2,6 +2,7 @@ extends RefCounted class_name InventoryContainer signal slot_pressed(id : int , index : Vector2i) +signal slot_hovered(id : int , index : Vector2i) var _slots : Dictionary[Vector2i,Slot] var _item : Dictionary[Vector2i,InvItem] @@ -29,6 +30,7 @@ func generate_cells(container : GridContainer) -> void: # setup the signals slot.button.pressed.connect(slot_is_pressed.bind(slot)) + slot.button.mouse_entered.connect(slot_is_hovered.bind(slot)) # set the slots index and inv id slot.index = Vector2i(x,y) @@ -36,12 +38,16 @@ func generate_cells(container : GridContainer) -> void: #slot.inventory_id = _id # set slot into the slots dict to be able to change the item sprite _slots[slot.index] = slot + _slots[slot.index].set_stack(0) # set the index into the items dict and set it to null to indicate its empty _item[slot.index] = null func slot_is_pressed(slot : Slot) -> void: slot_pressed.emit(_id,slot.index) +func slot_is_hovered(slot : Slot) -> void: + slot_hovered.emit(_id,slot.index) + func is_cell_free(index : Vector2i) -> bool: if not _item.has(index): return false @@ -57,6 +63,7 @@ func add_item(inv_item : InvItem) -> bool: # set item and item icon _item[index] = inv_item _slots[index].set_icon(inv_item.icon) + _slots[index].set_stack(inv_item.stack) return true @@ -64,6 +71,7 @@ func remove_item(inv_item : InvItem) -> void: var index : Vector2i = inv_item.origin _item[index] = null _slots[index].set_icon(null) + _slots[index].set_stack(0) func get_item(index : Vector2i) -> InvItem: return _item[index] diff --git a/scripts/inventory_system/classes/slot.gd b/scripts/inventory_system/classes/slot.gd index bd99e33..5c6fb06 100644 --- a/scripts/inventory_system/classes/slot.gd +++ b/scripts/inventory_system/classes/slot.gd @@ -5,9 +5,20 @@ var index :Vector2i @onready var icon : TextureRect = get_node("Icon") @onready var button : TextureButton = get_node("Button") +@onready var stack : Label = get_node("Stack") func set_icon(texture : Texture2D) -> void: if not icon: return icon.texture = texture + +func set_stack(amount : int) -> void: + + stack.visible = true + + if not stack or amount == 0: + stack.visible = false + return + + stack.text = str(amount) diff --git a/scripts/menus/inventory_menu.gd b/scripts/menus/inventory_menu.gd index 1eb2309..8462bf4 100644 --- a/scripts/menus/inventory_menu.gd +++ b/scripts/menus/inventory_menu.gd @@ -6,7 +6,7 @@ extends MenuBase @export var inventory_size : Vector2i = Vector2i(8,6) @export var held_icon : Sprite2D -enum states {Empty,Held,Drop,PickUp} +enum states {Empty,Held,Drop,PickUp,Swap,Add,Remove} var current_state : states = states.Empty var inventories : Dictionary[int,InventoryContainer] @@ -24,6 +24,7 @@ func _ready() -> void: player_inv.load_data(InventoryManager.player_items,database) # connect the slot pressed signal to a function in this script player_inv.slot_pressed.connect(on_slot_pressed) + player_inv.slot_hovered.connect(handle_hover_tooltip) func _process(delta: float) -> void: handle_state_update() @@ -42,29 +43,21 @@ func handle_state_update() -> void: pass states.Held: held_icon.global_position = get_global_mouse_position() + states.Drop: - # grab the inventory - var inv : InventoryContainer = _get_inventory(current_id) - # empty the held_icon and reset position - held_icon.global_position = Vector2(0,0) - held_icon.texture = null - # update the held items origin index if we dont it returns to the previous index - held_item.origin = current_index - # add the item from the previous inventory - inv.add_item(held_item) - # change the state to held + drop() current_state = states.Empty + states.PickUp: - # grab the inventory - var inv : InventoryContainer = _get_inventory(current_id) - # set the item to the held_item - held_item = inv.get_item(current_index) - # set the texture from the held item - held_icon.texture = held_item.icon - # remove the item from the previous inventory - inv.remove_item(held_item) - # change the state to held + pickup() current_state = states.Held + + states.Add: + pass + states.Remove: + pass + states.Swap: + pass ## Handles the logic in each state e.g empty state you can pick up an item func handle_state_transition(id: int, index : Vector2i) -> void: @@ -85,6 +78,54 @@ func handle_state_transition(id: int, index : Vector2i) -> void: pass states.PickUp: pass + states.Add: + pass + states.Remove: + pass + states.Swap: + pass + +func handle_hover_tooltip(id : int, index : Vector2i) -> void: + var inv : InventoryContainer = InventoryManager.get_inventory(id) + ## the hovered slot is empty + if inv.is_cell_free(index): + return + + ## show a tooltip for the item, maybe we can also add options like consumbe,drop, etc + var item : InvItem = inv.get_item(index) + var item_data : Item = database.database[item.id] + print("Item (%s) , Stack (%s)" % [item_data.item_name,item.stack]) + +func drop() -> void: + # grab the inventory + var inv : InventoryContainer = _get_inventory(current_id) + # empty the held_icon and reset position + held_icon.global_position = Vector2(-100,-100) + held_icon.texture = null + # update the held items origin index if we dont it returns to the previous index + held_item.origin = current_index + # add the item from the previous inventory + inv.add_item(held_item) + +func pickup() -> void: + # grab the inventory + var inv : InventoryContainer = _get_inventory(current_id) + # set the item to the held_item + held_item = inv.get_item(current_index) + # set the texture from the held item + held_icon.texture = held_item.icon + # remove the item from the previous inventory + inv.remove_item(held_item) + # change the state to held + +func swap_items(from_id : int,from_index : Vector2i,to_id : int,to_index : Vector2i) -> void: + var from_inv : InventoryContainer = InventoryManager.get_inventory(from_id) + var to_inv : InventoryContainer = InventoryManager.get_inventory(to_id) + + var from_item : InvItem = from_inv.get_item(from_index) + var to_item : InvItem = to_inv.get_item(to_index) + + ## Helper function to make it less painful to write func _get_inventory(id : int) -> InventoryContainer: From cad4a59559a38ca1798aba8b7070726cc44ee8b7 Mon Sep 17 00:00:00 2001 From: Dragon20C Date: Mon, 19 May 2025 10:04:18 +0100 Subject: [PATCH 4/9] Added the menu into the game! --- scenes/player/world.tscn | 48 +++++++++++++++++-- scripts/game_menu_system.gd | 3 +- scripts/global/manager.gd | 2 +- .../classes/inventory_container.gd | 4 +- scripts/menus/in_game_menu.gd | 2 + scripts/menus/inventory_menu.gd | 26 +++++++--- 6 files changed, 71 insertions(+), 14 deletions(-) diff --git a/scenes/player/world.tscn b/scenes/player/world.tscn index 24af01c..eb0dc7e 100644 --- a/scenes/player/world.tscn +++ b/scenes/player/world.tscn @@ -1,18 +1,55 @@ -[gd_scene load_steps=8 format=3 uid="uid://cjxiwvvqhuh0q"] +[gd_scene load_steps=16 format=4 uid="uid://cjxiwvvqhuh0q"] +[ext_resource type="PackedScene" uid="uid://dkkdcx534ran6" path="res://scenes/player/player.tscn" id="1_1vo14"] [ext_resource type="Script" uid="uid://eb3vs5x8edfb" path="res://scripts/world.gd" id="1_71hdg"] +[ext_resource type="Texture2D" uid="uid://b05hj6ognkfqi" path="res://assets/icon.svg" id="2_2nh4u"] +[ext_resource type="PackedScene" uid="uid://didh1mtde07hl" path="res://scenes/door.tscn" id="3_yy6hg"] +[ext_resource type="Script" uid="uid://mqyxoitrg52a" path="res://scripts/map_generator.gd" id="4_78f4u"] +[ext_resource type="PackedScene" uid="uid://cu6wnh1d65tf5" path="res://scenes/actor.tscn" id="4_gd2e3"] [ext_resource type="Script" uid="uid://bm0r4bkr3dki2" path="res://scripts/game_menu_system.gd" id="7_kej52"] [ext_resource type="PackedScene" uid="uid://2nq4ts7s3ojx" path="res://scenes/menus/in_game_menu.tscn" id="8_71hdg"] [ext_resource type="PackedScene" uid="uid://bo4uld1h02n47" path="res://scenes/menus/pause_menu.tscn" id="9_onws2"] [ext_resource type="PackedScene" uid="uid://vcaloblp0bi6" path="res://scenes/menus/settings_menu.tscn" id="10_36eim"] -[ext_resource type="PackedScene" uid="uid://dmfohcgyw6m8y" path="res://scenes/room_generator.tscn" id="10_kej52"] +[ext_resource type="PackedScene" uid="uid://kwglhhfyum7a" path="res://scenes/menus/inventory_menu.tscn" id="11_71hdg"] + +[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_4fw4l"] +texture = ExtResource("2_2nh4u") +texture_region_size = Vector2i(128, 128) +0:0/next_alternative_id = 9 +0:0/0 = 0 +0:0/1 = 1 +0:0/1/modulate = Color(100, 100, 100, 1) +0:0/1/custom_data_0 = 1 +0:0/2 = 2 +0:0/2/modulate = Color(100, 0, 0, 1) +0:0/8 = 8 +0:0/8/modulate = Color(0, 0, 0, 1) + +[sub_resource type="TileSetScenesCollectionSource" id="TileSetScenesCollectionSource_4su1h"] +scenes/1/scene = ExtResource("1_1vo14") +scenes/2/scene = ExtResource("3_yy6hg") +scenes/3/scene = ExtResource("4_gd2e3") + +[sub_resource type="TileSet" id="TileSet_4raql"] +tile_size = Vector2i(128, 128) +custom_data_layer_0/name = "Col" +custom_data_layer_0/type = 2 +sources/0 = SubResource("TileSetAtlasSource_4fw4l") +sources/1 = SubResource("TileSetScenesCollectionSource_4su1h") [sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_b1qyj"] [node name="Node2D" type="Node2D"] script = ExtResource("1_71hdg") -[node name="RoomGenerator" parent="." instance=ExtResource("10_kej52")] +[node name="Floor" type="TileMapLayer" parent="."] +tile_map_data = PackedByteArray("AAABAAAAAAAAAAAAAQACAAAAAAAAAAAAAQADAAEAAAAAAAAAAQACAAEAAAAAAAAAAQACAAIAAAAAAAAAAQABAAIAAAAAAAAAAQAAAAIAAAAAAAAAAQAAAAEAAAAAAAAAAQABAAEAAAAAAAAAAQADAAAAAAAAAAAAAQADAAIAAAAAAAAAAQAEAAIAAAAAAAAAAQAEAAMAAAAAAAAAAQADAAMAAAAAAAAAAQACAAMAAAAAAAAAAQABAAMAAAAAAAAAAQAAAAMAAAAAAAAAAQAFAAIAAAAAAAAAAQAFAAEAAAAAAAAAAQAFAAAAAAAAAAAAAQAGAAEAAAAAAAAAAgAGAAIAAAAAAAAAAQAFAAMAAAA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AAAgANAP7/AAAAAAAAAgAOAP7/AAAAAAAAAgAPAP7/AAAAAAAAAgAQAP7/AAAAAAAAAgARAP7/AAAAAAAAAgARAP//AAAAAAAAAgARAAAAAAAAAAAAAgARAAEAAAAAAAAAAgARAAIAAAAAAAAAAgARAAMAAAAAAAAAAgARAAQAAAAAAAAAAgARAAUAAAAAAAAAAgAQAAUAAAAAAAAAAgAPAAUAAAAAAAAAAgAOAAUAAAAAAAAAAgANAAUAAAAAAAAAAgAMAAUAAAAAAAAAAgAMAAQAAAAAAAAAAgAMAAMAAAAAAAAAAgAEAAAAAAAAAAAAAQAEAAEAAAAAAAAAAQAFAAQAAAAAAAAAAgAEAAQAAAAAAAAAAgADAAQAAAAAAAAAAgACAAQAAAAAAAAAAgABAAQAAAAAAAAAAgAAAAQAAAAAAAAAAgD//wQAAAAAAAAAAgAGAAQAAAAAAAAAAgAKAAUAAAAAAAAACAAKAAQAAAAAAAAACAAJAAQAAAAAAAAACAAIAAQAAAAAAAAACAAHAAQAAAAAAAAACAAHAAUAAAAAAAAACAAGAAUAAAAAAAAACAAFAAUAAAAAAAAACAAEAAUAAAAAAAAACAADAAUAAAAAAAAACAACAAUAAAAAAAAACAABAAUAAAAAAAAACAAAAAUAAAAAAAAACAD//wUAAAAAAAAACAAIAAUAAAAAAAAACAAJAAUAAAAAAAAACAALAAQAAAAAAAAACAALAAMAAAAAAAAACAALAAUAAAAAAAAACAALAP7/AAAAAAAACAAKAP7/AAAAAAAACAAJAP7/AAAAAAAACAAIAP7/AAAAAAAACAAHAP7/AAAAAAAACAAGAP7/AAAAAAAACAAFAP7/AAAAAAAACAAEAP7/AAAAAAAACAADAP7/AAAAAAAACAACAP7/AAAAAAAACAABAP7/AAAAAAAACAAAAP7/AAAAAAAACAD///7/AAAAAAAACAALAP//AAAAAAAACAAAAAAAAAAAAAAAAQA=") +tile_set = SubResource("TileSet_4raql") +script = ExtResource("4_78f4u") + +[node name="Objects" type="TileMapLayer" parent="."] +tile_map_data = PackedByteArray("AAAAAAAAAQAAAAAAAwABAAAAAQAAAAAAAQACAAAAAAAAAAAAAQADAAEAAAAAAAAAAQACAAEAAAAAAAAAAQACAAIAAAAAAAAAAQABAAIAAAAAAAAAAQAAAAIAAAAAAAAAAQAAAAEAAAAAAAAAAQABAAEAAAAAAAAAAQADAAAAAAAAAAAAAQADAAIAAAAAAAAAAQAGAAIAAQAAAAAAAgAKAAEAAQAAAAAAAgAMAAEAAQAAAAAAAgA=") +tile_set = SubResource("TileSet_4raql") [node name="CanvasLayer" type="CanvasLayer" parent="."] @@ -44,3 +81,8 @@ metadata/_tab_index = 1 visible = false layout_mode = 2 metadata/_tab_index = 2 + +[node name="InventoryMenu" parent="CanvasLayer/MenuSystem" instance=ExtResource("11_71hdg")] +visible = false +layout_mode = 2 +metadata/_tab_index = 3 diff --git a/scripts/game_menu_system.gd b/scripts/game_menu_system.gd index d5170a8..2b04fdd 100644 --- a/scripts/game_menu_system.gd +++ b/scripts/game_menu_system.gd @@ -4,5 +4,6 @@ class_name GameMenuSystem enum MENUS{ InGame, Pause, - Settings + Settings, + Inventory } diff --git a/scripts/global/manager.gd b/scripts/global/manager.gd index 81e4a5f..10f21c6 100644 --- a/scripts/global/manager.gd +++ b/scripts/global/manager.gd @@ -32,7 +32,7 @@ func _ready() -> void: add_child(preload(loading_scene).instantiate()) loader = get_child(0).get_child(0) # temporary disabled the menu to focus on working on the inventory system - #spawn_scene(Keys.main) + spawn_scene(Keys.main) ## adds scene path to dictionary with assignes key func add_scene(scene : String, key : Keys) -> void: diff --git a/scripts/inventory_system/classes/inventory_container.gd b/scripts/inventory_system/classes/inventory_container.gd index 9ac98bc..1eb2df7 100644 --- a/scripts/inventory_system/classes/inventory_container.gd +++ b/scripts/inventory_system/classes/inventory_container.gd @@ -57,8 +57,8 @@ func is_cell_free(index : Vector2i) -> bool: func add_item(inv_item : InvItem) -> bool: var index : Vector2i = inv_item.origin - if not is_cell_free(index): - return false + #if not is_cell_free(index): + #return false # set item and item icon _item[index] = inv_item diff --git a/scripts/menus/in_game_menu.gd b/scripts/menus/in_game_menu.gd index 4210a45..58a73be 100644 --- a/scripts/menus/in_game_menu.gd +++ b/scripts/menus/in_game_menu.gd @@ -11,3 +11,5 @@ func _input(event: InputEvent) -> void: if event.keycode == KEY_ESCAPE and event.is_pressed(): # load the pause menu. menu_manager.switch_menu(GameMenuSystem.MENUS.Pause) + elif event.keycode == KEY_E and event.is_pressed(): + menu_manager.switch_menu(GameMenuSystem.MENUS.Inventory) diff --git a/scripts/menus/inventory_menu.gd b/scripts/menus/inventory_menu.gd index 8462bf4..b384761 100644 --- a/scripts/menus/inventory_menu.gd +++ b/scripts/menus/inventory_menu.gd @@ -15,6 +15,8 @@ var inventory : InventoryContainer var held_item : InvItem var current_id : int var current_index : Vector2i +var swap_id : int +var swap_index : Vector2i func _ready() -> void: @@ -57,7 +59,8 @@ func handle_state_update() -> void: states.Remove: pass states.Swap: - pass + swap_items() + current_state = states.Held ## Handles the logic in each state e.g empty state you can pick up an item func handle_state_transition(id: int, index : Vector2i) -> void: @@ -74,6 +77,14 @@ func handle_state_transition(id: int, index : Vector2i) -> void: current_id = id current_index = index current_state = states.Drop + else: + var cur_item : InvItem = inv.get_item(index) + if held_item.id != cur_item.id: + print("Items are not the same so swap them!") + swap_id = id + swap_index = index + current_state = states.Swap + states.Drop: pass states.PickUp: @@ -116,16 +127,17 @@ func pickup() -> void: held_icon.texture = held_item.icon # remove the item from the previous inventory inv.remove_item(held_item) - # change the state to held -func swap_items(from_id : int,from_index : Vector2i,to_id : int,to_index : Vector2i) -> void: - var from_inv : InventoryContainer = InventoryManager.get_inventory(from_id) - var to_inv : InventoryContainer = InventoryManager.get_inventory(to_id) +func swap_items() -> void: - var from_item : InvItem = from_inv.get_item(from_index) - var to_item : InvItem = to_inv.get_item(to_index) + var to_inv : InventoryContainer = InventoryManager.get_inventory(swap_id) + var to_item : InvItem = to_inv.get_item(swap_index) + held_item.origin = swap_index + to_inv.add_item(held_item) + held_item = to_item + held_icon.texture = held_item.icon ## Helper function to make it less painful to write func _get_inventory(id : int) -> InventoryContainer: From 148d462cd59fee28282d02015f19e246b78c93f5 Mon Sep 17 00:00:00 2001 From: Dragon20C Date: Mon, 19 May 2025 10:10:38 +0100 Subject: [PATCH 5/9] Re-added the inventory menu. The inventory can now be accessed by using the E key in game. --- scenes/player/world.tscn | 40 ++++++++++++---------------------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/scenes/player/world.tscn b/scenes/player/world.tscn index eb0dc7e..5fed4b5 100644 --- a/scenes/player/world.tscn +++ b/scenes/player/world.tscn @@ -1,41 +1,25 @@ -[gd_scene load_steps=16 format=4 uid="uid://cjxiwvvqhuh0q"] +[gd_scene load_steps=14 format=4 uid="uid://cjxiwvvqhuh0q"] [ext_resource type="PackedScene" uid="uid://dkkdcx534ran6" path="res://scenes/player/player.tscn" id="1_1vo14"] [ext_resource type="Script" uid="uid://eb3vs5x8edfb" path="res://scripts/world.gd" id="1_71hdg"] -[ext_resource type="Texture2D" uid="uid://b05hj6ognkfqi" path="res://assets/icon.svg" id="2_2nh4u"] +[ext_resource type="TileSet" uid="uid://bsxyvnp83jqxa" path="res://resources/test2_terrain_procgen_tileset.tres" id="2_kej52"] [ext_resource type="PackedScene" uid="uid://didh1mtde07hl" path="res://scenes/door.tscn" id="3_yy6hg"] [ext_resource type="Script" uid="uid://mqyxoitrg52a" path="res://scripts/map_generator.gd" id="4_78f4u"] -[ext_resource type="PackedScene" uid="uid://cu6wnh1d65tf5" path="res://scenes/actor.tscn" id="4_gd2e3"] [ext_resource type="Script" uid="uid://bm0r4bkr3dki2" path="res://scripts/game_menu_system.gd" id="7_kej52"] [ext_resource type="PackedScene" uid="uid://2nq4ts7s3ojx" path="res://scenes/menus/in_game_menu.tscn" id="8_71hdg"] [ext_resource type="PackedScene" uid="uid://bo4uld1h02n47" path="res://scenes/menus/pause_menu.tscn" id="9_onws2"] [ext_resource type="PackedScene" uid="uid://vcaloblp0bi6" path="res://scenes/menus/settings_menu.tscn" id="10_36eim"] -[ext_resource type="PackedScene" uid="uid://kwglhhfyum7a" path="res://scenes/menus/inventory_menu.tscn" id="11_71hdg"] +[ext_resource type="PackedScene" uid="uid://kwglhhfyum7a" path="res://scenes/menus/inventory_menu.tscn" id="10_kej52"] -[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_4fw4l"] -texture = ExtResource("2_2nh4u") -texture_region_size = Vector2i(128, 128) -0:0/next_alternative_id = 9 -0:0/0 = 0 -0:0/1 = 1 -0:0/1/modulate = Color(100, 100, 100, 1) -0:0/1/custom_data_0 = 1 -0:0/2 = 2 -0:0/2/modulate = Color(100, 0, 0, 1) -0:0/8 = 8 -0:0/8/modulate = Color(0, 0, 0, 1) - -[sub_resource type="TileSetScenesCollectionSource" id="TileSetScenesCollectionSource_4su1h"] +[sub_resource type="TileSetScenesCollectionSource" id="TileSetScenesCollectionSource_onws2"] scenes/1/scene = ExtResource("1_1vo14") scenes/2/scene = ExtResource("3_yy6hg") -scenes/3/scene = ExtResource("4_gd2e3") -[sub_resource type="TileSet" id="TileSet_4raql"] -tile_size = Vector2i(128, 128) +[sub_resource type="TileSet" id="TileSet_36eim"] +tile_size = Vector2i(64, 64) custom_data_layer_0/name = "Col" custom_data_layer_0/type = 2 -sources/0 = SubResource("TileSetAtlasSource_4fw4l") -sources/1 = SubResource("TileSetScenesCollectionSource_4su1h") +sources/1 = SubResource("TileSetScenesCollectionSource_onws2") [sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_b1qyj"] @@ -43,13 +27,13 @@ sources/1 = SubResource("TileSetScenesCollectionSource_4su1h") script = ExtResource("1_71hdg") [node name="Floor" type="TileMapLayer" parent="."] -tile_map_data = PackedByteArray("AAABAAAAAAAAAAAAAQACAAAAAAAAAAAAAQADAAEAAAAAAAAAAQACAAEAAAAAAAAAAQACAAIAAAAAAAAAAQABAAIAAAAAAAAAAQAAAAIAAAAAAAAAAQAAAAEAAAAAAAAAAQABAAEAAAAAAAAA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ACAAMAAAABAPv/AAACAAMAAAACAPv/AAACAAMAAAADAPv/AAACAAMAAAAEAPv/AAACAAMAAAAFAPv/AAACAAMAAAAGAPv/AAADAAAAAAAGAPz/AAAAAAEAAAAGAP3/AAAAAAEAAAAGAP7/AAAAAAEAAAALAP//AAACAAMAAAAGAAEAAAAGAAUAAAA=") +tile_set = ExtResource("2_kej52") script = ExtResource("4_78f4u") [node name="Objects" type="TileMapLayer" parent="."] -tile_map_data = PackedByteArray("AAAAAAAAAQAAAAAAAwABAAAAAQAAAAAAAQACAAAAAAAAAAAAAQADAAEAAAAAAAAAAQACAAEAAAAAAAAAAQACAAIAAAAAAAAAAQABAAIAAAAAAAAAAQAAAAIAAAAAAAAAAQAAAAEAAAAAAAAAAQABAAEAAAAAAAAAAQADAAAAAAAAAAAAAQADAAIAAAAAAAAAAQAGAAIAAQAAAAAAAgAKAAEAAQAAAAAAAgAMAAEAAQAAAAAAAgA=") -tile_set = SubResource("TileSet_4raql") +tile_map_data = PackedByteArray("AAABAAAAAQAAAAAAAQAGAAIAAQAAAAAAAgAKAAEAAQAAAAAAAgAMAAEAAQAAAAAAAgAGAAEAAQAAAAAAAgAKAAAAAQAAAAAAAgAMAAAAAQAAAAAAAgAIAAMAAQAAAAAAAgAJAAMAAQAAAAAAAgA=") +tile_set = SubResource("TileSet_36eim") [node name="CanvasLayer" type="CanvasLayer" parent="."] @@ -82,7 +66,7 @@ visible = false layout_mode = 2 metadata/_tab_index = 2 -[node name="InventoryMenu" parent="CanvasLayer/MenuSystem" instance=ExtResource("11_71hdg")] +[node name="InventoryMenu" parent="CanvasLayer/MenuSystem" instance=ExtResource("10_kej52")] visible = false layout_mode = 2 metadata/_tab_index = 3 From c8d5e5d71425eccda4a4936c4a5e9f027f973b19 Mon Sep 17 00:00:00 2001 From: Dragon20C Date: Wed, 25 Jun 2025 09:58:39 +0100 Subject: [PATCH 6/9] Changed the way of storing inventories. Changed inventories variable from dictionary into an array with minimal changes. --- scripts/global/inventory_manager.gd | 27 ++++++++++++------- .../classes/inventory_container.gd | 5 +++- .../classes/inventory_manager.gd | 11 -------- .../classes/inventory_manager.gd.uid | 1 - 4 files changed, 21 insertions(+), 23 deletions(-) delete mode 100644 scripts/inventory_system/classes/inventory_manager.gd delete mode 100644 scripts/inventory_system/classes/inventory_manager.gd.uid diff --git a/scripts/global/inventory_manager.gd b/scripts/global/inventory_manager.gd index 08ccd4a..e36c23d 100644 --- a/scripts/global/inventory_manager.gd +++ b/scripts/global/inventory_manager.gd @@ -4,8 +4,9 @@ extends Node ## potentional issue is if the player opens to many inventories and the next id ## somehow becomes to big which I dont think will ever happen but we never know... -var inventories : Dictionary[int,InventoryContainer] -var next_id : int = -1 +#var inventories : Dictionary[int,InventoryContainer] +var inventories : Array[InventoryContainer] +var next_id : int = 0 ## Player related var inventory_size : Vector2i = Vector2i(8,6) @@ -23,16 +24,22 @@ func _ready() -> void: player_inv = InventoryContainer.new(inventory_size) register_inventory(player_inv) -## helper function for registering the inventory globally -func register_inventory(inventory : InventoryContainer) -> void: - next_id += 1 +func register_inventory(inv : InventoryContainer) -> void: + + ## if the id is -1, it means the inventory has not been set + match inv.get_id(): + -1: + inventories.append(inv) + inv.set_id(next_id) + ## this might not be needed if we just use the array size, leaving it for now. + next_id += 1 + _: + inventories[inv.get_id()] = inv - inventories[next_id] = inventory - inventory.set_id(next_id) - -## helper function that removes an inventory from its id func unregister_inventory(id : int) -> void: - inventories.erase(id) + ## when we want to not use an inventory it is better to set it to null + ## this is because we dont want to shuffle the array and also cause mismatch inventory IDs. + inventories[id] = null func get_inventory(id : int) -> InventoryContainer: return inventories.get(id) diff --git a/scripts/inventory_system/classes/inventory_container.gd b/scripts/inventory_system/classes/inventory_container.gd index 1eb2df7..622f58d 100644 --- a/scripts/inventory_system/classes/inventory_container.gd +++ b/scripts/inventory_system/classes/inventory_container.gd @@ -7,7 +7,7 @@ signal slot_hovered(id : int , index : Vector2i) var _slots : Dictionary[Vector2i,Slot] var _item : Dictionary[Vector2i,InvItem] var _size : Vector2i -var _id : int +var _id : int = -1 var _container : GridContainer const _spacing : float = 64 @@ -18,6 +18,9 @@ func _init(size : Vector2i) -> void: func set_id(id : int) -> void: _id = id +func get_id() -> int: + return _id + func generate_cells(container : GridContainer) -> void: _container = container _container.columns = _size.x diff --git a/scripts/inventory_system/classes/inventory_manager.gd b/scripts/inventory_system/classes/inventory_manager.gd deleted file mode 100644 index fae2c76..0000000 --- a/scripts/inventory_system/classes/inventory_manager.gd +++ /dev/null @@ -1,11 +0,0 @@ -extends Node - - -# Called when the node enters the scene tree for the first time. -func _ready() -> void: - pass # Replace with function body. - - -# Called every frame. 'delta' is the elapsed time since the previous frame. -func _process(delta: float) -> void: - pass diff --git a/scripts/inventory_system/classes/inventory_manager.gd.uid b/scripts/inventory_system/classes/inventory_manager.gd.uid deleted file mode 100644 index b3940f6..0000000 --- a/scripts/inventory_system/classes/inventory_manager.gd.uid +++ /dev/null @@ -1 +0,0 @@ -uid://bqo0ptn54lesw From ffbd00342aba1841e70955450e3a35b1fa913479 Mon Sep 17 00:00:00 2001 From: Dragon20C Date: Wed, 25 Jun 2025 17:48:48 +0100 Subject: [PATCH 7/9] Fixes. Removed IDs from items placed in the inventory slots. Fixed items being set into incorrect positions. Inventories now have an item inventory resource for storing items positions and item data, Requires a save and load method. --- scripts/global/inventory_manager.gd | 13 ++----- scripts/inventory_system/classes/inv_item.gd | 13 +++++-- .../classes/inventory_container.gd | 37 ++++++++++++++----- .../inventory_system/classes/item_database.gd | 1 + .../inventory_system/classes/item_resource.gd | 1 + .../resource classes/item_container.gd | 5 +++ .../resource classes/item_container.gd.uid | 1 + .../resource classes/item_inventory.gd | 6 +++ .../resource classes/item_inventory.gd.uid | 1 + .../temp folder/player_inventory.tres | 30 +++++++++++++++ scripts/menus/inventory_menu.gd | 6 +-- 11 files changed, 90 insertions(+), 24 deletions(-) create mode 100644 scripts/inventory_system/classes/resource classes/item_container.gd create mode 100644 scripts/inventory_system/classes/resource classes/item_container.gd.uid create mode 100644 scripts/inventory_system/classes/resource classes/item_inventory.gd create mode 100644 scripts/inventory_system/classes/resource classes/item_inventory.gd.uid create mode 100644 scripts/inventory_system/temp folder/player_inventory.tres diff --git a/scripts/global/inventory_manager.gd b/scripts/global/inventory_manager.gd index e36c23d..c4a11fb 100644 --- a/scripts/global/inventory_manager.gd +++ b/scripts/global/inventory_manager.gd @@ -10,18 +10,13 @@ var next_id : int = 0 ## Player related var inventory_size : Vector2i = Vector2i(8,6) -var player_inv : InventoryContainer +var player_inv : InventoryContainer = InventoryContainer.new(inventory_size) # this might change in the future for a better way of storing items -var player_items : Array[Dictionary] = [ - # ID is the item id, Position is the slot index, can add stack size here as well - {"ID" : 0, "Position" : Vector2i(0,0)}, - {"ID" : 3, "Position" : Vector2i(4,1)}, - {"ID" : 2, "Position" : Vector2i(5,0)}, - {"ID" : 1, "Position" : Vector2i(2,4)} - ] +var player_items : ItemInventory = preload("res://scripts/inventory_system/temp folder/player_inventory.tres") + func _ready() -> void: - player_inv = InventoryContainer.new(inventory_size) + #player_inv = register_inventory(player_inv) func register_inventory(inv : InventoryContainer) -> void: diff --git a/scripts/inventory_system/classes/inv_item.gd b/scripts/inventory_system/classes/inv_item.gd index 69f4daf..19d26dd 100644 --- a/scripts/inventory_system/classes/inv_item.gd +++ b/scripts/inventory_system/classes/inv_item.gd @@ -4,16 +4,23 @@ class_name InvItem # the top left of the item/slot var origin : Vector2i = Vector2i(-1,-1) - +# I dont think we need an id anymore, if the items are stored locally. +# but maybe we need to get an item var id : int = -1 var stackable : bool = false var stack : int = -1 var icon : Texture2D var object : Node2D +var data : Item -func _init(_origin : Vector2i,_id : int, item : Item) -> void: +func _init(_origin : Vector2i, item : Item) -> void: +#func _init(_origin : Vector2i,_id : int, item : Item) -> void: origin = _origin - id = _id + data = item + #id = _id stackable = item.stackable stack = 1 icon = item.item_texture + +func get_item_data() -> Item: + return data diff --git a/scripts/inventory_system/classes/inventory_container.gd b/scripts/inventory_system/classes/inventory_container.gd index 622f58d..8232a40 100644 --- a/scripts/inventory_system/classes/inventory_container.gd +++ b/scripts/inventory_system/classes/inventory_container.gd @@ -24,10 +24,13 @@ func get_id() -> int: func generate_cells(container : GridContainer) -> void: _container = container _container.columns = _size.x + print("This the columns %s" % _container.columns) var slot_pack : PackedScene = preload("res://scenes/inventory_system/slot.tscn") - - for x in range(_size.x): - for y in range(_size.y): + # This needs to created backwards because grid container... + print("Size %s" % _size) + for y in range(_size.y): + for x in range(_size.x): + await container.get_tree().create_timer(0.5).timeout var slot : Slot = slot_pack.instantiate() _container.add_child(slot) @@ -37,6 +40,8 @@ func generate_cells(container : GridContainer) -> void: # set the slots index and inv id slot.index = Vector2i(x,y) + print("Size x %s" % _size.x) + print("This is the index of the slot %s" % Vector2i(x,y)) ## this might be useful for detecting multiple different inventories #slot.inventory_id = _id # set slot into the slots dict to be able to change the item sprite @@ -59,7 +64,7 @@ func is_cell_free(index : Vector2i) -> bool: func add_item(inv_item : InvItem) -> bool: var index : Vector2i = inv_item.origin - + print(index) #if not is_cell_free(index): #return false @@ -79,10 +84,24 @@ func remove_item(inv_item : InvItem) -> void: func get_item(index : Vector2i) -> InvItem: return _item[index] -func load_data(items : Array[Dictionary],database : ItemDatabase) -> void: +## Database is not needed if the inventory res contains the items, this makes it so items are unique! +func load_data(items_container : ItemInventory) -> void: + # terriable way of naming stuff, sorry! + var items = items_container.inventory - for item in items: - var found_item : Item = database.database[item["ID"]] - - var inv_item : InvItem = InvItem.new(item["Position"],item["ID"],found_item) + for item_c in items: + var pos : Vector2i = item_c.position + var item : Item = item_c.item + ## Why do I need an id for adding an item into the inventory, what was I thinking? + ## Setting it to -1 to see if it even is needed. + var inv_item : InvItem = InvItem.new(pos,item) add_item(inv_item) + +## OLD way of loading data. +#func load_data(items : Array[Dictionary],database : ItemDatabase) -> void: + # + #for item in items: + #var found_item : Item = database.database[item["ID"]] + # + #var inv_item : InvItem = InvItem.new(item["Position"],item["ID"],found_item) + #add_item(inv_item) diff --git a/scripts/inventory_system/classes/item_database.gd b/scripts/inventory_system/classes/item_database.gd index 9379e02..50d3e82 100644 --- a/scripts/inventory_system/classes/item_database.gd +++ b/scripts/inventory_system/classes/item_database.gd @@ -1,4 +1,5 @@ extends Resource class_name ItemDatabase +## A place to store every item in the game... Might change in the future, not sure... @export var database : Dictionary[int,Item] diff --git a/scripts/inventory_system/classes/item_resource.gd b/scripts/inventory_system/classes/item_resource.gd index 5f74e92..57d7d11 100644 --- a/scripts/inventory_system/classes/item_resource.gd +++ b/scripts/inventory_system/classes/item_resource.gd @@ -1,4 +1,5 @@ extends Resource +## This was used for the database but this might change hmmmmm... class_name Item @export var item_name : String diff --git a/scripts/inventory_system/classes/resource classes/item_container.gd b/scripts/inventory_system/classes/resource classes/item_container.gd new file mode 100644 index 0000000..8fb1aea --- /dev/null +++ b/scripts/inventory_system/classes/resource classes/item_container.gd @@ -0,0 +1,5 @@ +extends Resource +class_name ItemContainer + +@export var position : Vector2i +@export var item : Item diff --git a/scripts/inventory_system/classes/resource classes/item_container.gd.uid b/scripts/inventory_system/classes/resource classes/item_container.gd.uid new file mode 100644 index 0000000..96afed4 --- /dev/null +++ b/scripts/inventory_system/classes/resource classes/item_container.gd.uid @@ -0,0 +1 @@ +uid://cwx8kabsi8ngp diff --git a/scripts/inventory_system/classes/resource classes/item_inventory.gd b/scripts/inventory_system/classes/resource classes/item_inventory.gd new file mode 100644 index 0000000..077ddd7 --- /dev/null +++ b/scripts/inventory_system/classes/resource classes/item_inventory.gd @@ -0,0 +1,6 @@ +extends Resource +class_name ItemInventory +## This is a terriable name for this class, the job for this class is to act as saving and loading items for +## specific inventories, needs a new name... + +@export var inventory : Array[ItemContainer] diff --git a/scripts/inventory_system/classes/resource classes/item_inventory.gd.uid b/scripts/inventory_system/classes/resource classes/item_inventory.gd.uid new file mode 100644 index 0000000..4b38552 --- /dev/null +++ b/scripts/inventory_system/classes/resource classes/item_inventory.gd.uid @@ -0,0 +1 @@ +uid://33e18nfurfst diff --git a/scripts/inventory_system/temp folder/player_inventory.tres b/scripts/inventory_system/temp folder/player_inventory.tres new file mode 100644 index 0000000..b85b4cb --- /dev/null +++ b/scripts/inventory_system/temp folder/player_inventory.tres @@ -0,0 +1,30 @@ +[gd_resource type="Resource" script_class="ItemInventory" load_steps=9 format=3 uid="uid://5mqcovutop40"] + +[ext_resource type="Script" uid="uid://cwx8kabsi8ngp" path="res://scripts/inventory_system/classes/resource classes/item_container.gd" id="1_hc3a2"] +[ext_resource type="Resource" uid="uid://cfhr0sg8bfjm4" path="res://resources/Items/Bandage.tres" id="2_7jmxm"] +[ext_resource type="Resource" uid="uid://31es6aujwcn1" path="res://resources/Items/Gernade.tres" id="3_h35uw"] +[ext_resource type="Resource" uid="uid://dborkiydh6s2c" path="res://resources/Items/Rifle.tres" id="5_ploc0"] +[ext_resource type="Script" uid="uid://33e18nfurfst" path="res://scripts/inventory_system/classes/resource classes/item_inventory.gd" id="6_hc3a2"] + +[sub_resource type="Resource" id="Resource_iuwu2"] +script = ExtResource("1_hc3a2") +position = Vector2i(0, 0) +item = ExtResource("2_7jmxm") +metadata/_custom_type_script = "uid://cwx8kabsi8ngp" + +[sub_resource type="Resource" id="Resource_r6hol"] +script = ExtResource("1_hc3a2") +position = Vector2i(2, 0) +item = ExtResource("3_h35uw") +metadata/_custom_type_script = "uid://cwx8kabsi8ngp" + +[sub_resource type="Resource" id="Resource_kltmp"] +script = ExtResource("1_hc3a2") +position = Vector2i(3, 3) +item = ExtResource("5_ploc0") +metadata/_custom_type_script = "uid://cwx8kabsi8ngp" + +[resource] +script = ExtResource("6_hc3a2") +inventory = Array[ExtResource("1_hc3a2")]([SubResource("Resource_iuwu2"), SubResource("Resource_r6hol"), SubResource("Resource_kltmp")]) +metadata/_custom_type_script = "uid://33e18nfurfst" diff --git a/scripts/menus/inventory_menu.gd b/scripts/menus/inventory_menu.gd index b384761..0f9d4c8 100644 --- a/scripts/menus/inventory_menu.gd +++ b/scripts/menus/inventory_menu.gd @@ -21,9 +21,9 @@ var swap_index : Vector2i func _ready() -> void: var player_inv : InventoryContainer = _get_inventory(0) # 0 is the players inv - player_inv.generate_cells(grid_container) + await player_inv.generate_cells(grid_container) # we need to generate the cells before we can load data, might not be the right way... - player_inv.load_data(InventoryManager.player_items,database) + player_inv.load_data(InventoryManager.player_items) # database has been removed # connect the slot pressed signal to a function in this script player_inv.slot_pressed.connect(on_slot_pressed) player_inv.slot_hovered.connect(handle_hover_tooltip) @@ -104,7 +104,7 @@ func handle_hover_tooltip(id : int, index : Vector2i) -> void: ## show a tooltip for the item, maybe we can also add options like consumbe,drop, etc var item : InvItem = inv.get_item(index) - var item_data : Item = database.database[item.id] + var item_data = item.get_item_data() print("Item (%s) , Stack (%s)" % [item_data.item_name,item.stack]) func drop() -> void: From 30f26feb2b765138edd65a4d01cb1b168602071f Mon Sep 17 00:00:00 2001 From: Dragon20C Date: Fri, 27 Jun 2025 08:08:39 +0100 Subject: [PATCH 8/9] Added descriptions to classes. --- .../inventories}/player_inventory.tres | 27 ++++++++++--------- scripts/global/inventory_manager.gd | 21 ++++++++++----- scripts/inventory_system/classes/inv_item.gd | 2 ++ .../classes/inventory_container.gd | 26 ++++-------------- .../inventory_system/classes/item_database.gd | 2 +- .../inventory_system/classes/item_resource.gd | 2 +- .../resource classes/item_container.gd | 1 + .../resource classes/item_inventory.gd | 6 ++--- scripts/inventory_system/classes/slot.gd | 1 + scripts/menus/inventory_menu.gd | 3 +-- 10 files changed, 43 insertions(+), 48 deletions(-) rename {scripts/inventory_system/temp folder => resources/inventories}/player_inventory.tres (68%) diff --git a/scripts/inventory_system/temp folder/player_inventory.tres b/resources/inventories/player_inventory.tres similarity index 68% rename from scripts/inventory_system/temp folder/player_inventory.tres rename to resources/inventories/player_inventory.tres index b85b4cb..b302457 100644 --- a/scripts/inventory_system/temp folder/player_inventory.tres +++ b/resources/inventories/player_inventory.tres @@ -1,30 +1,31 @@ [gd_resource type="Resource" script_class="ItemInventory" load_steps=9 format=3 uid="uid://5mqcovutop40"] -[ext_resource type="Script" uid="uid://cwx8kabsi8ngp" path="res://scripts/inventory_system/classes/resource classes/item_container.gd" id="1_hc3a2"] -[ext_resource type="Resource" uid="uid://cfhr0sg8bfjm4" path="res://resources/Items/Bandage.tres" id="2_7jmxm"] -[ext_resource type="Resource" uid="uid://31es6aujwcn1" path="res://resources/Items/Gernade.tres" id="3_h35uw"] -[ext_resource type="Resource" uid="uid://dborkiydh6s2c" path="res://resources/Items/Rifle.tres" id="5_ploc0"] -[ext_resource type="Script" uid="uid://33e18nfurfst" path="res://scripts/inventory_system/classes/resource classes/item_inventory.gd" id="6_hc3a2"] +[ext_resource type="Script" uid="uid://cwx8kabsi8ngp" path="res://scripts/inventory_system/classes/resource classes/item_container.gd" id="1_k12gj"] +[ext_resource type="Resource" uid="uid://cfhr0sg8bfjm4" path="res://resources/Items/Bandage.tres" id="2_hanmg"] +[ext_resource type="Resource" uid="uid://31es6aujwcn1" path="res://resources/Items/Gernade.tres" id="3_55tjb"] +[ext_resource type="Resource" uid="uid://dborkiydh6s2c" path="res://resources/Items/Rifle.tres" id="4_2kyjl"] +[ext_resource type="Script" uid="uid://33e18nfurfst" path="res://scripts/inventory_system/classes/resource classes/item_inventory.gd" id="5_l46mh"] [sub_resource type="Resource" id="Resource_iuwu2"] -script = ExtResource("1_hc3a2") +script = ExtResource("1_k12gj") position = Vector2i(0, 0) -item = ExtResource("2_7jmxm") +item = ExtResource("2_hanmg") metadata/_custom_type_script = "uid://cwx8kabsi8ngp" [sub_resource type="Resource" id="Resource_r6hol"] -script = ExtResource("1_hc3a2") +script = ExtResource("1_k12gj") position = Vector2i(2, 0) -item = ExtResource("3_h35uw") +item = ExtResource("3_55tjb") metadata/_custom_type_script = "uid://cwx8kabsi8ngp" [sub_resource type="Resource" id="Resource_kltmp"] -script = ExtResource("1_hc3a2") +script = ExtResource("1_k12gj") position = Vector2i(3, 3) -item = ExtResource("5_ploc0") +item = ExtResource("4_2kyjl") metadata/_custom_type_script = "uid://cwx8kabsi8ngp" [resource] -script = ExtResource("6_hc3a2") -inventory = Array[ExtResource("1_hc3a2")]([SubResource("Resource_iuwu2"), SubResource("Resource_r6hol"), SubResource("Resource_kltmp")]) +script = ExtResource("5_l46mh") +inventory_size = Vector2i(8, 6) +inventory = Array[ExtResource("1_k12gj")]([SubResource("Resource_iuwu2"), SubResource("Resource_r6hol"), SubResource("Resource_kltmp")]) metadata/_custom_type_script = "uid://33e18nfurfst" diff --git a/scripts/global/inventory_manager.gd b/scripts/global/inventory_manager.gd index c4a11fb..c9b2bcc 100644 --- a/scripts/global/inventory_manager.gd +++ b/scripts/global/inventory_manager.gd @@ -9,16 +9,19 @@ var inventories : Array[InventoryContainer] var next_id : int = 0 ## Player related -var inventory_size : Vector2i = Vector2i(8,6) -var player_inv : InventoryContainer = InventoryContainer.new(inventory_size) -# this might change in the future for a better way of storing items -var player_items : ItemInventory = preload("res://scripts/inventory_system/temp folder/player_inventory.tres") - +var player_items : ItemInventory = preload("res://resources/inventories/player_inventory.tres") +var player_inv : InventoryContainer = InventoryContainer.new(player_items.inventory_size): + set(value): + unregister_inventory(player_inv) + register_inventory(value) + player_inv = value func _ready() -> void: - #player_inv = register_inventory(player_inv) +## The register and unregister functions might need to be reworked because of how loading new scenes +## might be handled, if the inventory is fresh then it might not have an id already set when loading +## a new scene, but I think it will work still... func register_inventory(inv : InventoryContainer) -> void: ## if the id is -1, it means the inventory has not been set @@ -31,7 +34,11 @@ func register_inventory(inv : InventoryContainer) -> void: _: inventories[inv.get_id()] = inv -func unregister_inventory(id : int) -> void: +func unregister_inventory(inv : InventoryContainer) -> void: + var id : int = inv.get_id() + + if id <= -1: + return ## when we want to not use an inventory it is better to set it to null ## this is because we dont want to shuffle the array and also cause mismatch inventory IDs. inventories[id] = null diff --git a/scripts/inventory_system/classes/inv_item.gd b/scripts/inventory_system/classes/inv_item.gd index 19d26dd..f91c130 100644 --- a/scripts/inventory_system/classes/inv_item.gd +++ b/scripts/inventory_system/classes/inv_item.gd @@ -1,5 +1,7 @@ extends RefCounted class_name InvItem +## InvItem is mutable data, this is created on item loads when an inventory container +## is created and set. # the top left of the item/slot diff --git a/scripts/inventory_system/classes/inventory_container.gd b/scripts/inventory_system/classes/inventory_container.gd index 8232a40..cf44e88 100644 --- a/scripts/inventory_system/classes/inventory_container.gd +++ b/scripts/inventory_system/classes/inventory_container.gd @@ -1,5 +1,7 @@ extends RefCounted class_name InventoryContainer +## InventoryContainer handles the interactions between the slots. +## This includes, Loading item data on init, handling slot hover and presses which is handled externally signal slot_pressed(id : int , index : Vector2i) signal slot_hovered(id : int , index : Vector2i) @@ -24,13 +26,10 @@ func get_id() -> int: func generate_cells(container : GridContainer) -> void: _container = container _container.columns = _size.x - print("This the columns %s" % _container.columns) var slot_pack : PackedScene = preload("res://scenes/inventory_system/slot.tscn") - # This needs to created backwards because grid container... - print("Size %s" % _size) for y in range(_size.y): for x in range(_size.x): - await container.get_tree().create_timer(0.5).timeout + #await container.get_tree().create_timer(0.5).timeout var slot : Slot = slot_pack.instantiate() _container.add_child(slot) @@ -40,10 +39,8 @@ func generate_cells(container : GridContainer) -> void: # set the slots index and inv id slot.index = Vector2i(x,y) - print("Size x %s" % _size.x) - print("This is the index of the slot %s" % Vector2i(x,y)) ## this might be useful for detecting multiple different inventories - #slot.inventory_id = _id + ##slot.inventory_id = _id # set slot into the slots dict to be able to change the item sprite _slots[slot.index] = slot _slots[slot.index].set_stack(0) @@ -64,9 +61,6 @@ func is_cell_free(index : Vector2i) -> bool: func add_item(inv_item : InvItem) -> bool: var index : Vector2i = inv_item.origin - print(index) - #if not is_cell_free(index): - #return false # set item and item icon _item[index] = inv_item @@ -86,22 +80,12 @@ func get_item(index : Vector2i) -> InvItem: ## Database is not needed if the inventory res contains the items, this makes it so items are unique! func load_data(items_container : ItemInventory) -> void: - # terriable way of naming stuff, sorry! var items = items_container.inventory for item_c in items: var pos : Vector2i = item_c.position var item : Item = item_c.item - ## Why do I need an id for adding an item into the inventory, what was I thinking? - ## Setting it to -1 to see if it even is needed. + var inv_item : InvItem = InvItem.new(pos,item) add_item(inv_item) -## OLD way of loading data. -#func load_data(items : Array[Dictionary],database : ItemDatabase) -> void: - # - #for item in items: - #var found_item : Item = database.database[item["ID"]] - # - #var inv_item : InvItem = InvItem.new(item["Position"],item["ID"],found_item) - #add_item(inv_item) diff --git a/scripts/inventory_system/classes/item_database.gd b/scripts/inventory_system/classes/item_database.gd index 50d3e82..ce3b83a 100644 --- a/scripts/inventory_system/classes/item_database.gd +++ b/scripts/inventory_system/classes/item_database.gd @@ -1,5 +1,5 @@ extends Resource class_name ItemDatabase -## A place to store every item in the game... Might change in the future, not sure... +## This class might not be needed in the future, Leaving it for now until I add more features. @export var database : Dictionary[int,Item] diff --git a/scripts/inventory_system/classes/item_resource.gd b/scripts/inventory_system/classes/item_resource.gd index 57d7d11..80354be 100644 --- a/scripts/inventory_system/classes/item_resource.gd +++ b/scripts/inventory_system/classes/item_resource.gd @@ -1,6 +1,6 @@ extends Resource -## This was used for the database but this might change hmmmmm... class_name Item +## This is an important class, Item simply stores un-mutable data about the item @export var item_name : String @export_multiline var item_description : String diff --git a/scripts/inventory_system/classes/resource classes/item_container.gd b/scripts/inventory_system/classes/resource classes/item_container.gd index 8fb1aea..f9f8ae9 100644 --- a/scripts/inventory_system/classes/resource classes/item_container.gd +++ b/scripts/inventory_system/classes/resource classes/item_container.gd @@ -1,5 +1,6 @@ extends Resource class_name ItemContainer +## A data structure that simply holds the position and item for the item inventory. @export var position : Vector2i @export var item : Item diff --git a/scripts/inventory_system/classes/resource classes/item_inventory.gd b/scripts/inventory_system/classes/resource classes/item_inventory.gd index 077ddd7..8d8cb64 100644 --- a/scripts/inventory_system/classes/resource classes/item_inventory.gd +++ b/scripts/inventory_system/classes/resource classes/item_inventory.gd @@ -1,6 +1,6 @@ extends Resource class_name ItemInventory -## This is a terriable name for this class, the job for this class is to act as saving and loading items for -## specific inventories, needs a new name... - +## A resource class for storing item_containers which can be used for saving and loading. +## E.G the player would have an item inventory. +@export var inventory_size : Vector2i = Vector2i.ONE @export var inventory : Array[ItemContainer] diff --git a/scripts/inventory_system/classes/slot.gd b/scripts/inventory_system/classes/slot.gd index 5c6fb06..82f2c3d 100644 --- a/scripts/inventory_system/classes/slot.gd +++ b/scripts/inventory_system/classes/slot.gd @@ -1,5 +1,6 @@ extends PanelContainer class_name Slot +## Slot is simply a custom texture button that sets information about the set item. var index :Vector2i diff --git a/scripts/menus/inventory_menu.gd b/scripts/menus/inventory_menu.gd index 0f9d4c8..63f97e8 100644 --- a/scripts/menus/inventory_menu.gd +++ b/scripts/menus/inventory_menu.gd @@ -3,7 +3,6 @@ extends MenuBase @export_group("Settings") @export var database : ItemDatabase @export var grid_container : GridContainer -@export var inventory_size : Vector2i = Vector2i(8,6) @export var held_icon : Sprite2D enum states {Empty,Held,Drop,PickUp,Swap,Add,Remove} @@ -21,7 +20,7 @@ var swap_index : Vector2i func _ready() -> void: var player_inv : InventoryContainer = _get_inventory(0) # 0 is the players inv - await player_inv.generate_cells(grid_container) + player_inv.generate_cells(grid_container) # we need to generate the cells before we can load data, might not be the right way... player_inv.load_data(InventoryManager.player_items) # database has been removed # connect the slot pressed signal to a function in this script From 05e12ee2d42bc5bf0531066251e83ce09a2ade59 Mon Sep 17 00:00:00 2001 From: Dragon20C Date: Mon, 21 Jul 2025 07:38:22 +0100 Subject: [PATCH 9/9] Update in_game_menu.gd --- scripts/menus/in_game_menu.gd | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/scripts/menus/in_game_menu.gd b/scripts/menus/in_game_menu.gd index 58a73be..5abb55a 100644 --- a/scripts/menus/in_game_menu.gd +++ b/scripts/menus/in_game_menu.gd @@ -6,10 +6,20 @@ extends MenuBase # key then we should open the pause menu in this script # also we should call the GameManager script to delete the current scene if we # are going back to the main menu. + +var is_inv_open : bool = false + func _input(event: InputEvent) -> void: if event is InputEventKey: if event.keycode == KEY_ESCAPE and event.is_pressed(): # load the pause menu. menu_manager.switch_menu(GameMenuSystem.MENUS.Pause) elif event.keycode == KEY_E and event.is_pressed(): - menu_manager.switch_menu(GameMenuSystem.MENUS.Inventory) + match is_inv_open: + true: + is_inv_open = false + menu_manager.switch_to_previous_menu() + false: + menu_manager.switch_menu(GameMenuSystem.MENUS.Inventory) + is_inv_open = true +