class_name InventoryItemRect
|
|
extends Panel
|
|
|
|
|
|
@export var amount_label: Label
|
|
@export var item_resource: DBItemResource
|
|
@export var item_texture: TextureButton
|
|
|
|
var highlight_theme: Resource
|
|
|
|
|
|
func init(_item_resource: DBItemResource, _highlight_theme: Resource) -> void:
|
|
item_texture.mouse_entered.connect(_on_mouse_entered)
|
|
item_texture.mouse_exited.connect(_on_mouse_exited)
|
|
|
|
highlight_theme = _highlight_theme
|
|
item_resource = _item_resource
|
|
update_rect()
|
|
|
|
|
|
func clear_rect() -> void:
|
|
item_texture.texture_normal = null
|
|
amount_label.text = ""
|
|
item_texture.tooltip_text = ""
|
|
|
|
func update_rect() -> void:
|
|
if not item_resource:
|
|
clear_rect()
|
|
else:
|
|
if InventoryManager.creative_mode:
|
|
amount_label.text = "∞"
|
|
else:
|
|
amount_label.text = "x" + str(item_resource.amount)
|
|
item_texture.texture_normal = load(item_resource.item_texture)
|
|
item_texture.tooltip_text = item_resource.name + "\n" + item_resource.description
|
|
|
|
func on_stack_full(is_full: bool) -> void:
|
|
if is_full:
|
|
amount_label.add_theme_color_override("font_color", Color(1, 0, 0))
|
|
else:
|
|
amount_label.add_theme_color_override("font_color", Color(1, 1, 1))
|
|
|
|
|
|
func _on_mouse_entered() -> void:
|
|
set("theme_override_styles/panel", highlight_theme)
|
|
|
|
func _on_mouse_exited() -> void:
|
|
set("theme_override_styles/panel", null)
|