74 lines
1.8 KiB
GDScript
74 lines
1.8 KiB
GDScript
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
|
|
|
|
signal edit_item_button_pressed
|
|
signal delete_item_button_pressed
|
|
signal launch_item_button_pressed
|
|
|
|
signal name_changed(new_name: String)
|
|
|
|
|
|
func _ready() -> void:
|
|
edit_item_button.pressed.connect(func(): edit_item_button_pressed.emit())
|
|
delete_item_button.pressed.connect(func(): delete_item_button_pressed.emit())
|
|
|
|
name_label.gui_input.connect(_on_name_label_gui_input)
|
|
|
|
|
|
func set_icon(icon: Texture2D) -> void:
|
|
item_icon.texture = icon
|
|
|
|
|
|
func set_text(n: String) -> void:
|
|
name_label.text = n
|
|
|
|
|
|
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)
|
|
install_metadata.name = new_text
|
|
|
|
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()
|
|
|
|
|
|
func setup_from_metadata(p_metadata: InstallMetadata) -> void:
|
|
install_metadata = p_metadata
|
|
set_text(install_metadata.name)
|
|
# TODO: add icon
|