]> Untitled Git - wolf-seeking-sheep.git/blob - addons/dialogic/Modules/TextInput/event_text_input.gd
Initial Godot project with Dialogic 2.0-Alpha-17
[wolf-seeking-sheep.git] / addons / dialogic / Modules / TextInput / event_text_input.gd
1 @tool
2 class_name DialogicTextInputEvent
3 extends DialogicEvent
4
5 ## Event that shows an input field and will change a dialogic variable.
6
7
8 ### Settings
9
10 ## The promt to be shown.
11 var text := "Please enter some text:"
12 ## The name/path of the variable to set.
13 var variable := ""
14 ## The placeholder text to show in the line edit.
15 var placeholder := ""
16 ## The value that should be in the line edit by default.
17 var default := ""
18 ## If true, the player can continue if nothing is entered.
19 var allow_empty := false
20
21
22 ################################################################################
23 ##                                              EXECUTION
24 ################################################################################
25
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)
31
32
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.')
36                 finish()
37                 return
38         dialogic.VAR.set_variable(variable, input)
39         dialogic.TextInput.hide_text_input()
40         dialogic.current_state = DialogicGameHandler.States.IDLE
41         finish()
42
43
44 ################################################################################
45 ##                                              SAVING/LOADING
46 ################################################################################
47
48 func _init() -> void:
49         event_name = "Text Input"
50         set_default_color('Color6')
51         event_category = "Logic"
52         event_sorting_index = 6
53
54
55 ################################################################################
56 ##                                              SAVING/LOADING
57 ################################################################################
58
59 func get_shortcode() -> String:
60         return "text_input"
61
62
63 func get_shortcode_parameters() -> Dictionary:
64         return {
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},
71         }
72
73 ################################################################################
74 ##                                              EDITOR
75 ################################################################################
76
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:'})
87
88
89 func get_var_suggestions(filter:String="") -> Dictionary:
90         var suggestions := {}
91         if filter:
92                 suggestions[filter] = {
93                         'value'                 : 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")}
98         return suggestions