From d9ecf3ad9cbb9a42249479b70c1485f50c47c523 Mon Sep 17 00:00:00 2001 From: Sat <124409014+SatLess@users.noreply.github.com> Date: Sat, 31 Aug 2024 22:21:34 -0300 Subject: [PATCH] Allows functions calls in method track to be hidden by using GUI/Shortcut --- editor/animation_track_editor.cpp | 39 +++++++++++++++++++++++++++++-- editor/animation_track_editor.h | 4 ++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index dbb23d6f17a..9f6db63278b 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -2235,8 +2235,21 @@ void AnimationTrackEdit::_notification(int p_what) { offset_n = offset_n + editor->get_moving_selection_offset(); } offset_n = offset_n * scale + limit; - + float offset_last = limit_end; + if (i < animation->track_get_key_count(track) - 2) { + offset_last = animation->track_get_key_time(track, i + 2) - timeline->get_value(); + if (editor->is_key_selected(track, i + 2) && editor->is_moving_selection()) { + offset_last = offset_last + editor->get_moving_selection_offset(); + } + offset_last = offset_last * scale + limit; + } + int limit_string = (editor->is_key_selected(track, i + 1) && editor->is_moving_selection()) ? int(offset_last) : int(offset_n); + if (editor->is_key_selected(track, i) && editor->is_moving_selection()) { + limit_string = int(MAX(limit_end, offset_last)); + } draw_key_link(i, scale, int(offset), int(offset_n), limit, limit_end); + draw_key(i, scale, int(offset), editor->is_key_selected(track, i), limit, limit_string); + continue; } draw_key(i, scale, int(offset), editor->is_key_selected(track, i), limit, limit_end); @@ -2541,7 +2554,8 @@ void AnimationTrackEdit::draw_key(int p_index, float p_pixels_sec, int p_x, bool } text += ")"; - int limit = MAX(0, p_clip_right - p_x - icon_to_draw->get_width()); + int limit = ((p_selected && editor->is_moving_selection()) || editor->is_function_name_pressed()) ? 0 : MAX(0, p_clip_right - p_x - icon_to_draw->get_width() * 2); + if (limit > 0) { draw_string(font, Vector2(p_x + icon_to_draw->get_width(), int(get_size().height - font->get_height(font_size)) / 2 + font->get_ascent(font_size)), text, HORIZONTAL_ALIGNMENT_LEFT, limit, font_size, color); } @@ -5154,6 +5168,7 @@ void AnimationTrackEditor::_notification(int p_what) { snap_keys->set_button_icon(get_editor_theme_icon(SNAME("SnapKeys"))); fps_compat->set_button_icon(get_editor_theme_icon(SNAME("FPS"))); view_group->set_button_icon(get_editor_theme_icon(view_group->is_pressed() ? SNAME("AnimationTrackList") : SNAME("AnimationTrackGroup"))); + function_name_toggler->set_button_icon(get_editor_theme_icon(SNAME("MemberMethod"))); selected_filter->set_button_icon(get_editor_theme_icon(SNAME("AnimationFilter"))); imported_anim_warning->set_button_icon(get_editor_theme_icon(SNAME("NodeWarning"))); dummy_player_warning->set_button_icon(get_editor_theme_icon(SNAME("NodeWarning"))); @@ -5168,6 +5183,8 @@ void AnimationTrackEditor::_notification(int p_what) { const int track_separation = get_theme_constant(SNAME("track_v_separation"), SNAME("AnimationTrackEditor")); track_vbox->add_theme_constant_override("separation", track_separation); + + function_name_toggler->add_theme_color_override("icon_pressed_color", get_theme_color("icon_disabled_color", EditorStringName(Editor))); } break; case NOTIFICATION_READY: { @@ -7338,6 +7355,10 @@ void AnimationTrackEditor::_cleanup_animation(Ref p_animation) { _update_tracks(); } +void AnimationTrackEditor::_toggle_function_names() { + _redraw_tracks(); +} + void AnimationTrackEditor::_view_group_toggle() { _update_tracks(); view_group->set_button_icon(get_editor_theme_icon(view_group->is_pressed() ? SNAME("AnimationTrackList") : SNAME("AnimationTrackGroup"))); @@ -7352,6 +7373,10 @@ bool AnimationTrackEditor::is_grouping_tracks() { return !view_group->is_pressed(); } +bool AnimationTrackEditor::is_function_name_pressed() { + return function_name_toggler->is_pressed(); +} + void AnimationTrackEditor::_auto_fit() { timeline->auto_fit(); } @@ -7645,6 +7670,16 @@ AnimationTrackEditor::AnimationTrackEditor() { bottom_hf->add_child(bezier_edit_icon); + function_name_toggler = memnew(Button); + function_name_toggler->set_flat(true); + function_name_toggler->connect(SceneStringName(pressed), callable_mp(this, &AnimationTrackEditor::_toggle_function_names)); + function_name_toggler->set_shortcut(ED_SHORTCUT("animation_editor/toggle_function_names", TTRC("Toggle method names"))); + function_name_toggler->set_toggle_mode(true); + function_name_toggler->set_shortcut_in_tooltip(false); + function_name_toggler->set_tooltip_text(TTRC("Toggle function names in the track editor.")); + + bottom_hf->add_child(function_name_toggler); + selected_filter = memnew(Button); selected_filter->set_flat(true); selected_filter->connect(SceneStringName(pressed), callable_mp(this, &AnimationTrackEditor::_view_group_toggle)); // Same function works the same. diff --git a/editor/animation_track_editor.h b/editor/animation_track_editor.h index 5d998aed66f..d9a547f9c34 100644 --- a/editor/animation_track_editor.h +++ b/editor/animation_track_editor.h @@ -803,6 +803,9 @@ class AnimationTrackEditor : public VBoxContainer { void _anim_paste_keys(float p_ofs, bool p_ofs_valid, int p_track); + void _toggle_function_names(); + Button *function_name_toggler = nullptr; + void _view_group_toggle(); Button *view_group = nullptr; Button *selected_filter = nullptr; @@ -947,6 +950,7 @@ public: bool is_marker_selected(const StringName &p_marker) const; bool is_marker_moving_selection() const; float get_marker_moving_selection_offset() const; + bool is_function_name_pressed(); /** If `p_from_mouse_event` is `true`, handle Shift key presses for precise snapping. */ void goto_prev_step(bool p_from_mouse_event);