[go: nahoru, domu]

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

Fix issue #1383: Generic autofocus on event creation with button #1573

Merged
merged 11 commits into from
May 22, 2023
5 changes: 5 additions & 0 deletions addons/dialogic/Editor/Events/EventBlock/event_block.gd
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,11 @@ 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.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
Expand Down
3 changes: 3 additions & 0 deletions addons/dialogic/Editor/Events/Fields/ComplexPicker.gd
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ func _exit_tree():
event_resource = null


func take_autofocus():
%Search.grab_focus()

################################################################################
## SEARCH & SUGGESTION POPUP
################################################################################
Expand Down
2 changes: 2 additions & 0 deletions addons/dialogic/Editor/Events/Fields/MultilineText.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ func text_changed(value = ""):
func set_value(value):
$TextEdit.text = str(value)

func take_autofocus():
$TextEdit.grab_focus()
4 changes: 4 additions & 0 deletions addons/dialogic/Editor/Events/Fields/Number.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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()
3 changes: 3 additions & 0 deletions addons/dialogic/Editor/Events/Fields/SinglelineText.gd
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ func _on_text_changed(value := "") -> void:

func set_value(value:String) -> void:
text = str(value)

func take_autofocus():
grab_focus()
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion addons/dialogic/Modules/Character/event_character.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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, '', '',
Expand Down
2 changes: 1 addition & 1 deletion addons/dialogic/Modules/Choice/event_choice.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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': [
Expand Down
2 changes: 1 addition & 1 deletion addons/dialogic/Modules/Comment/event_comment.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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})
3 changes: 2 additions & 1 deletion addons/dialogic/Modules/Jump/event_jump.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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?")
Expand Down
2 changes: 1 addition & 1 deletion addons/dialogic/Modules/Jump/event_label.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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})
3 changes: 2 additions & 1 deletion addons/dialogic/Modules/Signal/event_signal.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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})
2 changes: 1 addition & 1 deletion addons/dialogic/Modules/Text/event_text.gd
Original file line number Diff line number Diff line change
Expand Up @@ -239,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()
Expand Down
2 changes: 1 addition & 1 deletion addons/dialogic/Modules/Wait/event_wait.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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:')
2 changes: 2 additions & 0 deletions addons/dialogic/Resources/event.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down