4 ## Editor that holds both the visual and the text timeline editors.
7 enum EditorMode {VISUAL, TEXT}
9 var current_editor_mode := EditorMode.VISUAL
10 var play_timeline_button: Button = null
13 ## Overwrite. Register to the editor manager in here.
14 func _register() -> void:
15 resource_unsaved.connect(_on_resource_unsaved)
16 resource_saved.connect(_on_resource_saved)
19 editors_manager.register_resource_editor('dtl', self)
21 var add_timeline_button: Button = editors_manager.add_icon_button(
22 load("res://addons/dialogic/Editor/Images/Toolbar/add-timeline.svg"),
25 add_timeline_button.pressed.connect(_on_create_timeline_button_pressed)
26 add_timeline_button.shortcut = Shortcut.new()
27 add_timeline_button.shortcut.events.append(InputEventKey.new())
28 add_timeline_button.shortcut.events[0].keycode = KEY_1
29 add_timeline_button.shortcut.events[0].ctrl_pressed = true
30 # play timeline button
31 play_timeline_button = editors_manager.add_custom_button(
33 get_theme_icon("PlayScene", "EditorIcons"),
35 play_timeline_button.pressed.connect(play_timeline)
36 play_timeline_button.tooltip_text = "Play the current timeline (CTRL+F5)"
37 if OS.get_name() == "macOS":
38 play_timeline_button.tooltip_text = "Play the current timeline (CTRL+B)"
40 %VisualEditor.load_event_buttons()
42 current_editor_mode = DialogicUtil.get_editor_setting('timeline_editor_mode', 0)
44 match current_editor_mode:
48 %SwitchEditorMode.text = "Text Editor"
52 %SwitchEditorMode.text = "Visual Editor"
54 $NoTimelineScreen.show()
55 play_timeline_button.disabled = true
58 func _get_title() -> String:
62 func _get_icon() -> Texture:
63 return get_theme_icon("TripleBar", "EditorIcons")
66 ## If this editor supports editing resources, load them here (overwrite in subclass)
67 func _open_resource(resource:Resource) -> void:
68 current_resource = resource
69 current_resource_state = ResourceStates.SAVED
70 match current_editor_mode:
72 %VisualEditor.load_timeline(current_resource)
74 %TextEditor.load_timeline(current_resource)
75 $NoTimelineScreen.hide()
76 %TimelineName.text = DialogicResourceUtil.get_unique_identifier(current_resource.resource_path)
77 play_timeline_button.disabled = false
80 ## If this editor supports editing resources, save them here (overwrite in subclass)
82 match current_editor_mode:
84 %VisualEditor.save_timeline()
86 %TextEditor.save_timeline()
89 func _input(event: InputEvent) -> void:
90 if event is InputEventKey:
92 if OS.get_name() == "macOS":
94 if event.keycode == keycode and event.pressed:
95 if Input.is_key_pressed(KEY_CTRL):
98 if event.keycode == KEY_F and event.pressed:
99 if Input.is_key_pressed(KEY_CTRL):
100 if is_ancestor_of(get_viewport().gui_get_focus_owner()):
104 ## Method to play the current timeline. Connected to the button in the sidebar.
105 func play_timeline() -> void:
108 var dialogic_plugin := DialogicUtil.get_dialogic_plugin()
110 # Save the current opened timeline
111 DialogicUtil.set_editor_setting('current_timeline_path', current_resource.resource_path)
113 DialogicUtil.get_dialogic_plugin().get_editor_interface().play_custom_scene("res://addons/dialogic/Editor/TimelineEditor/test_timeline_scene.tscn")
116 ## Method to switch from visual to text editor (and vice versa). Connected to the button in the sidebar.
117 func toggle_editor_mode() -> void:
118 match current_editor_mode:
120 current_editor_mode = EditorMode.TEXT
121 %VisualEditor.save_timeline()
124 %TextEditor.load_timeline(current_resource)
125 %SwitchEditorMode.text = "Visual Editor"
127 current_editor_mode = EditorMode.VISUAL
128 %TextEditor.save_timeline()
130 %VisualEditor.load_timeline(current_resource)
132 %SwitchEditorMode.text = "Text Editor"
133 _on_search_text_changed(%Search.text)
134 DialogicUtil.set_editor_setting('timeline_editor_mode', current_editor_mode)
137 func _on_resource_unsaved() -> void:
139 current_resource.set_meta("timeline_not_saved", true)
142 func _on_resource_saved() -> void:
144 current_resource.set_meta("timeline_not_saved", false)
147 func new_timeline(path:String) -> void:
149 var new_timeline := DialogicTimeline.new()
150 new_timeline.resource_path = path
151 new_timeline.set_meta('timeline_not_saved', true)
152 var err := ResourceSaver.save(new_timeline)
153 EditorInterface.get_resource_filesystem().update_file(new_timeline.resource_path)
154 DialogicResourceUtil.update_directory('dtl')
155 editors_manager.edit_resource(new_timeline)
158 func _ready() -> void:
159 $NoTimelineScreen.add_theme_stylebox_override("panel", get_theme_stylebox("Background", "EditorStyles"))
161 # switch editor mode button
162 %SwitchEditorMode.text = "Text editor"
163 %SwitchEditorMode.icon = get_theme_icon("ArrowRight", "EditorIcons")
164 %SwitchEditorMode.pressed.connect(toggle_editor_mode)
165 %SwitchEditorMode.custom_minimum_size.x = 200 * DialogicUtil.get_editor_scale()
167 %SearchClose.icon = get_theme_icon("Close", "EditorIcons")
168 %SearchUp.icon = get_theme_icon("MoveUp", "EditorIcons")
169 %SearchDown.icon = get_theme_icon("MoveDown", "EditorIcons")
173 func _on_create_timeline_button_pressed() -> void:
174 editors_manager.show_add_resource_dialog(
176 '*.dtl; DialogicTimeline',
177 'Create new timeline',
182 func _clear() -> void:
183 current_resource = null
184 current_resource_state = ResourceStates.SAVED
185 match current_editor_mode:
187 %VisualEditor.clear_timeline_nodes()
189 %TextEditor.clear_timeline()
190 $NoTimelineScreen.show()
191 play_timeline_button.disabled = true
194 func get_current_editor() -> Node:
195 if current_editor_mode == 1:
201 func search_timeline() -> void:
202 %SearchSection.show()
203 if get_viewport().gui_get_focus_owner() is TextEdit:
204 %Search.text = get_viewport().gui_get_focus_owner().get_selected_text()
205 _on_search_text_changed(%Search.text)
211 func _on_close_search_pressed() -> void:
212 %SearchSection.hide()
214 _on_search_text_changed('')
217 func _on_search_text_changed(new_text: String) -> void:
218 var editor: Node = null
219 var anything_found: bool = get_current_editor()._search_timeline(new_text)
220 if anything_found or new_text.is_empty():
222 %Search.add_theme_color_override("font_color", get_theme_color("font_color", "Editor"))
225 %SearchLabel.add_theme_color_override("font_color", get_theme_color("error_color", "Editor"))
226 %Search.add_theme_color_override("font_color", get_theme_color("error_color", "Editor"))
227 %SearchLabel.text = "No Match"
230 func _on_search_down_pressed() -> void:
231 get_current_editor()._search_navigate_down()
234 func _on_search_up_pressed() -> void:
235 get_current_editor()._search_navigate_up()