Skip to content

Commit 25981be

Browse files
committed
Merge pull request #107511 from shadow-foss/insert-at-timeline-cursor-button
Add toggle for inserting keys/markers at current time vs mouse cursor's position
2 parents 40bd868 + c5490f7 commit 25981be

File tree

5 files changed

+38
-2
lines changed

5 files changed

+38
-2
lines changed

doc/classes/EditorSettings.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,10 @@
547547
<member name="editors/animation/default_fps_mode" type="int" setter="" getter="">
548548
Default step mode for [AnimationPlayer] (seconds or FPS). The option is remembered locally for a scene and this option only determines the default value when scene doesn't have local state yet.
549549
</member>
550+
<member name="editors/animation/insert_at_current_time" type="bool" setter="" getter="">
551+
If [code]true[/code], animation keys and markers are inserted at the current time in the animation.
552+
If [code]false[/code], they are inserted at the mouse cursor's position.
553+
</member>
550554
<member name="editors/animation/onion_layers_future_color" type="Color" setter="" getter="">
551555
The modulate color to use for "future" frames displayed in the animation editor's onion skinning feature.
552556
</member>

editor/animation/animation_track_editor.cpp

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3596,7 +3596,7 @@ void AnimationTrackEdit::_menu_selected(int p_index) {
35963596
emit_signal(SNAME("insert_key"), insert_at_pos);
35973597
} break;
35983598
case MENU_KEY_DUPLICATE: {
3599-
emit_signal(SNAME("duplicate_request"), insert_at_pos, true);
3599+
emit_signal(SNAME("duplicate_request"), insert_at_pos, !editor->is_insert_at_current_time_enabled());
36003600
} break;
36013601
case MENU_KEY_CUT: {
36023602
emit_signal(SNAME("cut_request"));
@@ -3605,7 +3605,7 @@ void AnimationTrackEdit::_menu_selected(int p_index) {
36053605
emit_signal(SNAME("copy_request"));
36063606
} break;
36073607
case MENU_KEY_PASTE: {
3608-
emit_signal(SNAME("paste_request"), insert_at_pos, true);
3608+
emit_signal(SNAME("paste_request"), insert_at_pos, !editor->is_insert_at_current_time_enabled());
36093609
} break;
36103610
case MENU_KEY_ADD_RESET: {
36113611
emit_signal(SNAME("create_reset_request"));
@@ -3948,6 +3948,7 @@ void AnimationTrackEditor::set_animation(const Ref<Animation> &p_anim, bool p_re
39483948
step->set_read_only(false);
39493949
snap_keys->set_disabled(false);
39503950
snap_timeline->set_disabled(false);
3951+
insert_at_current_time->set_disabled(false);
39513952
fps_compat->set_disabled(false);
39523953
snap_mode->set_disabled(false);
39533954
auto_fit->set_disabled(false);
@@ -3971,6 +3972,7 @@ void AnimationTrackEditor::set_animation(const Ref<Animation> &p_anim, bool p_re
39713972
step->set_read_only(true);
39723973
snap_keys->set_disabled(true);
39733974
snap_timeline->set_disabled(true);
3975+
insert_at_current_time->set_disabled(true);
39743976
fps_compat->set_disabled(true);
39753977
snap_mode->set_disabled(true);
39763978
bezier_edit_icon->set_disabled(true);
@@ -4930,6 +4932,16 @@ bool AnimationTrackEditor::is_snap_keys_enabled() const {
49304932
return snap_keys->is_pressed() ^ Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL);
49314933
}
49324934

4935+
bool AnimationTrackEditor::is_insert_at_current_time_enabled() const {
4936+
return insert_at_current_time->is_pressed();
4937+
}
4938+
4939+
void AnimationTrackEditor::resolve_insertion_offset(float &r_offset) const {
4940+
if (is_insert_at_current_time_enabled()) {
4941+
r_offset = timeline->get_play_position();
4942+
}
4943+
}
4944+
49334945
bool AnimationTrackEditor::is_bezier_editor_active() const {
49344946
return bezier_edit->is_visible();
49354947
}
@@ -5342,6 +5354,7 @@ void AnimationTrackEditor::_notification(int p_what) {
53425354
bezier_edit_icon->set_button_icon(get_editor_theme_icon(SNAME("EditBezier")));
53435355
snap_timeline->set_button_icon(get_editor_theme_icon(SNAME("SnapTimeline")));
53445356
snap_keys->set_button_icon(get_editor_theme_icon(SNAME("SnapKeys")));
5357+
insert_at_current_time->set_button_icon(get_editor_theme_icon(SNAME("InsertAtCurrentTime")));
53455358
fps_compat->set_button_icon(get_editor_theme_icon(SNAME("FPS")));
53465359
view_group->set_button_icon(get_editor_theme_icon(view_group->is_pressed() ? SNAME("AnimationTrackList") : SNAME("AnimationTrackGroup")));
53475360
function_name_toggler->set_button_icon(get_editor_theme_icon(SNAME("MemberMethod")));
@@ -5696,6 +5709,9 @@ void AnimationTrackEditor::_insert_key_from_track(float p_ofs, int p_track) {
56965709
if (snap_keys->is_pressed() && step->get_value() != 0) {
56975710
p_ofs = snap_time(p_ofs);
56985711
}
5712+
5713+
resolve_insertion_offset(p_ofs);
5714+
56995715
while (animation->track_find_key(p_track, p_ofs, Animation::FIND_MODE_APPROX) != -1) { // Make sure insertion point is valid.
57005716
p_ofs += SECOND_DECIMAL;
57015717
}
@@ -7909,6 +7925,15 @@ AnimationTrackEditor::AnimationTrackEditor() {
79097925
view_group->set_tooltip_text(TTR("Group tracks by node or display them as plain list."));
79107926

79117927
bottom_hf->add_child(view_group);
7928+
7929+
insert_at_current_time = memnew(Button);
7930+
insert_at_current_time->set_flat(true);
7931+
bottom_hf->add_child(insert_at_current_time);
7932+
insert_at_current_time->set_disabled(true);
7933+
insert_at_current_time->set_toggle_mode(true);
7934+
insert_at_current_time->set_pressed(EDITOR_GET("editors/animation/insert_at_current_time"));
7935+
insert_at_current_time->set_tooltip_text(TTRC("Insert at current time."));
7936+
79127937
bottom_hf->add_child(memnew(VSeparator));
79137938

79147939
snap_timeline = memnew(Button);
@@ -9222,6 +9247,8 @@ void AnimationMarkerEdit::_insert_marker(float p_ofs) {
92229247
p_ofs = editor->snap_time(p_ofs);
92239248
}
92249249

9250+
editor->resolve_insertion_offset(p_ofs);
9251+
92259252
marker_insert_confirm->popup_centered(Size2(200, 100) * EDSCALE);
92269253
marker_insert_color->set_pick_color(Color(1, 1, 1));
92279254

editor/animation/animation_track_editor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,7 @@ class AnimationTrackEditor : public VBoxContainer {
613613
Label *nearest_fps_label = nullptr;
614614
TextureRect *zoom_icon = nullptr;
615615
Button *snap_keys = nullptr;
616+
Button *insert_at_current_time = nullptr;
616617
Button *snap_timeline = nullptr;
617618
Button *bezier_edit_icon = nullptr;
618619
OptionButton *snap_mode = nullptr;
@@ -954,6 +955,8 @@ class AnimationTrackEditor : public VBoxContainer {
954955
bool is_moving_selection() const;
955956
bool is_snap_timeline_enabled() const;
956957
bool is_snap_keys_enabled() const;
958+
bool is_insert_at_current_time_enabled() const;
959+
void resolve_insertion_offset(float &r_offset) const;
957960
bool is_bezier_editor_active() const;
958961
bool can_add_reset_key() const;
959962
void _on_filter_updated(const String &p_filter);
Lines changed: 1 addition & 0 deletions
Loading

editor/settings/editor_settings.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
999999
_initial_set("editors/animation/confirm_insert_track", true, true);
10001000
_initial_set("editors/animation/default_create_bezier_tracks", false, true);
10011001
_initial_set("editors/animation/default_create_reset_tracks", true, true);
1002+
_initial_set("editors/animation/insert_at_current_time", false, true);
10021003
_initial_set("editors/animation/onion_layers_past_color", Color(1, 0, 0));
10031004
_initial_set("editors/animation/onion_layers_future_color", Color(0, 1, 0));
10041005

0 commit comments

Comments
 (0)