PopochiuInventoryItem

Extends: TextureRect

Description

Constants Descriptions

CURSOR

const CURSOR: res://addons/popochiu/engine/cursor/cursor.gd = preload("res://addons/popochiu/engine/cursor/cursor.gd")

Used to allow devs to define the cursor type for the clickable.

Property Descriptions

script_name

@export var script_name: String = ""

The identifier of the item used in scripts.

description

@export var description: String = ""
  • Getter: @description_getter

The text shown to players when the cursor hovers the item.

cursor

@export var cursor: cursor.gd.Type = 10

The cursor to use when the mouse hovers the object.

in_inventory

var in_inventory: bool = false
  • Setter: @in_inventory_setter

Whether this item is actually inside the inventory GUI.

last_click_button

var last_click_button: int = -1

Stores the last [enum MouseButton] pressed on this object.

Method Descriptions

queue_add

func queue_add(animate: bool = true) -> Callable

Adds this item to the inventory. If [param animate] is [code]true[/code], the inventory GUI will show an animation as a feedback of this action. It will depend on the implementation of the inventory in the GUI.[br][br] [i]This method is intended to be used inside a [method Popochiu.queue] of instructions.[/i] [br][br]Example of how to use it when interacting with a [PopochiuProp]: [codeblock] func on_click() -> void: E.queue([ C.queue_walk_to_clicked(), "Player: I'm gonna take this with me", I.Key.queue_add() ]) [/codeblock]

add

func add(animate: bool = true) -> void

Adds this item to the inventory. If [param animate] is [code]true[/code], the inventory GUI will show an animation as a feedback of this action. It will depend on the implementation of the inventory in the GUI. [br][br]Example of how to use it when interacting with a [PopochiuProp]: [codeblock] func on_click() -> void: await C.walk_to_clicked() await C.player.say("I'm gonna take this with me") await I.Key.add() [/codeblock]

queue_add_as_active

func queue_add_as_active(animate: bool = true) -> Callable

Adds this item to the inventory and makes it the current selected item (the cursor will look like the item's texture). Pass [param animate] as [code]false[/code] if you do not want the inventory GUI to animate when the item is added.[br][br] [i]This method is intended to be used inside a [method Popochiu.queue] of instructions.[/i]

add_as_active

func add_as_active(animate: bool = true) -> void

Adds this item to the inventory and makes it the current selected item (the cursor will look like the item's texture). Pass [param animate] as [code]false[/code] if you do not want the inventory GUI to animate when the item is added.

queue_remove

func queue_remove(animate: bool = false) -> Callable

Removes the item from the inventory (its instance will be kept in memory). Pass [param animate] as [code]true[/code] if you want the inventory GUI to animate when the item is removed.[br][br] [i]This method is intended to be used inside a [method Popochiu.queue] of instructions.[/i] [br][br]Example of how to use it when using an item on a [PopochiuProp]: [codeblock] func on_item_used(item: PopochiuInventoryItem) -> void: if item == I.ToyCar: E.queue([ "Player: Here is your toy car", I.ToyCar.queue_remove() ]) [/codeblock]

remove

func remove(animate: bool = false) -> void

Removes the item from the inventory (its instance will be kept in memory). Pass [param animate] as [code]true[/code] if you want the inventory GUI to animate when the item is removed. [br][br]Example of how to use it when using an item on a [PopochiuProp]: [codeblock] func on_item_used(item: PopochiuInventoryItem) -> void: if item == I.ToyCar: await C.player.say("Here is your toy car") await I.ToyCar.remove() [/codeblock]

queue_replace

func queue_replace(new_item: PopochiuInventoryItem) -> Callable

Replaces this inventory item by [param new_item]. Useful when combining items.[br][br] [i]This method is intended to be used inside a [method Popochiu.queue] of instructions.[/i] [br][br]Example of how to use it when combining two inventory items: [codeblock]

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) ]) [/codeblock]

replace

func replace(new_item: PopochiuInventoryItem) -> void

Replaces this inventory item by [param new_item]. Useful when combining items. [br][br]Example of how to use it when combining two inventory items: [codeblock]

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) [/codeblock]

queue_discard

func queue_discard(animate: bool = false) -> Callable

Removes the item from the inventory (its instance will be kept in memory). Pass [param animate] as [code]true[/code] if you want the inventory GUI to animate when the item is removed.[br][br] [i]This method is intended to be used inside a [method Popochiu.queue] of instructions.[/i]

discard

func discard(animate: bool = false) -> void

Removes the item from the inventory (its instance will be kept in memory). Pass [param animate] as [code]true[/code] if you want the inventory GUI to animate when the item is removed.

set_active

func set_active(_ignore_block: bool = false) -> void

Makes this item the current active item (the cursor will look like the item's texture).

on_click

func on_click() -> void

Called when the item is clicked in the inventory.

on_right_click

func on_right_click() -> void

Called when the item is right clicked in the inventory.

on_middle_click

func on_middle_click() -> void

Called when the item is middle clicked in the inventory.

on_item_used

func on_item_used(item: PopochiuInventoryItem) -> void

Called when the item is clicked and there is another [param item] currently selected.

handle_command

func handle_command(button_idx: int) -> void

Triggers the proper GUI command for the clicked mouse button identified with [param button_idx], which can be [enum MouseButton].MOUSE_BUTTON_LEFT, [enum MouseButton].MOUSE_BUTTON_RIGHT or [enum MouseButton].MOUSE_BUTTON_MIDDLE.

deselect

func deselect() -> void

Deselects this item if it is the current [member PopochiuIInventory.active] item.

set_in_inventory

func set_in_inventory(value: bool) -> void

get_description

func get_description() -> String

Signals

  • signal selected(item): Emitted when the item is selected.
  • signal unselected(): Emitted when the item is unselected (in most GUIs, this happens when right-clicking anywhere on the screen).