Skip to content

Commit 742fd28

Browse files
Implement proper timeline ending logic (#2536)
* Adjust clear event to only await music fade if music is playing * Implement dialog ending timeline This timeline (by default just a [clear] event) plays when dialog ends (or end_timeline() is called). * Make sure instant clear event is actually instant
1 parent 5d96384 commit 742fd28

File tree

4 files changed

+38
-19
lines changed

4 files changed

+38
-19
lines changed

addons/dialogic/Core/DialogicGameHandler.gd

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ var paused := false:
7070

7171
dialogic_resumed.emit()
7272

73+
## A timeline that will be played when dialog ends.
74+
## By default this timeline only contains a clear event.
75+
var dialog_ending_timeline: DialogicTimeline
76+
7377
## Emitted when [member paused] changes to `true`.
7478
signal dialogic_paused
7579
## Emitted when [member paused] changes to `false`.
@@ -158,6 +162,9 @@ func _ready() -> void:
158162

159163
clear()
160164

165+
dialog_ending_timeline = DialogicTimeline.new()
166+
dialog_ending_timeline.from_text("[clear]")
167+
161168

162169
#region TIMELINE & EVENT HANDLING
163170
################################################################################
@@ -242,9 +249,22 @@ func preload_timeline(timeline_resource:Variant) -> Variant:
242249

243250

244251
## Clears and stops the current timeline.
245-
func end_timeline() -> void:
252+
## If [param skip_ending] is `true`, the dialog_ending_timeline is not getting played
253+
func end_timeline(skip_ending := false) -> void:
254+
if not skip_ending and dialog_ending_timeline and current_timeline != dialog_ending_timeline:
255+
start(dialog_ending_timeline)
256+
return
257+
246258
await clear(ClearFlags.TIMELINE_INFO_ONLY)
247-
_on_timeline_ended()
259+
260+
if Styles.has_active_layout_node() and Styles.get_layout_node().is_inside_tree():
261+
match ProjectSettings.get_setting('dialogic/layout/end_behaviour', 0):
262+
0:
263+
Styles.get_layout_node().get_parent().remove_child(Styles.get_layout_node())
264+
Styles.get_layout_node().queue_free()
265+
1:
266+
Styles.get_layout_node().hide()
267+
248268
timeline_ended.emit()
249269

250270

@@ -368,7 +388,7 @@ func load_full_state(state_info:Dictionary) -> void:
368388
if current_state_info.get('current_timeline', null):
369389
start_timeline(current_state_info.current_timeline, current_state_info.get('current_event_idx', 0))
370390
else:
371-
end_timeline.call_deferred()
391+
end_timeline.call_deferred(true)
372392
#endregion
373393

374394

@@ -413,16 +433,6 @@ func add_subsystem(subsystem_name:String, script_path:String) -> DialogicSubsyst
413433
#region HELPERS
414434
################################################################################
415435

416-
## This handles the `Layout End Behaviour` setting that can be changed in the Dialogic settings.
417-
func _on_timeline_ended() -> void:
418-
if self.Styles.has_active_layout_node() and self.Styles.get_layout_node().is_inside_tree():
419-
match ProjectSettings.get_setting('dialogic/layout/end_behaviour', 0):
420-
0:
421-
self.Styles.get_layout_node().get_parent().remove_child(self.Styles.get_layout_node())
422-
self.Styles.get_layout_node().queue_free()
423-
1:
424-
@warning_ignore("unsafe_method_access")
425-
self.Styles.get_layout_node().hide()
426436

427437

428438
func print_debug_moment() -> void:

addons/dialogic/Modules/Audio/subsystem_audio.gd

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func update_audio(channel_name:= "", path := "", settings_overrides := {}) -> vo
194194
current_audio_channels[channel_name] = new_player
195195

196196

197-
## Returns true if any audio is playing on the given [param channel_name].
197+
## Returns `true` if any audio is playing on the given [param channel_name].
198198
func is_channel_playing(channel_name: String) -> bool:
199199
return (current_audio_channels.has(channel_name)
200200
and is_instance_valid(current_audio_channels[channel_name])
@@ -226,6 +226,14 @@ func is_channel_playing_file(file_path: String, channel_name: String) -> bool:
226226
and current_audio_channels[channel_name].stream.resource_path == file_path)
227227

228228

229+
## Returns `true` if any channel is playing.
230+
func is_any_channel_playing() -> bool:
231+
for channel in current_audio_channels:
232+
if is_channel_playing(channel):
233+
return true
234+
return false
235+
236+
229237
func _on_audio_finished(player: AudioStreamPlayer, channel_name: String, path: String) -> void:
230238
if current_audio_channels.has(channel_name) and current_audio_channels[channel_name] == player:
231239
current_audio_channels.erase(channel_name)

addons/dialogic/Modules/Clear/event_clear.gd

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ func _execute() -> void:
2626
var time_per_event: float = dialogic.Inputs.auto_skip.time_per_event
2727
final_time = min(time, time_per_event)
2828

29-
if clear_textbox and dialogic.has_subsystem("Text"):
29+
if clear_textbox and dialogic.has_subsystem("Text") and dialogic.Text.is_textbox_visible():
3030
dialogic.Text.update_dialog_text('')
31-
dialogic.Text.hide_textbox()
31+
dialogic.Text.hide_textbox(final_time == 0)
3232
dialogic.current_state = dialogic.States.IDLE
3333
if step_by_step: await dialogic.get_tree().create_timer(final_time).timeout
3434

@@ -44,9 +44,10 @@ func _execute() -> void:
4444
if step_by_step: await dialogic.get_tree().create_timer(final_time).timeout
4545

4646
if clear_music and dialogic.has_subsystem('Audio'):
47-
dialogic.Audio.stop_all_channels(final_time)
4847
dialogic.Audio.stop_all_one_shot_sounds()
49-
if step_by_step: await dialogic.get_tree().create_timer(final_time).timeout
48+
if dialogic.Audio.is_any_channel_playing():
49+
dialogic.Audio.stop_all_channels(final_time)
50+
if step_by_step: await dialogic.get_tree().create_timer(final_time).timeout
5051

5152
if clear_style and dialogic.has_subsystem('Styles'):
5253
dialogic.Styles.change_style()

addons/dialogic/Modules/Jump/event_return.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ extends DialogicEvent
1111
################################################################################
1212

1313
func _execute() -> void:
14-
if !dialogic.Jump.is_jump_stack_empty():
14+
if not dialogic.Jump.is_jump_stack_empty():
1515
dialogic.Jump.resume_from_last_jump()
1616
else:
1717
dialogic.end_timeline()

0 commit comments

Comments
 (0)