Skip to content

Commit

Permalink
Inventory Item drop behavior (please read)
Browse files Browse the repository at this point in the history
Inventory item:
- Added flag `is_droppable`, on by default. If off, player can't drop this item into the world (but can still move it to external inventories). Useful to prevent loss of important items.
- Changed item stack drop behavior of mouse clicks: clicking left or right each has the same behavior: dropping a single item from a stack.

Readme:
- Added more contributors. Thanks for all your hard work!
  • Loading branch information
Phazorknight committed Sep 5, 2024
1 parent 505c429 commit afdb5d5
Show file tree
Hide file tree
Showing 22 changed files with 126 additions and 96 deletions.
2 changes: 2 additions & 0 deletions COGITO/InventoryPD/CustomResources/InventoryItemPD.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class_name InventoryItemPD
@export var icon : Texture2D
## Sets if an item can be stackable or not. Usually used for consumables or ammo.
@export var is_stackable : bool = false
## Sets if an item can be dropped or not. Used for important items so they can't get lost. Items can still be moved to external inventories.
@export var is_droppable : bool = true
@export_range(1, 99) var stack_size : int
## Path to Scene that will be spawned when item is removed from inventory to be dropped into the world.
@export_file("*.tscn") var drop_scene
Expand Down
1 change: 1 addition & 0 deletions COGITO/InventoryPD/Items/Cogito_Battery.tres
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ name = "Battery"
description = "Can be combined with the Flashlight. Non-rechargeable."
icon = ExtResource("1_fjosn")
is_stackable = true
is_droppable = true
stack_size = 5
drop_scene = "res://COGITO/PackedScenes/Pickups/pickup_battery.tscn"
hint_icon_on_use = ExtResource("1_54cn8")
Expand Down
1 change: 1 addition & 0 deletions COGITO/InventoryPD/Items/Cogito_Dart.tres
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ name = "Dart"
description = "A simple foam dart. Squishy."
icon = ExtResource("1_m1vko")
is_stackable = true
is_droppable = true
stack_size = 5
drop_scene = "res://COGITO/PackedScenes/Pickups/pickup_dart.tscn"
hint_text_on_use = ""
Expand Down
1 change: 1 addition & 0 deletions COGITO/InventoryPD/Items/Cogito_Dart_Fire.tres
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ name = "Fire Dart"
description = "Who needs matches if you got these."
icon = ExtResource("1_w1vsy")
is_stackable = true
is_droppable = true
stack_size = 5
drop_scene = "res://COGITO/PackedScenes/Pickups/pickup_dart_fire.tscn"
hint_text_on_use = ""
Expand Down
1 change: 1 addition & 0 deletions COGITO/InventoryPD/Items/Cogito_Dart_Water.tres
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ name = "Water Dart"
description = "Perpetually dripping water."
icon = ExtResource("1_413bt")
is_stackable = true
is_droppable = true
stack_size = 5
drop_scene = "res://COGITO/PackedScenes/Pickups/pickup_dart_water.tscn"
hint_text_on_use = ""
Expand Down
1 change: 1 addition & 0 deletions COGITO/InventoryPD/Items/Cogito_DiamondKey_A.tres
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ name = "Diamond Half A"
description = "Looks like it's only half of some kind of shape."
icon = ExtResource("1_xkbwk")
is_stackable = false
is_droppable = true
stack_size = 0
drop_scene = "res://COGITO/PackedScenes/Pickups/pickup_diamond_key_a.tscn"
hint_icon_on_use = ExtResource("1_xojlq")
Expand Down
1 change: 1 addition & 0 deletions COGITO/InventoryPD/Items/Cogito_DiamondKey_B.tres
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ name = "Diamond Half B"
description = "Looks incomplete. Maybe I can find the rest of it?"
icon = ExtResource("1_gdixu")
is_stackable = false
is_droppable = true
stack_size = 0
drop_scene = "res://COGITO/PackedScenes/Pickups/pickup_diamond_key_b.tscn"
hint_icon_on_use = ExtResource("1_txwkg")
Expand Down
1 change: 1 addition & 0 deletions COGITO/InventoryPD/Items/Cogito_HealthPotion.tres
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ name = "Health Potion"
description = "Tastes better than it looks."
icon = ExtResource("1_net5f")
is_stackable = true
is_droppable = true
stack_size = 5
drop_scene = "res://COGITO/PackedScenes/Pickups/pickup_health_potion.tscn"
hint_icon_on_use = ExtResource("1_5eqwj")
Expand Down
1 change: 1 addition & 0 deletions COGITO/InventoryPD/Items/Cogito_Key.tres
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ name = "Key"
description = "Opens a locked door."
icon = ExtResource("1_n8yj5")
is_stackable = false
is_droppable = true
stack_size = 1
drop_scene = "res://COGITO/PackedScenes/Pickups/pickup_key.tscn"
hint_icon_on_use = ExtResource("1_17jgp")
Expand Down
1 change: 1 addition & 0 deletions COGITO/InventoryPD/Items/Cogito_Laptop.tres
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ description = "Feels light and doesn't turn on.
Does that matter?"
icon = ExtResource("1_ovk1j")
is_stackable = false
is_droppable = true
stack_size = 0
drop_scene = "res://COGITO/DemoScenes/DemoPrefabs/laptop.tscn"
hint_text_on_use = "I was supposed to do something with this."
Expand Down
1 change: 1 addition & 0 deletions COGITO/InventoryPD/Items/Cogito_LaptopReal.tres
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ name = "CEOs Laptop"
description = "The CEO's laptop. There's probably a lot of valuable data on here."
icon = ExtResource("1_bw20e")
is_stackable = false
is_droppable = true
stack_size = 0
drop_scene = "res://COGITO/DemoScenes/DemoPrefabs/laptop_real.tscn"
hint_text_on_use = "I was supposed to do somoething with this."
Expand Down
1 change: 1 addition & 0 deletions COGITO/InventoryPD/Items/Cogito_LaserAmmo.tres
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ name = "Laser Ammo"
description = "Tends to get hot. One clip has a charge of 50."
icon = ExtResource("1_6hnrl")
is_stackable = true
is_droppable = true
stack_size = 5
drop_scene = "res://COGITO/PackedScenes/Pickups/pickup_laser_ammo.tscn"
hint_text_on_use = ""
Expand Down
1 change: 1 addition & 0 deletions COGITO/InventoryPD/Items/Cogito_LaserRifle.tres
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ name = "Laser Rifle"
description = "Goes pew pew pew. Needs Laser Ammo to reload."
icon = ExtResource("1_jjb1o")
is_stackable = false
is_droppable = true
stack_size = 0
drop_scene = "res://COGITO/PackedScenes/Pickups/pickup_laser_rifle.tscn"
hint_text_on_use = ""
Expand Down
1 change: 1 addition & 0 deletions COGITO/InventoryPD/Items/Cogito_PageCombined.tres
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ name = "Combined Page"
description = "Reassembled page from the ripped pieces. It says \"New code is 0451\" on it."
icon = ExtResource("1_g83kf")
is_stackable = false
is_droppable = true
stack_size = 0
drop_scene = "res://COGITO/PackedScenes/Pickups/page_combined_pickup.tscn"
hint_text_on_use = "I should probably read this."
Expand Down
1 change: 1 addition & 0 deletions COGITO/InventoryPD/Items/Cogito_Pickaxe.tres
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ name = "Pickaxe"
description = "Don't go digging for diamonds now."
icon = ExtResource("1_a7clm")
is_stackable = false
is_droppable = true
stack_size = 0
drop_scene = "res://COGITO/PackedScenes/Pickups/pickup_pickaxe.tscn"
hint_text_on_use = ""
Expand Down
1 change: 1 addition & 0 deletions COGITO/InventoryPD/Items/Cogito_Pistol.tres
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ name = "Foam Pistol"
description = "There's a reason it looks like a toy. Shoots foam bullets."
icon = ExtResource("1_dj2ew")
is_stackable = false
is_droppable = true
stack_size = 0
drop_scene = "res://COGITO/PackedScenes/Pickups/pickup_pistol.tscn"
hint_text_on_use = ""
Expand Down
1 change: 1 addition & 0 deletions COGITO/InventoryPD/Items/Cogito_RippedPage_A.tres
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ name = "Ripped Page A"
description = "A piece of paper ripped in half. It has some numbers on it but parts are missing."
icon = ExtResource("1_hcvti")
is_stackable = false
is_droppable = false
stack_size = 0
drop_scene = "res://COGITO/PackedScenes/Pickups/ripped_page_a_pickup.tscn"
hint_text_on_use = "I need the other half."
Expand Down
1 change: 1 addition & 0 deletions COGITO/InventoryPD/Items/Cogito_RippedPage_B.tres
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ name = "Ripped Page B"
description = "A piece of paper ripped in half. It has some numbers on it but parts are missing."
icon = ExtResource("1_xupyp")
is_stackable = false
is_droppable = false
stack_size = 0
drop_scene = "res://COGITO/PackedScenes/Pickups/ripped_page_b_pickup.tscn"
hint_text_on_use = "I need the other half."
Expand Down
14 changes: 10 additions & 4 deletions COGITO/InventoryPD/UiScenes/inventory_interface.gd
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func on_inventory_button_press(inventory_data: CogitoInventory, index: int, acti
grabbed_slot_data = inventory_data.drop_single_slot_data(grabbed_slot_data, index)
[null, "inventory_drop_item"]:
grabbed_slot_data = inventory_data.get_slot_data(index)
if grabbed_slot_data:
if grabbed_slot_data and grabbed_slot_data.inventory_item.is_droppable:
if grabbed_slot_data.inventory_item.has_method("update_wieldable_data") and grabbed_slot_data.inventory_item.is_being_wielded:
#if grabbed_slot_data.inventory_item.ItemType.WIELDABLE and grabbed_slot_data.inventory_item.is_being_wielded:
Audio.play_sound(sound_error)
Expand Down Expand Up @@ -213,16 +213,22 @@ func _on_gui_input(event):

match event.button_index:
MOUSE_BUTTON_LEFT:
if !grabbed_slot_data.inventory_item.is_droppable:
print("This item isn't droppable.")
return
if grabbed_slot_data.inventory_item.has_method("update_wieldable_data") and grabbed_slot_data.inventory_item.is_being_wielded:
#if grabbed_slot_data.inventory_item.ItemType.WIELDABLE and grabbed_slot_data.inventory_item.is_being_wielded:
Audio.play_sound(sound_error)
print("Can't drop while wielding this item.")
else:
drop_slot_data.emit(grabbed_slot_data)
print("Dropping ", grabbed_slot_data)
grabbed_slot_data = null
drop_slot_data.emit(grabbed_slot_data.create_single_slot_data(grabbed_slot_data.origin_index))
if grabbed_slot_data.quantity < 1:
grabbed_slot_data = null

MOUSE_BUTTON_RIGHT:
if !grabbed_slot_data.inventory_item.is_droppable:
print("This item isn't droppable.")
return
if grabbed_slot_data.inventory_item.has_method("update_wieldable_data") and grabbed_slot_data.inventory_item.is_being_wielded:
#if grabbed_slot_data.inventory_item.ItemType.WIELDABLE and grabbed_slot_data.inventory_item.is_being_wielded:
Audio.play_sound(sound_error)
Expand Down
Loading

0 comments on commit afdb5d5

Please sign in to comment.