yagvm/UI/Components/InstallItem.gd

79 lines
1.9 KiB
GDScript3
Raw Normal View History

2023-03-05 12:44:53 +00:00
extends HBoxContainer
class_name InstallItem
@onready var item_icon: TextureRect = %ItemIcon
@onready var name_label: Label = %NameLabel
@onready var edit_item_button: Button = %EditItemButton
@onready var delete_item_button: Button = %DeleteItemButton
@onready var launch_item_button: Button = %LaunchItemButton
var install_metadata: InstallMetadata
2023-03-05 12:44:53 +00:00
signal edit_item_button_pressed
signal launch_item_button_pressed
2023-05-27 04:36:20 +00:00
signal about_to_delete(install_metadata: InstallMetadata)
2023-03-05 12:44:53 +00:00
signal name_changed(new_name: String)
func _ready() -> void:
edit_item_button.pressed.connect(func(): edit_item_button_pressed.emit())
2023-05-27 04:36:20 +00:00
delete_item_button.pressed.connect(_on_delete_button_pressed)
2023-03-05 12:44:53 +00:00
name_label.gui_input.connect(_on_name_label_gui_input)
func set_icon(icon: Texture2D) -> void:
item_icon.texture = icon
2023-05-25 22:41:48 +00:00
func set_text(n: String) -> void:
name_label.text = n
2023-03-05 12:44:53 +00:00
func set_icon_visible(p_visible: bool) -> void:
item_icon.visible = p_visible
func setup_rename() -> void:
name_label.visible = false
var l := RenameLineEdit.new(name_label.text)
l.size_flags_horizontal = name_label.size_flags_horizontal
var label_index := name_label.get_index()
add_child(l)
move_child(l, label_index)
l.canceled.connect(name_label.set_visible.bind(true))
l.text_submitted.connect(
func(new_text: String):
name_label.text = new_text
name_changed.emit(new_text)
2023-05-27 00:46:46 +00:00
install_metadata.name = new_text
2023-03-05 12:44:53 +00:00
name_label.visible = true
)
l.grab_focus()
func _on_name_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()
2023-05-25 22:41:48 +00:00
func setup_from_metadata(p_metadata: InstallMetadata) -> void:
install_metadata = p_metadata
set_text(install_metadata.name)
# TODO: add icon
2023-05-27 04:36:20 +00:00
func _on_delete_button_pressed() -> void:
about_to_delete.emit(install_metadata)
queue_free()