Randoloot/scripts/planets/freighter_storage_slot.gd
2026-10-25 22:38:13 +01:00

57 lines
2.3 KiB
GDScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

extends Button
## One click transfers the exact expected item; normal inventory guards stay authoritative.
var item: ItemInstance
var retrieve := false
var transfer: Callable
var locked := false
func _ready() -> void:
custom_minimum_size = Vector2(48,48)
mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND if item != null else Control.CURSOR_ARROW
var accent: Color = item.get_type_color() if item != null else Color("425554")
for state in ["normal","hover","pressed","disabled","focus"]:
var box := StyleBoxFlat.new()
box.bg_color = Color("13222a") if not locked else Color("11191d")
box.bg_color.a = 0.36
box.border_color = accent if state != "hover" else Color("e7c38a")
box.set_border_width_all(1)
box.set_corner_radius_all(4)
add_theme_stylebox_override(state,box)
if item != null:
var art := TextureRect.new()
art.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
art.texture = item.definition.icon
art.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
art.texture_filter = CanvasItem.TEXTURE_FILTER_LINEAR_WITH_MIPMAPS
art.mouse_filter = Control.MOUSE_FILTER_IGNORE
add_child(art)
art.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
art.offset_left = 4
art.offset_top = 4
art.offset_right = -4
art.offset_bottom = -7
var arrow := Label.new()
arrow.text = "←" if retrieve else "→"
arrow.position = Vector2(31,29)
arrow.add_theme_font_override("font",ThemeDB.fallback_font)
arrow.add_theme_font_size_override("font_size",15)
arrow.add_theme_color_override("font_color",Color("f1cc8a"))
arrow.add_theme_color_override("font_shadow_color",Color.BLACK)
arrow.add_theme_constant_override("shadow_outline_size",3)
arrow.mouse_filter = Control.MOUSE_FILTER_IGNORE
add_child(arrow)
set_meta("transfer_action","← ODBIERZ" if retrieve else "ODŁÓŻ →")
tooltip_text = item.get_tooltip_text()+"\nKliknij: "+("odbierz do statku" if retrieve else "przenieś na fregatę")
pressed.connect(_activate)
else:
disabled = true
text = "×" if locked else "·"
tooltip_text = "Odblokuj 1 slot ładowni w hangarze: 100 żelaza + 50 aluminium." if locked else "Wolny slot"
func _activate() -> void:
var inventory := get_tree().get_first_node_in_group("ship_inventory")
if inventory != null and inventory.selected_orb != null:
inventory.use_selected_orb(item)
else:
transfer.call()