2 class_name DialogicTextInputEvent
5 ## Event that shows an input field and will change a dialogic variable.
10 ## The promt to be shown.
11 var text := "Please enter some text:"
12 ## The name/path of the variable to set.
14 ## The placeholder text to show in the line edit.
16 ## The value that should be in the line edit by default.
18 ## If true, the player can continue if nothing is entered.
19 var allow_empty := false
22 ################################################################################
24 ################################################################################
26 func _execute() -> void:
27 dialogic.Inputs.auto_skip.enabled = false
28 dialogic.current_state = DialogicGameHandler.States.WAITING
29 dialogic.TextInput.show_text_input(text, default, placeholder, allow_empty)
30 dialogic.TextInput.input_confirmed.connect(_on_DialogicTextInput_input_confirmed, CONNECT_ONE_SHOT)
33 func _on_DialogicTextInput_input_confirmed(input:String) -> void:
34 if !dialogic.has_subsystem('VAR'):
35 printerr('[Dialogic] The TextInput event needs the variable subsystem to be present.')
38 dialogic.VAR.set_variable(variable, input)
39 dialogic.TextInput.hide_text_input()
40 dialogic.current_state = DialogicGameHandler.States.IDLE
44 ################################################################################
46 ################################################################################
49 event_name = "Text Input"
50 set_default_color('Color6')
51 event_category = "Logic"
52 event_sorting_index = 6
55 ################################################################################
57 ################################################################################
59 func get_shortcode() -> String:
63 func get_shortcode_parameters() -> Dictionary:
65 #param_name : property_info
66 "text" : {"property": "text", "default": "Please enter some text:"},
67 "var" : {"property": "variable", "default": "", "suggestions":get_var_suggestions},
68 "placeholder" : {"property": "placeholder", "default": ""},
69 "default" : {"property": "default", "default": ""},
70 "allow_empty" : {"property": "allow_empty", "default": false},
73 ################################################################################
75 ################################################################################
77 func build_event_editor() -> void:
78 add_header_label('Show an input and store it in')
79 add_header_edit('variable', ValueType.DYNAMIC_OPTIONS,
80 {'suggestions_func' : get_var_suggestions,
81 'icon' : load("res://addons/dialogic/Editor/Images/Pieces/variable.svg"),
82 'placeholder':'Select Variable'})
83 add_body_edit('text', ValueType.SINGLELINE_TEXT, {'left_text':'Text:'})
84 add_body_edit('placeholder', ValueType.SINGLELINE_TEXT, {'left_text':'Placeholder:'})
85 add_body_edit('default', ValueType.SINGLELINE_TEXT, {'left_text':'Default:'})
86 add_body_edit('allow_empty', ValueType.BOOL, {'left_text':'Allow empty:'})
89 func get_var_suggestions(filter:String="") -> Dictionary:
92 suggestions[filter] = {
94 'editor_icon' : ["GuiScrollArrowRight", "EditorIcons"]}
95 var vars: Dictionary = ProjectSettings.get_setting('dialogic/variables', {})
96 for var_path in DialogicUtil.list_variables(vars, "", DialogicUtil.VarTypes.STRING):
97 suggestions[var_path] = {'value':var_path, 'icon':load("res://addons/dialogic/Editor/Images/Pieces/variable.svg")}