Make decor occupy individual inventory slots

This commit is contained in:
Alexander Sellite 2026-09-01 17:29:57 -04:00
parent f2239d248a
commit 4196cda1d5
9 changed files with 516 additions and 79 deletions

View file

@ -21,6 +21,7 @@ var slot_index: int = -1
var container: int = -1
var entry_kind: int = -1
var entry_identity: StringName
var entry_key: String = ""
var _locked: bool = false
var _layout: PlayerInventoryLayout
@ -107,6 +108,7 @@ func refresh() -> void:
call_deferred("_update_context_presence")
entry_kind = -1
entry_identity = StringName()
entry_key = ""
_context_text = ""
_quality_tier = -1
_icon.texture = null
@ -142,6 +144,7 @@ func refresh() -> void:
return
entry_kind = int(entry.get("kind", -1))
entry_identity = StringName(str(entry.get("identity", "")))
entry_key = str(entry.get("key", ""))
if entry_kind == PlayerInventoryLayout.EntryKind.ITEM:
var item: ItemDataType = (
_item_catalog.get_item_by_id(entry_identity)
@ -150,7 +153,11 @@ func refresh() -> void:
if item == null:
return
_icon.texture = item.icon
var quantity := _bag.get_quantity(entry_identity) if _bag != null else 0
var quantity := (
1
if int(entry.get("unit", -1)) >= 0
else _bag.get_quantity(entry_identity) if _bag != null else 0
)
_quantity.text = "×%d" % quantity if quantity > 1 else ""
_context_text = _item_context_text(item, quantity)
accessibility_name = "%s, slot %d" % [item.display_name, slot_index + 1]
@ -273,6 +280,7 @@ func _get_drag_data(_at_position: Vector2) -> Variant:
return {
"kind": "bag_item",
"item_id": String(entry_identity),
"entry_key": entry_key,
}
@ -310,7 +318,12 @@ func _drop_data(_at_position: Vector2, data: Variant) -> void:
"",
)
))
moved = _layout.move_entry(kind, identity, container, slot_index)
var source_key: String = str(payload.get("entry_key", ""))
moved = (
_layout.move_entry_by_key(source_key, container, slot_index)
if not source_key.is_empty()
else _layout.move_entry(kind, identity, container, slot_index)
)
if moved:
entry_moved.emit()

View file

@ -359,6 +359,7 @@ var _selected_inventory_kind: int = -1
var _selected_inventory_identity: StringName
var _inventory_move_kind: int = -1
var _inventory_move_identity: StringName
var _inventory_move_key: String = ""
var _context_tooltip: PanelContainer
var _context_tooltip_label: Label
var _context_tooltip_source: Control
@ -3865,6 +3866,7 @@ func _on_general_inventory_slot_activated(
return
_inventory_move_kind = slot.entry_kind
_inventory_move_identity = slot.entry_identity
_inventory_move_key = slot.entry_key
_selected_inventory_kind = slot.entry_kind
_selected_inventory_identity = slot.entry_identity
_selected_bag_item_id = (
@ -3883,15 +3885,23 @@ func _on_general_inventory_slot_activated(
return
var move_kind: int = _inventory_move_kind
var move_identity: StringName = _inventory_move_identity
var move_key: String = _inventory_move_key
_cancel_inventory_move(false)
if _inventory_layout == null:
return
_inventory_layout.move_entry(
move_kind,
move_identity,
PlayerInventoryLayout.InventoryContainer.INVENTORY,
slot.slot_index,
)
if not move_key.is_empty():
_inventory_layout.move_entry_by_key(
move_key,
PlayerInventoryLayout.InventoryContainer.INVENTORY,
slot.slot_index,
)
else:
_inventory_layout.move_entry(
move_kind,
move_identity,
PlayerInventoryLayout.InventoryContainer.INVENTORY,
slot.slot_index,
)
func _open_general_inventory_notepad(
@ -3944,6 +3954,7 @@ func _cancel_inventory_move(hide_tooltip: bool = true) -> bool:
return false
_inventory_move_kind = -1
_inventory_move_identity = StringName()
_inventory_move_key = ""
if _general_inventory_grid != null:
for slot: GeneralInventorySlotType in _general_inventory_grid.get_slots():
slot.set_move_source(false)
@ -4316,12 +4327,6 @@ func _sort_bag_storage_items(a: OwnedItemType, b: OwnedItemType) -> bool:
func _sort_tackle_items(a: OwnedItemType, b: OwnedItemType) -> bool:
if a.storage_slot >= 0 and b.storage_slot >= 0:
return a.storage_slot < b.storage_slot
if a.storage_slot >= 0:
return true
if b.storage_slot >= 0:
return false
var order_a := FishingShopStockType.get_stock_order_index(a.item_id)
var order_b := FishingShopStockType.get_stock_order_index(b.item_id)
if order_a >= 0 and order_b >= 0 and order_a != order_b:

View file

@ -59,13 +59,13 @@ func setup(
item_catalog,
PlayerInventoryLayout.InventoryContainer.STORAGE,
)
_inventory_grid.entry_selected.connect(
_on_entry_selected.bind(
_inventory_grid.slot_activated.connect(
_on_slot_activated.bind(
PlayerInventoryLayout.InventoryContainer.STORAGE
)
)
_storage_grid.entry_selected.connect(
_on_entry_selected.bind(
_storage_grid.slot_activated.connect(
_on_slot_activated.bind(
PlayerInventoryLayout.InventoryContainer.INVENTORY
)
)
@ -170,20 +170,24 @@ func consume_escape() -> bool:
func _unhandled_input(event: InputEvent) -> void:
if not visible or not event.is_action_pressed("ui_cancel"):
if not visible:
return
var close_requested: bool = event.is_action_pressed("ui_cancel") or (
_home_access and event.is_action_pressed("interact")
)
if not close_requested or (event is InputEventKey and event.echo):
return
close_storage()
get_viewport().set_input_as_handled()
func _on_entry_selected(
kind: int,
identity: StringName,
func _on_slot_activated(
slot: GeneralInventorySlot,
target_container: int,
) -> void:
if kind < 0 or identity.is_empty() or _layout == null:
if slot == null or slot.entry_key.is_empty() or _layout == null:
return
if _layout.move_entry_to_first_free(kind, identity, target_container):
if _layout.move_entry_key_to_first_free(slot.entry_key, target_container):
_feedback.text = (
"moved to storage"
if target_container == PlayerInventoryLayout.InventoryContainer.STORAGE