summaryrefslogtreecommitdiff
path: root/addons/escoria-core/ui_library/inventory
diff options
context:
space:
mode:
authorRadio <radiohotline@disroot.org>2026-06-04 15:15:11 +0300
committerRadio <radiohotline@disroot.org>2026-06-04 15:15:11 +0300
commit9d74b49ab62908d4acf53dde444413886b8b28e5 (patch)
tree0cb785267ea7e239b19d88684c0d64b9bd5d52f0 /addons/escoria-core/ui_library/inventory
parent2c85d452ad02a5f89cd43bad7f9de31d0e4fa0c1 (diff)
escoria setup and old branch archives
Diffstat (limited to 'addons/escoria-core/ui_library/inventory')
-rw-r--r--addons/escoria-core/ui_library/inventory/esc_inventory_button.gd178
-rw-r--r--addons/escoria-core/ui_library/inventory/esc_inventory_button.gd.uid1
-rw-r--r--addons/escoria-core/ui_library/inventory/esc_inventory_container.gd102
-rw-r--r--addons/escoria-core/ui_library/inventory/esc_inventory_container.gd.uid1
4 files changed, 282 insertions, 0 deletions
diff --git a/addons/escoria-core/ui_library/inventory/esc_inventory_button.gd b/addons/escoria-core/ui_library/inventory/esc_inventory_button.gd
new file mode 100644
index 0000000..b109c38
--- /dev/null
+++ b/addons/escoria-core/ui_library/inventory/esc_inventory_button.gd
@@ -0,0 +1,178 @@
+## The inventory representation of an ESC item if pickable (only used by
+## the inventory components)
+extends TextureButton
+class_name ESCInventoryButton
+
+## Signal emitted when the item was left clicked.[br]
+## [br]
+## #### Parameters[br]
+## [br]
+## | Name | Type | Description | Required? |[br]
+## |:-----|:-----|:------------|:----------|[br]
+## |item_id|`Variant`|Global ID of the clicked item|yes|[br]
+## [br]
+signal mouse_left_inventory_item(item_id)
+
+## Signal emitted when the item was right clicked.[br]
+## [br]
+## #### Parameters[br]
+## [br]
+## | Name | Type | Description | Required? |[br]
+## |:-----|:-----|:------------|:----------|[br]
+## |item_id|`Variant`|Global ID of the clicked item|yes|[br]
+## [br]
+signal mouse_right_inventory_item(item_id)
+
+## Signal emitted when the item was double clicked.[br]
+## [br]
+## #### Parameters[br]
+## [br]
+## | Name | Type | Description | Required? |[br]
+## |:-----|:-----|:------------|:----------|[br]
+## |item_id|`Variant`|Global ID of the clicked item|yes|[br]
+## [br]
+signal mouse_double_left_inventory_item(item_id)
+
+## Signal emitted when the item was focused.[br]
+## [br]
+## #### Parameters[br]
+## [br]
+## | Name | Type | Description | Required? |[br]
+## |:-----|:-----|:------------|:----------|[br]
+## |item_id|`Variant`|Global ID of the clicked item|yes|[br]
+## [br]
+signal inventory_item_focused(item_id)
+
+## Signal emitted when the item is not focused anymore.[br]
+## [br]
+## #### Parameters[br]
+## [br]
+## None.
+## [br]
+signal inventory_item_unfocused()
+
+## Global ID of the ESCItem that uses this ESCInventoryItem.
+var global_id: String = ""
+
+
+
+## Initializes the inventory button with the given item.[br]
+## [br]
+## #### Parameters[br]
+## [br]
+## | Name | Type | Description | Required? |[br]
+## |:-----|:-----|:------------|:----------|[br]
+## |p_item|`ESCInventoryItem`|The ESCInventoryItem to represent.|yes|[br]
+## [br]
+## #### Returns[br]
+## [br]
+## Returns nothing.
+func _init(p_item: ESCInventoryItem) -> void:
+ global_id = p_item.global_id
+ texture_normal = p_item.texture_normal
+ texture_hover = p_item.texture_hovered
+ stretch_mode = TextureButton.STRETCH_KEEP_ASPECT
+
+
+
+## Updates the size of the inventory button every frame.[br]
+## [br]
+## #### Parameters[br]
+## [br]
+## | Name | Type | Description | Required? |[br]
+## |:-----|:-----|:------------|:----------|[br]
+## |_delta|`float`|The frame time delta (unused).|yes|[br]
+## [br]
+## #### Returns[br]
+## [br]
+## Returns nothing.
+func _process(_delta: float) -> void:
+ size = ProjectSettings.get_setting("escoria/ui/inventory_item_size")
+ custom_minimum_size = ProjectSettings.get_setting(
+ "escoria/ui/inventory_item_size"
+ )
+
+
+## Connects input handlers for the inventory button.[br]
+## [br]
+## #### Parameters[br]
+## [br]
+## None.
+## [br]
+## #### Returns[br]
+## [br]
+## Returns nothing.
+func _ready():
+ gui_input.connect(_on_inventory_item_gui_input)
+ mouse_entered.connect(_on_inventory_item_mouse_enter)
+ mouse_exited.connect(_on_inventory_item_mouse_exit)
+
+
+
+## Handles the gui input and emits the respective signals.[br]
+## [br]
+## #### Parameters[br]
+## [br]
+## | Name | Type | Description | Required? |[br]
+## |:-----|:-----|:------------|:----------|[br]
+## |event|`InputEvent`|The event received.|yes|[br]
+## [br]
+## #### Returns[br]
+## [br]
+## Returns nothing.
+func _on_inventory_item_gui_input(event: InputEvent):
+ if event is InputEventMouseButton and event.is_pressed():
+ if event.button_index == MOUSE_BUTTON_WHEEL_UP:
+ escoria.inputs_manager._on_mousewheel_action(-1)
+ get_viewport().set_input_as_handled()
+ elif event.button_index == MOUSE_BUTTON_WHEEL_DOWN:
+ escoria.inputs_manager._on_mousewheel_action(1)
+ get_viewport().set_input_as_handled()
+ elif event.double_click:
+ if event.button_index == MOUSE_BUTTON_LEFT:
+ mouse_double_left_inventory_item.emit(
+ global_id,
+ event
+ )
+ # Make sure fast right clicks in the inventory aren't ignored
+ elif event.button_index == MOUSE_BUTTON_RIGHT:
+ mouse_right_inventory_item.emit(
+ global_id,
+ event
+ )
+ else:
+ if event.button_index == MOUSE_BUTTON_LEFT:
+ mouse_left_inventory_item.emit(
+ global_id,
+ event
+ )
+ if event.button_index == MOUSE_BUTTON_RIGHT:
+ mouse_right_inventory_item.emit(
+ global_id,
+ event
+ )
+
+
+## Handles mouse entering the item and sends the respective signal.[br]
+## [br]
+## #### Parameters[br]
+## [br]
+## None.
+## [br]
+## #### Returns[br]
+## [br]
+## Returns nothing.
+func _on_inventory_item_mouse_enter():
+ inventory_item_focused.emit(global_id)
+
+## Handles mouse leaving the item and sends the respective signal.[br]
+## [br]
+## #### Parameters[br]
+## [br]
+## None.
+## [br]
+## #### Returns[br]
+## [br]
+## Returns nothing.
+func _on_inventory_item_mouse_exit():
+ inventory_item_unfocused.emit()
diff --git a/addons/escoria-core/ui_library/inventory/esc_inventory_button.gd.uid b/addons/escoria-core/ui_library/inventory/esc_inventory_button.gd.uid
new file mode 100644
index 0000000..3fdb883
--- /dev/null
+++ b/addons/escoria-core/ui_library/inventory/esc_inventory_button.gd.uid
@@ -0,0 +1 @@
+uid://c1hfi1dlwh3hq
diff --git a/addons/escoria-core/ui_library/inventory/esc_inventory_container.gd b/addons/escoria-core/ui_library/inventory/esc_inventory_container.gd
new file mode 100644
index 0000000..1e6dab8
--- /dev/null
+++ b/addons/escoria-core/ui_library/inventory/esc_inventory_container.gd
@@ -0,0 +1,102 @@
+
+## Inventory container handler that acts as a base for UIs inventory containers.
+extends Control
+class_name ESCInventoryContainer
+
+## Whether any item in the container is currently focused.[br]
+var item_focused: bool = false
+
+## Whether the inventory container currently is empty.[br]
+## [br]
+## #### Parameters[br]
+## [br]
+## None.
+## [br]
+## #### Returns[br]
+## [br]
+## Returns whether the inventory container currently is empty. Whether the container is empty or not. (`bool`)
+func is_empty() -> bool:
+ return get_child_count() > 0
+
+## Adds a new item into the container and returns the control generated for it so its events can be handled by the inputs manager.[br]
+## [br]
+## #### Parameters[br]
+## [br]
+## | Name | Type | Description | Required? |[br]
+## |:-----|:-----|:------------|:----------|[br]
+## |inventory_item|`ESCInventoryItem`|Item to add.|yes|[br]
+## [br]
+## #### Returns[br]
+## [br]
+## Returns the button generated for the item. (`ESCInventoryButton`)
+func add_item(inventory_item: ESCInventoryItem) -> ESCInventoryButton:
+ var button = ESCInventoryButton.new(inventory_item)
+ button.inventory_item_focused.connect(_on_inventory_item_focused)
+ button.inventory_item_unfocused.connect(_on_inventory_item_unfocused)
+ add_child(button)
+ return button
+
+## Removes an item from the container.[br]
+## [br]
+## #### Parameters[br]
+## [br]
+## | Name | Type | Description | Required? |[br]
+## |:-----|:-----|:------------|:----------|[br]
+## |inventory_item|`ESCInventoryItem`|Item to remove.|yes|[br]
+## [br]
+## #### Returns[br]
+## [br]
+## Returns nothing.
+func remove_item(inventory_item: ESCInventoryItem):
+ for c in get_children():
+ if c is ESCInventoryButton and c.global_id == inventory_item.global_id:
+ remove_child(c)
+ c.queue_free()
+
+
+## An Inventory button from the container, using an ESCInventoryItem.[br]
+## [br]
+## #### Parameters[br]
+## [br]
+## | Name | Type | Description | Required? |[br]
+## |:-----|:-----|:------------|:----------|[br]
+## |inventory_item|`ESCInventoryItem`|Inventory item to return the button node from.|yes|[br]
+## [br]
+## #### Returns[br]
+## [br]
+## Returns an Inventory button from the container, using an ESCInventoryItem. The inventory button node, or null if not found. (`ESCInventoryButton`)
+func get_inventory_button(inventory_item: ESCInventoryItem) -> ESCInventoryButton:
+ var inventory_button = null
+ for c in get_children():
+ if c.global_id == inventory_item.global_id:
+ inventory_button = c
+ break
+ return inventory_button
+
+
+## Called when an inventory item is focused.[br]
+## [br]
+## #### Parameters[br]
+## [br]
+## | Name | Type | Description | Required? |[br]
+## |:-----|:-----|:------------|:----------|[br]
+## |item_id|`Variant`|The global ID of the focused item.|yes|[br]
+## [br]
+## #### Returns[br]
+## [br]
+## Returns nothing.
+func _on_inventory_item_focused(item_id):
+ item_focused = true
+
+
+## Called when an inventory item is unfocused.[br]
+## [br]
+## #### Parameters[br]
+## [br]
+## None.
+## [br]
+## #### Returns[br]
+## [br]
+## Returns nothing.
+func _on_inventory_item_unfocused():
+ item_focused = false
diff --git a/addons/escoria-core/ui_library/inventory/esc_inventory_container.gd.uid b/addons/escoria-core/ui_library/inventory/esc_inventory_container.gd.uid
new file mode 100644
index 0000000..1ad5d75
--- /dev/null
+++ b/addons/escoria-core/ui_library/inventory/esc_inventory_container.gd.uid
@@ -0,0 +1 @@
+uid://c4syt26p7mg66