diff options
Diffstat (limited to 'scene/animation')
-rw-r--r-- | scene/animation/animation_player.cpp | 22 | ||||
-rw-r--r-- | scene/animation/animation_player.h | 4 | ||||
-rw-r--r-- | scene/animation/tween.cpp | 20 | ||||
-rw-r--r-- | scene/animation/tween.h | 2 |
4 files changed, 36 insertions, 12 deletions
diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index d0875c2ba6..0febe580db 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -1736,11 +1736,11 @@ String AnimationPlayer::get_assigned_animation() const { } void AnimationPlayer::pause() { - _stop_internal(false); + _stop_internal(false, false); } -void AnimationPlayer::stop() { - _stop_internal(true); +void AnimationPlayer::stop(bool p_keep_state) { + _stop_internal(true, p_keep_state); } void AnimationPlayer::set_speed_scale(float p_speed) { @@ -1960,14 +1960,18 @@ void AnimationPlayer::_set_process(bool p_process, bool p_force) { processing = p_process; } -void AnimationPlayer::_stop_internal(bool p_reset) { +void AnimationPlayer::_stop_internal(bool p_reset, bool p_keep_state) { _stop_playing_caches(p_reset); Playback &c = playback; c.blend.clear(); if (p_reset) { - is_stopping = true; - seek(0, true); - is_stopping = false; + if (p_keep_state) { + c.current.pos = 0; + } else { + is_stopping = true; + seek(0, true); + is_stopping = false; + } c.current.from = nullptr; c.current.speed_scale = 1; } @@ -2100,7 +2104,7 @@ Ref<AnimatedValuesBackup> AnimationPlayer::apply_reset(bool p_user_initiated) { Ref<AnimatedValuesBackup> new_values = aux_player->backup_animated_values(); old_values->restore(); - Ref<EditorUndoRedoManager> &ur = EditorNode::get_undo_redo(); + EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton(); ur->create_action(TTR("Animation Apply Reset")); ur->add_do_method(new_values.ptr(), "restore"); ur->add_undo_method(old_values.ptr(), "restore"); @@ -2139,7 +2143,7 @@ void AnimationPlayer::_bind_methods() { ClassDB::bind_method(D_METHOD("play", "name", "custom_blend", "custom_speed", "from_end"), &AnimationPlayer::play, DEFVAL(""), DEFVAL(-1), DEFVAL(1.0), DEFVAL(false)); ClassDB::bind_method(D_METHOD("play_backwards", "name", "custom_blend"), &AnimationPlayer::play_backwards, DEFVAL(""), DEFVAL(-1)); ClassDB::bind_method(D_METHOD("pause"), &AnimationPlayer::pause); - ClassDB::bind_method(D_METHOD("stop"), &AnimationPlayer::stop); + ClassDB::bind_method(D_METHOD("stop", "keep_state"), &AnimationPlayer::stop, DEFVAL(false)); ClassDB::bind_method(D_METHOD("is_playing"), &AnimationPlayer::is_playing); ClassDB::bind_method(D_METHOD("set_current_animation", "anim"), &AnimationPlayer::set_current_animation); diff --git a/scene/animation/animation_player.h b/scene/animation/animation_player.h index 8dfa7aed27..7e7d12f982 100644 --- a/scene/animation/animation_player.h +++ b/scene/animation/animation_player.h @@ -295,7 +295,7 @@ private: void _animation_changed(const StringName &p_name); void _set_process(bool p_process, bool p_force = false); - void _stop_internal(bool p_reset); + void _stop_internal(bool p_reset, bool p_keep_state); bool playing = false; @@ -349,7 +349,7 @@ public: Vector<String> get_queue(); void clear_queue(); void pause(); - void stop(); + void stop(bool p_keep_state = false); bool is_playing() const; String get_current_animation() const; void set_current_animation(const String &p_anim); diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp index be8c23844f..39d1793368 100644 --- a/scene/animation/tween.cpp +++ b/scene/animation/tween.cpp @@ -280,7 +280,16 @@ bool Tween::step(double p_delta) { } if (!started) { - ERR_FAIL_COND_V_MSG(tweeners.is_empty(), false, "Tween started, but has no Tweeners."); + if (tweeners.is_empty()) { + String tween_id; + Node *node = get_bound_node(); + if (node) { + tween_id = vformat("Tween (bound to %s)", node->is_inside_tree() ? (String)node->get_path() : (String)node->get_name()); + } else { + tween_id = to_string(); + } + ERR_FAIL_V_MSG(false, tween_id + ": started with no Tweeners."); + } current_step = 0; loops_done = 0; total_time = 0; @@ -393,6 +402,15 @@ Variant Tween::interpolate_variant(Variant p_initial_val, Variant p_delta_val, d return ret; } +String Tween::to_string() { + String ret = Object::to_string(); + Node *node = get_bound_node(); + if (node) { + ret += vformat(" (bound to %s)", node->get_name()); + } + return ret; +} + void Tween::_bind_methods() { ClassDB::bind_method(D_METHOD("tween_property", "object", "property", "final_val", "duration"), &Tween::tween_property); ClassDB::bind_method(D_METHOD("tween_interval", "time"), &Tween::tween_interval); diff --git a/scene/animation/tween.h b/scene/animation/tween.h index 08911d6623..58217db535 100644 --- a/scene/animation/tween.h +++ b/scene/animation/tween.h @@ -130,6 +130,8 @@ protected: static void _bind_methods(); public: + virtual String to_string() override; + Ref<PropertyTweener> tween_property(Object *p_target, NodePath p_property, Variant p_to, double p_duration); Ref<IntervalTweener> tween_interval(double p_time); Ref<CallbackTweener> tween_callback(Callable p_callback); |