Fix weird bezier edit button update timing in AnimationTrackEditor

This commit is contained in:
Silc Renew 2023-02-11 20:39:02 +09:00
parent c1f556c85d
commit 4c5bd4cb0a
2 changed files with 22 additions and 13 deletions

View File

@ -2003,7 +2003,6 @@ void AnimationTrackEdit::_notification(int p_what) {
draw_texture(down_icon, Vector2(ofs, int(get_size().height - down_icon->get_height()) / 2)); draw_texture(down_icon, Vector2(ofs, int(get_size().height - down_icon->get_height()) / 2));
update_mode_rect.size.x += down_icon->get_width(); update_mode_rect.size.x += down_icon->get_width();
} else if (animation->track_get_type(track) == Animation::TYPE_BEZIER) { } else if (animation->track_get_type(track) == Animation::TYPE_BEZIER) {
Ref<Texture2D> bezier_icon = get_theme_icon(SNAME("EditBezier"), SNAME("EditorIcons"));
update_mode_rect.size.x += down_icon->get_width(); update_mode_rect.size.x += down_icon->get_width();
update_mode_rect = Rect2(); update_mode_rect = Rect2();
} else { } else {
@ -3311,25 +3310,15 @@ void AnimationTrackEditor::set_animation(const Ref<Animation> &p_anim, bool p_re
snap->set_disabled(false); snap->set_disabled(false);
snap_mode->set_disabled(false); snap_mode->set_disabled(false);
bezier_edit_icon->set_disabled(true);
imported_anim_warning->hide(); imported_anim_warning->hide();
bool import_warning_done = false;
bool bezier_done = false;
for (int i = 0; i < animation->get_track_count(); i++) { for (int i = 0; i < animation->get_track_count(); i++) {
if (animation->track_is_imported(i)) { if (animation->track_is_imported(i)) {
imported_anim_warning->show(); imported_anim_warning->show();
import_warning_done = true;
}
if (animation->track_get_type(i) == Animation::TrackType::TYPE_BEZIER) {
bezier_edit_icon->set_disabled(false);
bezier_done = true;
}
if (import_warning_done && bezier_done) {
break; break;
} }
} }
_check_bezier_exist();
} else { } else {
hscroll->hide(); hscroll->hide();
edit->set_disabled(true); edit->set_disabled(true);
@ -3343,6 +3332,24 @@ void AnimationTrackEditor::set_animation(const Ref<Animation> &p_anim, bool p_re
} }
} }
void AnimationTrackEditor::_check_bezier_exist() {
bool is_exist = false;
for (int i = 0; i < animation->get_track_count(); i++) {
if (animation->track_get_type(i) == Animation::TrackType::TYPE_BEZIER) {
is_exist = true;
break;
}
}
if (is_exist) {
bezier_edit_icon->set_disabled(false);
} else {
if (bezier_edit->is_visible()) {
_cancel_bezier_edit();
}
bezier_edit_icon->set_disabled(true);
}
}
Ref<Animation> AnimationTrackEditor::get_current_animation() const { Ref<Animation> AnimationTrackEditor::get_current_animation() const {
return animation; return animation;
} }
@ -4490,6 +4497,8 @@ void AnimationTrackEditor::_animation_changed() {
return; // All will be updated, don't bother with anything. return; // All will be updated, don't bother with anything.
} }
_check_bezier_exist();
if (key_edit) { if (key_edit) {
if (key_edit->setting) { if (key_edit->setting) {
// If editing a key, just redraw the edited track, makes refresh less costly. // If editing a key, just redraw the edited track, makes refresh less costly.
@ -4710,7 +4719,6 @@ void AnimationTrackEditor::_new_track_node_selected(NodePath p_path) {
adding_track_path = path_to; adding_track_path = path_to;
prop_selector->set_type_filter(filter); prop_selector->set_type_filter(filter);
prop_selector->select_property_from_instance(node); prop_selector->select_property_from_instance(node);
bezier_edit_icon->set_disabled(false);
} break; } break;
case Animation::TYPE_AUDIO: { case Animation::TYPE_AUDIO: {
if (!node->is_class("AudioStreamPlayer") && !node->is_class("AudioStreamPlayer2D") && !node->is_class("AudioStreamPlayer3D")) { if (!node->is_class("AudioStreamPlayer") && !node->is_class("AudioStreamPlayer2D") && !node->is_class("AudioStreamPlayer3D")) {

View File

@ -399,6 +399,7 @@ class AnimationTrackEditor : public VBoxContainer {
void _update_tracks(); void _update_tracks();
void _redraw_tracks(); void _redraw_tracks();
void _redraw_groups(); void _redraw_groups();
void _check_bezier_exist();
void _name_limit_changed(); void _name_limit_changed();
void _timeline_changed(float p_new_pos, bool p_drag, bool p_timeline_only); void _timeline_changed(float p_new_pos, bool p_drag, bool p_timeline_only);