basic inventory system added

yeah i vibecoded it for now, it will be custom written later.
sooorrryyyy :(
This commit is contained in:
Hellie-xd 2026-08-13 13:28:13 +02:00
parent 900f5eb6c3
commit c5a907cec2
77 changed files with 1428 additions and 246 deletions

3
.gitignore vendored
View file

@ -1,3 +1,6 @@
# Godot 4+ specific ignores
.godot/
/android/
#icon assets
assets/at-icons/*

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,45 @@
[remap]
importer="scene"
importer_version=1
type="PackedScene"
uid="uid://bi5wdy6yi6r36"
path="res://.godot/imported/bakpakbruh.glb-7cae4a63bff2f8306a326424f1ffcc36.scn"
[deps]
source_file="res://assets/models/bakpakbruh.glb"
dest_files=["res://.godot/imported/bakpakbruh.glb-7cae4a63bff2f8306a326424f1ffcc36.scn"]
[params]
nodes/root_type="res://entities/backpack/backpack.gd"
nodes/root_name=""
nodes/root_script=Resource("uid://r4y2lmkaoou6", "res://entities/backpack/backpack.gd")
mesh_library/use_node_names_as_mesh_names=false
array_mesh/deduplicate_surfaces=true
nodes/apply_root_scale=true
nodes/root_scale=1.0
nodes/import_as_skeleton_bones=false
nodes/use_name_suffixes=true
nodes/use_node_type_suffixes=true
meshes/ensure_tangents=true
meshes/generate_lods=true
meshes/create_shadow_meshes=true
meshes/light_baking=1
meshes/lightmap_texel_size=0.2
meshes/force_disable_compression=false
skins/use_named_skins=true
animation/import=true
animation/fps=30
animation/trimming=false
animation/remove_immutable_tracks=true
animation/import_rest_as_RESET=false
import_script/path=""
materials/extract=0
materials/extract_format=0
materials/extract_path=""
_subresources={}
gltf/naming_version=2
gltf/embedded_image_handling=1
gltf/texture_map_mode=1

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

View file

@ -0,0 +1,44 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cxuoyjdelh6rk"
path.s3tc="res://.godot/imported/bakpakbruh_bakpak_textur.png-6af4e025f97bdcc0b8b0114625fb634b.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
generator_parameters={
"md5": "9fb4947635fbb14479f02229ef80fba3"
}
[deps]
source_file="res://assets/models/bakpakbruh_bakpak_textur.png"
dest_files=["res://.godot/imported/bakpakbruh_bakpak_textur.png-6af4e025f97bdcc0b8b0114625fb634b.s3tc.ctex"]
[params]
compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=0

BIN
assets/models/pocket.blend Normal file

Binary file not shown.

BIN
assets/models/pocket.blend1 Normal file

Binary file not shown.

BIN
assets/models/pocket.glb Normal file

Binary file not shown.

View file

@ -0,0 +1,45 @@
[remap]
importer="scene"
importer_version=1
type="PackedScene"
uid="uid://dlr62xnyqw58o"
path="res://.godot/imported/pocket.glb-a4b661a1f385d9da9b62617c26eda594.scn"
[deps]
source_file="res://assets/models/pocket.glb"
dest_files=["res://.godot/imported/pocket.glb-a4b661a1f385d9da9b62617c26eda594.scn"]
[params]
nodes/root_type="res://entities/pocket/pocket.gd"
nodes/root_name=""
nodes/root_script=Resource("uid://bqyxpmihywvgo", "res://entities/pocket/pocket.gd")
mesh_library/use_node_names_as_mesh_names=false
array_mesh/deduplicate_surfaces=true
nodes/apply_root_scale=true
nodes/root_scale=1.0
nodes/import_as_skeleton_bones=false
nodes/use_name_suffixes=true
nodes/use_node_type_suffixes=true
meshes/ensure_tangents=true
meshes/generate_lods=true
meshes/create_shadow_meshes=true
meshes/light_baking=1
meshes/lightmap_texel_size=0.2
meshes/force_disable_compression=false
skins/use_named_skins=true
animation/import=true
animation/fps=30
animation/trimming=false
animation/remove_immutable_tracks=true
animation/import_rest_as_RESET=false
import_script/path=""
materials/extract=0
materials/extract_format=0
materials/extract_path=""
_subresources={}
gltf/naming_version=2
gltf/embedded_image_handling=1
gltf/texture_map_mode=1

View file

@ -1,5 +1,13 @@
@icon("res://addons/at-icons/node3d/hand.svg")
class_name EquippableItem extends RigidBody3D
# The @export_file tag creates a folder icon in the Inspector
# that only lets you select saved .tscn files!
@export_file("*.tscn") var scene_path: String
@export var mesh: MeshInstance3D
@export var collision: CollisionShape3D
var weight: float = 10.0
func _ready() -> void:

View file

@ -0,0 +1,9 @@
class_name GrabbableItem extends RigidBody3D
var weight: float = 10.0
func _ready() -> void:
self.add_to_group("grabbable")
for x in get_children():
x.add_to_group("grabbable")
collision_layer = 17

View file

@ -0,0 +1 @@
uid://d5aotywdqlh5

View file

@ -0,0 +1,22 @@
@icon("res://addons/at-icons/node3d/backpack.svg")
class_name Backpack extends EquippableItem
@export var inventory_size: int = 10
var inventory: Array[ItemData] = []
func change_backpack_mesh(new_mesh: MeshInstance3D):
mesh = new_mesh
func change_backpack(new_backpack: Backpack):
mesh = new_backpack.mesh
inventory_size = new_backpack.inventory_size
inventory = new_backpack.inventory
func _ready() -> void:
for i in range(inventory_size):
inventory.append(null)
add_to_group("equippable")
for i in get_children():
i.add_to_group("equippable")

View file

@ -0,0 +1 @@
uid://r4y2lmkaoou6

View file

@ -0,0 +1,17 @@
[gd_scene format=3 uid="uid://bmqm4andgetsd"]
[ext_resource type="Script" uid="uid://r4y2lmkaoou6" path="res://entities/backpack/backpack.gd" id="1_lb1lj"]
[sub_resource type="PlaceholderMesh" id="PlaceholderMesh_b5l5s"]
[sub_resource type="BoxShape3D" id="BoxShape3D_60a4j"]
[node name="BackpackBase" type="RigidBody3D" unique_id=1120864530]
script = ExtResource("1_lb1lj")
metadata/_custom_type_script = "uid://r4y2lmkaoou6"
[node name="MeshInstance3D" type="MeshInstance3D" parent="." unique_id=320717816]
mesh = SubResource("PlaceholderMesh_b5l5s")
[node name="CollisionShape3D" type="CollisionShape3D" parent="." unique_id=2030682082]
shape = SubResource("BoxShape3D_60a4j")

View file

@ -0,0 +1,17 @@
[gd_scene format=3 uid="uid://bgfcri1syevxy"]
[ext_resource type="Script" uid="uid://r4y2lmkaoou6" path="res://entities/backpack/backpack.gd" id="1_plucm"]
[ext_resource type="PackedScene" uid="uid://dvw51mhd42wg7" path="res://entities/backpack/bakpakbruh.tscn" id="2_450c1"]
[sub_resource type="BoxShape3D" id="BoxShape3D_b5l5s"]
size = Vector3(0.69036865, 0.9343262, 0.6944885)
[node name="BackpackMedium" type="RigidBody3D" unique_id=63698594]
script = ExtResource("1_plucm")
metadata/_custom_type_script = "uid://r4y2lmkaoou6"
[node name="bakpakbruh" parent="." unique_id=829759791 instance=ExtResource("2_450c1")]
[node name="CollisionShape3D" type="CollisionShape3D" parent="." unique_id=1351735382]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.008392334, -0.026245117, 0.0037384033)
shape = SubResource("BoxShape3D_b5l5s")

View file

@ -0,0 +1,14 @@
[gd_scene format=3 uid="uid://dvw51mhd42wg7"]
[ext_resource type="PackedScene" uid="uid://bi5wdy6yi6r36" path="res://assets/models/bakpakbruh.glb" id="1_8o2x0"]
[sub_resource type="BoxShape3D" id="BoxShape3D_b5l5s"]
size = Vector3(0.7092285, 0.9375, 0.69781494)
[node name="bakpakbruh" unique_id=829759791 node_paths=PackedStringArray("mesh", "collision") instance=ExtResource("1_8o2x0")]
mesh = NodePath("Plane")
collision = NodePath("CollisionShape3D")
[node name="CollisionShape3D" type="CollisionShape3D" parent="." index="1" unique_id=1180246807]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0064697266, -0.03125, 0.008636475)
shape = SubResource("BoxShape3D_b5l5s")

View file

@ -0,0 +1,21 @@
[gd_scene format=3 uid="uid://don2g5auhwbl8"]
[ext_resource type="Script" uid="uid://yggv7ie8yere" path="res://classes/equippable_item.gd" id="1_xb40d"]
[sub_resource type="BoxShape3D" id="BoxShape3D_yf5fn"]
[sub_resource type="BoxMesh" id="BoxMesh_yf5fn"]
[node name="TestObjectEquippable" type="RigidBody3D" unique_id=2137836052 node_paths=PackedStringArray("mesh", "collision") groups=["equippable"]]
collision_layer = 17
collision_mask = 17
script = ExtResource("1_xb40d")
mesh = NodePath("MeshInstance3D")
collision = NodePath("CollisionShape3D")
metadata/_custom_type_script = "uid://yggv7ie8yere"
[node name="CollisionShape3D" type="CollisionShape3D" parent="." unique_id=1885578117]
shape = SubResource("BoxShape3D_yf5fn")
[node name="MeshInstance3D" type="MeshInstance3D" parent="." unique_id=1140899741]
mesh = SubResource("BoxMesh_yf5fn")

View file

@ -0,0 +1,21 @@
[gd_scene format=3 uid="uid://codt2h7ojcsae"]
[ext_resource type="Script" uid="uid://yggv7ie8yere" path="res://classes/equippable_item.gd" id="1_sb4pp"]
[sub_resource type="BoxShape3D" id="BoxShape3D_yf5fn"]
[sub_resource type="PrismMesh" id="PrismMesh_fm80t"]
[node name="TestObjectEquippable2" type="RigidBody3D" unique_id=1920911339 node_paths=PackedStringArray("mesh", "collision") groups=["equippable"]]
collision_layer = 17
collision_mask = 17
script = ExtResource("1_sb4pp")
mesh = NodePath("MeshInstance3D")
collision = NodePath("CollisionShape3D")
metadata/_custom_type_script = "uid://yggv7ie8yere"
[node name="CollisionShape3D" type="CollisionShape3D" parent="." unique_id=1618140963]
shape = SubResource("BoxShape3D_yf5fn")
[node name="MeshInstance3D" type="MeshInstance3D" parent="." unique_id=335531169]
mesh = SubResource("PrismMesh_fm80t")

View file

@ -1,6 +1,6 @@
[gd_scene format=3 uid="uid://csj6ipagcwmeu"]
[ext_resource type="Script" uid="uid://cg6uae2pbr7eq" path="res://scenes/grabbable_base/grabbable_base.gd" id="1_rs3u4"]
[ext_resource type="Script" uid="uid://cg6uae2pbr7eq" path="res://entities/grabbable_base/grabbable_base.gd" id="1_rs3u4"]
[sub_resource type="PrismMesh" id="PrismMesh_60a4j"]

View file

@ -0,0 +1,6 @@
class_name BackpackComponent extends Node
@export var backpack: Backpack
func change_backpack(new_backpack:Backpack):
backpack.change_backpack(new_backpack)

View file

@ -0,0 +1 @@
uid://ba5xw7i0xesdw

View file

@ -21,7 +21,6 @@ func toggle_flashlight():
flashlight_on = !flashlight_on
flashlight.visible = flashlight_on
print("flashlight ", flashlight_on)
flashlight_toggled.emit(true)
func _process(delta: float) -> void:

View file

@ -0,0 +1,341 @@
class_name HotbarComponent extends Node
var selected_item: int = 0
var prev_selected_item: int = 0
var inventory: Array[ItemData] = [null, null]
@export var equipped_item_mesh: MeshInstance3D
@export var hold_position: Marker3D
@export var cursor_raycast: RayCast3D
signal added_inventory_slot(successful: bool)
signal removed_inventory_slot(successful: bool)
signal select_item(index: int)
# For UI elements
signal add_item(index: int, item: ItemData)
signal remove_item(index: int)
func add_inventory_slot() -> bool:
if len(inventory) < 5:
inventory.append(null)
added_inventory_slot.emit(true)
return true
added_inventory_slot.emit(false)
return false
func remove_inventory_slot() -> bool:
if len(inventory) > 2:
inventory.remove_at(len(inventory) - 1)
removed_inventory_slot.emit(true)
return true
removed_inventory_slot.emit(false)
return false
func next_item():
prev_selected_item = selected_item
if selected_item + 1 > len(inventory) - 1:
selected_item = 0
else:
selected_item += 1
_select_item()
func prev_item():
prev_selected_item = selected_item
if selected_item - 1 < 0:
selected_item = len(inventory) - 1
else:
selected_item -= 1
_select_item()
func _select_item(index: int = selected_item):
selected_item = index
if index >= 0 and index < len(inventory):
select_item.emit(index)
# Update the hand visual
if inventory[index] == null:
equipped_item_mesh.mesh = PlaceholderMesh.new()
else:
# Apply the mesh directly from the ItemData!
equipped_item_mesh.mesh = inventory[index].hand_mesh
func _add_item(item: EquippableItem):
var target_index = -1
# 1. Decide which slot to use (current slot first, then first empty)
if inventory[selected_item] == null:
target_index = selected_item
else:
for i in range(len(inventory)):
if inventory[i] == null:
target_index = i
break
# If inventory is full, do nothing
if target_index == -1:
print("Inventory Full!")
return
# 2. Extract Data from the physical item
var new_item_data: ItemData = ItemData.new()
new_item_data.name = item.name
new_item_data.weight = item.weight
new_item_data.scene_path = item.scene_file_path
if item is Backpack:
new_item_data.item_type = ItemData.ItemType.BACKPACK
new_item_data.provided_slots = item.inventory_size
elif item is Pocket:
new_item_data.item_type = ItemData.ItemType.POCKET
else:
new_item_data.item_type = ItemData.ItemType.NORMAL
# Save the mesh so we can display it in the player's hand later
if item.mesh:
new_item_data.hand_mesh = item.mesh.mesh
# Await your custom icon generator (if it requires awaiting)
new_item_data.ui_icon = await GrabbableBase.create_icon_from_mesh(item.mesh.mesh)
# 3. Add to inventory array and UI
inventory[target_index] = new_item_data
add_item.emit(target_index, new_item_data)
# 4. CRITICAL: Delete the physical item from the world!
item.queue_free()
# Update the hand model if we added it to our currently selected slot
_select_item(selected_item)
func update_slot(index: int, new_item: ItemData) -> void:
inventory[index] = new_item
# Tell the in-game HUD that the slot changed
if new_item != null:
add_item.emit(index, new_item)
else:
remove_item.emit(index)
# If this is the slot the player is currently holding, update the 3D hand mesh!
if index == selected_item:
_select_item(selected_item)
func _drop_item(index: int = selected_item):
var item_data = inventory[index]
if item_data != null and item_data.scene_path != "":
# 1. Load the original scene file for the item
var packed_scene = load(item_data.scene_path) as PackedScene
if not packed_scene:
push_error("Could not load scene path: " + item_data.scene_path)
return
# 2. Instantiate a brand new physical object
var new_object = packed_scene.instantiate() as RigidBody3D
# 3. Add it to the world (Parent it to the main scene, not the player!)
get_tree().current_scene.add_child(new_object)
# 4. Place it in front of the player
new_object.global_position = hold_position.global_position
new_object.global_rotation = Vector3.ZERO
# 5. Clear the inventory slot
_remove_item(index)
func _remove_item(index: int):
remove_item.emit(index)
inventory[index] = null
_select_item(selected_item) # Refresh the hand model
func get_selected_item() -> ItemData:
return inventory[selected_item]
func _ready() -> void:
get_tree().create_timer(0.1).timeout.connect(func(): _select_item(0))
func _process(_delta: float) -> void:
if Console.toggled or UiManager.in_game_menu.visible:
return
if Input.is_action_just_pressed("next_item"):
next_item()
if Input.is_action_just_pressed("prev_item"):
prev_item()
if Input.is_action_just_pressed("select_item_1"): _select_item(0)
if Input.is_action_just_pressed("select_item_2"): _select_item(1)
if Input.is_action_just_pressed("select_item_3"): _select_item(2)
if Input.is_action_just_pressed("select_item_4"): _select_item(3)
if Input.is_action_just_pressed("select_item_5"): _select_item(4)
if Input.is_action_just_pressed("equip"):
if cursor_raycast.is_colliding():
var hit_object = cursor_raycast.get_collider()
if hit_object is EquippableItem:
_add_item(hit_object)
if Input.is_action_just_pressed("drop"):
_drop_item()
#class_name HotbarComponent extends Node
#
#var selected_item: int = 0
#var prev_selected_item: int = 0
#var selected_item_object: EquippableItem = null
#var inventory: Array[ItemData] = [null,null]
#
#@export var equipped_item_mesh: MeshInstance3D
#@export var hold_position: Marker3D
#@export var cursor_raycast: RayCast3D
#
#signal added_inventory_slot(successful:bool)
#signal removed_inventory_slot(successful:bool)
#signal select_item(index: int)
#
##for ui elements
#signal add_item(index: int, item: ItemData)
#signal remove_item(index: int)
#
#func add_inventory_slot() -> bool:
#if len(inventory) < 5:
#inventory.append(null)
#added_inventory_slot.emit(true)
#return true
#added_inventory_slot.emit(false)
#return false
#
#func remove_inventory_slot() -> bool:
#if len(inventory) > 2:
#inventory.remove_at(len(inventory) - 1)
#removed_inventory_slot.emit(true)
#return true
#added_inventory_slot.emit(false)
#return false
#
#func next_item():
#prev_selected_item = selected_item
#if selected_item + 1 > len(inventory) - 1:
#selected_item = 0
#else:
#selected_item += 1
#_select_item()
#
#func prev_item():
#prev_selected_item = selected_item
#if selected_item - 1 < 0:
#selected_item = len(inventory) - 1
#else:
#selected_item -= 1
#_select_item()
#
#func _select_item(index:int = selected_item):
#if index >= 0 and index < len(inventory):
#select_item.emit(index)
#
#if inventory[index] == null:
##if current index is empty in the inventory, replace held object with placeholder (empty mesh)
#equipped_item_mesh.mesh = PlaceholderMesh.new()
#else:
#var mesh = null
#for i in inventory[index].get_children():
#if i is MeshInstance3D:
#equipped_item_mesh.mesh = i.mesh
#
#func _add_item(item: EquippableItem):
##add item to current equipped slot if empty
#
#var new_item_data = ItemData.new()
#new_item_data.name = item.name
#new_item_data.weight = item.weight
#new_item_data.scene_path = item.scene_file_path
#new_item_data.ui_icon = await GrabbableBase.create_icon_from_mesh(item.mesh.mesh)
#if inventory[selected_item] == null:
#inventory[selected_item] = new_item_data
#
#add_item.emit(selected_item, new_item_data)
#
##ui.add_item(selected_item, item)
#item.reparent(get_parent().get_parent())
#item.collision_layer = 0
#item.visible = false
#_select_item(selected_item)
#return
#
##add item to first empty slot if currently equipped slot is full
#for i in range(0, len(inventory)):
#if inventory[i] == null:
#inventory[i] = new_item_data
#
#add_item.emit(i, new_item_data)
##ui.add_item(i, item)
#item.reparent(get_parent().get_parent())
#item.collision_layer = 0
#item.visible = false
#return
#
##dont equip item if inventory full
#
#func _drop_item(index: int = selected_item):
#if inventory[index] != null:
#var object = inventory[index]
#
#object.scale = Vector3.ONE
#
#if object.is_inside_tree():
#object.reparent(get_tree().current_scene, true)
#
#object.collision_layer = 17
#object.global_position = hold_position.global_position
#object.visible = true
#object.global_rotation = Vector3.ZERO
#
#_remove_item(index)
#
#func _remove_item(index: int):
##ui.remove_item(index)
#remove_item.emit(index)
#inventory[index] = null
#_select_item(index)
#
#func get_selected_item() -> ItemData:
#return inventory[selected_item]
#
#func _ready() -> void:
#get_tree().create_timer(0.1).timeout.connect(func (): _select_item(0))
#
#func _process(_delta: float) -> void:
#if not Console.toggled and not UiManager.in_game_menu.visible:
#if Input.is_action_just_pressed("next_item"):
#next_item()
#
#if Input.is_action_just_pressed("prev_item"):
#prev_item()
#
#if Input.is_action_just_pressed("select_item_1"):
#_select_item(0)
#
#if Input.is_action_just_pressed("select_item_2"):
#_select_item(1)
#
#if Input.is_action_just_pressed("select_item_3"):
#_select_item(2)
#
#if Input.is_action_just_pressed("select_item_4"):
#_select_item(3)
#
#if Input.is_action_just_pressed("select_item_5"):
#_select_item(4)
#
#if Input.is_action_just_pressed("equip"):
#if cursor_raycast.is_colliding():
#var hit_object = cursor_raycast.get_collider()
#
#if hit_object is EquippableItem:
#_add_item(hit_object)
#
#if Input.is_action_just_pressed("drop"):
#_drop_item()

View file

@ -0,0 +1,18 @@
class_name InventoryComponent extends Node
var toggled: bool = false
@onready var inventory_menu = UiManager.inventory_menu
signal toggle(toggle: bool)
func _process(delta: float) -> void:
if Input.is_action_just_pressed("open_inventory"):
if toggled:
print("toggle off")
UiManager.toggle_inventory_menu(false)
toggle.emit(false)
else:
print("toggle on")
UiManager.toggle_inventory_menu(true)
toggle.emit(true)
toggled = !toggled

View file

@ -0,0 +1 @@
uid://c32j8acbe3myf

View file

@ -16,6 +16,7 @@ var walks: bool = false
var _player_spawned: bool = false
var _current_state: String = "idle"
var _move_toggled: bool = false
func handle_joypad_movement():
var controller_look_vector = Input.get_vector("look_left", "look_right", "look_up", "look_down") * 50
@ -24,6 +25,13 @@ func handle_joypad_movement():
mouse_motion += controller_look_vector
mouse_motion_delta += controller_look_vector
func toggle_movement():
_move_toggled = !_move_toggled
if _move_toggled:
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
else:
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
func _input(event: InputEvent) -> void:
if not UiManager.in_game_menu.visible:
if event is InputEventMouseMotion:
@ -40,7 +48,7 @@ func _ready() -> void:
get_tree().create_timer(0.5).timeout.connect(func(): _player_spawned = true)
func _physics_process(delta: float) -> void:
if Console.toggled or UiManager.in_game_menu.visible:
if Console.toggled or UiManager.in_game_menu.visible or UiManager.inventory_menu.visible:
player.velocity.x = lerpf(player.velocity.x, 0, delta * 10)
player.velocity.z = lerpf(player.velocity.z, 0, delta * 10)
player.move_and_slide()
@ -61,7 +69,13 @@ func _physics_process(delta: float) -> void:
if not was_on_floor:
player.velocity += player.get_gravity() * delta
var input_dir = Input.get_vector("left", "right", "forward", "backward")
var input_dir: Vector2
if not _move_toggled:
input_dir = Input.get_vector("left", "right", "forward", "backward")
else:
input_dir = Vector2.ZERO
var target_speed = PlayerConsts.SPEED
var new_state = "idle"
var is_moving = input_dir != Vector2.ZERO
@ -107,6 +121,7 @@ func _physics_process(delta: float) -> void:
else:
camera_pivot.rotation.z = lerpf(camera_pivot.rotation.z, 0, delta*10)
camera_pivot.position.x = lerpf(camera_pivot.position.x, 0, delta * 7)
player.move_and_slide()
if not was_on_floor and player.is_on_floor() and _player_spawned:

View file

@ -7,12 +7,15 @@ class_name Player extends CharacterBody3D
@export_category("Components")
@export var stamina_component: StaminaComponent
@export var flashlight_component: FlashlightComponent
@export var inventory_component: InventoryComponent
@export var hotbar_component: HotbarComponent
@export var movement_component: MovementComponent
@export var input_controller: InputController
@export var procedural_animator: ProceduralAnimator
@export var sound_controller: SoundController
@export var player_state: PlayerState
@export var inventory_component: InventoryComponent
@export var equipped_backpack: Backpack
static var player: Player
@ -26,11 +29,15 @@ func _ready() -> void:
player = self
#signal connections
inventory_component.select_item.connect(ui.select_item)
inventory_component.add_item.connect(ui.add_item)
inventory_component.remove_item.connect(ui.remove_item)
inventory_component.added_inventory_slot.connect(ui.add_inventory_slot)
inventory_component.removed_inventory_slot.connect(ui.remove_inventory_slot)
hotbar_component.select_item.connect(ui.select_item)
hotbar_component.add_item.connect(ui.add_item)
hotbar_component.remove_item.connect(ui.remove_item)
hotbar_component.added_inventory_slot.connect(ui.add_inventory_slot)
hotbar_component.removed_inventory_slot.connect(ui.remove_inventory_slot)
inventory_component.toggle.connect(ui.anti_toggle)
ui.visibility_changed.connect(movement_component.toggle_movement)
procedural_animator.breath.connect(sound_controller.play_breath_sound)
procedural_animator.footstep.connect(sound_controller.play_footstep_sound)
@ -57,3 +64,14 @@ func _ready() -> void:
else: \
stamina_component.run(false))
movement_component.state_changed.connect(player_state.handle_state_change)
#temporary so i can prototype
func _process(delta: float) -> void:
if Input.is_action_just_pressed("open_inventory"):
if UiManager.inventory_menu.visible:
UiManager.toggle_inventory_menu(false)
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
else:
UiManager.toggle_inventory_menu(true)
UiManager.inventory_menu.open_inventory(equipped_backpack, hotbar_component)
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE

View file

@ -1,42 +1,47 @@
[gd_scene format=3 uid="uid://kqq30y24c6kd"]
[ext_resource type="Script" uid="uid://bawpnca3v51gv" path="res://scenes/player/player.gd" id="1_76ube"]
[ext_resource type="PackedScene" uid="uid://bsccbqq04umeg" path="res://scenes/player/player_ui.tscn" id="2_rkbax"]
[ext_resource type="Script" uid="uid://2mpqfiofksnu" path="res://scenes/player/inventory_component.gd" id="10_ugbui"]
[ext_resource type="Script" uid="uid://dntoi54g4hqce" path="res://scenes/player/flashlight_component.gd" id="11_myrg7"]
[ext_resource type="Script" uid="uid://cdfis3askl3gb" path="res://scenes/player/stamina_component.gd" id="12_kvlxm"]
[ext_resource type="PackedScene" uid="uid://c02fkimxlbrje" path="res://scenes/player/prompt.tscn" id="13_ugbui"]
[ext_resource type="PackedScene" uid="uid://blh2biuk44qqj" path="res://scenes/player/cursor.tscn" id="14_fcs02"]
[ext_resource type="Script" uid="uid://bawpnca3v51gv" path="res://entities/player/player.gd" id="1_76ube"]
[ext_resource type="PackedScene" uid="uid://bsccbqq04umeg" path="res://entities/player/player_ui.tscn" id="2_rkbax"]
[ext_resource type="Script" uid="uid://2mpqfiofksnu" path="res://entities/player/hotbar_component.gd" id="10_ugbui"]
[ext_resource type="Script" uid="uid://c32j8acbe3myf" path="res://entities/player/inventory_component.gd" id="11_b2kln"]
[ext_resource type="Script" uid="uid://dntoi54g4hqce" path="res://entities/player/flashlight_component.gd" id="11_myrg7"]
[ext_resource type="Script" uid="uid://cdfis3askl3gb" path="res://entities/player/stamina_component.gd" id="12_kvlxm"]
[ext_resource type="PackedScene" uid="uid://bmqm4andgetsd" path="res://entities/backpack/backpack_base.tscn" id="13_b2kln"]
[ext_resource type="PackedScene" uid="uid://c02fkimxlbrje" path="res://entities/player/prompt.tscn" id="13_ugbui"]
[ext_resource type="PackedScene" uid="uid://blh2biuk44qqj" path="res://entities/player/cursor.tscn" id="14_fcs02"]
[ext_resource type="AudioStream" uid="uid://0q6nhlhgnxu2" path="res://assets/sounds/whitenoise.mp3" id="14_ugbui"]
[ext_resource type="Script" uid="uid://dr2lwciaohf6f" path="res://scenes/player/movement_component.gd" id="60_s3g0c"]
[ext_resource type="Script" uid="uid://cjk6a0da11ge6" path="res://scenes/player/procedural_animator.gd" id="61_hggc2"]
[ext_resource type="Script" uid="uid://v8er7yn0hdh8" path="res://scenes/player/sound_controller_component.gd" id="62_b2j0d"]
[ext_resource type="Script" uid="uid://dr2lwciaohf6f" path="res://entities/player/movement_component.gd" id="60_s3g0c"]
[ext_resource type="Script" uid="uid://cjk6a0da11ge6" path="res://entities/player/procedural_animator.gd" id="61_hggc2"]
[ext_resource type="Script" uid="uid://v8er7yn0hdh8" path="res://entities/player/sound_controller_component.gd" id="62_b2j0d"]
[ext_resource type="Script" uid="uid://y8x4svl5kej2" path="res://addons/spatial_audio_3d/spatial_audio_3d.gd" id="62_jbx34"]
[ext_resource type="Script" uid="uid://7aa26wi66kqq" path="res://scenes/player/prompt_handler.gd" id="63_7l6ig"]
[ext_resource type="Script" uid="uid://bvvwwkswavy5x" path="res://scenes/player/input_controller_component.gd" id="64_j3r50"]
[ext_resource type="Script" uid="uid://7hmwhf7acwpj" path="res://scenes/player/state_handler_component.gd" id="65_kssj8"]
[ext_resource type="Script" uid="uid://7aa26wi66kqq" path="res://entities/player/prompt_handler.gd" id="63_7l6ig"]
[ext_resource type="Script" uid="uid://bvvwwkswavy5x" path="res://entities/player/input_controller_component.gd" id="64_j3r50"]
[ext_resource type="Script" uid="uid://7hmwhf7acwpj" path="res://entities/player/state_handler_component.gd" id="65_kssj8"]
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_g4v7s"]
[sub_resource type="CapsuleMesh" id="CapsuleMesh_b5l5s"]
radius = 0.6166992
[sub_resource type="PlaceholderMesh" id="PlaceholderMesh_b5l5s"]
[sub_resource type="CylinderShape3D" id="CylinderShape3D_g4v7s"]
radius = 0.04638672
[node name="Player" type="CharacterBody3D" unique_id=423228143 node_paths=PackedStringArray("stamina_component", "flashlight_component", "inventory_component", "movement_component", "input_controller", "procedural_animator", "sound_controller", "player_state") groups=["player"]]
[sub_resource type="CapsuleMesh" id="CapsuleMesh_b5l5s"]
[node name="Player" type="CharacterBody3D" unique_id=423228143 node_paths=PackedStringArray("stamina_component", "flashlight_component", "hotbar_component", "movement_component", "input_controller", "procedural_animator", "sound_controller", "player_state", "inventory_component", "equipped_backpack") groups=["player"]]
collision_layer = 16
collision_mask = 16
script = ExtResource("1_76ube")
stamina_component = NodePath("Components/StaminaComponent")
flashlight_component = NodePath("Components/FlashlightComponent")
inventory_component = NodePath("Components/InventoryComponent")
hotbar_component = NodePath("Components/HotbarComponent")
movement_component = NodePath("Components/MovementComponent")
input_controller = NodePath("Components/InputController")
procedural_animator = NodePath("Components/ProceduralAnimator")
sound_controller = NodePath("Components/SoundController")
player_state = NodePath("Components/PlayerState")
inventory_component = NodePath("Components/InventoryComponent")
equipped_backpack = NodePath("CameraPivot/MeshInstance3D/BackpackBase")
[node name="Components" type="Node" parent="." unique_id=1652812621]
@ -86,7 +91,7 @@ unique_name_in_owner = true
script = ExtResource("65_kssj8")
player = NodePath("../..")
[node name="InventoryComponent" type="Node" parent="Components" unique_id=1980833408 node_paths=PackedStringArray("equipped_item_mesh", "hold_position", "cursor_raycast")]
[node name="HotbarComponent" type="Node" parent="Components" unique_id=1980833408 node_paths=PackedStringArray("equipped_item_mesh", "hold_position", "cursor_raycast")]
unique_name_in_owner = true
script = ExtResource("10_ugbui")
equipped_item_mesh = NodePath("../../CameraPivot/PlayerCamera/EquippedItemMesh")
@ -102,12 +107,13 @@ flashlight = NodePath("../../CameraPivot/PlayerCamera/Flashlight")
unique_name_in_owner = true
script = ExtResource("12_kvlxm")
[node name="InventoryComponent" type="Node" parent="Components" unique_id=1611449751]
unique_name_in_owner = true
script = ExtResource("11_b2kln")
[node name="PlayerHitBox" type="CollisionShape3D" parent="." unique_id=1513955228]
shape = SubResource("CapsuleShape3D_g4v7s")
[node name="MeshInstance3D" type="MeshInstance3D" parent="PlayerHitBox" unique_id=539906244]
mesh = SubResource("CapsuleMesh_b5l5s")
[node name="CameraPivot" type="Node3D" parent="." unique_id=963377832]
unique_name_in_owner = true
@ -170,6 +176,14 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.7621309, 0)
doppler_tracking = 2
current = true
[node name="MeshInstance3D" type="MeshInstance3D" parent="CameraPivot" unique_id=539906244]
mesh = SubResource("CapsuleMesh_b5l5s")
[node name="BackpackBase" parent="CameraPivot/MeshInstance3D" unique_id=1120864530 instance=ExtResource("13_b2kln")]
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.18192899, 0.7772218)
inventory_size = 5
[node name="Prompt" parent="." unique_id=318901794 instance=ExtResource("13_ugbui")]
unique_name_in_owner = true
visible = false

View file

@ -45,14 +45,9 @@ func select_item(index):
if index >= 0 and index < inventory_size:
inventory_slots_panels[index].get_parent().add_theme_stylebox_override("panel", selected_stylebox)
func add_item(index: int, object: RigidBody3D):
func add_item(index: int, object: ItemData):
if index >= 0 and index < inventory_size:
var meshes = object.get_children()
var texture = null
for i in meshes:
if i is MeshInstance3D:
texture = await GrabbableBase.create_icon_from_mesh(i.mesh)
inventory_slots_panels[index].texture = texture
inventory_slots_panels[index].texture = object.ui_icon
func remove_item(index: int):
if index >= 0 and index < inventory_size:
@ -67,6 +62,13 @@ func set_stamina(value:float):
func set_flashlight(value:float):
flashlight = value
# i hate myself
func anti_toggle(on:bool):
visible = !on
func toggle(on:bool):
visible = on
func _process(delta: float) -> void:
stamina_bar.value = lerpf(stamina_bar.value, stamina, delta * 5)
flashlight_bar.value = lerpf(flashlight_bar.value, flashlight, delta * 5)

View file

@ -1,6 +1,6 @@
[gd_scene format=3 uid="uid://bsccbqq04umeg"]
[ext_resource type="Script" uid="uid://lkb0o8too0mj" path="res://scenes/player/player_ui.gd" id="1_32d7b"]
[ext_resource type="Script" uid="uid://lkb0o8too0mj" path="res://entities/player/player_ui.gd" id="1_32d7b"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_m6sn8"]
bg_color = Color(0.23921569, 0.23921569, 0.23921569, 0.47058824)

View file

@ -1,6 +1,6 @@
[gd_scene format=3 uid="uid://c02fkimxlbrje"]
[ext_resource type="Script" uid="uid://csmi0dkeaejty" path="res://scenes/player/prompt.gd" id="1_ddq1g"]
[ext_resource type="Script" uid="uid://csmi0dkeaejty" path="res://entities/player/prompt.gd" id="1_ddq1g"]
[ext_resource type="PackedScene" uid="uid://bfg4q1t8s06vv" path="res://scenes/ui/optimized_blur_panel.tscn" id="2_onkvn"]
[node name="Prompt" type="Control" unique_id=318901794]

View file

@ -40,6 +40,15 @@ var _current_breath_in_sound = null
var _current_breath_out_sound = null
var _current_leg_is_right = false
var cur_priorities: Dictionary = {
left_foot: -1,
right_foot: -1,
right_foot_texture: -1,
left_foot_texture: -1,
head: -1,
head_texture: -1
}
@export var player: Player
@export var left_foot: SpatialAudio3D
@ -50,14 +59,14 @@ var _current_leg_is_right = false
@export var head_texture: SpatialAudio3D
@export var wind: AudioStreamPlayer3D
var audio_cooldowns = {
"left_foot": 0,
"right_foot": 0,
"right_foot_texture": 0,
"left_foot_texture": 0,
"head": 0,
"head_texture": 0
}
#var audio_cooldowns = {
#"left_foot": 0,
#"right_foot": 0,
#"right_foot_texture": 0,
#"left_foot_texture": 0,
#"head": 0,
#"head_texture": 0
#}
var get_player_str = func (player:SpatialAudio3D):
match player:
@ -69,6 +78,12 @@ var get_player_str = func (player:SpatialAudio3D):
head_texture: return "head_texture"
_: push_error("problem in get_player_str in sound_controller_component.gd. fuck????")
enum Priority {
LOW = 0,
MEDIUM = 1,
HIGH = 2,
MAX = 3
}
var debug: bool = false
var reverb: bool = true
@ -79,15 +94,16 @@ func _ready() -> void:
for i in sound_players:
i.debug = debug
i.reverb_enabled = reverb
cur_priorities.get_or_add(i, -1)
get_tree().create_timer(1).timeout.connect(init_wind)
func _process(delta: float) -> void:
if audio_cooldowns != null:
for i in audio_cooldowns:
if audio_cooldowns[i] > 0:
audio_cooldowns[i] -= delta
#if audio_cooldowns != null:
#for i in audio_cooldowns:
#if audio_cooldowns[i] > 0:
#audio_cooldowns[i] -= delta
play_wind()
@ -105,6 +121,7 @@ func create_spatial_audio_sphere(pos:Vector3, audio:AudioStream, pitch:float = 1
spatial_audio.collision_mask = 1
spatial_audio.stream = audio
spatial_audio.pitch_scale = pitch
add_child(spatial_audio)
@ -121,16 +138,24 @@ func create_spatial_audio_sphere(pos:Vector3, audio:AudioStream, pitch:float = 1
elif is_instance_valid(spatial_audio):
spatial_audio.queue_free()
func play_stream_on_player(player:SpatialAudio3D, audio:AudioStream, pitch: float = randf_range(.8, 1.2), volume = 1.0):
if not is_instance_valid(player) or audio == null:
@warning_ignore("shadowed_variable")
func play_stream_on_player(audio_player:SpatialAudio3D, audio:AudioStream, pitch: float = randf_range(.8, 1.2), volume = 1.0, priority: Priority = Priority.LOW):
if not is_instance_valid(audio_player) or audio == null or not audio_player:
return
if audio_cooldowns[get_player_str.call(player)] <= 0:
player.do_set_stream(audio)
player.pitch_scale = pitch
player.volume_linear = volume ** 2
player.do_play()
audio_cooldowns[get_player_str.call(player)] = audio.get_length() / 1.5
if audio_player.playing:
if priority < cur_priorities[audio_player]:
return
#dont play shi
cur_priorities[audio_player] = priority
audio_player.do_stop()
audio_player.do_set_stream(audio)
audio_player.pitch_scale = pitch
audio_player.volume_linear = volume ** 2
audio_player.do_play()
#audio_cooldowns[get_player_str.call(player)] = audio.get_length() / 1.5
func play_breath_sound(breathe_in:bool = true):
var play_sound
@ -169,7 +194,7 @@ func play_breath_sound(breathe_in:bool = true):
play_sound = Sounds.get_random_sound(Sounds.BREATHE_OUT_EXHAUSTED)
_current_breath_out_sound = play_sound
play_stream_on_player(head, play_sound)
play_stream_on_player(head, play_sound, randf_range(0.1, 1.0))
func play_flashlight_sound():
var play_sound = Sounds.get_random_sound(Sounds.FLASHLIGHT_CLICK_SOUNDS)
@ -183,8 +208,8 @@ func play_flashlight_sound():
_current_flashlight_sound = play_sound
func play_land_sound(velocity: float):
var sound_to_play_foot: AudioStream = null
var sound_to_play_breath: AudioStream = null
var sound_to_play_foot: AudioStream = Sounds.get_random_sound(Sounds.JUMP_LANDING_SOUNDS)
var sound_to_play_breath: AudioStream = Sounds.get_random_sound(Sounds.JUMP_LANDING_BREATH_SOUNDS)
var volume:float = 1.0
##TODO: make the landing sound volume scale with the fallen height (the higher you fall from, the bigger the stomp)
@ -198,12 +223,12 @@ func play_land_sound(velocity: float):
_current_jump_land_sound = sound_to_play_foot
_current_jump_land_breath_sound = sound_to_play_breath
play_stream_on_player(head, sound_to_play_breath, randf_range(.8, 1.2), volume)
play_stream_on_player(is_right_leg.call(), sound_to_play_foot)
play_stream_on_player(head, sound_to_play_breath, randf_range(.8, 1.2), volume, Priority.HIGH)
play_stream_on_player(is_right_leg.call(), sound_to_play_foot, randf_range(.8, 1.2), volume, Priority.HIGH)
func play_jump_sound():
var sound_to_play_foot: AudioStream = null
var sound_to_play_breath: AudioStream = null
var sound_to_play_foot: AudioStream = Sounds.get_random_sound(Sounds.JUMP_STARTING_SOUNDS)
var sound_to_play_breath: AudioStream = Sounds.get_random_sound(Sounds.JUMP_STARTING_BREATH_SOUNDS)
var volume:float = 1.0
while sound_to_play_foot == _current_jump_start_sound:

View file

@ -0,0 +1,3 @@
class_name Pocket extends EquippableItem
#TODO: add pocket logic later

View file

@ -0,0 +1 @@
uid://bqyxpmihywvgo

View file

@ -0,0 +1,15 @@
[gd_scene format=3 uid="uid://wvsly1kbdney"]
[ext_resource type="PackedScene" uid="uid://dlr62xnyqw58o" path="res://assets/models/pocket.glb" id="1_7udx3"]
[sub_resource type="BoxShape3D" id="BoxShape3D_b5l5s"]
size = Vector3(0.15527344, 0.40649414, 0.41345215)
[node name="pocket" unique_id=1810053707 node_paths=PackedStringArray("mesh", "collision") instance=ExtResource("1_7udx3")]
scene_path = "uid://wvsly1kbdney"
mesh = NodePath("Cube")
collision = NodePath("CollisionShape3D")
[node name="CollisionShape3D" type="CollisionShape3D" parent="." index="1" unique_id=101175855]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0012207031, 0.002319336, 0.001159668)
shape = SubResource("BoxShape3D_b5l5s")

View file

@ -1,9 +1,13 @@
[gd_scene format=3 uid="uid://chykk2a3opu0d"]
[ext_resource type="Script" uid="uid://yggv7ie8yere" path="res://classes/equippable_item.gd" id="1_mtlx8"]
[ext_resource type="PackedScene" uid="uid://kqq30y24c6kd" path="res://scenes/player/player.tscn" id="1_s8b7j"]
[ext_resource type="PackedScene" uid="uid://dvw51mhd42wg7" path="res://entities/backpack/bakpakbruh.tscn" id="1_de016"]
[ext_resource type="Script" uid="uid://d5aotywdqlh5" path="res://classes/grabbable_item.gd" id="1_l7v2h"]
[ext_resource type="PackedScene" uid="uid://kqq30y24c6kd" path="res://entities/player/player.tscn" id="1_s8b7j"]
[ext_resource type="AudioStream" uid="uid://b6wlbiittcu48" path="res://assets/sounds/ambiance/harmonika-paulstretched.mp3" id="3_mtlx8"]
[ext_resource type="PackedScene" uid="uid://don2g5auhwbl8" path="res://entities/equippable/test_object_equippable.tscn" id="3_omlgy"]
[ext_resource type="PackedScene" uid="uid://codt2h7ojcsae" path="res://entities/equippable/test_object_equippable_2.tscn" id="4_8r7k8"]
[ext_resource type="Script" uid="uid://y8x4svl5kej2" path="res://addons/spatial_audio_3d/spatial_audio_3d.gd" id="4_yb1w3"]
[ext_resource type="PackedScene" uid="uid://wvsly1kbdney" path="res://entities/pocket/pocket.tscn" id="5_8r7k8"]
[sub_resource type="WorldBoundaryShape3D" id="WorldBoundaryShape3D_g4v7s"]
@ -17,8 +21,6 @@
[sub_resource type="BoxMesh" id="BoxMesh_yf5fn"]
[sub_resource type="PrismMesh" id="PrismMesh_fm80t"]
[sub_resource type="BoxShape3D" id="BoxShape3D_57qmd"]
size = Vector3(20.447998, 11.038544, 1)
@ -35,6 +37,9 @@ auto_exposure_max_sensitivity = 14462.9
[node name="DevMap" type="Node3D" unique_id=471389571]
[node name="bakpakbruh" parent="." unique_id=829759791 instance=ExtResource("1_de016")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.197802, 1.0212646, 0)
[node name="Plane" type="StaticBody3D" parent="." unique_id=1943923809]
collision_layer = 17
collision_mask = 17
@ -57,10 +62,12 @@ shape = SubResource("BoxShape3D_g4v7s")
[node name="MeshInstance3D" type="MeshInstance3D" parent="TestObject" unique_id=1356474788]
mesh = SubResource("BoxMesh_g4v7s")
[node name="TestObjectGrabbable" type="RigidBody3D" parent="." unique_id=162241126 groups=["grabbable"]]
[node name="TestObjectGrabbable" type="RigidBody3D" parent="." unique_id=147588042 groups=["grabbable"]]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.776662, -3.2358055)
collision_layer = 17
collision_mask = 17
script = ExtResource("1_l7v2h")
metadata/_custom_type_script = "uid://d5aotywdqlh5"
[node name="CollisionShape3D" type="CollisionShape3D" parent="TestObjectGrabbable" unique_id=2049402651]
shape = SubResource("BoxShape3D_yf5fn")
@ -68,32 +75,19 @@ shape = SubResource("BoxShape3D_yf5fn")
[node name="MeshInstance3D" type="MeshInstance3D" parent="TestObjectGrabbable" unique_id=1899834557]
mesh = SubResource("BoxMesh_yf5fn")
[node name="TestObjectEquippable" type="RigidBody3D" parent="." unique_id=661564513 groups=["equippable"]]
[node name="TestObjectEquippable" parent="." unique_id=2137836052 instance=ExtResource("3_omlgy")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -2.874709, 1.0290127, -3.1515453)
collision_layer = 17
collision_mask = 17
script = ExtResource("1_mtlx8")
scene_path = "uid://don2g5auhwbl8"
[node name="CollisionShape3D" type="CollisionShape3D" parent="TestObjectEquippable" unique_id=740741417]
shape = SubResource("BoxShape3D_yf5fn")
[node name="MeshInstance3D" type="MeshInstance3D" parent="TestObjectEquippable" unique_id=1967579265]
mesh = SubResource("BoxMesh_yf5fn")
[node name="TestObjectEquippable2" type="RigidBody3D" parent="." unique_id=565168632 groups=["equippable"]]
[node name="TestObjectEquippable2" parent="." unique_id=1920911339 instance=ExtResource("4_8r7k8")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -2.874709, 1.0290127, -0.18258262)
collision_layer = 17
collision_mask = 17
script = ExtResource("1_mtlx8")
scene_path = "uid://codt2h7ojcsae"
[node name="CollisionShape3D" type="CollisionShape3D" parent="TestObjectEquippable2" unique_id=1155644968]
shape = SubResource("BoxShape3D_yf5fn")
[node name="MeshInstance3D" type="MeshInstance3D" parent="TestObjectEquippable2" unique_id=976512750]
mesh = SubResource("PrismMesh_fm80t")
[node name="pocket" parent="." unique_id=1810053707 instance=ExtResource("5_8r7k8")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 3.1668408, 0.48519003, 0)
[node name="Player" parent="." unique_id=423228143 instance=ExtResource("1_s8b7j")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.77974355, 1.137004)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.3125359, 1.137004)
[node name="OmniLight3D" type="OmniLight3D" parent="." unique_id=1317582521]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.2949467, -3.755646)

View file

@ -1,6 +1,6 @@
[gd_scene format=3 uid="uid://b7e2tqywq2mn2"]
[ext_resource type="PackedScene" uid="uid://kqq30y24c6kd" path="res://scenes/player/player.tscn" id="5_svl6s"]
[ext_resource type="PackedScene" uid="uid://kqq30y24c6kd" path="res://entities/player/player.tscn" id="5_svl6s"]
[sub_resource type="WorldBoundaryShape3D" id="WorldBoundaryShape3D_riqys"]

View file

@ -64,6 +64,10 @@ folder_colors={
"res://shaders/": "pink"
}
[filesystem]
import/blender/enabled=false
[global_group]
grabbable="this object can be grabbed"
@ -280,6 +284,11 @@ show_debug_menu={
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194333,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
open_inventory={
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194306,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
[layer_names]

View file

@ -1,152 +0,0 @@
class_name InventoryComponent extends Node
var selected_item: int = 0
var prev_selected_item: int = 0
var selected_item_object: EquippableItem = null
var inventory: Array[EquippableItem] = [null,null]
@export var equipped_item_mesh: MeshInstance3D
@export var hold_position: Marker3D
@export var cursor_raycast: RayCast3D
signal added_inventory_slot(successful:bool)
signal removed_inventory_slot(successful:bool)
signal select_item(index: int)
#for ui elements
signal add_item(index: int, item: EquippableItem)
signal remove_item(index: int)
func add_inventory_slot() -> bool:
if len(inventory) < 5:
inventory.append(null)
added_inventory_slot.emit(true)
return true
added_inventory_slot.emit(false)
return false
func remove_inventory_slot() -> bool:
if len(inventory) > 2:
inventory.remove_at(len(inventory) - 1)
removed_inventory_slot.emit(true)
return true
added_inventory_slot.emit(false)
return false
func next_item():
prev_selected_item = selected_item
if selected_item + 1 > len(inventory) - 1:
selected_item = 0
else:
selected_item += 1
_select_item()
func prev_item():
prev_selected_item = selected_item
if selected_item - 1 < 0:
selected_item = len(inventory) - 1
else:
selected_item -= 1
_select_item()
func _select_item(index:int = selected_item):
if index >= 0 and index < len(inventory):
select_item.emit(index)
if inventory[index] == null:
#if current index is empty in the inventory, replace held object with placeholder (empty mesh)
equipped_item_mesh.mesh = PlaceholderMesh.new()
else:
var mesh = null
for i in inventory[index].get_children():
if i is MeshInstance3D:
equipped_item_mesh.mesh = i.mesh
func _add_item(item: EquippableItem):
#add item to current equipped slot if empty
if inventory[selected_item] == null:
inventory[selected_item] = item
add_item.emit(selected_item, item)
#ui.add_item(selected_item, item)
item.reparent(get_parent().get_parent())
item.collision_layer = 0
item.visible = false
_select_item(selected_item)
return
#add item to first empty slot if currently equipped slot is full
for i in range(0, len(inventory)):
if inventory[i] == null:
inventory[i] = item
add_item.emit(i, item)
#ui.add_item(i, item)
item.reparent(get_parent().get_parent())
item.collision_layer = 0
item.visible = false
return
#dont equip item if inventory full
func _drop_item(index: int = selected_item):
if inventory[index] != null:
var object = inventory[index]
object.scale = Vector3.ONE
if object.is_inside_tree():
object.reparent(get_tree().current_scene, true)
object.collision_layer = 17
object.global_position = hold_position.global_position
object.visible = true
object.global_rotation = Vector3.ZERO
_remove_item(index)
func _remove_item(index: int):
#ui.remove_item(index)
remove_item.emit(index)
inventory[index] = null
_select_item(index)
func get_selected_item() -> EquippableItem:
return inventory[selected_item]
func _ready() -> void:
get_tree().create_timer(0.1).timeout.connect(func (): _select_item(0))
func _process(_delta: float) -> void:
if not Console.toggled and not UiManager.in_game_menu.visible:
if Input.is_action_just_pressed("next_item"):
next_item()
if Input.is_action_just_pressed("prev_item"):
prev_item()
if Input.is_action_just_pressed("select_item_1"):
_select_item(0)
if Input.is_action_just_pressed("select_item_2"):
_select_item(1)
if Input.is_action_just_pressed("select_item_3"):
_select_item(2)
if Input.is_action_just_pressed("select_item_4"):
_select_item(3)
if Input.is_action_just_pressed("select_item_5"):
_select_item(4)
if Input.is_action_just_pressed("equip"):
if cursor_raycast.is_colliding():
var hit_object = cursor_raycast.get_collider()
if hit_object is EquippableItem:
_add_item(hit_object)
if Input.is_action_just_pressed("drop"):
_drop_item()

View file

@ -0,0 +1,354 @@
extends Control
class_name InventoryMenu
@onready var backpack_grid: GridContainer = $PanelContainer/HBoxContainer/VBoxContainer2/BackpackGrid
@onready var hotbar_containers: Array[AspectRatioContainer] = [%Item1Container, %Item2Container, %Item3Container, %Item4Container, %Item5Container]
@onready var equipment_containers: Array[AspectRatioContainer] = [%EquipBackpack, %EquipPocket1, %EquipPocket2, %EquipPocket3]
var current_backpack: Backpack
var player_hotbar: HotbarComponent
var context_menu: PopupMenu
var active_context_slot: InventorySlotUI
# This tracks what is actually in the 4 equipment slots (Index 0 = Backpack, 1-3 = Pockets)
var equipped_items: Array[ItemData] = [null, null, null, null]
func _ready() -> void:
# 1. Create the PopupMenu dynamically so you don't have to place it in the editor
context_menu = PopupMenu.new()
add_child(context_menu)
# 2. Connect its click signal to our logic function
context_menu.id_pressed.connect(_on_context_menu_id_pressed)
func open_inventory(backpack: Backpack, hotbar_component: HotbarComponent) -> void:
current_backpack = backpack
player_hotbar = hotbar_component
update_all_ui()
show()
func update_all_ui() -> void:
update_equipment_ui()
update_hotbar_ui()
update_backpack_ui()
func update_equipment_ui() -> void:
for i in range(equipment_containers.size()):
var container = equipment_containers[i]
if container.get_children():
for child in container.get_children():
child.queue_free()
var slot_ui = _create_slot_ui(i, "equipment")
container.add_child(slot_ui)
func update_hotbar_ui() -> void:
if not player_hotbar: return
for i in range(hotbar_containers.size()):
var container = hotbar_containers[i]
for child in container.get_children():
child.queue_free()
if i < player_hotbar.inventory.size():
container.visible = true
var slot_ui = _create_slot_ui(i, "hotbar")
container.add_child(slot_ui)
else:
container.visible = false
func update_backpack_ui() -> void:
if not current_backpack: return
for child in backpack_grid.get_children():
child.queue_free()
for i in range(current_backpack.inventory_size):
var slot_ui = _create_slot_ui(i, "backpack")
backpack_grid.add_child(slot_ui)
func _create_slot_ui(index: int, type: String) -> Control:
var slot = InventorySlotUI.new()
slot.slot_index = index
slot.slot_type = type
slot.inventory_menu = self
slot.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
slot.mouse_filter = Control.MOUSE_FILTER_STOP
var item: ItemData = null
if type == "backpack": item = current_backpack.inventory[index]
elif type == "hotbar": item = player_hotbar.inventory[index]
elif type == "equipment": item = equipped_items[index]
slot.item_data = item
if item != null:
slot.texture = item.ui_icon
slot.tooltip_text = "Name: " + item.name + "\nWeight: " + str(item.weight) + "kg"
else:
if type == "equipment":
slot.tooltip_text = "Empty Backpack Slot" if index == 0 else "Empty Pocket Slot"
else:
slot.tooltip_text = "Empty Slot"
if type == "hotbar" or type == "equipment":
return slot # These already live inside AspectRatioContainers in your scene
var aspect_rect = AspectRatioContainer.new()
aspect_rect.size_flags_horizontal = Control.SIZE_EXPAND_FILL
aspect_rect.size_flags_vertical = Control.SIZE_EXPAND_FILL
aspect_rect.add_child(slot)
return aspect_rect
func swap_items(source_type: String, source_index: int, target_type: String, target_index: int) -> void:
if source_type == target_type and source_index == target_index:
return
var source_array = _get_array_by_type(source_type)
var target_array = _get_array_by_type(target_type)
var source_item = source_array[source_index]
var target_item = target_array[target_index]
# --- VALIDATION: Can this item be placed in this equipment slot? ---
if target_type == "equipment" and source_item != null:
if target_index == 0 and source_item.item_type != ItemData.ItemType.BACKPACK: return
if target_index > 0 and source_item.item_type != ItemData.ItemType.POCKET: return
if source_type == "equipment" and target_item != null:
if source_index == 0 and target_item.item_type != ItemData.ItemType.BACKPACK: return
if source_index > 0 and target_item.item_type != ItemData.ItemType.POCKET: return
# --- PERFORM SWAP ---
if source_type == "hotbar": player_hotbar.update_slot(source_index, target_item)
else: source_array[source_index] = target_item
if target_type == "hotbar": player_hotbar.update_slot(target_index, source_item)
else: target_array[target_index] = source_item
# --- APPLY DYNAMIC RESIZING ---
_recalculate_equipment_stats()
update_all_ui()
# Helper function to get the correct array
func _get_array_by_type(type: String) -> Array[ItemData]:
if type == "backpack": return current_backpack.inventory
if type == "hotbar": return player_hotbar.inventory
return equipped_items
# This is where the magic happens!
func _recalculate_equipment_stats() -> void:
# --- 1. UPDATE BASE INVENTORY (BACKPACK) ---
var target_inventory_size = 5 # The base size without any bag equipped!
if equipped_items[0] != null:
target_inventory_size += equipped_items[0].provided_slots
# If the inventory is shrinking (we removed a bag), we MUST drop overflow items!
if current_backpack.inventory.size() > target_inventory_size:
# Loop from the new size boundary to the end of the old array
for i in range(target_inventory_size, current_backpack.inventory.size()):
var overflow_item = current_backpack.inventory[i]
if overflow_item != null:
_spawn_item_in_world(overflow_item)
# Apply the new size and resize the actual array
# (.resize() automatically deletes overflow data and pads with nulls if expanding)
current_backpack.inventory_size = target_inventory_size
current_backpack.inventory.resize(target_inventory_size)
# --- 2. UPDATE HOTBAR SIZE (POCKETS) ---
# --- 2. UPDATE HOTBAR SIZE (POCKETS) ---
var target_hotbar_size = 2 # The base hotbar size
# Loop through the 3 pocket slots (indices 1, 2, and 3)
for i in range(1, 4):
if equipped_items[i] != null:
# Automatically increase hotbar size by exactly 1 for each equipped pocket
target_hotbar_size += 1
# Tell the HotbarComponent to grow to match the new size
while player_hotbar.inventory.size() < target_hotbar_size:
player_hotbar.add_inventory_slot()
# Tell the HotbarComponent to shrink if we removed pockets
while player_hotbar.inventory.size() > target_hotbar_size:
# Drop the item in the last slot before deleting the slot
if player_hotbar.inventory.back() != null:
player_hotbar._drop_item(player_hotbar.inventory.size() - 1)
player_hotbar.remove_inventory_slot()
func show_context_menu(slot: InventorySlotUI, mouse_pos: Vector2) -> void:
active_context_slot = slot
context_menu.clear()
var item = slot.item_data
if item == null: return
# Option 1: Equip / Unequip (ID: 0 or 1)
if item.item_type == ItemData.ItemType.BACKPACK or item.item_type == ItemData.ItemType.POCKET:
if slot.slot_type == "equipment":
context_menu.add_item("Unequip", 0)
else:
context_menu.add_item("Equip", 1)
# Option 2: Drop (ID: 2)
context_menu.add_item("Drop", 2)
# Option 3: Info (ID: 3)
context_menu.add_item("Info", 3)
# Show the menu exactly where the mouse is!
context_menu.position = mouse_pos
context_menu.popup()
func _on_context_menu_id_pressed(id: int) -> void:
if not active_context_slot or not active_context_slot.item_data: return
var slot = active_context_slot
match id:
0: _auto_unequip(slot)
1: _auto_equip(slot)
2: _drop_from_menu(slot)
3: _show_info(slot.item_data)
func _auto_equip(slot: InventorySlotUI) -> void:
var item = slot.item_data
var target_index = -1
# Determine which equipment slot to put it in
if item.item_type == ItemData.ItemType.BACKPACK:
target_index = 0
elif item.item_type == ItemData.ItemType.POCKET:
# Find the first empty pocket slot (Indices 1 to 3)
for i in range(1, 4):
if equipped_items[i] == null:
target_index = i
break
# If all pockets are full, just swap with pocket 1
if target_index == -1: target_index = 1
if target_index != -1:
swap_items(slot.slot_type, slot.slot_index, "equipment", target_index)
func _auto_unequip(slot: InventorySlotUI) -> void:
var target_index = -1
# If we are unequipping the Backpack (Equipment Slot 0)
if slot.slot_index == 0:
# Search the Hotbar for an empty spot
for i in range(player_hotbar.inventory.size()):
if player_hotbar.inventory[i] == null:
target_index = i
break
if target_index != -1:
swap_items(slot.slot_type, slot.slot_index, "hotbar", target_index)
else:
print("Hotbar is full! Dropping the Backpack.")
_drop_from_menu(slot)
# If we are unequipping a Pocket (Equipment Slots 1-3)
else:
# Search the Main Inventory for an empty spot
for i in range(current_backpack.inventory_size):
if current_backpack.inventory[i] == null:
target_index = i
break
if target_index != -1:
swap_items(slot.slot_type, slot.slot_index, "backpack", target_index)
else:
print("Inventory is full! Dropping the Pocket.")
_drop_from_menu(slot)
func _drop_from_menu(slot: InventorySlotUI) -> void:
# 1. Spawn the item on the ground
_spawn_item_in_world(slot.item_data)
# 2. Clear the item from whichever array it was sitting in
var array = _get_array_by_type(slot.slot_type)
if slot.slot_type == "hotbar":
player_hotbar.update_slot(slot.slot_index, null)
else:
array[slot.slot_index] = null
# 3. Redraw UI and recalculate sizes
_recalculate_equipment_stats()
update_all_ui()
func _show_info(item: ItemData) -> void:
# Creates a quick native popup window to show item details
var dialog = AcceptDialog.new()
dialog.title = "Item Info"
dialog.dialog_text = "Name: %s\nWeight: %s kg\nType: %s" % [
item.name,
item.weight,
ItemData.ItemType.keys()[item.item_type]
]
add_child(dialog)
dialog.popup_centered()
func _spawn_item_in_world(item: ItemData) -> void:
if item and item.scene_path != "":
var packed_scene = load(item.scene_path) as PackedScene
if packed_scene:
var new_object = packed_scene.instantiate() as RigidBody3D
get_tree().current_scene.add_child(new_object)
# Drop it at the player's hold position
new_object.global_position = player_hotbar.hold_position.global_position
new_object.global_rotation = Vector3.ZERO
func quick_move_item(slot: InventorySlotUI) -> void:
var item = slot.item_data
if item == null: return
# 1. Quick Unequip (If it's already in an equipment slot)
if slot.slot_type == "equipment":
_auto_unequip(slot)
return
# 2. Try Quick Equip for Backpacks
if item.item_type == ItemData.ItemType.BACKPACK:
# Only quick-equip if the backpack slot is empty
if equipped_items[0] == null:
swap_items(slot.slot_type, slot.slot_index, "equipment", 0)
return
# 3. Try Quick Equip for Pockets
if item.item_type == ItemData.ItemType.POCKET:
for i in range(1, 4):
# Find the first empty pocket slot and equip it
if equipped_items[i] == null:
swap_items(slot.slot_type, slot.slot_index, "equipment", i)
return
# 4. REGULAR ITEM MOVE (Or if equipment slots were full)
if slot.slot_type == "hotbar":
# Move Hotbar -> Backpack
var target_index = -1
for i in range(current_backpack.inventory_size):
if current_backpack.inventory[i] == null:
target_index = i
break
if target_index != -1:
swap_items("hotbar", slot.slot_index, "backpack", target_index)
else:
print("Backpack is full! Cannot quick-move.")
elif slot.slot_type == "backpack":
# Move Backpack -> Hotbar
var target_index = -1
for i in range(player_hotbar.inventory.size()):
if player_hotbar.inventory[i] == null:
target_index = i
break
if target_index != -1:
swap_items("backpack", slot.slot_index, "hotbar", target_index)
else:
print("Hotbar is full! Cannot quick-move.")

View file

@ -0,0 +1 @@
uid://c4xrcopqmqc1u

View file

@ -0,0 +1,156 @@
[gd_scene format=3 uid="uid://b6uty5ygh5202"]
[ext_resource type="Script" uid="uid://c4xrcopqmqc1u" path="res://scenes/ui/inventory/inventory_menu.gd" id="1_05ake"]
[ext_resource type="Shader" uid="uid://dfocpicc6jowx" path="res://shaders/optimized_blur.gdshader" id="1_igkbf"]
[ext_resource type="PackedScene" uid="uid://bfg4q1t8s06vv" path="res://scenes/ui/optimized_blur_panel.tscn" id="2_btuyx"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_b5l5s"]
shader = ExtResource("1_igkbf")
shader_parameter/direction = Vector2(1, 0)
shader_parameter/size = 2.0
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_beykx"]
bg_color = Color(0.6, 0.6, 0.6, 0)
[sub_resource type="Gradient" id="Gradient_igkbf"]
[sub_resource type="GradientTexture1D" id="GradientTexture1D_b5l5s"]
gradient = SubResource("Gradient_igkbf")
[node name="InventoryMenu" type="Control" unique_id=899998133]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_05ake")
[node name="OptimizedBlurPanel" parent="." unique_id=1779763293 instance=ExtResource("2_btuyx")]
layout_mode = 1
[node name="PanelContainer" type="MarginContainer" parent="." unique_id=845726662]
material = SubResource("ShaderMaterial_b5l5s")
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 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="HBoxContainer" type="HBoxContainer" parent="PanelContainer" unique_id=212583021]
layout_mode = 2
[node name="VBoxContainer2" type="VBoxContainer" parent="PanelContainer/HBoxContainer" unique_id=1700571445]
layout_mode = 2
size_flags_horizontal = 3
[node name="Label" type="Label" parent="PanelContainer/HBoxContainer/VBoxContainer2" unique_id=2062304692]
layout_mode = 2
size_flags_vertical = 6
size_flags_stretch_ratio = 1.95
theme_override_font_sizes/font_size = 64
text = "BACKPACK"
horizontal_alignment = 1
[node name="BackpackGrid" type="GridContainer" parent="PanelContainer/HBoxContainer/VBoxContainer2" unique_id=484827503]
layout_mode = 2
size_flags_vertical = 3
columns = 5
[node name="Panel" type="Panel" parent="PanelContainer/HBoxContainer" unique_id=114418448]
layout_mode = 2
size_flags_horizontal = 3
size_flags_stretch_ratio = 0.26
theme_override_styles/panel = SubResource("StyleBoxFlat_beykx")
[node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer/HBoxContainer" unique_id=2037593729]
layout_mode = 2
size_flags_horizontal = 3
[node name="EquippedItems" type="HBoxContainer" parent="PanelContainer/HBoxContainer/VBoxContainer" unique_id=1105627170]
layout_mode = 2
size_flags_vertical = 3
[node name="PlayerLook" type="TextureRect" parent="PanelContainer/HBoxContainer/VBoxContainer/EquippedItems" unique_id=127092246]
layout_mode = 2
size_flags_horizontal = 3
texture = SubResource("GradientTexture1D_b5l5s")
[node name="Equipment" type="VBoxContainer" parent="PanelContainer/HBoxContainer/VBoxContainer/EquippedItems" unique_id=2029647268]
layout_mode = 2
size_flags_horizontal = 3
[node name="EquipBackpack" type="AspectRatioContainer" parent="PanelContainer/HBoxContainer/VBoxContainer/EquippedItems/Equipment" unique_id=1316255663]
unique_name_in_owner = true
layout_mode = 2
size_flags_vertical = 3
[node name="EquipPocket1" type="AspectRatioContainer" parent="PanelContainer/HBoxContainer/VBoxContainer/EquippedItems/Equipment" unique_id=317114705]
unique_name_in_owner = true
layout_mode = 2
size_flags_vertical = 3
[node name="EquipPocket2" type="AspectRatioContainer" parent="PanelContainer/HBoxContainer/VBoxContainer/EquippedItems/Equipment" unique_id=761585547]
unique_name_in_owner = true
layout_mode = 2
size_flags_vertical = 3
[node name="EquipPocket3" type="AspectRatioContainer" parent="PanelContainer/HBoxContainer/VBoxContainer/EquippedItems/Equipment" unique_id=1821074955]
unique_name_in_owner = true
layout_mode = 2
size_flags_vertical = 3
[node name="Panel" type="Panel" parent="PanelContainer/HBoxContainer/VBoxContainer" unique_id=1755897052]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
size_flags_stretch_ratio = 0.26
theme_override_styles/panel = SubResource("StyleBoxFlat_beykx")
[node name="Label" type="Label" parent="PanelContainer/HBoxContainer/VBoxContainer" unique_id=296506986]
layout_mode = 2
size_flags_vertical = 6
size_flags_stretch_ratio = 0.0
theme_override_font_sizes/font_size = 64
text = "HOTBAR"
horizontal_alignment = 1
[node name="Hotbar" type="HBoxContainer" parent="PanelContainer/HBoxContainer/VBoxContainer" unique_id=478079846]
layout_mode = 2
size_flags_vertical = 3
size_flags_stretch_ratio = 0.47
[node name="Item1Container" type="AspectRatioContainer" parent="PanelContainer/HBoxContainer/VBoxContainer/Hotbar" unique_id=1883638357]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 7
size_flags_vertical = 3
[node name="Item2Container" type="AspectRatioContainer" parent="PanelContainer/HBoxContainer/VBoxContainer/Hotbar" unique_id=1445055183]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 7
size_flags_vertical = 3
[node name="Item3Container" type="AspectRatioContainer" parent="PanelContainer/HBoxContainer/VBoxContainer/Hotbar" unique_id=467085643]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 7
size_flags_vertical = 3
[node name="Item4Container" type="AspectRatioContainer" parent="PanelContainer/HBoxContainer/VBoxContainer/Hotbar" unique_id=1175154186]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 7
size_flags_vertical = 3
[node name="Item5Container" type="AspectRatioContainer" parent="PanelContainer/HBoxContainer/VBoxContainer/Hotbar" unique_id=1144755994]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 7
size_flags_vertical = 3

View file

@ -0,0 +1,70 @@
class_name InventorySlotUI extends TextureRect
var slot_index: int = -1
var slot_type: String = "backpack" # Can be "backpack" or "hotbar"
var inventory_menu: InventoryMenu
var item_data: ItemData
# _init() runs the exact millisecond this node is created in memory
func _init() -> void:
# 1. Create a background panel
var bg = Panel.new()
bg.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) # Make it fill the slot
bg.show_behind_parent = true # CRITICAL: Forces it to render BEHIND your item icon
bg.mouse_filter = Control.MOUSE_FILTER_IGNORE # Prevents it from eating drag-and-drop clicks
# 2. Give it a nice, dark, rounded style
var style = StyleBoxFlat.new()
style.bg_color = Color(0.15, 0.15, 0.15, 0.8) # Dark gray, slightly transparent
style.border_width_bottom = 2
style.border_width_top = 2
style.border_width_left = 2
style.border_width_right = 2
style.border_color = Color(0.3, 0.3, 0.3, 1.0) # Lighter gray border
style.corner_radius_top_left = 8
style.corner_radius_top_right = 8
style.corner_radius_bottom_left = 8
style.corner_radius_bottom_right = 8
bg.add_theme_stylebox_override("panel", style)
add_child(bg)
func _get_drag_data(_at_position: Vector2) -> Variant:
if item_data == null:
return null
var preview = TextureRect.new()
preview.texture = texture
preview.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
preview.custom_minimum_size = Vector2(64, 64)
var preview_container = Control.new()
preview_container.add_child(preview)
preview.position = -preview.custom_minimum_size / 2
set_drag_preview(preview_container)
return {"source_index": slot_index, "source_type": slot_type}
func _can_drop_data(_at_position: Vector2, data: Variant) -> bool:
return typeof(data) == TYPE_DICTIONARY and data.has("source_index") and data.has("source_type")
func _drop_data(_at_position: Vector2, data: Variant) -> void:
var source_index = data["source_index"]
var source_type = data["source_type"]
inventory_menu.swap_items(source_type, source_index, slot_type, slot_index)
func _gui_input(event: InputEvent) -> void:
if event is InputEventMouseButton and event.pressed:
# RIGHT CLICK: Show Context Menu
if event.button_index == MOUSE_BUTTON_RIGHT:
if item_data != null:
inventory_menu.show_context_menu(self, get_global_mouse_position())
accept_event() # Tells Godot we handled this input
# CTRL + LEFT CLICK: Quick Move
elif event.button_index == MOUSE_BUTTON_LEFT and event.is_command_or_control_pressed():
if item_data != null:
inventory_menu.quick_move_item(self)
accept_event()

View file

@ -0,0 +1 @@
uid://wblcdlfnhy1y

View file

@ -0,0 +1,11 @@
class_name ItemData extends Resource
enum ItemType { NORMAL, BACKPACK, POCKET }
@export var item_type: ItemType = ItemType.NORMAL
@export var provided_slots: int
@export var name: String = ""
@export var weight: float = 10.0
@export var scene_path: String = ""
@export var ui_icon: Texture2D
@export var hand_mesh: Mesh # We need to save the mesh to show it in the player's hand!

View file

@ -0,0 +1 @@
uid://bwxhl0j1vgc14

View file

@ -2,10 +2,14 @@ extends Control
@onready var in_game_menu: Control = %InGameMenu
@onready var debug_menu: Control = %DebugMenu
@onready var inventory_menu: Control = %InventoryMenu
func toggle_debug_menu():
debug_menu.visible = !debug_menu.visible
func toggle_inventory_menu(on:bool):
inventory_menu.visible = on
func toggle_in_game_menu():
if not Console.toggled:
in_game_menu.visible = !in_game_menu.visible

View file

@ -3,6 +3,7 @@
[ext_resource type="Script" uid="uid://33wtl3qa013n" path="res://scenes/ui/ui_manager.gd" id="1_b2463"]
[ext_resource type="PackedScene" uid="uid://y5f3db7clptv" path="res://scenes/ui/in_game_menu/in_game_menu.tscn" id="2_js4l8"]
[ext_resource type="PackedScene" uid="uid://c57oxgn18vrdv" path="res://scenes/ui/debug_menu/debug_menu.tscn" id="3_61ox6"]
[ext_resource type="PackedScene" uid="uid://b6uty5ygh5202" path="res://scenes/ui/inventory/inventory_menu.tscn" id="4_js4l8"]
[node name="UIManager" type="Control" unique_id=585290585]
layout_mode = 3
@ -22,3 +23,8 @@ layout_mode = 1
unique_name_in_owner = true
visible = false
layout_mode = 1
[node name="InventoryMenu" parent="." unique_id=899998133 instance=ExtResource("4_js4l8")]
unique_name_in_owner = true
visible = false
layout_mode = 1