-
-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add TextInput event # Text Input event Options: - Variable (the variable that the input will be stored to) - Text (will by default be displayed above the line edit) - Default - Placeholder - Allow Empty *Is missing an icon* # Text input display node A control node that has three exported node paths to a text label, an input line edit and a confirmation button. A node of this type along the needed child nodes was added to the DefaultDialogNode scene. * Update addons/dialogic/Events/TextInput/DialogicDisplay_TextInput.gd * Adding new icon * making a small update to the icon Co-authored-by: Emi <coppolaemilio@protonmail.com>
- Loading branch information
1 parent
47e2b66
commit b69ee8e
Showing
9 changed files
with
244 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,50 @@ | ||
[gd_scene load_steps=3 format=3 uid="uid://cdmst5tcv87kd"] | ||
[gd_scene load_steps=4 format=3 uid="uid://c0vkcehgjsjy"] | ||
|
||
[ext_resource type="Script" path="res://addons/dialogic/Editor/Events/Fields/Text.gd" id="1"] | ||
[ext_resource type="Script" path="res://addons/dialogic/Editor/Events/Fields/SinglelineText.gd" id="1"] | ||
[ext_resource type="Theme" uid="uid://d3g4i4dshtdpu" path="res://addons/dialogic/Editor/Events/styles/InputFieldsStyle.tres" id="2"] | ||
|
||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_t3hgn"] | ||
content_margin_left = 5.0 | ||
content_margin_top = 5.0 | ||
content_margin_right = 5.0 | ||
content_margin_bottom = 5.0 | ||
bg_color = Color(0.113725, 0.121569, 0.145098, 1) | ||
border_width_left = 1 | ||
border_width_top = 1 | ||
border_width_right = 1 | ||
border_width_bottom = 1 | ||
border_color = Color(0.0784314, 0.0862745, 0.101961, 1) | ||
corner_radius_top_left = 3 | ||
corner_radius_top_right = 3 | ||
corner_radius_bottom_right = 3 | ||
corner_radius_bottom_left = 3 | ||
|
||
[node name="SinglelineText" type="HBoxContainer"] | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
offset_bottom = -567.0 | ||
size_flags_horizontal = 0 | ||
theme = ExtResource("2") | ||
script = ExtResource("1") | ||
|
||
[node name="LeftText" type="Label" parent="."] | ||
offset_top = 288.0 | ||
offset_top = 5.0 | ||
offset_right = 1.0 | ||
offset_bottom = 311.0 | ||
offset_bottom = 28.0 | ||
|
||
[node name="TextEdit" type="LineEdit" parent="."] | ||
offset_left = 5.0 | ||
offset_right = 1019.0 | ||
offset_bottom = 600.0 | ||
offset_bottom = 33.0 | ||
size_flags_horizontal = 3 | ||
size_flags_vertical = 3 | ||
theme_override_styles/normal = SubResource("StyleBoxFlat_t3hgn") | ||
theme_override_styles/focus = SubResource("StyleBoxFlat_t3hgn") | ||
theme_override_styles/read_only = SubResource("StyleBoxFlat_t3hgn") | ||
expand_to_text_length = true | ||
|
||
[node name="RightText" type="Label" parent="."] | ||
offset_left = 1023.0 | ||
offset_top = 288.0 | ||
offset_top = 5.0 | ||
offset_right = 1024.0 | ||
offset_bottom = 311.0 | ||
offset_bottom = 28.0 |
45 changes: 45 additions & 0 deletions
45
addons/dialogic/Events/TextInput/DialogicDisplay_TextInput.gd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
extends Control | ||
|
||
class_name DialogicDisplay_TextInput | ||
|
||
@export_node_path var input_line_edit:NodePath | ||
@export_node_path var text_label:NodePath | ||
@export_node_path var confirmation_button:NodePath | ||
|
||
var allow_empty : bool = false | ||
|
||
func _ready(): | ||
add_to_group('dialogic_text_input') | ||
if confirmation_button: | ||
get_node(confirmation_button).pressed.connect(_on_confirmation_button_pressed) | ||
if input_line_edit: | ||
get_node(input_line_edit).text_changed.connect(_on_input_text_changed) | ||
hide() | ||
|
||
func set_text(text:String) -> void: | ||
if get_node(text_label) is Label: | ||
get_node(text_label).text = text | ||
|
||
func set_placeholder(placeholder:String) -> void: | ||
if get_node(input_line_edit) is LineEdit: | ||
get_node(input_line_edit).placeholder_text = placeholder | ||
get_node(input_line_edit).grab_focus() | ||
|
||
func set_default(default:String) -> void: | ||
if get_node(input_line_edit) is LineEdit: | ||
get_node(input_line_edit).text = default | ||
_on_input_text_changed(default) | ||
|
||
|
||
func set_allow_empty(boolean:bool) -> void: | ||
allow_empty = boolean | ||
|
||
func _on_input_text_changed(text:String) -> void: | ||
if confirmation_button.is_empty(): | ||
return | ||
get_node(confirmation_button).disabled = !allow_empty and text.is_empty() | ||
|
||
func _on_confirmation_button_pressed() -> void: | ||
if get_node(input_line_edit) is LineEdit: | ||
if !get_node(input_line_edit).text.is_empty() or allow_empty: | ||
Dialogic.TextInput.input_confirmed.emit(get_node(input_line_edit).text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
extends DialogicSubsystem | ||
|
||
signal input_confirmed(input:String) | ||
|
||
#################################################################################################### | ||
## STATE | ||
#################################################################################################### | ||
func clear_game_state() -> void: | ||
hide_text_input() | ||
|
||
#################################################################################################### | ||
## MAIN METHODS | ||
#################################################################################################### | ||
func show_text_input(text:String = '', default:String = '', placeholder:String = '', allow_empty:bool = false) -> void: | ||
for node in get_tree().get_nodes_in_group('dialogic_text_input'): | ||
node.show() | ||
if node.has_method('set_allow_empty'): node.set_allow_empty(allow_empty) | ||
if node.has_method('set_text'): node.set_text(text) | ||
if node.has_method('set_default'): node.set_default(default) | ||
if node.has_method('set_placeholder'): node.set_placeholder(placeholder) | ||
|
||
func hide_text_input() -> void: | ||
for node in get_tree().get_nodes_in_group('dialogic_text_input'): | ||
node.hide() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
@tool | ||
extends DialogicEvent | ||
class_name DialogicTextInputEvent | ||
|
||
var Text : String = "Please enter some text:" | ||
var Variable : String = "" | ||
var Placeholder : String = "" | ||
var Default : String = "" | ||
var AllowEmpty : bool = false | ||
|
||
func _execute() -> void: | ||
dialogic.current_state = Dialogic.states.WAITING | ||
dialogic.TextInput.show_text_input(Text, Default, Placeholder, AllowEmpty) | ||
dialogic.TextInput.input_confirmed.connect(_on_DialogicTextInput_input_confirmed) | ||
|
||
func _on_DialogicTextInput_input_confirmed(input:String) -> void: | ||
assert (Dialogic.has_subsystem('VAR'), 'The TextInput event needs the variable subsystem to be present.') | ||
dialogic.VAR.set_variable(Variable, input) | ||
dialogic.TextInput.hide_text_input() | ||
dialogic.current_state = Dialogic.states.IDLE | ||
finish() | ||
|
||
func get_required_subsystems() -> Array: | ||
return [ | ||
{'name':'TextInput', | ||
'subsystem': get_script().resource_path.get_base_dir().plus_file('Subsystem_TextInput.gd'), | ||
}, | ||
] | ||
|
||
func _init() -> void: | ||
event_name = "Text Input" | ||
set_default_color('Color1') | ||
event_category = Category.GODOT | ||
event_sorting_index = 6 | ||
continue_at_end = true | ||
expand_by_default = false | ||
|
||
################################################################################ | ||
## SAVING/LOADING | ||
################################################################################ | ||
func get_shortcode() -> String: | ||
return "text_input" | ||
|
||
func get_shortcode_parameters() -> Dictionary: | ||
return { | ||
#param_name : property_name | ||
"text" : "Text", | ||
"var" : "Variable", | ||
"placeholder" : "Placeholder", | ||
"default" : "Default", | ||
"allow_empty" : "AllowEmpty" | ||
} | ||
|
||
################################################################################ | ||
## EDITOR | ||
################################################################################ | ||
func build_event_editor() -> void: | ||
add_header_label('Show an input field. The value will be stored to') | ||
add_header_edit('Variable', ValueType.ComplexPicker, '', '', {'suggestions_func':[self, 'get_var_suggestions'], 'editor_icon':["ClassList", "EditorIcons"], 'disable_pretty_name':true}) | ||
add_body_edit('Text', ValueType.SinglelineText, 'Text:') | ||
add_body_edit('Placeholder', ValueType.SinglelineText, 'Placeholder:') | ||
add_body_edit('Default', ValueType.SinglelineText, 'Default:') | ||
add_body_edit('AllowEmpty', ValueType.Bool, 'Allow empty:') | ||
|
||
|
||
func get_var_suggestions(filter:String) -> Dictionary: | ||
var suggestions := {} | ||
if filter: | ||
suggestions[filter] = {'value':filter, 'editor_icon':["GuiScrollArrowRight", "EditorIcons"]} | ||
var vars :Dictionary = DialogicUtil.get_project_setting('dialogic/variables', {}) | ||
for var_path in list_variables(vars): | ||
if filter.is_empty() or filter.to_lower() in var_path.to_lower(): | ||
suggestions[var_path] = {'value':var_path, 'editor_icon':["ClassList", "EditorIcons"]} | ||
return suggestions | ||
|
||
func list_variables(dict:Dictionary, path := "") -> Array: | ||
var array := [] | ||
for key in dict.keys(): | ||
if typeof(dict[key]) == TYPE_DICTIONARY: | ||
array.append_array(list_variables(dict[key], path+key+".")) | ||
else: | ||
array.append(path+key) | ||
return array |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters