@@ -1357,13 +1357,23 @@ float AnimationTimelineEdit::_get_zoom_scale(double p_zoom_value) const {
1357
1357
}
1358
1358
}
1359
1359
1360
+ void AnimationTimelineEdit::_timeline_mode_changed (int p_mode) {
1361
+ bool use_fps = p_mode == 1 ;
1362
+ set_use_fps_timeline (use_fps);
1363
+ if (track_edit->editor ->key_edit ) {
1364
+ track_edit->editor ->key_edit ->set_use_fps (use_fps);
1365
+ }
1366
+ track_edit->editor ->marker_edit ->set_use_fps (use_fps);
1367
+ }
1368
+
1360
1369
void AnimationTimelineEdit::_anim_length_changed (double p_new_len) {
1361
1370
if (editing) {
1362
1371
return ;
1363
1372
}
1364
1373
1365
1374
p_new_len = MAX (SECOND_DECIMAL, p_new_len);
1366
- if (use_fps && animation->get_step () > 0 ) {
1375
+ if (use_fps_timeline && animation->get_step () > 0 ) {
1376
+ p_new_len = Math::snapped (p_new_len, FPS_STEP_FRACTION);
1367
1377
p_new_len *= animation->get_step ();
1368
1378
}
1369
1379
@@ -1442,7 +1452,10 @@ void AnimationTimelineEdit::_notification(int p_what) {
1442
1452
case NOTIFICATION_THEME_CHANGED: {
1443
1453
add_track->set_icon (get_editor_theme_icon (SNAME (" Add" )));
1444
1454
loop->set_icon (get_editor_theme_icon (SNAME (" Loop" )));
1445
- time_icon->set_texture (get_editor_theme_icon (SNAME (" Time" )));
1455
+
1456
+ time_gauge->get_popup ()->clear ();
1457
+ time_gauge->get_popup ()->add_icon_item (get_editor_theme_icon (SNAME (" Time" )), TTR (" Second" ));
1458
+ time_gauge->get_popup ()->add_icon_item (get_editor_theme_icon (SNAME (" Time" )), TTR (" FPS" ));
1446
1459
1447
1460
add_track->get_popup ()->clear ();
1448
1461
add_track->get_popup ()->add_icon_item (get_editor_theme_icon (SNAME (" KeyValue" )), TTR (" Property Track..." ));
@@ -1618,7 +1631,7 @@ void AnimationTimelineEdit::_notification(int p_what) {
1618
1631
}
1619
1632
}
1620
1633
1621
- if (use_fps ) {
1634
+ if (use_fps_timeline ) {
1622
1635
float step_size = animation->get_step ();
1623
1636
if (step_size > 0 ) {
1624
1637
int prev_frame_ofs = -10000000 ;
@@ -1800,11 +1813,10 @@ void AnimationTimelineEdit::update_values() {
1800
1813
}
1801
1814
1802
1815
editing = true ;
1803
- if (use_fps && animation->get_step () > 0.0 ) {
1816
+ if (use_fps_timeline && animation->get_step () > 0.0 ) {
1804
1817
length->set_value (animation->get_length () / animation->get_step ());
1805
1818
length->set_step (FPS_DECIMAL);
1806
1819
length->set_tooltip_text (TTR (" Animation length (frames)" ));
1807
- time_icon->set_tooltip_text (TTR (" Animation length (frames)" ));
1808
1820
if (track_edit) {
1809
1821
track_edit->editor ->_update_key_edit ();
1810
1822
track_edit->editor ->marker_edit ->_update_key_edit ();
@@ -1813,7 +1825,6 @@ void AnimationTimelineEdit::update_values() {
1813
1825
length->set_value (animation->get_length ());
1814
1826
length->set_step (SECOND_DECIMAL);
1815
1827
length->set_tooltip_text (TTR (" Animation length (seconds)" ));
1816
- time_icon->set_tooltip_text (TTR (" Animation length (seconds)" ));
1817
1828
}
1818
1829
1819
1830
switch (animation->get_loop_mode ()) {
@@ -1943,13 +1954,21 @@ void AnimationTimelineEdit::_zoom_callback(float p_zoom_factor, Vector2 p_origin
1943
1954
get_zoom ()->set_value (MAX (0.01 , current_zoom_value - (1.0 - p_zoom_factor)));
1944
1955
}
1945
1956
1946
- void AnimationTimelineEdit::set_use_fps (bool p_use_fps) {
1947
- use_fps = p_use_fps;
1957
+ void AnimationTimelineEdit::set_use_fps_timeline (bool p_use_fps) {
1958
+ use_fps_timeline = p_use_fps;
1948
1959
queue_redraw ();
1949
1960
}
1950
1961
1951
- bool AnimationTimelineEdit::is_using_fps () const {
1952
- return use_fps;
1962
+ bool AnimationTimelineEdit::is_using_fps_timeline () const {
1963
+ return use_fps_timeline;
1964
+ }
1965
+
1966
+ void AnimationTimelineEdit::set_use_fps_snap (bool p_use_fps) {
1967
+ use_fps_snap = p_use_fps;
1968
+ }
1969
+
1970
+ bool AnimationTimelineEdit::is_using_fps_snap () const {
1971
+ return use_fps_snap;
1953
1972
}
1954
1973
1955
1974
void AnimationTimelineEdit::set_hscroll (HScrollBar *p_hscroll) {
@@ -1990,10 +2009,15 @@ AnimationTimelineEdit::AnimationTimelineEdit() {
1990
2009
expander->set_h_size_flags (SIZE_EXPAND_FILL);
1991
2010
expander->set_mouse_filter (MOUSE_FILTER_IGNORE);
1992
2011
len_hb->add_child (expander);
1993
- time_icon = memnew (TextureRect);
1994
- time_icon->set_v_size_flags (SIZE_SHRINK_CENTER);
1995
- time_icon->set_tooltip_text (TTR (" Animation length (seconds)" ));
1996
- len_hb->add_child (time_icon);
2012
+ time_gauge = memnew (OptionButton);
2013
+ time_gauge->set_v_size_flags (SIZE_SHRINK_CENTER);
2014
+ time_gauge->set_tooltip_text (TTR (" Animation length" ));
2015
+ time_gauge->set_clip_text (true );
2016
+ time_gauge->add_item (TTR (" Seconds" ));
2017
+ time_gauge->add_item (TTR (" FPS" ));
2018
+ time_gauge->connect (SceneStringName (item_selected), callable_mp (this , &AnimationTimelineEdit::_timeline_mode_changed));
2019
+ time_gauge->set_custom_minimum_size (Vector2 (70 * EDSCALE, 0 ));
2020
+ len_hb->add_child (time_gauge);
1997
2021
length = memnew (EditorSpinSlider);
1998
2022
length->set_min (SECOND_DECIMAL);
1999
2023
length->set_max (36000 );
@@ -2021,6 +2045,8 @@ AnimationTimelineEdit::AnimationTimelineEdit() {
2021
2045
panner->set_callbacks (callable_mp (this , &AnimationTimelineEdit::_pan_callback), callable_mp (this , &AnimationTimelineEdit::_zoom_callback));
2022
2046
panner->set_pan_axis (ViewPanner::PAN_AXIS_HORIZONTAL);
2023
2047
2048
+ time_gauge->select (0 );
2049
+
2024
2050
set_layout_direction (Control::LAYOUT_DIRECTION_LTR);
2025
2051
}
2026
2052
@@ -3873,26 +3899,39 @@ bool AnimationTrackEditor::has_keying() const {
3873
3899
3874
3900
Dictionary AnimationTrackEditor::get_state () const {
3875
3901
Dictionary state;
3876
- state[" fps_mode" ] = timeline->is_using_fps ();
3902
+ state[" fps_mode_snap" ] = timeline->is_using_fps_snap ();
3903
+ state[" fps_mode_timeline" ] = timeline->is_using_fps_timeline ();
3877
3904
state[" zoom" ] = zoom->get_value ();
3878
3905
state[" offset" ] = timeline->get_value ();
3879
3906
state[" v_scroll" ] = scroll->get_v_scroll_bar ()->get_value ();
3880
3907
return state;
3881
3908
}
3882
3909
3883
3910
void AnimationTrackEditor::set_state (const Dictionary &p_state) {
3884
- if (p_state.has (" fps_mode " )) {
3885
- bool fps_mode = p_state[" fps_mode " ];
3911
+ if (p_state.has (" fps_mode_snap " )) {
3912
+ bool fps_mode = p_state[" fps_mode_snap " ];
3886
3913
if (fps_mode) {
3887
3914
snap_mode->select (1 );
3888
3915
} else {
3889
3916
snap_mode->select (0 );
3890
3917
}
3891
3918
_snap_mode_changed (snap_mode->get_selected ());
3892
3919
} else {
3893
- snap_mode->select (0 );
3920
+ snap_mode->select (1 );
3894
3921
_snap_mode_changed (snap_mode->get_selected ());
3895
3922
}
3923
+ if (p_state.has (" fps_mode_timeline" )) {
3924
+ bool fps_mode = p_state[" fps_mode_timeline" ];
3925
+ if (fps_mode) {
3926
+ timeline->time_gauge ->select (1 );
3927
+ } else {
3928
+ timeline->time_gauge ->select (0 );
3929
+ }
3930
+ timeline->_timeline_mode_changed (timeline->time_gauge ->get_selected ());
3931
+ } else {
3932
+ timeline->time_gauge ->select (0 );
3933
+ timeline->_timeline_mode_changed (timeline->time_gauge ->get_selected ());
3934
+ }
3896
3935
if (p_state.has (" zoom" )) {
3897
3936
zoom->set_value (p_state[" zoom" ]);
3898
3937
} else {
@@ -5023,12 +5062,8 @@ void AnimationTrackEditor::_animation_changed() {
5023
5062
5024
5063
void AnimationTrackEditor::_snap_mode_changed (int p_mode) {
5025
5064
bool use_fps = p_mode == 1 ;
5026
- timeline->set_use_fps (use_fps);
5027
- if (key_edit) {
5028
- key_edit->set_use_fps (use_fps);
5029
- }
5030
- marker_edit->set_use_fps (use_fps);
5031
5065
// To ensure that the conversion results are consistent between serialization and load, the value is snapped with 0.0625 to be a rational number when FPS mode is used.
5066
+ timeline->set_use_fps_snap (use_fps);
5032
5067
step->set_step (use_fps ? FPS_STEP_FRACTION : SECOND_DECIMAL);
5033
5068
_update_step_spinbox ();
5034
5069
}
@@ -5039,7 +5074,7 @@ void AnimationTrackEditor::_update_step_spinbox() {
5039
5074
}
5040
5075
step->set_block_signals (true );
5041
5076
5042
- if (timeline->is_using_fps ()) {
5077
+ if (timeline->is_using_fps_snap ()) {
5043
5078
if (animation->get_step () == 0.0 ) {
5044
5079
step->set_value (0.0 );
5045
5080
} else {
@@ -5158,11 +5193,10 @@ void AnimationTrackEditor::_update_step(double p_new_step) {
5158
5193
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton ();
5159
5194
undo_redo->create_action (TTR (" Change Animation Step" ));
5160
5195
double step_value = p_new_step;
5161
- if (timeline->is_using_fps ()) {
5196
+ if (timeline->is_using_fps_snap ()) {
5162
5197
if (step_value != 0.0 ) {
5163
- // step_value must also be less than or equal to 1000 to ensure that no error accumulates due to interactions with retrieving values from inner range.
5198
+ // Step_value must also be less than or equal to 1000 to ensure that no error accumulates due to interactions with retrieving values from inner range.
5164
5199
step_value = 1.0 / MIN (1000.0 , p_new_step);
5165
- ;
5166
5200
}
5167
5201
timeline->queue_redraw ();
5168
5202
}
@@ -5696,7 +5730,7 @@ void AnimationTrackEditor::_update_key_edit() {
5696
5730
key_edit->animation = animation;
5697
5731
key_edit->animation_read_only = read_only;
5698
5732
key_edit->track = selection.front ()->key ().track ;
5699
- key_edit->use_fps = timeline->is_using_fps ();
5733
+ key_edit->use_fps = timeline->is_using_fps_timeline ();
5700
5734
key_edit->editor = this ;
5701
5735
5702
5736
int key_id = selection.front ()->key ().key ;
@@ -5743,7 +5777,7 @@ void AnimationTrackEditor::_update_key_edit() {
5743
5777
multi_key_edit->key_ofs_map = key_ofs_map;
5744
5778
multi_key_edit->base_map = base_map;
5745
5779
multi_key_edit->hint = _find_hint_for_track (first_track, base_map[first_track]);
5746
- multi_key_edit->use_fps = timeline->is_using_fps ();
5780
+ multi_key_edit->use_fps = timeline->is_using_fps_timeline ();
5747
5781
multi_key_edit->root_path = root;
5748
5782
5749
5783
EditorNode::get_singleton ()->push_item (multi_key_edit);
@@ -7318,13 +7352,10 @@ void AnimationTrackEditor::_update_snap_unit() {
7318
7352
return ; // Avoid zero div.
7319
7353
}
7320
7354
7321
- if (timeline->is_using_fps ()) {
7355
+ if (timeline->is_using_fps_snap ()) {
7322
7356
snap_unit = 1.0 / step->get_value ();
7323
7357
} else {
7324
- double integer;
7325
- double fraction = Math::modf (step->get_value (), &integer);
7326
- fraction = 1.0 / Math::round (1.0 / fraction);
7327
- snap_unit = integer + fraction;
7358
+ snap_unit = step->get_value ();
7328
7359
}
7329
7360
}
7330
7361
@@ -7900,6 +7931,8 @@ AnimationTrackEditor::AnimationTrackEditor() {
7900
7931
track_copy_select->set_hide_root (true );
7901
7932
track_copy_vbox->add_child (track_copy_select);
7902
7933
track_copy_dialog->connect (SceneStringName (confirmed), callable_mp (this , &AnimationTrackEditor::_edit_menu_pressed).bind (EDIT_COPY_TRACKS_CONFIRM));
7934
+
7935
+ snap_mode->select (1 );
7903
7936
}
7904
7937
7905
7938
AnimationTrackEditor::~AnimationTrackEditor () {
@@ -8170,7 +8203,7 @@ void AnimationMarkerEdit::_update_key_edit() {
8170
8203
key_edit->animation = animation;
8171
8204
key_edit->animation_read_only = read_only;
8172
8205
key_edit->marker_name = *selection.begin ();
8173
- key_edit->use_fps = timeline->is_using_fps ();
8206
+ key_edit->use_fps = timeline->is_using_fps_timeline ();
8174
8207
key_edit->marker_edit = this ;
8175
8208
8176
8209
EditorNode::get_singleton ()->push_item (key_edit);
@@ -8702,6 +8735,7 @@ void AnimationMarkerEdit::update_play_position() {
8702
8735
}
8703
8736
8704
8737
void AnimationMarkerEdit::set_use_fps (bool p_use_fps) {
8738
+ timeline->set_use_fps_snap (p_use_fps);
8705
8739
if (key_edit) {
8706
8740
key_edit->use_fps = p_use_fps;
8707
8741
key_edit->notify_property_list_changed ();
0 commit comments