From fe9bdd3d7a459f79edf4a4068da650c9c05e337e Mon Sep 17 00:00:00 2001 From: Cristian Ros Date: Mon, 22 May 2023 10:40:40 +0200 Subject: [PATCH 01/11] Created a flag to track if the event is created by a button --- .../TimelineEditor/VisualEditor/timeline_editor_visual.gd | 4 ++++ addons/dialogic/Resources/event.gd | 2 ++ 2 files changed, 6 insertions(+) diff --git a/addons/dialogic/Editor/TimelineEditor/VisualEditor/timeline_editor_visual.gd b/addons/dialogic/Editor/TimelineEditor/VisualEditor/timeline_editor_visual.gd index 4ba418daa..5872badf9 100644 --- a/addons/dialogic/Editor/TimelineEditor/VisualEditor/timeline_editor_visual.gd +++ b/addons/dialogic/Editor/TimelineEditor/VisualEditor/timeline_editor_visual.gd @@ -686,6 +686,8 @@ func _add_event_button_pressed(event_resource:DialogicEvent): var resource := event_resource.duplicate() resource._load_custom_defaults() + resource.created_by_button = true + TimelineUndoRedo.create_action("[D] Add "+event_resource.event_name+" event.") if event_resource.can_contain_events: TimelineUndoRedo.add_do_method(add_event_with_end_branch.bind(resource, at_index, true, true)) @@ -695,6 +697,8 @@ func _add_event_button_pressed(event_resource:DialogicEvent): TimelineUndoRedo.add_undo_method(remove_events_at_index.bind(at_index, 1)) TimelineUndoRedo.commit_action() + resource.created_by_button = false + something_changed() scroll_to_piece(at_index) indent_events() diff --git a/addons/dialogic/Resources/event.gd b/addons/dialogic/Resources/event.gd index 25c92aea3..b42a65e37 100644 --- a/addons/dialogic/Resources/event.gd +++ b/addons/dialogic/Resources/event.gd @@ -67,6 +67,8 @@ var disable_editor_button: bool = false var expand_by_default : bool = true ## The URL to open when right_click>Documentation is selected var help_page_path : String = "" +## Is the event block created by a button? +var created_by_button : bool = false ## Reference to the node, that represents this event. Only works while in visual editor mode. ## Use with care. From 515fd1cf61fb462bc3200c3cfeae325804a71a67 Mon Sep 17 00:00:00 2001 From: Cristian Ros Date: Mon, 22 May 2023 11:17:15 +0200 Subject: [PATCH 02/11] Added autofocus functionality to events on button creation --- .../dialogic/Editor/Events/EventBlock/event_block.gd | 11 +++++++++++ addons/dialogic/Resources/event.gd | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/addons/dialogic/Editor/Events/EventBlock/event_block.gd b/addons/dialogic/Editor/Events/EventBlock/event_block.gd index 37c21bb1c..5dd3c1a4c 100644 --- a/addons/dialogic/Editor/Events/EventBlock/event_block.gd +++ b/addons/dialogic/Editor/Events/EventBlock/event_block.gd @@ -132,6 +132,7 @@ func toggle_collapse(toggled:bool) -> void: func build_editor(build_header:bool = true, build_body:bool = false) -> void: var current_body_container :HFlowContainer = null + var nodepath_to_focus : NodePath if build_body and body_was_build: build_body = false if build_body: @@ -287,6 +288,12 @@ func build_editor(build_header:bool = true, build_body:bool = false) -> void: field_list.append({'node': left_label, 'condition':p.condition, 'location':p.location}) if right_label: field_list.append({'node': right_label, 'condition':p.condition, 'location':p.location}) + + ### -------------------------------------------------------------------- + ### 4. GETTING THE PATH OF THE FIELD WE WANT TO FOCUS (in case we want) + if(resource.autofocus_field_index != -1 and resource.created_by_button): + if(p == resource.editor_list[resource.autofocus_field_index]): + nodepath_to_focus = str(editor_node.get_path()) + resource.autofocus_relative_path if build_body: # has_body_content = true @@ -296,6 +303,7 @@ func build_editor(build_header:bool = true, build_body:bool = false) -> void: body_container.visible = false recalculate_field_visibility() + focus_field(nodepath_to_focus) func recalculate_field_visibility() -> void: @@ -321,6 +329,9 @@ func recalculate_field_visibility() -> void: printerr("[Dialogic] Failed executing visibility condition for '",p.get('property', 'unnamed'),"': " + expr.get_error_text()) %ExpandButton.visible = has_any_enabled_body_content +func focus_field(path) -> void: + if(!path.is_empty()): + get_node(path).grab_focus() func set_property(property_name:String, value:Variant) -> void: resource.set(property_name, value) diff --git a/addons/dialogic/Resources/event.gd b/addons/dialogic/Resources/event.gd index b42a65e37..6f8852f21 100644 --- a/addons/dialogic/Resources/event.gd +++ b/addons/dialogic/Resources/event.gd @@ -70,6 +70,11 @@ var help_page_path : String = "" ## Is the event block created by a button? var created_by_button : bool = false +## Which field in the event block we want to autofocus +var autofocus_field_index : int = -1 # -1 for NONE +## Relative path of the field we want to autofocus in case we need access to a child of it +var autofocus_relative_path : String = "" + ## Reference to the node, that represents this event. Only works while in visual editor mode. ## Use with care. var _editor_node : Control = null From dabea86b543e4b82191782d74af7c1854d02dfb1 Mon Sep 17 00:00:00 2001 From: Cristian Ros Date: Mon, 22 May 2023 11:22:47 +0200 Subject: [PATCH 03/11] Fix #1383: Autofocus text editor when text event is created --- addons/dialogic/Modules/Text/event_text.gd | 2 ++ 1 file changed, 2 insertions(+) diff --git a/addons/dialogic/Modules/Text/event_text.gd b/addons/dialogic/Modules/Text/event_text.gd index ff352a144..bc2ea5c26 100644 --- a/addons/dialogic/Modules/Text/event_text.gd +++ b/addons/dialogic/Modules/Text/event_text.gd @@ -115,6 +115,8 @@ func _init() -> void: event_sorting_index = 0 help_page_path = "https://dialogic.coppolaemilio.com/documentation/Events/000/" continue_at_end = false + autofocus_field_index = 2 + autofocus_relative_path = "/TextEdit" ################################################################################ From 854d21f61c2c3090567edeed5d8273c38863c524 Mon Sep 17 00:00:00 2001 From: Cristian Ros Date: Mon, 22 May 2023 13:29:49 +0200 Subject: [PATCH 04/11] Made autofocus field usability in event blocks easier - Removed autofocus properties - Pass autofocus through display_info dict - Now every field takes implementation on how to autofocus --- .../dialogic/Editor/Events/EventBlock/event_block.gd | 10 ++-------- addons/dialogic/Editor/Events/Fields/MultilineText.gd | 2 ++ addons/dialogic/Modules/Text/event_text.gd | 4 +--- addons/dialogic/Resources/event.gd | 5 ----- 4 files changed, 5 insertions(+), 16 deletions(-) diff --git a/addons/dialogic/Editor/Events/EventBlock/event_block.gd b/addons/dialogic/Editor/Events/EventBlock/event_block.gd index 5dd3c1a4c..c7d716d7c 100644 --- a/addons/dialogic/Editor/Events/EventBlock/event_block.gd +++ b/addons/dialogic/Editor/Events/EventBlock/event_block.gd @@ -132,7 +132,6 @@ func toggle_collapse(toggled:bool) -> void: func build_editor(build_header:bool = true, build_body:bool = false) -> void: var current_body_container :HFlowContainer = null - var nodepath_to_focus : NodePath if build_body and body_was_build: build_body = false if build_body: @@ -291,9 +290,8 @@ func build_editor(build_header:bool = true, build_body:bool = false) -> void: ### -------------------------------------------------------------------- ### 4. GETTING THE PATH OF THE FIELD WE WANT TO FOCUS (in case we want) - if(resource.autofocus_field_index != -1 and resource.created_by_button): - if(p == resource.editor_list[resource.autofocus_field_index]): - nodepath_to_focus = str(editor_node.get_path()) + resource.autofocus_relative_path + if resource.created_by_button and p.display_info.get('autofocus', false) and editor_node.has_method('take_autofocus'): + editor_node.take_autofocus() if build_body: # has_body_content = true @@ -303,7 +301,6 @@ func build_editor(build_header:bool = true, build_body:bool = false) -> void: body_container.visible = false recalculate_field_visibility() - focus_field(nodepath_to_focus) func recalculate_field_visibility() -> void: @@ -329,9 +326,6 @@ func recalculate_field_visibility() -> void: printerr("[Dialogic] Failed executing visibility condition for '",p.get('property', 'unnamed'),"': " + expr.get_error_text()) %ExpandButton.visible = has_any_enabled_body_content -func focus_field(path) -> void: - if(!path.is_empty()): - get_node(path).grab_focus() func set_property(property_name:String, value:Variant) -> void: resource.set(property_name, value) diff --git a/addons/dialogic/Editor/Events/Fields/MultilineText.gd b/addons/dialogic/Editor/Events/Fields/MultilineText.gd index bc765cfb1..a8b21a1cc 100644 --- a/addons/dialogic/Editor/Events/Fields/MultilineText.gd +++ b/addons/dialogic/Editor/Events/Fields/MultilineText.gd @@ -15,3 +15,5 @@ func text_changed(value = ""): func set_value(value): $TextEdit.text = str(value) +func take_autofocus(): + $TextEdit.grab_focus() diff --git a/addons/dialogic/Modules/Text/event_text.gd b/addons/dialogic/Modules/Text/event_text.gd index bc2ea5c26..42dbc8e53 100644 --- a/addons/dialogic/Modules/Text/event_text.gd +++ b/addons/dialogic/Modules/Text/event_text.gd @@ -115,8 +115,6 @@ func _init() -> void: event_sorting_index = 0 help_page_path = "https://dialogic.coppolaemilio.com/documentation/Events/000/" continue_at_end = false - autofocus_field_index = 2 - autofocus_relative_path = "/TextEdit" ################################################################################ @@ -241,7 +239,7 @@ func build_event_editor(): 'placeholder' : "(Don't change)", 'icon' : load("res://addons/dialogic/Editor/Images/Resources/portrait.svg")}, 'character != null and !has_no_portraits()') - add_body_edit('text', ValueType.MultilineText) + add_body_edit('text', ValueType.MultilineText, '', '', {'autofocus' = true}) func do_any_characters_exist() -> bool: return !DialogicUtil.list_resources_of_type(".dch").is_empty() diff --git a/addons/dialogic/Resources/event.gd b/addons/dialogic/Resources/event.gd index 6f8852f21..b42a65e37 100644 --- a/addons/dialogic/Resources/event.gd +++ b/addons/dialogic/Resources/event.gd @@ -70,11 +70,6 @@ var help_page_path : String = "" ## Is the event block created by a button? var created_by_button : bool = false -## Which field in the event block we want to autofocus -var autofocus_field_index : int = -1 # -1 for NONE -## Relative path of the field we want to autofocus in case we need access to a child of it -var autofocus_relative_path : String = "" - ## Reference to the node, that represents this event. Only works while in visual editor mode. ## Use with care. var _editor_node : Control = null From bb34b9df056f21bd1cab0e115fc984fb40a30bb0 Mon Sep 17 00:00:00 2001 From: Cristian Ros Date: Mon, 22 May 2023 13:47:00 +0200 Subject: [PATCH 05/11] Added autofocus to choice event block --- addons/dialogic/Editor/Events/Fields/SinglelineText.gd | 3 +++ addons/dialogic/Modules/Choice/event_choice.gd | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/dialogic/Editor/Events/Fields/SinglelineText.gd b/addons/dialogic/Editor/Events/Fields/SinglelineText.gd index 1c60a4555..4bd5010b1 100644 --- a/addons/dialogic/Editor/Events/Fields/SinglelineText.gd +++ b/addons/dialogic/Editor/Events/Fields/SinglelineText.gd @@ -24,3 +24,6 @@ func _on_text_changed(value := "") -> void: func set_value(value:String) -> void: text = str(value) + +func take_autofocus(): + grab_focus() diff --git a/addons/dialogic/Modules/Choice/event_choice.gd b/addons/dialogic/Modules/Choice/event_choice.gd index f53069ca2..705c778f9 100644 --- a/addons/dialogic/Modules/Choice/event_choice.gd +++ b/addons/dialogic/Modules/Choice/event_choice.gd @@ -132,7 +132,7 @@ func _get_property_original_translation(property:String) -> String: ################################################################################ func build_event_editor() -> void: - add_header_edit("text", ValueType.SinglelineText) + add_header_edit("text", ValueType.SinglelineText, '','', {'autofocus':true}) add_body_edit("condition", ValueType.Condition, 'if ') add_body_edit("else_action", ValueType.FixedOptionSelector, 'else ', '', { 'selector_options': [ From 7b2318d8539a9ffa50858b79c7bd03243c3afab3 Mon Sep 17 00:00:00 2001 From: Cristian Ros Date: Mon, 22 May 2023 14:24:18 +0200 Subject: [PATCH 06/11] Added autofocus to character event block --- addons/dialogic/Editor/Events/Fields/ComplexPicker.gd | 3 +++ addons/dialogic/Modules/Character/event_character.gd | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/addons/dialogic/Editor/Events/Fields/ComplexPicker.gd b/addons/dialogic/Editor/Events/Fields/ComplexPicker.gd index 9b83dca9d..a516f65e3 100644 --- a/addons/dialogic/Editor/Events/Fields/ComplexPicker.gd +++ b/addons/dialogic/Editor/Events/Fields/ComplexPicker.gd @@ -88,6 +88,9 @@ func _exit_tree(): event_resource = null +func take_autofocus(): + %Search.grab_focus() + ################################################################################ ## SEARCH & SUGGESTION POPUP ################################################################################ diff --git a/addons/dialogic/Modules/Character/event_character.gd b/addons/dialogic/Modules/Character/event_character.gd index 447bce0c9..518a11248 100644 --- a/addons/dialogic/Modules/Character/event_character.gd +++ b/addons/dialogic/Modules/Character/event_character.gd @@ -404,7 +404,8 @@ func build_event_editor() -> void: {'empty_text' : 'Character', 'file_extension' : '.dch', 'suggestions_func' : get_character_suggestions, - 'icon' : load("res://addons/dialogic/Editor/Images/Resources/character.svg")}) + 'icon' : load("res://addons/dialogic/Editor/Images/Resources/character.svg"), + 'autofocus' : true}) add_header_button('', _on_character_edit_pressed, 'Edit character', ["ExternalLink", "EditorIcons"], 'character != null and _character_from_directory != "--All--"') add_header_edit('portrait', ValueType.ComplexPicker, '', '', From 1cb250df4d31b85223efaec4d2131f1c12aad89a Mon Sep 17 00:00:00 2001 From: Cristian Ros Date: Mon, 22 May 2023 15:36:58 +0200 Subject: [PATCH 07/11] Added autofocus to Wait event block --- addons/dialogic/Editor/Events/Fields/Number.gd | 4 ++++ addons/dialogic/Modules/Wait/event_wait.gd | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/addons/dialogic/Editor/Events/Fields/Number.gd b/addons/dialogic/Editor/Events/Fields/Number.gd index 44b04cefe..6d0e97062 100644 --- a/addons/dialogic/Editor/Events/Fields/Number.gd +++ b/addons/dialogic/Editor/Events/Fields/Number.gd @@ -78,3 +78,7 @@ func _on_value_text_submitted(new_text): func _on_value_focus_exited(): _on_value_text_submitted($Value.text) + + +func take_autofocus(): + $Value.grab_focus() diff --git a/addons/dialogic/Modules/Wait/event_wait.gd b/addons/dialogic/Modules/Wait/event_wait.gd index 0fbfeb20a..87d7c24c4 100644 --- a/addons/dialogic/Modules/Wait/event_wait.gd +++ b/addons/dialogic/Modules/Wait/event_wait.gd @@ -61,6 +61,6 @@ func get_shortcode_parameters() -> Dictionary: ################################################################################ func build_event_editor(): - add_header_edit('time', ValueType.Float) + add_header_edit('time', ValueType.Float, '','', {'autofocus':true}) add_header_label('seconds.') add_body_edit('hide_text', ValueType.Bool, 'Hide text box:') From 54e50ed4050fa4dc4acd6db267bfb2195fb87d9f Mon Sep 17 00:00:00 2001 From: Cristian Ros Date: Mon, 22 May 2023 15:42:54 +0200 Subject: [PATCH 08/11] Added autofocus to signal event block --- addons/dialogic/Modules/Signal/event_signal.gd | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/dialogic/Modules/Signal/event_signal.gd b/addons/dialogic/Modules/Signal/event_signal.gd index 8553468b5..24fbb7c3b 100644 --- a/addons/dialogic/Modules/Signal/event_signal.gd +++ b/addons/dialogic/Modules/Signal/event_signal.gd @@ -51,4 +51,5 @@ func get_shortcode_parameters() -> Dictionary: ################################################################################ func build_event_editor(): - add_header_edit('argument', ValueType.SinglelineText, 'Emit "signal_event" signal with argument') + add_header_edit('argument', ValueType.SinglelineText, + 'Emit "signal_event" signal with argument', '', {'autofocus':true}) From 9a701f51a2d6a670393eacfde209887be412447f Mon Sep 17 00:00:00 2001 From: Cristian Ros Date: Mon, 22 May 2023 15:44:47 +0200 Subject: [PATCH 09/11] Added autofocus to jump event block --- addons/dialogic/Modules/Jump/event_jump.gd | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/dialogic/Modules/Jump/event_jump.gd b/addons/dialogic/Modules/Jump/event_jump.gd index c905d3631..26bf830b3 100644 --- a/addons/dialogic/Modules/Jump/event_jump.gd +++ b/addons/dialogic/Modules/Jump/event_jump.gd @@ -93,7 +93,8 @@ func build_event_editor(): 'file_extension': '.dtl', 'suggestions_func': get_timeline_suggestions, 'editor_icon': ["TripleBar", "EditorIcons"], - 'empty_text': '(this timeline)' + 'empty_text': '(this timeline)', + 'autofocus':true }) add_header_edit("label_name", ValueType.SinglelineText, "at", '', {'placeholder':'the beginning'}) add_body_edit("return_after", ValueType.Bool, "Return to this spot after completed?") From 8fb09b485f8c4ab540e802ef91f8fb4c6bab5e19 Mon Sep 17 00:00:00 2001 From: Cristian Ros Date: Mon, 22 May 2023 15:47:30 +0200 Subject: [PATCH 10/11] Added autofocus to label event block --- addons/dialogic/Modules/Jump/event_label.gd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/dialogic/Modules/Jump/event_label.gd b/addons/dialogic/Modules/Jump/event_label.gd index 28502d28f..7e5a7abf1 100644 --- a/addons/dialogic/Modules/Jump/event_label.gd +++ b/addons/dialogic/Modules/Jump/event_label.gd @@ -56,4 +56,4 @@ func get_shortcode_parameters() -> Dictionary: ################################################################################ func build_event_editor(): - add_header_edit('name', ValueType.SinglelineText) + add_header_edit('name', ValueType.SinglelineText, '', '', {'autofocus':true}) From f4ab14cbd7fe93f77a33fd885aaa549633e7d394 Mon Sep 17 00:00:00 2001 From: Cristian Ros Date: Mon, 22 May 2023 15:49:13 +0200 Subject: [PATCH 11/11] Added autofocus to comment event block --- addons/dialogic/Modules/Comment/event_comment.gd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/dialogic/Modules/Comment/event_comment.gd b/addons/dialogic/Modules/Comment/event_comment.gd index 9afedeb08..a939b81b7 100644 --- a/addons/dialogic/Modules/Comment/event_comment.gd +++ b/addons/dialogic/Modules/Comment/event_comment.gd @@ -56,4 +56,4 @@ func is_valid_event(string:String) -> bool: ################################################################################ func build_event_editor(): - add_header_edit('text', ValueType.SinglelineText, '#') + add_header_edit('text', ValueType.SinglelineText, '#','',{'autofocus':true})