diff --git a/Scripts/AnimationTimeline.gd b/Scripts/AnimationTimeline.gd index 80240c9c3..290010574 100644 --- a/Scripts/AnimationTimeline.gd +++ b/Scripts/AnimationTimeline.gd @@ -3,6 +3,8 @@ extends Panel var fps := 6.0 var animation_loop := 1 # 0 is no loop, 1 is cycle loop, 2 is ping-pong loop var animation_forward := true +var first_frame := 0 +var last_frame := Global.canvases.size() - 1 onready var timeline_scroll : ScrollContainer = $AnimationContainer/TimelineContainer/TimelineScroll onready var tag_scroll_container : ScrollContainer = $AnimationContainer/TimelineContainer/OpacityAndTagContainer/TagScroll @@ -175,54 +177,23 @@ func _on_LoopAnim_pressed() -> void: Global.loop_animation_button.texture_hover = load("res://Assets/Graphics/%s Themes/Timeline/Loop_None_Hover.png" % Global.theme_type) Global.loop_animation_button.hint_tooltip = "No loop" -func _on_PlayForward_toggled(button_pressed : bool) -> void: - Global.play_backwards.pressed = false - if Global.canvases.size() == 1: - Global.play_forward.pressed = false - return - if button_pressed: - Global.animation_timer.wait_time = 1 / fps - Global.animation_timer.start() - animation_forward = true - else: - Global.animation_timer.stop() +func _on_PlayForward_toggled(button_pressed : bool) -> void: + play_animation(button_pressed, true) + func _on_PlayBackwards_toggled(button_pressed : bool) -> void: - Global.play_forward.pressed = false - if Global.canvases.size() == 1: - Global.play_backwards.pressed = false - return + play_animation(button_pressed, false) - if button_pressed: - Global.animation_timer.wait_time = 1 / fps - Global.animation_timer.start() - animation_forward = false - else: - Global.animation_timer.stop() - -func _on_NextFrame_pressed() -> void: - if Global.current_frame < Global.canvases.size() - 1: - Global.current_frame += 1 - -func _on_PreviousFrame_pressed() -> void: - if Global.current_frame > 0: - Global.current_frame -= 1 - -func _on_LastFrame_pressed() -> void: - Global.current_frame = Global.canvases.size() - 1 - -func _on_FirstFrame_pressed() -> void: - Global.current_frame = 0 func _on_AnimationTimer_timeout() -> void: - var first_frame := 0 - var last_frame := Global.canvases.size() - 1 - if Global.play_only_tags: - for tag in Global.animation_tags: - if Global.current_frame + 1 >= tag[2] && Global.current_frame + 1 <= tag[3]: - first_frame = tag[2] - 1 - last_frame = min(Global.canvases.size() - 1, tag[3] - 1) +# var first_frame := 0 +# var last_frame := Global.canvases.size() - 1 +# if Global.play_only_tags: +# for tag in Global.animation_tags: +# if Global.current_frame + 1 >= tag[2] && Global.current_frame + 1 <= tag[3]: +# first_frame = tag[2] - 1 +# last_frame = min(Global.canvases.size() - 1, tag[3] - 1) if animation_forward: if Global.current_frame < last_frame: @@ -254,6 +225,53 @@ func _on_AnimationTimer_timeout() -> void: animation_forward = true _on_AnimationTimer_timeout() + +func play_animation(play : bool, forward_dir : bool) -> void: + if forward_dir: + Global.play_backwards.pressed = false + else: + Global.play_forward.pressed = false + if Global.canvases.size() == 1: + if forward_dir: + Global.play_forward.pressed = false + else: + Global.play_backwards.pressed = false + return + + first_frame = 0 + last_frame = Global.canvases.size() - 1 + if Global.play_only_tags: + for tag in Global.animation_tags: + if Global.current_frame + 1 >= tag[2] && Global.current_frame + 1 <= tag[3]: + first_frame = tag[2] - 1 + last_frame = min(Global.canvases.size() - 1, tag[3] - 1) + + if play: + Global.animation_timer.wait_time = 1 / fps + Global.animation_timer.start() + animation_forward = forward_dir + else: + Global.animation_timer.stop() + + +func _on_NextFrame_pressed() -> void: + if Global.current_frame < Global.canvases.size() - 1: + Global.current_frame += 1 + + +func _on_PreviousFrame_pressed() -> void: + if Global.current_frame > 0: + Global.current_frame -= 1 + + +func _on_LastFrame_pressed() -> void: + Global.current_frame = Global.canvases.size() - 1 + + +func _on_FirstFrame_pressed() -> void: + Global.current_frame = 0 + + func _on_FPSValue_value_changed(value) -> void: fps = float(value) Global.animation_timer.wait_time = 1 / fps diff --git a/Scripts/Global.gd b/Scripts/Global.gd index acd0ad862..96bb58e1d 100644 --- a/Scripts/Global.gd +++ b/Scripts/Global.gd @@ -539,6 +539,17 @@ func canvases_changed(value : Array) -> void: layers[i][3].add_child(frame_button) + # This is useful in case tagged frames get deleted DURING the animation is playing + # otherwise, this code is useless in this context, since these values are being set + # when the play buttons get pressed, anyway + animation_timeline.first_frame = 0 + animation_timeline.last_frame = canvases.size() - 1 + if play_only_tags: + for tag in animation_tags: + if current_frame + 1 >= tag[2] && current_frame + 1 <= tag[3]: + animation_timeline.first_frame = tag[2] - 1 + animation_timeline.last_frame = min(canvases.size() - 1, tag[3] - 1) + func clear_canvases() -> void: for child in canvas_parent.get_children(): if child is Canvas: @@ -694,6 +705,17 @@ func animation_tags_changed(value : Array) -> void: tag_c.get_node("Line2D").points[2] = Vector2(tag_c.rect_min_size.x, 0) tag_c.get_node("Line2D").points[3] = Vector2(tag_c.rect_min_size.x, 32) + # This is useful in case tags get modified DURING the animation is playing + # otherwise, this code is useless in this context, since these values are being set + # when the play buttons get pressed, anyway + animation_timeline.first_frame = 0 + animation_timeline.last_frame = canvases.size() - 1 + if play_only_tags: + for tag in animation_tags: + if current_frame + 1 >= tag[2] && current_frame + 1 <= tag[3]: + animation_timeline.first_frame = tag[2] - 1 + animation_timeline.last_frame = min(canvases.size() - 1, tag[3] - 1) + func update_hint_tooltips() -> void: var root = get_tree().get_root()