grabbables work

title says all. next up: fixing the bugs of the texturerects in the
inventory after equipping an item, it gets bigger because the created
image is 128x128, but should be dynamic dependant on the viewport window
size
This commit is contained in:
Hellie-xd 2026-08-06 01:00:09 +02:00
parent e8580fb8d1
commit 4bdd4d1708
7 changed files with 74 additions and 28 deletions

View file

@ -184,7 +184,12 @@ open_menu={
}
equip={
"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":69,"key_label":0,"unicode":101,"location":0,"echo":false,"script":null)
"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":82,"key_label":0,"unicode":114,"location":0,"echo":false,"script":null)
]
}
drop={
"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":71,"key_label":0,"unicode":103,"location":0,"echo":false,"script":null)
]
}
select_item_1={

View file

@ -24,6 +24,6 @@ near = 0.106
unique_name_in_owner = true
mesh = SubResource("PrismMesh_60a4j")
[node name="AreaLight3D" type="AreaLight3D" parent="SubViewport" unique_id=283063489]
transform = Transform3D(0.74197584, -0.40812987, 0.5318852, 0, 0.7933533, 0.6087615, -0.6704266, -0.45168626, 0.58864903, 0.8652531, 0.7732402, 0.9565933)
area_range = 544.72
[node name="AreaLight3D" type="OmniLight3D" parent="SubViewport" unique_id=953860355]
transform = Transform3D(0.6835227, -0.68462586, 0.25314865, 0.2886606, 0.5720725, 0.7677292, -0.6704266, -0.4516863, 0.58864903, 0.8652531, 1.1601115, 0.9565933)
light_energy = 1.5

View file

@ -28,6 +28,6 @@ layout_mode = 2
[node name="Label" type="Label" parent="AspectRatioContainer" unique_id=1563300647]
layout_mode = 2
text = "[E] to equip"
text = "[R] to equip"
horizontal_alignment = 1
vertical_alignment = 1

View file

@ -57,6 +57,15 @@ func handle_joypad_movement(delta: float):
func equip_object(object: RigidBody3D):
player_manager.add_item(object)
func check_raycast(raycast):
if raycast.is_colliding():
var hit_object = raycast.get_collider()
# THIS WILL REVEAL THE BUG:
print("Raycast hit: ", hit_object.name)
print("Is hit object equippable? ", hit_object.is_in_group("equippable"))
print("Is hit object's parent equippable? ", hit_object.get_parent().is_in_group("equippable"))
func _input(event: InputEvent) -> void:
if not player_state.in_menu:
if event is InputEventMouseMotion:
@ -107,7 +116,7 @@ func _process(delta: float) -> void:
if cursor_raycast.is_colliding():
var hit_object = cursor_raycast.get_collider()
if hit_object is RigidBody3D and hit_object.is_in_group("grabbable"):
if hit_object is RigidBody3D and hit_object.is_in_group("grabbable") or hit_object.is_in_group("equippable"):
held_object = hit_object
held_object.gravity_scale = 0.0
held_object.angular_damp = 5.0
@ -125,6 +134,9 @@ func _process(delta: float) -> void:
if hit_object is RigidBody3D and hit_object.is_in_group("equippable"):
equip_object(hit_object)
if Input.is_action_just_pressed("drop"):
player_manager.drop_item()
#func _unhandled_input(event: InputEvent) -> void:
#if event is InputEventMouseMotion:

View file

@ -78,11 +78,25 @@ func add_item(item: RigidBody3D):
#dont equip item if inventory full
func remove_current_item():
remove_item(selected_item)
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 = 1
object.add_to_group("equippable")
for child in object.get_children():
if child is CollisionObject3D:
child.add_to_group("equippable")
remove_item(index)
func remove_item(index: int):
add_child(inventory[index])
inventory[index] = null
ui.remove_item(index)

View file

@ -40,59 +40,74 @@ layout_mode = 2
size_flags_horizontal = 3
stretch_mode = 1
[node name="InvSlot1" type="PanelContainer" parent="InvContainer/InventoryPanels/AspectRatioContainer" unique_id=1847508075]
unique_name_in_owner = true
[node name="InvSlot1Container" type="PanelContainer" parent="InvContainer/InventoryPanels/AspectRatioContainer" unique_id=1847508075]
layout_mode = 2
size_flags_horizontal = 3
theme_override_styles/panel = SubResource("StyleBoxFlat_m6sn8")
[node name="InvSlot1" type="TextureRect" parent="InvContainer/InventoryPanels/AspectRatioContainer/InvSlot1Container" unique_id=707719551]
unique_name_in_owner = true
layout_mode = 2
[node name="AspectRatioContainer2" type="AspectRatioContainer" parent="InvContainer/InventoryPanels" unique_id=305641278]
layout_mode = 2
size_flags_horizontal = 3
stretch_mode = 1
[node name="InvSlot2" type="PanelContainer" parent="InvContainer/InventoryPanels/AspectRatioContainer2" unique_id=2121530771]
unique_name_in_owner = true
[node name="InvSlot2Container" type="PanelContainer" parent="InvContainer/InventoryPanels/AspectRatioContainer2" unique_id=2121530771]
layout_mode = 2
size_flags_horizontal = 3
theme_override_styles/panel = SubResource("StyleBoxFlat_m6sn8")
[node name="InvSlot2" type="TextureRect" parent="InvContainer/InventoryPanels/AspectRatioContainer2/InvSlot2Container" unique_id=265967012]
unique_name_in_owner = true
layout_mode = 2
[node name="AspectRatioContainer3" type="AspectRatioContainer" parent="InvContainer/InventoryPanels" unique_id=1408216345]
visible = false
layout_mode = 2
size_flags_horizontal = 3
stretch_mode = 1
[node name="InvSlot3" type="PanelContainer" parent="InvContainer/InventoryPanels/AspectRatioContainer3" unique_id=1616781961]
unique_name_in_owner = true
[node name="InvSlot3Container" type="PanelContainer" parent="InvContainer/InventoryPanels/AspectRatioContainer3" unique_id=1616781961]
layout_mode = 2
size_flags_horizontal = 3
theme_override_styles/panel = SubResource("StyleBoxFlat_m6sn8")
[node name="InvSlot3" type="TextureRect" parent="InvContainer/InventoryPanels/AspectRatioContainer3/InvSlot3Container" unique_id=1230703223]
unique_name_in_owner = true
layout_mode = 2
[node name="AspectRatioContainer4" type="AspectRatioContainer" parent="InvContainer/InventoryPanels" unique_id=876478547]
visible = false
layout_mode = 2
size_flags_horizontal = 3
stretch_mode = 1
[node name="InvSlot4" type="PanelContainer" parent="InvContainer/InventoryPanels/AspectRatioContainer4" unique_id=1782511400]
unique_name_in_owner = true
[node name="InvSlot4Container" type="PanelContainer" parent="InvContainer/InventoryPanels/AspectRatioContainer4" unique_id=1782511400]
layout_mode = 2
size_flags_horizontal = 3
theme_override_styles/panel = SubResource("StyleBoxFlat_m6sn8")
[node name="InvSlot4" type="TextureRect" parent="InvContainer/InventoryPanels/AspectRatioContainer4/InvSlot4Container" unique_id=522773629]
unique_name_in_owner = true
layout_mode = 2
[node name="AspectRatioContainer5" type="AspectRatioContainer" parent="InvContainer/InventoryPanels" unique_id=1510462561]
visible = false
layout_mode = 2
size_flags_horizontal = 3
stretch_mode = 1
[node name="InvSlot5" type="PanelContainer" parent="InvContainer/InventoryPanels/AspectRatioContainer5" unique_id=1512950913]
unique_name_in_owner = true
[node name="InvSlot5Container" type="PanelContainer" parent="InvContainer/InventoryPanels/AspectRatioContainer5" unique_id=1512950913]
layout_mode = 2
size_flags_horizontal = 3
theme_override_styles/panel = SubResource("StyleBoxFlat_m6sn8")
[node name="InvSlot5" type="TextureRect" parent="InvContainer/InventoryPanels/AspectRatioContainer5/InvSlot5Container" unique_id=143698041]
unique_name_in_owner = true
layout_mode = 2
[node name="StaminaBarMargin" type="MarginContainer" parent="." unique_id=707986637]
layout_mode = 1
anchors_preset = -1

View file

@ -2,7 +2,7 @@ extends Control
@onready var stamina_bar: ProgressBar = %StaminaBar
@onready var flashlight_bar: ProgressBar = %FlashlightBar
@onready var inventory_slots_panels: Array[PanelContainer] = [%InvSlot1, %InvSlot2, %InvSlot3, %InvSlot4, %InvSlot5]
@onready var inventory_slots_panels: Array[TextureRect] = [%InvSlot1, %InvSlot2, %InvSlot3, %InvSlot4, %InvSlot5]
@onready var player_manager: Node = %PlayerManager
@ -48,9 +48,9 @@ func _ready():
func select_item(index):
if index >= 0 and index < len(player_manager.inventory):
for i in inventory_slots_panels:
i.add_theme_stylebox_override("panel", unselected_stylebox)
i.get_parent().add_theme_stylebox_override("panel", unselected_stylebox)
if index >= 0 and index < len(player_manager.inventory):
inventory_slots_panels[index].add_theme_stylebox_override("panel", selected_stylebox)
inventory_slots_panels[index].get_parent().add_theme_stylebox_override("panel", selected_stylebox)
func add_item(index: int, object: RigidBody3D):
if index >= 0 and index < len(player_manager.inventory):
@ -59,12 +59,12 @@ func add_item(index: int, object: RigidBody3D):
for i in meshes:
if i is MeshInstance3D:
texture = await GrabbableBase.create_icon_from_mesh(i.mesh)
var texture_rect = TextureRect.new()
texture_rect.texture = texture
inventory_slots_panels[index].add_child(texture_rect)
inventory_slots_panels[index].texture = texture
func remove_item(index: int):
if index >= 0 and index < len(player_manager.inventory):
inventory_slots_panels[index].texture = null
func _process(delta: float) -> void:
if player_manager != null:
stamina_bar.value = lerpf(stamina_bar.value, player_manager.stamina, delta * 5)