28 lines
647 B
GDScript
28 lines
647 B
GDScript
extends LineEdit
|
|
class_name RenameLineEdit
|
|
|
|
signal canceled
|
|
|
|
|
|
func _init(initial_text: String) -> void:
|
|
set_text(initial_text)
|
|
select_all()
|
|
clear_button_enabled = true
|
|
|
|
text_submitted.connect(queue_free.unbind(1))
|
|
|
|
|
|
# delete self if clicked outside
|
|
func _input(event: InputEvent) -> void:
|
|
if event is InputEventMouseButton && !(event as InputEventMouseButton).pressed:
|
|
if !get_global_rect().has_point((event as InputEventMouseButton).global_position):
|
|
canceled.emit()
|
|
queue_free()
|
|
|
|
|
|
# delete self if pressed escape
|
|
func _gui_input(event: InputEvent) -> void:
|
|
if event.is_action_pressed("ui_cancel"):
|
|
canceled.emit()
|
|
queue_free()
|