yagvm/UI/Components/GroupMenu.gd

97 lines
2.4 KiB
GDScript

extends VBoxContainer
@onready var collapse_button: Button = %CollapseButton
@onready var header_icon: TextureRect = %HeaderIcon
@onready var header_text_label: Label = %HeaderTextLabel
@onready var header_custom_control_container: HBoxContainer = %HeaderCustomControlContainer
@onready var child_container: VBoxContainer = %ChildContainer
@onready var add_install_button_container: CenterContainer = %AddInstallButtonContainer
@onready var add_install_button: Button = %AddInstallButton
@onready var edit_text_button: Button = %EditTextButton
@onready var delete_group_button: Button = %DeleteGroupButton
@onready var header_container: HBoxContainer = %HeaderContainer
signal add_install_button_pressed
signal delete_button_pressed
signal header_text_changed(new_text: String)
func _ready() -> void:
collapse_button.pressed.connect(
func():
var b := collapse_button
set_children_visible(b.button_pressed)
)
add_install_button.pressed.connect(func(): add_install_button_pressed.emit())
edit_text_button.pressed.connect(setup_rename)
delete_group_button.pressed.connect(func(): delete_button_pressed.emit())
func add(item) -> void:
pass
func free_item(at_idx: int) -> void:
child_container.get_child(at_idx).queue_free()
func clear() -> void:
child_container.get_children().map(
func(child: Node):
child.queue_free()
)
func set_text(text: String) -> void:
header_text_label.text = text
func set_icon(icon: Texture2D) -> void:
header_icon.texture = icon
func set_icon_visible(p_visible: bool) -> void:
header_icon.visible = p_visible
func set_children_visible(p_visible: bool) -> void:
collapse_button.text = "v" if p_visible else ">"
child_container.visible = p_visible
add_install_button_container.visible = p_visible
func add_custom(control: Control) -> void:
header_custom_control_container.add_child(control)
func setup_rename() -> void:
header_text_label.visible = false
var l := RenameLineEdit.new(header_text_label.text)
l.size_flags_horizontal = header_text_label.size_flags_horizontal
edit_text_button.disabled = true
header_container.add_child(l)
header_container.move_child(l, 2)
var reenable = func():
header_text_label.visible = true
edit_text_button.disabled = false
l.canceled.connect(reenable)
l.text_submitted.connect(
func(new_text: String):
header_text_label.text = new_text
header_text_changed.emit(new_text)
reenable.call()
)
l.grab_focus()