summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
Diffstat (limited to 'editor')
-rw-r--r--editor/animation_track_editor_plugins.cpp40
1 files changed, 34 insertions, 6 deletions
diff --git a/editor/animation_track_editor_plugins.cpp b/editor/animation_track_editor_plugins.cpp
index 660c69f4a4..d0c91f10d9 100644
--- a/editor/animation_track_editor_plugins.cpp
+++ b/editor/animation_track_editor_plugins.cpp
@@ -357,14 +357,28 @@ Rect2 AnimationTrackEditSpriteFrame::get_key_rect(int p_index, float p_pixels_se
}
} else if (Object::cast_to<AnimatedSprite>(object) || Object::cast_to<AnimatedSprite3D>(object)) {
- int frame = get_animation()->track_get_key_value(get_track(), p_index);
- String animation = "default"; //may be smart and go through other tracks to find if animation is set
-
Ref<SpriteFrames> sf = object->call("get_sprite_frames");
if (sf.is_null()) {
return AnimationTrackEdit::get_key_rect(p_index, p_pixels_sec);
}
+ List<StringName> animations;
+ sf->get_animation_list(&animations);
+
+ int frame = get_animation()->track_get_key_value(get_track(), p_index);
+ String animation;
+ if (animations.size() == 1) {
+ animation = animations.front()->get();
+ } else {
+ // Go through other track to find if animation is set
+ String animation_path = get_animation()->track_get_path(get_track());
+ animation_path = animation_path.replace(":frame", ":animation");
+ int animation_track = get_animation()->find_track(animation_path);
+ float track_time = get_animation()->track_get_key_time(get_track(), p_index);
+ int animaiton_index = get_animation()->track_find_key(animation_track, track_time);
+ animation = get_animation()->track_get_key_value(animation_track, animaiton_index);
+ }
+
Ref<Texture> texture = sf->get_frame(animation, frame);
if (!texture.is_valid()) {
return AnimationTrackEdit::get_key_rect(p_index, p_pixels_sec);
@@ -430,15 +444,29 @@ void AnimationTrackEditSpriteFrame::draw_key(int p_index, float p_pixels_sec, in
} else if (Object::cast_to<AnimatedSprite>(object) || Object::cast_to<AnimatedSprite3D>(object)) {
- int frame = get_animation()->track_get_key_value(get_track(), p_index);
- String animation = "default"; //may be smart and go through other tracks to find if animation is set
-
Ref<SpriteFrames> sf = object->call("get_sprite_frames");
if (sf.is_null()) {
AnimationTrackEdit::draw_key(p_index, p_pixels_sec, p_x, p_selected, p_clip_left, p_clip_right);
return;
}
+ List<StringName> animations;
+ sf->get_animation_list(&animations);
+
+ int frame = get_animation()->track_get_key_value(get_track(), p_index);
+ String animation;
+ if (animations.size() == 1) {
+ animation = animations.front()->get();
+ } else {
+ // Go through other track to find if animation is set
+ String animation_path = get_animation()->track_get_path(get_track());
+ animation_path = animation_path.replace(":frame", ":animation");
+ int animation_track = get_animation()->find_track(animation_path);
+ float track_time = get_animation()->track_get_key_time(get_track(), p_index);
+ int animaiton_index = get_animation()->track_find_key(animation_track, track_time);
+ animation = get_animation()->track_get_key_value(animation_track, animaiton_index);
+ }
+
texture = sf->get_frame(animation, frame);
if (!texture.is_valid()) {
AnimationTrackEdit::draw_key(p_index, p_pixels_sec, p_x, p_selected, p_clip_left, p_clip_right);