From 761d988d4735a2d0d1c30ddfad37693aedbf5f94 Mon Sep 17 00:00:00 2001 From: kobewi Date: Thu, 15 Aug 2024 08:41:51 +0200 Subject: [PATCH] Add internal _finish() method to Tweener --- scene/animation/tween.cpp | 17 +++++++++-------- scene/animation/tween.h | 1 + 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp index 6a61e8693d1..f8bbd704f40 100644 --- a/scene/animation/tween.cpp +++ b/scene/animation/tween.cpp @@ -61,6 +61,11 @@ Ref Tweener::_get_tween() { return Ref(ObjectDB::get_instance(tween_id)); } +void Tweener::_finish() { + finished = true; + emit_signal(SceneStringName(finished)); +} + void Tweener::_bind_methods() { ADD_SIGNAL(MethodInfo("finished")); } @@ -612,9 +617,8 @@ bool PropertyTweener::step(double &r_delta) { return true; } else { target_instance->set_indexed(property, final_val); - finished = true; r_delta = elapsed_time - delay - duration; - emit_signal(SceneStringName(finished)); + _finish(); return false; } } @@ -672,9 +676,8 @@ bool IntervalTweener::step(double &r_delta) { r_delta = 0; return true; } else { - finished = true; r_delta = elapsed_time - duration; - emit_signal(SceneStringName(finished)); + _finish(); return false; } } @@ -715,9 +718,8 @@ bool CallbackTweener::step(double &r_delta) { ERR_FAIL_V_MSG(false, "Error calling method from CallbackTweener: " + Variant::get_callable_error_text(callback, nullptr, 0, ce) + "."); } - finished = true; r_delta = elapsed_time - delay; - emit_signal(SceneStringName(finished)); + _finish(); return false; } @@ -801,9 +803,8 @@ bool MethodTweener::step(double &r_delta) { r_delta = 0; return true; } else { - finished = true; r_delta = elapsed_time - delay - duration; - emit_signal(SceneStringName(finished)); + _finish(); return false; } } diff --git a/scene/animation/tween.h b/scene/animation/tween.h index f5ae5e97764..40e1da0ad3c 100644 --- a/scene/animation/tween.h +++ b/scene/animation/tween.h @@ -50,6 +50,7 @@ protected: static void _bind_methods(); Ref _get_tween(); + void _finish(); double elapsed_time = 0; bool finished = false;