diff --git a/src/UI/Timeline/AnimationTimeline.gd b/src/UI/Timeline/AnimationTimeline.gd index e1c1cd0e4..685f7e1f9 100644 --- a/src/UI/Timeline/AnimationTimeline.gd +++ b/src/UI/Timeline/AnimationTimeline.gd @@ -1,7 +1,14 @@ extends Panel +## Emitted when the animation starts playing. signal animation_started(forward: bool) +## Emitted when the animation reaches the final frame and is not looping, +## or if the animation is manually paused. +## Note: This signal is not emitted if the animation is looping. signal animation_finished +## Emitted when the animation loops, meaning when it reaches the final frame +## and the animation keeps playing. +signal animation_looped enum LoopType { NO, CYCLE, PINGPONG } @@ -688,9 +695,11 @@ func _on_AnimationTimer_timeout() -> void: animation_timer.wait_time = ( project.frames[project.current_frame].duration * (1 / fps) ) + animation_looped.emit() animation_timer.start() LoopType.PINGPONG: animation_forward = false + animation_looped.emit() _on_AnimationTimer_timeout() else: @@ -713,9 +722,11 @@ func _on_AnimationTimer_timeout() -> void: animation_timer.wait_time = ( project.frames[project.current_frame].duration * (1 / fps) ) + animation_looped.emit() animation_timer.start() LoopType.PINGPONG: animation_forward = true + animation_looped.emit() _on_AnimationTimer_timeout() frame_scroll_container.ensure_control_visible( Global.frame_hbox.get_child(project.current_frame) diff --git a/src/UI/Timeline/LayerButton.gd b/src/UI/Timeline/LayerButton.gd index 8ef90e984..a82cceb51 100644 --- a/src/UI/Timeline/LayerButton.gd +++ b/src/UI/Timeline/LayerButton.gd @@ -47,6 +47,7 @@ func _ready() -> void: layer.audio_changed.connect(func(): audio_player.stream = layer.audio) add_child(audio_player) Global.animation_timeline.animation_started.connect(_on_animation_started) + Global.animation_timeline.animation_looped.connect(_on_animation_looped) Global.animation_timeline.animation_finished.connect(_on_animation_finished) custom_minimum_size.y = Global.animation_timeline.cel_size label.text = layer.name @@ -78,6 +79,14 @@ func _on_animation_started(_dir: bool) -> void: _play_audio() +func _on_animation_looped() -> void: + var layer := Global.current_project.layers[layer_index] + if layer is AudioLayer: + if layer.playback_frame != 0: + if is_instance_valid(audio_player): + audio_player.stop() + + func _on_animation_finished() -> void: animation_running = false if is_instance_valid(audio_player):