RustHacker/inv_system/item_slot.gd

74 lines
1.6 KiB
GDScript3
Raw Normal View History

2026-01-10 18:05:09 +11:00
extends Panel
2026-01-10 23:17:55 +11:00
class_name ItemSlot
2026-01-10 18:05:09 +11:00
@export var icon : TextureRect
@export var item: ItemData
@export var label : Label
2026-01-11 18:11:14 +11:00
var type : String
2026-01-12 19:32:35 +11:00
var block_taking : bool = false
const DEFAULT = preload("uid://hgjmkwj0dbqr")
2026-01-14 19:00:40 +11:00
var extra_data : String = ""
2026-01-10 18:05:09 +11:00
func _ready() -> void:
update_ui()
func update_ui():
if not item:
icon.texture = null
label.text = ""
add_theme_stylebox_override("panel",DEFAULT)
2026-01-10 18:05:09 +11:00
return
if item.custom_panel_style:
add_theme_stylebox_override("panel",item.custom_panel_style)
else:
#remove_theme_stylebox_override("panel")
add_theme_stylebox_override("panel",DEFAULT)
2026-01-10 18:05:09 +11:00
icon.texture = item.icon
2026-01-11 16:05:12 +11:00
#tooltip_text = item.item_name
label.text = item.value
2026-01-10 18:05:09 +11:00
2026-01-11 18:11:14 +11:00
2026-01-10 18:05:09 +11:00
func _get_drag_data(at_position: Vector2) -> Variant:
2026-01-12 19:32:35 +11:00
if not item or block_taking:
2026-01-10 18:05:09 +11:00
return
var preview = duplicate()
var c = Control.new()
c.add_child(preview)
preview.position -= Vector2(32,32)
preview.self_modulate = Color.TRANSPARENT
2026-01-11 16:05:12 +11:00
c.z_index = 3
c.modulate = Color(c.modulate,0.6)
2026-01-10 18:05:09 +11:00
set_drag_preview(c)
icon.hide()
return self
func _can_drop_data(at_position: Vector2, data: Variant) -> bool:
2026-01-12 19:32:35 +11:00
return !block_taking
2026-01-10 18:05:09 +11:00
func _drop_data(at_position: Vector2, data: Variant) -> void:
var temp = item
item = data.item
data.item = temp
icon.show()
data.icon.show()
update_ui()
data.update_ui()
func _on_mouse_entered() -> void:
2026-01-11 16:05:12 +11:00
#print("im real?")
if item:
2026-01-17 17:07:53 +11:00
Tooltip.show_tip(item, extra_data)
2026-01-11 18:11:14 +11:00
MouseTweaks.hovered_slot = self
pass # Replace with function body.
func _on_mouse_exited() -> void:
Tooltip.hide_tip()
2026-01-11 18:11:14 +11:00
MouseTweaks.hovered_slot = null
pass # Replace with function body.