Skip to content

Commit

Permalink
Merge branch 'develop' into addon
Browse files Browse the repository at this point in the history
  • Loading branch information
scriptsengineer committed Nov 12, 2023
2 parents 2189c3c + 802e0eb commit 4aa222b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
9 changes: 6 additions & 3 deletions addons/inventory-system/core/inventory_handler.gd
Original file line number Diff line number Diff line change
Expand Up @@ -244,16 +244,19 @@ func to_transaction(slot_index : int, inventory : Inventory, amount : int):


## Moves transfer slot information to the [code]slot_index[/code] slot of [Inventory].
func transaction_to_at(slot_index : int, inventory : Inventory):
func transaction_to_at(slot_index : int, inventory : Inventory, amount_to_move : int = -1):
if not is_transaction_active():
return
var slot = inventory.slots[slot_index]
var item = transaction_slot.item
if item == null:
return
if inventory.is_empty_slot(slot_index) or slot.item == item:
var amount_no_add = inventory.add_at(slot_index, item, transaction_slot.amount)
_set_transaction_slot(item, amount_no_add)
var amount = transaction_slot.amount
if amount_to_move >= 0:
amount = amount_to_move
var amount_no_add = inventory.add_at(slot_index, item, amount)
_set_transaction_slot(item, (transaction_slot.amount - amount) + amount_no_add)
else:
# Different items in slot and other_slot
# Check if transaction_slot amount is equal of origin_slot amount
Expand Down
10 changes: 5 additions & 5 deletions addons/inventory-system/multiplayer/networked_handler.gd
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ func to_transaction(slot_index : int , inventory : Inventory, amount : int):
to_transaction_rpc(slot_index, inventory.get_path(), amount)


func transaction_to_at(slot_index : int, inventory : Inventory):
func transaction_to_at(slot_index : int, inventory : Inventory, amount_to_move : int = -1):
if not multiplayer.is_server():
transaction_to_at_rpc.rpc_id(1, slot_index, inventory.get_path())
transaction_to_at_rpc.rpc_id(1, slot_index, inventory.get_path(), amount_to_move)
else:
transaction_to_at_rpc(slot_index, inventory.get_path())
transaction_to_at_rpc(slot_index, inventory.get_path(), amount_to_move)


func transaction_to(inventory : Inventory):
Expand Down Expand Up @@ -211,7 +211,7 @@ func to_transaction_rpc(slot_index : int, object_path : NodePath, amount : int):


@rpc("any_peer")
func transaction_to_at_rpc(slot_index : int, object_path : NodePath):
func transaction_to_at_rpc(slot_index : int, object_path : NodePath, amount_to_move : int):
if not multiplayer.is_server():
return
var object = get_node(object_path)
Expand All @@ -220,7 +220,7 @@ func transaction_to_at_rpc(slot_index : int, object_path : NodePath):
var inventory = object as Inventory
if inventory == null:
return
super.transaction_to_at(slot_index, inventory)
super.transaction_to_at(slot_index, inventory, amount_to_move)


@rpc("any_peer")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[ext_resource type="Resource" uid="uid://c2cuwwcpbs81y" path="res://addons/inventory-system/ui/interactor/default_input_icons.tres" id="3_rgd78"]

[sub_resource type="LabelSettings" id="LabelSettings_8sxuh"]
outline_size = 4
outline_size = 8
outline_color = Color(0, 0, 0, 1)

[node name="ActionMessageUI" type="HBoxContainer" node_paths=PackedStringArray("texture_rect", "interact_message")]
Expand Down
22 changes: 17 additions & 5 deletions addons/inventory-system/ui/inventory_system_ui.gd
Original file line number Diff line number Diff line change
Expand Up @@ -169,19 +169,31 @@ func _close_player_inventory():


func _slot_point_down(event : InputEvent, slot_index : int, inventory : Inventory):
if not event is InputEventMouseButton:
return
var mouse_event : InputEventMouseButton = event as InputEventMouseButton
if inventory_handler.is_transaction_active():
inventory_handler.transaction_to_at(slot_index, inventory)
var amount = _get_amount_per_mouse_event(mouse_event, inventory_handler.transaction_slot.amount)
inventory_handler.transaction_to_at(slot_index, inventory, amount)
$SlotDrop.play()
else:
if inventory.is_empty_slot(slot_index):
return
var slot = inventory.slots[slot_index]
var amount = slot.amount
if event is InputEventMouseButton and event.button_index == 2:
amount = ceili(slot.amount/2.0)
var amount = _get_amount_per_mouse_event(mouse_event, slot.amount)
inventory_handler.to_transaction(slot_index, inventory, amount)
$SlotClick.play()



func _get_amount_per_mouse_event(mouse_event : InputEventMouseButton, amount : int) -> int:
if mouse_event.button_index == MOUSE_BUTTON_LEFT:
return amount
if mouse_event.button_index == MOUSE_BUTTON_RIGHT:
return ceili(amount / 2.0)
if mouse_event.button_index == MOUSE_BUTTON_MIDDLE:
return 1
return 0


func _inventory_point_down(event : InputEvent, inventory : Inventory):
if event.button_index == 3:
Expand Down

0 comments on commit 4aa222b

Please sign in to comment.