diff options
Diffstat (limited to 'scene/animation')
-rw-r--r-- | scene/animation/animation_player.cpp | 2 | ||||
-rw-r--r-- | scene/animation/animation_player.h | 1 | ||||
-rw-r--r-- | scene/animation/animation_tree.cpp | 8 | ||||
-rw-r--r-- | scene/animation/tween.cpp | 20 | ||||
-rw-r--r-- | scene/animation/tween.h | 3 |
5 files changed, 25 insertions, 9 deletions
diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index 402418e5a9..1ab2e2419e 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -1789,7 +1789,7 @@ Ref<AnimatedValuesBackup> AnimationPlayer::apply_reset(bool p_user_initiated) { bool AnimationPlayer::can_apply_reset() const { return has_animation(SceneStringNames::get_singleton()->RESET) && playback.assigned != SceneStringNames::get_singleton()->RESET; } -#endif +#endif // TOOLS_ENABLED void AnimationPlayer::_bind_methods() { ClassDB::bind_method(D_METHOD("add_animation", "name", "animation"), &AnimationPlayer::add_animation); diff --git a/scene/animation/animation_player.h b/scene/animation/animation_player.h index c4fc69f370..a68f6b9d5b 100644 --- a/scene/animation/animation_player.h +++ b/scene/animation/animation_player.h @@ -62,7 +62,6 @@ public: class AnimationPlayer : public Node { GDCLASS(AnimationPlayer, Node); - OBJ_CATEGORY("Animation Nodes"); public: enum AnimationProcessCallback { diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp index 309c2b5245..64c71697a5 100644 --- a/scene/animation/animation_tree.cpp +++ b/scene/animation/animation_tree.cpp @@ -1641,18 +1641,18 @@ TypedArray<String> AnimationTree::get_configuration_warnings() const { TypedArray<String> warnings = Node::get_configuration_warnings(); if (!root.is_valid()) { - warnings.push_back(TTR("No root AnimationNode for the graph is set.")); + warnings.push_back(RTR("No root AnimationNode for the graph is set.")); } if (!has_node(animation_player)) { - warnings.push_back(TTR("Path to an AnimationPlayer node containing animations is not set.")); + warnings.push_back(RTR("Path to an AnimationPlayer node containing animations is not set.")); } else { AnimationPlayer *player = Object::cast_to<AnimationPlayer>(get_node(animation_player)); if (!player) { - warnings.push_back(TTR("Path set for AnimationPlayer does not lead to an AnimationPlayer node.")); + warnings.push_back(RTR("Path set for AnimationPlayer does not lead to an AnimationPlayer node.")); } else if (!player->has_node(player->get_root())) { - warnings.push_back(TTR("The AnimationPlayer root node is not a valid node.")); + warnings.push_back(RTR("The AnimationPlayer root node is not a valid node.")); } } diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp index a2fed718be..ccc878a6ec 100644 --- a/scene/animation/tween.cpp +++ b/scene/animation/tween.cpp @@ -130,6 +130,7 @@ void Tween::stop() { started = false; running = false; dead = false; + total_time = 0; } void Tween::pause() { @@ -272,12 +273,14 @@ bool Tween::step(float p_delta) { ERR_FAIL_COND_V_MSG(tweeners.is_empty(), false, "Tween started, but has no Tweeners."); current_step = 0; loops_done = 0; + total_time = 0; start_tweeners(); started = true; } float rem_delta = p_delta * speed_scale; bool step_active = false; + total_time += rem_delta; while (rem_delta > 0 && running) { float step_delta = rem_delta; @@ -346,6 +349,10 @@ Node *Tween::get_bound_node() const { } } +float Tween::get_total_time() const { + return total_time; +} + real_t Tween::run_equation(TransitionType p_trans_type, EaseType p_ease_type, real_t p_time, real_t p_initial, real_t p_delta, real_t p_duration) { if (p_duration == 0) { // Special case to avoid dividing by 0 in equations. @@ -624,6 +631,7 @@ void Tween::_bind_methods() { ClassDB::bind_method(D_METHOD("pause"), &Tween::pause); ClassDB::bind_method(D_METHOD("play"), &Tween::play); ClassDB::bind_method(D_METHOD("kill"), &Tween::kill); + ClassDB::bind_method(D_METHOD("get_total_elapsed_time"), &Tween::get_total_time); ClassDB::bind_method(D_METHOD("is_running"), &Tween::is_running); ClassDB::bind_method(D_METHOD("is_valid"), &Tween::is_valid); @@ -741,12 +749,12 @@ bool PropertyTweener::step(float &r_delta) { } float time = MIN(elapsed_time - delay, duration); - target_instance->set_indexed(property, tween->interpolate_variant(initial_val, delta_val, time, duration, trans_type, ease_type)); - if (time < duration) { + target_instance->set_indexed(property, tween->interpolate_variant(initial_val, delta_val, time, duration, trans_type, ease_type)); r_delta = 0; return true; } else { + target_instance->set_indexed(property, final_val); finished = true; r_delta = elapsed_time - delay - duration; emit_signal(SNAME("finished")); @@ -895,8 +903,13 @@ bool MethodTweener::step(float &r_delta) { return true; } + Variant current_val; float time = MIN(elapsed_time - delay, duration); - Variant current_val = tween->interpolate_variant(initial_val, delta_val, time, duration, trans_type, ease_type); + if (time < duration) { + current_val = tween->interpolate_variant(initial_val, delta_val, time, duration, trans_type, ease_type); + } else { + current_val = final_val; + } const Variant **argptr = (const Variant **)alloca(sizeof(Variant *)); argptr[0] = ¤t_val; @@ -938,6 +951,7 @@ MethodTweener::MethodTweener(Callable p_callback, Variant p_from, Variant p_to, callback = p_callback; initial_val = p_from; delta_val = tween->calculate_delta_value(p_from, p_to); + final_val = p_to; duration = p_duration; } diff --git a/scene/animation/tween.h b/scene/animation/tween.h index 5b0745b2b3..e28a499259 100644 --- a/scene/animation/tween.h +++ b/scene/animation/tween.h @@ -103,6 +103,7 @@ private: ObjectID bound_node; Vector<List<Ref<Tweener>>> tweeners; + float total_time = 0; int current_step = -1; int loops = 1; int loops_done = 0; @@ -166,6 +167,7 @@ public: bool step(float p_delta); bool can_process(bool p_tree_paused) const; Node *get_bound_node() const; + float get_total_time() const; Tween() {} }; @@ -274,6 +276,7 @@ private: Ref<Tween> tween; Variant initial_val; Variant delta_val; + Variant final_val; Callable callback; }; |