122 lines
4.4 KiB
GDScript
122 lines
4.4 KiB
GDScript
extends PanelContainer
|
||
const GEAR := preload("res://scripts/planets/captain_equipment.gd")
|
||
var _wardrobe: PanelContainer
|
||
var _grid: GridContainer
|
||
var _gear_signature := ""
|
||
|
||
func _ready() -> void:
|
||
var frame := StyleBoxFlat.new()
|
||
frame.bg_color = Color(0.025, 0.045, 0.065, 0.65)
|
||
frame.border_color = Color("35515d")
|
||
frame.set_border_width_all(1)
|
||
frame.set_corner_radius_all(6)
|
||
frame.set_content_margin_all(7)
|
||
add_theme_stylebox_override("panel", frame)
|
||
custom_minimum_size.x = 244
|
||
var contents := VBoxContainer.new()
|
||
contents.add_theme_constant_override("separation", 4)
|
||
add_child(contents)
|
||
var title := Label.new()
|
||
title.text = "EKWIPUNEK KAPITANA"
|
||
title.add_theme_font_size_override("font_size", 10)
|
||
title.add_theme_color_override("font_color", Color("8fbfc6"))
|
||
contents.add_child(title)
|
||
var row := HBoxContainer.new()
|
||
row.alignment = BoxContainer.ALIGNMENT_CENTER
|
||
row.add_theme_constant_override("separation", 12)
|
||
contents.add_child(row)
|
||
for kind in GEAR.KINDS:
|
||
var slot := PanelContainer.new()
|
||
slot.name = kind.capitalize() + "Slot"
|
||
slot.set_script(preload("res://scripts/ui/captain_gear_slot.gd"))
|
||
slot.set("kind", kind)
|
||
row.add_child(slot)
|
||
var button := Button.new()
|
||
button.name = "OpenEquipment"
|
||
button.text = "WYPOSAŻENIE"
|
||
preload("res://scripts/ui/hud_button_style.gd").apply(button, Color("82cddd"))
|
||
button.add_theme_font_size_override("font_size", 9)
|
||
button.custom_minimum_size.y = 22
|
||
contents.add_child(button)
|
||
button.pressed.connect(_toggle_wardrobe)
|
||
_create_wardrobe()
|
||
GameState.captain.changed.connect(_refresh_wardrobe)
|
||
_refresh_wardrobe()
|
||
|
||
func _process(_delta: float) -> void:
|
||
var captain := get_parent().get_node_or_null("CaptainPanel") as Control
|
||
if captain:
|
||
position = captain.position + Vector2(0, captain.size.y + 7)
|
||
size = Vector2(captain.size.x, get_combined_minimum_size().y)
|
||
|
||
func _create_wardrobe() -> void:
|
||
_wardrobe = PanelContainer.new()
|
||
_wardrobe.name = "CaptainGearInventory"
|
||
var frame := StyleBoxFlat.new()
|
||
frame.bg_color = Color("0b1823")
|
||
frame.border_color = Color("537e91")
|
||
frame.set_border_width_all(1)
|
||
frame.set_corner_radius_all(8)
|
||
frame.set_content_margin_all(12)
|
||
_wardrobe.add_theme_stylebox_override("panel", frame)
|
||
_wardrobe.custom_minimum_size = Vector2(350, 180)
|
||
get_parent().add_child(_wardrobe)
|
||
var contents := VBoxContainer.new()
|
||
contents.add_theme_constant_override("separation", 9)
|
||
_wardrobe.add_child(contents)
|
||
var header := HBoxContainer.new()
|
||
contents.add_child(header)
|
||
var title := Label.new()
|
||
title.text = "WYPOSAŻENIE KAPITANA"
|
||
title.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||
title.add_theme_font_size_override("font_size", 12)
|
||
header.add_child(title)
|
||
var close := Button.new()
|
||
close.text = "×"
|
||
close.pressed.connect(func() -> void: _wardrobe.hide())
|
||
header.add_child(close)
|
||
var hint := Label.new()
|
||
hint.text = "Przeciągnij na slot kapitana lub kliknij dwukrotnie."
|
||
hint.add_theme_font_size_override("font_size", 10)
|
||
contents.add_child(hint)
|
||
var scroll := ScrollContainer.new()
|
||
scroll.custom_minimum_size.y = 160
|
||
scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED
|
||
contents.add_child(scroll)
|
||
_grid = GridContainer.new()
|
||
_grid.columns = 4
|
||
_grid.add_theme_constant_override("h_separation", 10)
|
||
_grid.add_theme_constant_override("v_separation", 10)
|
||
scroll.add_child(_grid)
|
||
var return_area := PanelContainer.new()
|
||
return_area.set_script(preload("res://scripts/ui/captain_gear_slot.gd"))
|
||
return_area.set("return_slot", true)
|
||
return_area.custom_minimum_size = Vector2(0, 36)
|
||
contents.add_child(return_area)
|
||
get_parent().get_node("FloatingWindows").register_window(_wardrobe, _wardrobe, header)
|
||
_wardrobe.hide()
|
||
|
||
func _toggle_wardrobe() -> void:
|
||
_wardrobe.visible = not _wardrobe.visible
|
||
_wardrobe.position = position + Vector2(size.x + 12, 0)
|
||
if _wardrobe.visible:
|
||
get_parent().get_node("FloatingWindows").focus_window(_wardrobe)
|
||
|
||
func _refresh_wardrobe() -> void:
|
||
var signature := str(GameState.captain.gear_items)
|
||
if signature == _gear_signature:
|
||
return
|
||
_gear_signature = signature
|
||
if not is_instance_valid(_grid):
|
||
return
|
||
for child in _grid.get_children():
|
||
_grid.remove_child(child)
|
||
child.queue_free()
|
||
for gear in GameState.captain.gear_items:
|
||
var slot := PanelContainer.new()
|
||
slot.set_script(preload("res://scripts/ui/captain_gear_slot.gd"))
|
||
slot.set("equipped_slot", false)
|
||
slot.set("uid", int(gear.uid))
|
||
slot.set("kind", str(gear.kind))
|
||
_grid.add_child(slot)
|