From faf17a3ae1b4a41a301a9c2017ac8be8f6bbad46 Mon Sep 17 00:00:00 2001 From: "Silc Lizard (Tokage) Renew" <61938263+TokageItLab@users.noreply.github.com> Date: Thu, 4 Jul 2024 23:37:34 +0900 Subject: [PATCH] Cherry-pick animation fix for 4.2 --- scene/animation/animation_blend_space_1d.cpp | 2 +- scene/animation/animation_blend_space_2d.cpp | 6 ++++- scene/animation/animation_mixer.cpp | 7 ++++-- scene/animation/animation_player.cpp | 2 +- scene/gui/control.cpp | 25 ++++++++++++++++++++ scene/gui/control.h | 4 ++++ 6 files changed, 41 insertions(+), 5 deletions(-) diff --git a/scene/animation/animation_blend_space_1d.cpp b/scene/animation/animation_blend_space_1d.cpp index 981bb88bc4e..ae89ad4bd9f 100644 --- a/scene/animation/animation_blend_space_1d.cpp +++ b/scene/animation/animation_blend_space_1d.cpp @@ -273,7 +273,7 @@ void AnimationNodeBlendSpace1D::_add_blend_point(int p_index, const Reftrack_find_key(i, time, is_external_seeking ? Animation::FIND_MODE_NEAREST : Animation::FIND_MODE_EXACT); + int idx = a->track_find_key(i, time, Animation::FIND_MODE_NEAREST); if (idx < 0) { continue; } @@ -1585,6 +1585,9 @@ void AnimationMixer::_blend_process(double p_delta, bool p_update_only) { double at_anim_pos = 0.0; switch (anim->get_loop_mode()) { case Animation::LOOP_NONE: { + if (!is_external_seeking && ((!backward && time >= pos + (double)anim->get_length()) || (backward && time <= pos))) { + continue; // Do nothing if current time is outside of length when started. + } at_anim_pos = MIN((double)anim->get_length(), time - pos); // Seek to end. } break; case Animation::LOOP_LINEAR: { @@ -1596,7 +1599,7 @@ void AnimationMixer::_blend_process(double p_delta, bool p_update_only) { default: break; } - if (player2->is_playing()) { + if (player2->is_playing() || !is_external_seeking) { player2->seek(at_anim_pos, false, p_update_only); player2->play(anim_name); t->playing = true; diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index deced61ddc9..b845bfc6080 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -149,7 +149,7 @@ void AnimationPlayer::_notification(int p_what) { switch (p_what) { case NOTIFICATION_READY: { if (!Engine::get_singleton()->is_editor_hint() && animation_set.has(autoplay)) { - set_active(true); + set_active(active); play(autoplay); _check_immediately_after_start(); } diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index c74996d242a..ebf24ff3dd6 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -1397,6 +1397,15 @@ void Control::_set_position(const Point2 &p_point) { void Control::set_position(const Point2 &p_point, bool p_keep_offsets) { ERR_MAIN_THREAD_GUARD; + +#ifdef TOOLS_ENABLED + // Can't compute anchors, set position directly and return immediately. + if (saving && !is_inside_tree()) { + data.pos_cache = p_point; + return; + } +#endif + if (p_keep_offsets) { _compute_anchors(Rect2(p_point, data.size_cache), data.offset, data.anchor); } else { @@ -1457,6 +1466,14 @@ void Control::set_size(const Size2 &p_size, bool p_keep_offsets) { new_size.y = min.y; } +#ifdef TOOLS_ENABLED + // Can't compute anchors, set size directly and return immediately. + if (saving && !is_inside_tree()) { + data.size_cache = new_size; + return; + } +#endif + if (p_keep_offsets) { _compute_anchors(Rect2(data.pos_cache, new_size), data.offset, data.anchor); } else { @@ -3135,6 +3152,14 @@ Control *Control::make_custom_tooltip(const String &p_text) const { void Control::_notification(int p_notification) { ERR_MAIN_THREAD_GUARD; switch (p_notification) { +#ifdef TOOLS_ENABLED + case NOTIFICATION_EDITOR_PRE_SAVE: { + saving = true; + } break; + case NOTIFICATION_EDITOR_POST_SAVE: { + saving = false; + } break; +#endif case NOTIFICATION_POSTINITIALIZE: { data.initialized = true; diff --git a/scene/gui/control.h b/scene/gui/control.h index db1bd3a346a..67fab061583 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -47,6 +47,10 @@ class ThemeContext; class Control : public CanvasItem { GDCLASS(Control, CanvasItem); +#ifdef TOOLS_ENABLED + bool saving = false; +#endif + public: enum Anchor { ANCHOR_BEGIN = 0,