2025-08-27 08:02:11 -04:00
|
|
|
class_name ItemSlot extends Control
|
2025-08-21 11:41:16 -04:00
|
|
|
|
2025-08-30 08:01:48 -04:00
|
|
|
|
|
|
|
|
@onready var item_sprite : TextureRect = $Item
|
|
|
|
|
|
2025-08-21 11:41:16 -04:00
|
|
|
var dragging : bool = false
|
|
|
|
|
var last_click : int = 0
|
2025-08-21 22:23:14 -04:00
|
|
|
var item : Item
|
2025-08-27 08:02:11 -04:00
|
|
|
|
2025-08-30 08:01:48 -04:00
|
|
|
signal display_item(itm)
|
2025-08-27 08:02:11 -04:00
|
|
|
func assign(itm : Item) -> void:
|
2025-08-28 08:36:20 -04:00
|
|
|
item = itm
|
|
|
|
|
if item.image != null:
|
|
|
|
|
item_sprite.texture = item.image
|
2025-08-27 08:02:11 -04:00
|
|
|
|
|
|
|
|
func swap(item_slot : ItemSlot) -> void:
|
|
|
|
|
var itm = item
|
|
|
|
|
assign(itm)
|
|
|
|
|
item_slot.assign(itm)
|
|
|
|
|
|
2025-08-28 08:36:20 -04:00
|
|
|
func update(itm : Item) -> void:
|
|
|
|
|
if itm == null:
|
|
|
|
|
clear()
|
|
|
|
|
elif itm != item:
|
|
|
|
|
assign(itm)
|
|
|
|
|
|
|
|
|
|
func clear() -> void:
|
|
|
|
|
item = null
|
|
|
|
|
item_sprite.texture = null
|
|
|
|
|
|
2025-08-21 11:41:16 -04:00
|
|
|
func _on_gui_input(event: InputEvent) -> void:
|
|
|
|
|
var mmevt = event as InputEventMouseMotion
|
|
|
|
|
var mbevt = event as InputEventMouseButton
|
2025-08-30 08:01:48 -04:00
|
|
|
if mbevt != null:
|
|
|
|
|
if mbevt.pressed and mbevt.button_index == MOUSE_BUTTON_LEFT and item != null:
|
|
|
|
|
display_item.emit(item)
|
2025-08-21 22:23:14 -04:00
|
|
|
#if mbevt and mbevt.button_index == MOUSE_BUTTON_MASK_LEFT:
|
|
|
|
|
#if !mbevt.pressed:
|
|
|
|
|
#if dragging and
|
2025-08-21 11:41:16 -04:00
|
|
|
#Press, drag, double click
|
|
|
|
|
pass # Replace with function body.
|