PopochiuInventoryItem
Inherits: TextureRect
Description
Represents an item that can be collected, stored in the inventory, and used on objects.
Inventory items can handle click interactions and be combined with other items or used on PopochiuClickable objects.
Properties
| Type | Name | Default |
|---|---|---|
| CURSOR | cursor | CURSOR.Type.USE |
| Variant | description | "" |
| Variant | ever_collected | false |
| Variant | in_inventory | false |
| Variant | last_click_button | -1 # NOTE Don't know if this will make sense, or if it this object should |
| Variant | script_name | "" |
Methods
| Return Type | Method |
|---|---|
| void | _on_added_to_inventory() virtual |
| void | _on_click() virtual |
| void | _on_discard() virtual |
| void | _on_item_used(item: PopochiuInventoryItem) virtual |
| void | _on_middle_click() virtual |
| void | _on_right_click() virtual |
| void | add(animate = true) |
| void | add_as_active(animate = true) |
| int | count_invoked(command: int) |
| void | deselect() |
| void | discard(animate = false) |
| bool | ever_invoked(command: int) |
| bool | first_invoked(command: int) |
| String | get_description() |
| void | handle_command(button_idx: int) |
| void | on_click() |
| void | on_item_used(item: PopochiuInventoryItem) |
| void | on_middle_click() |
| void | on_right_click() |
| Callable | queue_add(animate = true) |
| Callable | queue_add_as_active(animate = true) |
| Callable | queue_discard(animate = false) |
| Callable | queue_remove(animate = false) |
| Callable | queue_replace(new_item: PopochiuInventoryItem) |
| void | remove(animate = false) |
| void | replace(new_item: PopochiuInventoryItem) |
| void | set_active(_ignore_block = false) |
| void | set_ever_collected(value: bool) |
| void | set_in_inventory(value: bool) |
Signals
- selected(item)
- unselected()
Signal Descriptions
selected
signal selected(item)
Emitted when the item is selected.
unselected
signal unselected()
Emitted when the item is unselected (in most GUIs, this happens when right-clicking anywhere on the screen).
Property Descriptions
cursor
@export var cursor : CURSOR = CURSOR.Type.USE
The cursor to use when the mouse hovers the object.
description
@export var description = ""
- Getter:
get_description
The text shown to players when the cursor hovers the item.
ever_collected
var ever_collected = false
- Setter:
set_ever_collected
Whether this item has ever been in the inventory. Once true, it stays true.
in_inventory
var in_inventory = false
- Setter:
set_in_inventory
Whether this item is actually inside the inventory GUI.
last_click_button
var last_click_button = -1 # NOTE Don't know if this will make sense, or if it this object should
Stores the last MouseButton pressed on this object.
script_name
@export var script_name = ""
The identifier of the item used in scripts.
Method Descriptions
_on_added_to_inventory
func _on_added_to_inventory() -> void
This is a virtual method. Override it in your subclass.
Called after the item is added to the inventory.
Override this to implement custom behavior (e.g. playing a sound).
_on_click
func _on_click() -> void
This is a virtual method. Override it in your subclass.
Called when the item is clicked in the inventory GUI.
Override this to define what happens when the item is clicked.
_on_discard
func _on_discard() -> void
This is a virtual method. Override it in your subclass.
Called when the item is discarded from the inventory.
Override this to implement custom behavior (e.g. playing a sound).
_on_item_used
func _on_item_used(item: PopochiuInventoryItem) -> void
This is a virtual method. Override it in your subclass.
Called when this item is clicked while another item is selected.
Override this to define what happens when this item is used on another item.
_on_middle_click
func _on_middle_click() -> void
This is a virtual method. Override it in your subclass.
Called when the item is middle-clicked in the inventory GUI.
Override this to define what happens when the item is middle-clicked.
_on_right_click
func _on_right_click() -> void
This is a virtual method. Override it in your subclass.
Called when the item is right-clicked in the inventory GUI.
Override this to define what happens when the item is right-clicked.
add
func add(animate = true) -> void
Adds this item to the inventory. If animate is true, the inventory GUI
shows an animation (implementation depends on the GUI).
Example:
func on_click() -> void:
await C.walk_to_clicked()
await C.player.say("I'm gonna take this with me")
await I.Key.add()
add_as_active
func add_as_active(animate = true) -> void
Adds this item to the inventory and makes it the active item (cursor shows the item's texture).
Pass animate as false to skip the inventory GUI animation.
count_invoked
func count_invoked(command: int) -> int
Returns the number of times the command has been invoked on this object.
deselect
func deselect() -> void
Deselects this item if it is the current active item.
discard
func discard(animate = false) -> void
Removes the item from the inventory without destroying the instance. Pass animate as
true to animate the removal in the inventory GUI.
ever_invoked
func ever_invoked(command: int) -> bool
Returns true if the command has ever been invoked on this object.
This function is typically used in a command handler to provide different behaviors
depending on whether the command has been used before or not.
first_invoked
func first_invoked(command: int) -> bool
Returns true if this is the first time the command is being invoked on this object.
This function is typically used in a command handler to provide different behaviors
depending on whether the command has been used before or not.
get_description
func get_description() -> String
handle_command
func handle_command(button_idx: int) -> void
Triggers the proper GUI command for the clicked mouse button identified with button_idx,
which can be MouseButton.MOUSE_BUTTON_LEFT, MouseButton.MOUSE_BUTTON_RIGHT or
MouseButton.MOUSE_BUTTON_MIDDLE.
on_click
func on_click() -> void
Called when the item is clicked in the inventory.
on_item_used
func on_item_used(item: PopochiuInventoryItem) -> void
Called when the item is clicked and there is another item currently selected.
on_middle_click
func on_middle_click() -> void
Called when the item is middle clicked in the inventory.
on_right_click
func on_right_click() -> void
Called when the item is right clicked in the inventory.
queue_add
func queue_add(animate = true) -> Callable
Adds this item to the inventory. If animate is true, the inventory GUI
shows an animation (implementation depends on the GUI).
This method is intended to be used inside a queue() of instructions.
Example:
func on_click() -> void:
E.queue([
C.queue_walk_to_clicked(),
"Player: I'm gonna take this with me",
I.Key.queue_add()
])
queue_add_as_active
func queue_add_as_active(animate = true) -> Callable
Adds this item to the inventory and makes it the active item (cursor shows the item's texture).
Pass animate as false to skip the inventory GUI animation.
This method is intended to be used inside a queue() of instructions.
queue_discard
func queue_discard(animate = false) -> Callable
Removes the item from the inventory without destroying the instance. Pass animate as
true to animate the removal in the inventory GUI.
This method is intended to be used inside a queue() of instructions.
queue_remove
func queue_remove(animate = false) -> Callable
Removes the item from the inventory (instance is kept in memory). Pass animate as
true to animate the removal in the inventory GUI.
This method is intended to be used inside a queue() of instructions.
Example:
func on_item_used(item: PopochiuInventoryItem) -> void:
if item == I.ToyCar:
E.queue([
"Player: Here is your toy car",
I.ToyCar.queue_remove()
])
queue_replace
func queue_replace(new_item: PopochiuInventoryItem) -> Callable
Replaces this inventory item with new_item. Useful when combining items.
This method is intended to be used inside a queue() of instructions.
Example:
# This is the script of the InventoryItemHook.gd (I.Hook)
func on_item_used(item: PopochiuInventoryItem) -> void:
if item == I.Rope:
E.queue([
I.Rope.queue_remove(),
queue_replace(I.RopeWithHook)
])
remove
func remove(animate = false) -> void
Removes the item from the inventory (instance is kept in memory). Pass animate as
true to animate the removal in the inventory GUI.
Example:
func on_item_used(item: PopochiuInventoryItem) -> void:
if item == I.ToyCar:
await C.player.say("Here is your toy car")
await I.ToyCar.remove()
replace
func replace(new_item: PopochiuInventoryItem) -> void
Replaces this inventory item with new_item. Useful when combining items.
Example:
# This is the script of the InventoryItemHook.gd (I.Hook)
func on_item_used(item: PopochiuInventoryItem) -> void:
if item == I.Rope:
await I.Rope.remove()
await replace(I.RopeWithHook)
set_active
func set_active(_ignore_block = false) -> void
Makes this item the current active item (the cursor will look like the item's texture).
set_ever_collected
func set_ever_collected(value: bool) -> void
set_in_inventory
func set_in_inventory(value: bool) -> void