]> Untitled Git - wolf-seeking-sheep.git/blob - addons/dialogic/Modules/TextInput/node_text_input.gd
Updated export config options
[wolf-seeking-sheep.git] / addons / dialogic / Modules / TextInput / node_text_input.gd
1 class_name DialogicNode_TextInput
2 extends Control
3
4 ## Node that will show when a text input field is reached.
5 ## Should be connected to a (probably contained) label, a line edit and a button to work.
6
7 ## The LineEdit to use.
8 @export_node_path var input_line_edit: NodePath
9 ## The Label to use.
10 @export_node_path var text_label: NodePath
11 ## The Button to use.
12 @export_node_path var confirmation_button: NodePath
13
14 # This is set by the subsystem and used as a confirmation check.
15 var _allow_empty := false
16
17
18 func _ready() -> void:
19         add_to_group('dialogic_text_input')
20         if confirmation_button:
21                 get_node(confirmation_button).pressed.connect(_on_confirmation_button_pressed)
22         if input_line_edit:
23                 get_node(input_line_edit).text_changed.connect(_on_input_text_changed)
24                 get_node(input_line_edit).text_submitted.connect(_on_confirmation_button_pressed)
25         visible = false
26
27
28 func set_text(text:String) -> void:
29         if get_node(text_label) is Label:
30                 get_node(text_label).text = text
31
32
33 func set_placeholder(placeholder:String) -> void:
34         if get_node(input_line_edit) is LineEdit:
35                 get_node(input_line_edit).placeholder_text = placeholder
36                 get_node(input_line_edit).grab_focus()
37
38
39 func set_default(default:String) -> void:
40         if get_node(input_line_edit) is LineEdit:
41                 get_node(input_line_edit).text = default
42                 _on_input_text_changed(default)
43
44
45 func set_allow_empty(boolean:bool) -> void:
46         _allow_empty = boolean
47
48
49 func _on_input_text_changed(text:String) -> void:
50         if confirmation_button.is_empty():
51                 return
52         get_node(confirmation_button).disabled = !_allow_empty and text.is_empty()
53
54
55 func _on_confirmation_button_pressed(text:="") -> void:
56         if get_node(input_line_edit) is LineEdit:
57                 if !get_node(input_line_edit).text.is_empty() or _allow_empty:
58                         DialogicUtil.autoload().TextInput.input_confirmed.emit(get_node(input_line_edit).text)