Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TextInput event #1144

Merged
merged 4 commits into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addons/dialogic/Editor/Events/EventNode/EventNode.gd
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ func build_editor():
elif p.dialogic_type == resource.ValueType.Label:
editor_node = Label.new()
editor_node.text = p.display_info.text
editor_node.vertical_alignment = VERTICAL_ALIGNMENT_CENTER

## CUSTOM
elif p.dialogic_type == resource.ValueType.Custom:
Expand Down
24 changes: 12 additions & 12 deletions addons/dialogic/Editor/Events/EventNode/EventNode.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ corner_radius_top_right = 5
corner_radius_bottom_right = 5
corner_radius_bottom_left = 5

[sub_resource type="Image" id="Image_2domf"]
[sub_resource type="Image" id="Image_pgkt2"]
data = {
"data": PackedByteArray(255, 255, 255, 0, 255, 255, 255, 0, 255, 128, 128, 4, 255, 128, 128, 4, 255, 128, 128, 4, 255, 128, 128, 4, 255, 128, 128, 4, 255, 128, 128, 4, 255, 128, 128, 4, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 131, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 131, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 131, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 252, 255, 93, 93, 252, 255, 93, 93, 252, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 128, 128, 4, 255, 128, 128, 4, 255, 128, 128, 4, 255, 128, 128, 4, 255, 128, 128, 4, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 231, 255, 93, 93, 55, 255, 97, 97, 58, 255, 93, 93, 233, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 231, 255, 94, 94, 54, 255, 94, 94, 57, 255, 93, 93, 233, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 93, 93, 233, 255, 93, 93, 232, 255, 93, 93, 41, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 93, 93, 233, 255, 93, 93, 232, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 97, 97, 42, 255, 255, 255, 0, 255, 97, 97, 42, 255, 97, 97, 42, 255, 255, 255, 0, 255, 98, 98, 47, 255, 97, 97, 42, 255, 255, 255, 0, 255, 97, 97, 42, 255, 97, 97, 42, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 235, 255, 93, 93, 233, 255, 97, 97, 42, 255, 255, 255, 0, 255, 255, 255, 0, 255, 94, 94, 46, 255, 93, 93, 236, 255, 93, 93, 233, 255, 97, 97, 42, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 235, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 233, 255, 95, 95, 59, 255, 96, 96, 61, 255, 93, 93, 235, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 233, 255, 95, 95, 59, 255, 96, 96, 61, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 252, 255, 93, 93, 252, 255, 93, 93, 252, 255, 93, 93, 252, 255, 93, 93, 252, 255, 93, 93, 252, 255, 93, 93, 252, 255, 93, 93, 252, 255, 93, 93, 252, 255, 93, 93, 252, 255, 93, 93, 252, 255, 93, 93, 252, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0),
"format": "RGBA8",
Expand All @@ -22,14 +22,14 @@ data = {
"width": 16
}

[sub_resource type="ImageTexture" id="ImageTexture_ioh8t"]
image = SubResource("Image_2domf")
[sub_resource type="ImageTexture" id="ImageTexture_epmna"]
image = SubResource("Image_pgkt2")

[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_omwh0"]
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_axtfj"]

[sub_resource type="Theme" id="Theme_g6f7f"]
PopupMenu/colors/font_color_hover = Color(0, 0, 0, 1)
PopupMenu/styles/hover = SubResource("StyleBoxEmpty_omwh0")
PopupMenu/styles/hover = SubResource("StyleBoxEmpty_axtfj")
PopupMenu/styles/panel = ExtResource("5_wntx6")

[node name="EventNode" type="HBoxContainer"]
Expand Down Expand Up @@ -114,7 +114,7 @@ and [End branch] events.
[Choice]
[...]
[End branch]"
texture = SubResource("ImageTexture_ioh8t")
texture = SubResource("ImageTexture_epmna")
stretch_mode = 5

[node name="TitleLabel" type="Label" parent="PanelContainer/MarginContainer/VBoxContainer/Header"]
Expand Down Expand Up @@ -145,14 +145,14 @@ offset_left = 993.0
offset_right = 1017.0
offset_bottom = 24.0
toggle_mode = true
icon = SubResource("ImageTexture_ioh8t")
icon = SubResource("ImageTexture_epmna")
flat = true

[node name="CollapseButton" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer/Header"]
unique_name_in_owner = true
visible = false
toggle_mode = true
icon = SubResource("ImageTexture_ioh8t")
icon = SubResource("ImageTexture_epmna")
flat = true

[node name="CollapsedBody" type="HBoxContainer" parent="PanelContainer/MarginContainer/VBoxContainer"]
Expand Down Expand Up @@ -193,22 +193,22 @@ mouse_filter = 2
theme = SubResource("Theme_g6f7f")
item_count = 6
item_0/text = "Documentation"
item_0/icon = SubResource("ImageTexture_ioh8t")
item_0/icon = SubResource("ImageTexture_epmna")
item_0/id = 0
item_1/text = ""
item_1/id = -1
item_1/separator = true
item_2/text = "Move up"
item_2/icon = SubResource("ImageTexture_ioh8t")
item_2/icon = SubResource("ImageTexture_epmna")
item_2/id = 2
item_3/text = "Move down"
item_3/icon = SubResource("ImageTexture_ioh8t")
item_3/icon = SubResource("ImageTexture_epmna")
item_3/id = 3
item_4/text = ""
item_4/id = -1
item_4/separator = true
item_5/text = "Delete"
item_5/icon = SubResource("ImageTexture_ioh8t")
item_5/icon = SubResource("ImageTexture_epmna")
item_5/id = 5
script = ExtResource("8")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ func text_changed(value = ""):

func set_left_text(value):
$LeftText.text = str(value)
$LeftText.visible = value.is_empty()
$LeftText.visible = !value.is_empty()

func set_right_text(value):
$RightText.text = str(value)
$RightText.visible = value.is_empty()
$RightText.visible = !value.is_empty()

func set_value(value):
$TextEdit.text = str(value)
34 changes: 27 additions & 7 deletions addons/dialogic/Editor/Events/Fields/SinglelineText.tscn
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 addons/dialogic/Events/TextInput/DialogicDisplay_TextInput.gd
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)
24 changes: 24 additions & 0 deletions addons/dialogic/Events/TextInput/Subsystem_TextInput.gd
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()
83 changes: 83 additions & 0 deletions addons/dialogic/Events/TextInput/event.gd
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
Binary file added addons/dialogic/Events/TextInput/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=28 format=3 uid="uid://bx0fhxkbryo8w"]
[gd_scene load_steps=29 format=3 uid="uid://bx0fhxkbryo8w"]

[ext_resource type="Script" path="res://addons/dialogic/Example Assets/ExampleScenes/DefaultDialogNode.gd" id="1"]
[ext_resource type="Script" path="res://addons/dialogic/Events/Text/Display_DialogText.gd" id="2"]
Expand All @@ -21,7 +21,8 @@
[ext_resource type="Script" path="res://addons/dialogic/Events/Text/Display_NextIndicator.gd" id="20_ljcq2"]
[ext_resource type="Script" path="res://addons/dialogic/Example Assets/ExampleScenes/ExampleGlossaryPopup.gd" id="20_vmnp2"]
[ext_resource type="Script" path="res://addons/dialogic/Events/Voice/dialogic_dialog_voice.gd" id="20_x1o37"]
[ext_resource type="Texture2D" uid="uid://c8w17dsl8cin5" path="res://addons/dialogic/Example Assets/next-indicator/next-indicator.png" id="21_rp1u3"]
[ext_resource type="Texture2D" uid="uid://d3g6vvn16a6gn" path="res://addons/dialogic/Example Assets/next-indicator/next-indicator.png" id="21_rp1u3"]
[ext_resource type="Script" path="res://addons/dialogic/Events/TextInput/DialogicDisplay_TextInput.gd" id="22_ltkcf"]
[ext_resource type="Script" path="res://addons/dialogic/Example Assets/ExampleScenes/HideWithChild.gd" id="23"]

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_dpede"]
Expand Down Expand Up @@ -262,6 +263,53 @@ texture = ExtResource("21_rp1u3")
ignore_texture_size = true
stretch_mode = 5

[node name="DialogicDisplay_TextInput" type="Control" parent="DefaultTheme"]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -210.0
offset_top = -50.0
offset_right = 210.0
offset_bottom = 50.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("22_ltkcf")
input_line_edit = NodePath("PanelContainer/VBoxContainer/InputField")
text_label = NodePath("PanelContainer/VBoxContainer/TextLabel")
confirmation_button = NodePath("PanelContainer/VBoxContainer/ConfirmationButton")
metadata/_edit_layout_mode = 1

[node name="PanelContainer" type="PanelContainer" parent="DefaultTheme/DialogicDisplay_TextInput"]
anchor_right = 1.0
anchor_bottom = 1.0
theme_override_styles/panel = SubResource("StyleBoxFlat_e4oel")

[node name="VBoxContainer" type="VBoxContainer" parent="DefaultTheme/DialogicDisplay_TextInput/PanelContainer"]
offset_left = 10.0
offset_top = 5.0
offset_right = 410.0
offset_bottom = 101.0

[node name="TextLabel" type="Label" parent="DefaultTheme/DialogicDisplay_TextInput/PanelContainer/VBoxContainer"]
offset_right = 400.0
offset_bottom = 26.0
text = "Please enter some text:"
autowrap_mode = 3

[node name="InputField" type="LineEdit" parent="DefaultTheme/DialogicDisplay_TextInput/PanelContainer/VBoxContainer"]
offset_top = 30.0
offset_right = 400.0
offset_bottom = 61.0

[node name="ConfirmationButton" type="Button" parent="DefaultTheme/DialogicDisplay_TextInput/PanelContainer/VBoxContainer"]
offset_left = 329.0
offset_top = 65.0
offset_right = 400.0
offset_bottom = 96.0
size_flags_horizontal = 8
text = "Confirm"

[node name="Glossary" type="Control" parent="DefaultTheme"]
script = ExtResource("20_vmnp2")

Expand Down