2023-03-05 11:03:08 +00:00
|
|
|
extends VBoxContainer
|
2023-03-05 12:08:54 +00:00
|
|
|
class_name GroupMenu
|
2023-03-05 11:03:08 +00:00
|
|
|
|
2023-05-25 22:41:48 +00:00
|
|
|
const ITEM_SCENE := preload("res://UI/Components/InstallItem.tscn")
|
|
|
|
|
2023-03-05 11:03:08 +00:00
|
|
|
@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
|
2023-03-05 12:08:54 +00:00
|
|
|
@onready var description_label: Label = %DescriptionLabel
|
2023-03-06 13:33:46 +00:00
|
|
|
@onready var inner_separator: HSeparator = %InnerSeparator
|
2023-03-05 11:03:08 +00:00
|
|
|
|
2023-03-05 12:08:54 +00:00
|
|
|
@onready var edit_group_button: Button = %EditGroupButton
|
2023-03-05 11:03:08 +00:00
|
|
|
@onready var delete_group_button: Button = %DeleteGroupButton
|
|
|
|
|
|
|
|
@onready var header_container: HBoxContainer = %HeaderContainer
|
|
|
|
|
2023-05-25 22:41:48 +00:00
|
|
|
@onready var install_edit_dialog: InstallEditDialog = %InstallEditDialog
|
|
|
|
|
2023-03-06 13:33:46 +00:00
|
|
|
var group_metadata: GroupMetadata
|
|
|
|
|
2023-03-05 11:03:08 +00:00
|
|
|
signal add_install_button_pressed
|
|
|
|
|
2023-03-05 12:08:54 +00:00
|
|
|
signal edit_group_button_pressed
|
2023-03-05 11:03:08 +00:00
|
|
|
signal delete_button_pressed
|
|
|
|
|
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
collapse_button.pressed.connect(
|
|
|
|
func():
|
|
|
|
var b := collapse_button
|
|
|
|
set_children_visible(b.button_pressed)
|
|
|
|
)
|
|
|
|
|
2023-05-25 22:41:48 +00:00
|
|
|
add_install_button.pressed.connect(add_new_install)
|
|
|
|
install_edit_dialog.canceled.connect(install_edit_dialog.clear_ok_button_connections)
|
2023-03-05 12:08:54 +00:00
|
|
|
# edit_group_button.pressed.connect(setup_rename)
|
|
|
|
edit_group_button.pressed.connect(func(): edit_group_button_pressed.emit())
|
2023-03-05 11:03:08 +00:00
|
|
|
delete_group_button.pressed.connect(func(): delete_button_pressed.emit())
|
|
|
|
|
2023-03-05 12:08:54 +00:00
|
|
|
header_text_label.gui_input.connect(_on_header_text_label_gui_input)
|
2023-03-05 11:03:08 +00:00
|
|
|
|
2023-03-05 12:08:54 +00:00
|
|
|
|
2023-05-25 22:41:48 +00:00
|
|
|
func add_new_install() -> void:
|
|
|
|
install_edit_dialog.clear()
|
|
|
|
install_edit_dialog.ok_button_text = "Create"
|
|
|
|
|
|
|
|
install_edit_dialog.confirmed.connect(
|
|
|
|
func():
|
|
|
|
var im := install_edit_dialog.get_install_metadata()
|
|
|
|
var install_item: InstallItem = ITEM_SCENE.instantiate()
|
|
|
|
child_container.add_child(install_item)
|
2023-05-27 00:46:46 +00:00
|
|
|
install_item.setup_from_metadata(im)
|
2023-05-25 22:41:48 +00:00
|
|
|
install_item.edit_item_button_pressed.connect(edit_install.bind(install_item))
|
2023-05-27 00:46:46 +00:00
|
|
|
group_metadata.installs.append(im)
|
2023-05-25 22:41:48 +00:00
|
|
|
, CONNECT_ONE_SHOT)
|
|
|
|
|
|
|
|
install_edit_dialog.show()
|
|
|
|
|
|
|
|
|
|
|
|
func edit_install(install_item: InstallItem) -> void:
|
|
|
|
install_edit_dialog.clear()
|
|
|
|
install_edit_dialog.ok_button_text = "OK"
|
|
|
|
install_edit_dialog.install_metadata = install_item.install_metadata
|
|
|
|
install_edit_dialog.fill_from_install_metadata()
|
|
|
|
|
|
|
|
install_edit_dialog.confirmed.connect(
|
|
|
|
func():
|
|
|
|
install_item.setup_from_metadata(install_edit_dialog.get_install_metadata())
|
|
|
|
, CONNECT_ONE_SHOT)
|
|
|
|
install_edit_dialog.show()
|
2023-03-05 11:03:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
2023-03-08 07:24:34 +00:00
|
|
|
func get_text() -> String:
|
|
|
|
return header_text_label.text
|
|
|
|
|
|
|
|
|
2023-03-05 12:08:54 +00:00
|
|
|
func set_description(text: String) -> void:
|
|
|
|
if text == "":
|
|
|
|
description_label.visible = false
|
|
|
|
return
|
|
|
|
|
|
|
|
description_label.visible = true
|
|
|
|
description_label.text = text
|
|
|
|
|
|
|
|
|
2023-03-05 11:03:08 +00:00
|
|
|
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
|
2023-03-06 13:33:46 +00:00
|
|
|
inner_separator.visible = p_visible
|
2023-03-08 07:24:34 +00:00
|
|
|
description_label.visible = p_visible && !description_label.text.is_empty()
|
2023-05-27 00:46:46 +00:00
|
|
|
group_metadata.set_meta("collapsed", p_visible)
|
2023-03-08 07:24:34 +00:00
|
|
|
|
2023-03-05 11:03:08 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2023-03-05 12:08:54 +00:00
|
|
|
# edit_group_button.disabled = true
|
2023-03-05 12:44:53 +00:00
|
|
|
var label_index := header_text_label.get_index()
|
2023-03-05 11:03:08 +00:00
|
|
|
|
|
|
|
header_container.add_child(l)
|
2023-03-05 12:44:53 +00:00
|
|
|
header_container.move_child(l, label_index)
|
2023-03-05 11:03:08 +00:00
|
|
|
|
|
|
|
var reenable = func():
|
|
|
|
header_text_label.visible = true
|
2023-03-05 12:08:54 +00:00
|
|
|
# edit_group_button.disabled = false
|
2023-03-05 11:03:08 +00:00
|
|
|
|
|
|
|
l.canceled.connect(reenable)
|
|
|
|
|
|
|
|
l.text_submitted.connect(
|
|
|
|
func(new_text: String):
|
|
|
|
header_text_label.text = new_text
|
2023-05-27 00:46:46 +00:00
|
|
|
group_metadata.name = new_text
|
2023-03-05 11:03:08 +00:00
|
|
|
|
|
|
|
reenable.call()
|
|
|
|
)
|
|
|
|
|
|
|
|
l.grab_focus()
|
2023-03-05 12:08:54 +00:00
|
|
|
|
|
|
|
|
2023-05-27 00:46:46 +00:00
|
|
|
func setup_from_metadata(p_group_metadata: GroupMetadata) -> void:
|
2023-03-06 13:33:46 +00:00
|
|
|
group_metadata = p_group_metadata
|
2023-05-27 00:46:46 +00:00
|
|
|
set_text(p_group_metadata.name)
|
2023-03-06 13:33:46 +00:00
|
|
|
set_description(group_metadata.description)
|
|
|
|
# TODO: add installs
|
|
|
|
# TODO: add icon
|
|
|
|
|
|
|
|
|
2023-03-05 12:08:54 +00:00
|
|
|
func _on_header_text_label_gui_input(event: InputEvent) -> void:
|
|
|
|
if event is InputEventMouseButton && \
|
|
|
|
(event as InputEventMouseButton).double_click && \
|
|
|
|
(event as InputEventMouseButton).button_index == MOUSE_BUTTON_LEFT:
|
|
|
|
get_viewport().set_input_as_handled()
|
|
|
|
setup_rename()
|
|
|
|
|