Skip to content

Commit 7d1e236

Browse files
committed
Merge pull request #102189 from KoBeWi/frames_per_setting
Add editor setting for FPS mode and compat
2 parents 37fed77 + 0b397d9 commit 7d1e236

File tree

6 files changed

+33
-10
lines changed

6 files changed

+33
-10
lines changed

doc/classes/EditorSettings.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,12 @@
528528
<member name="editors/animation/default_create_reset_tracks" type="bool" setter="" getter="">
529529
If [code]true[/code], create a [code]RESET[/code] track when creating a new animation track. This track can be used to restore the animation to a "default" state.
530530
</member>
531+
<member name="editors/animation/default_fps_compatibility" type="bool" setter="" getter="">
532+
Controls whether [AnimationPlayer] will apply snapping to nearest integer FPS when snapping is in Seconds mode. The option is remembered locally for a scene and this option only determines the default value when scene doesn't have local state yet.
533+
</member>
534+
<member name="editors/animation/default_fps_mode" type="int" setter="" getter="">
535+
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.
536+
</member>
531537
<member name="editors/animation/onion_layers_future_color" type="Color" setter="" getter="">
532538
The modulate color to use for "future" frames displayed in the animation editor's onion skinning feature.
533539
</member>

editor/animation_track_editor.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3894,6 +3894,7 @@ bool AnimationTrackEditor::has_keying() const {
38943894
Dictionary AnimationTrackEditor::get_state() const {
38953895
Dictionary state;
38963896
state["fps_mode"] = timeline->is_using_fps();
3897+
state["fps_compat"] = fps_compat->is_pressed();
38973898
state["zoom"] = zoom->get_value();
38983899
state["offset"] = timeline->get_value();
38993900
state["v_scroll"] = scroll->get_v_scroll_bar()->get_value();
@@ -3909,27 +3910,34 @@ void AnimationTrackEditor::set_state(const Dictionary &p_state) {
39093910
snap_mode->select(0);
39103911
}
39113912
_snap_mode_changed(snap_mode->get_selected());
3912-
} else {
3913-
snap_mode->select(0);
3914-
_snap_mode_changed(snap_mode->get_selected());
39153913
}
3914+
3915+
if (p_state.has("fps_compat")) {
3916+
fps_compat->set_pressed(p_state["fps_compat"]);
3917+
}
3918+
39163919
if (p_state.has("zoom")) {
39173920
zoom->set_value(p_state["zoom"]);
3918-
} else {
3919-
zoom->set_value(1.0);
39203921
}
3922+
39213923
if (p_state.has("offset")) {
39223924
timeline->set_value(p_state["offset"]);
3923-
} else {
3924-
timeline->set_value(0);
39253925
}
3926+
39263927
if (p_state.has("v_scroll")) {
39273928
scroll->get_v_scroll_bar()->set_value(p_state["v_scroll"]);
3928-
} else {
3929-
scroll->get_v_scroll_bar()->set_value(0);
39303929
}
39313930
}
39323931

3932+
void AnimationTrackEditor::clear() {
3933+
snap_mode->select(EDITOR_GET("editors/animation/default_fps_mode"));
3934+
_snap_mode_changed(snap_mode->get_selected());
3935+
fps_compat->set_pressed(EDITOR_GET("editors/animation/default_fps_compatibility"));
3936+
zoom->set_value(1.0);
3937+
timeline->set_value(0);
3938+
scroll->get_v_scroll_bar()->set_value(0);
3939+
}
3940+
39333941
void AnimationTrackEditor::cleanup() {
39343942
set_animation(Ref<Animation>(), read_only);
39353943
}
@@ -7704,9 +7712,9 @@ AnimationTrackEditor::AnimationTrackEditor() {
77047712
snap_mode = memnew(OptionButton);
77057713
snap_mode->add_item(TTR("Seconds"));
77067714
snap_mode->add_item(TTR("FPS"));
7715+
snap_mode->set_disabled(true);
77077716
bottom_hf->add_child(snap_mode);
77087717
snap_mode->connect(SceneStringName(item_selected), callable_mp(this, &AnimationTrackEditor::_snap_mode_changed));
7709-
snap_mode->set_disabled(true);
77107718

77117719
bottom_hf->add_child(memnew(VSeparator));
77127720

editor/animation_track_editor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,7 @@ class AnimationTrackEditor : public VBoxContainer {
915915

916916
Dictionary get_state() const;
917917
void set_state(const Dictionary &p_state);
918+
void clear();
918919

919920
void cleanup();
920921

editor/editor_settings.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,8 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
918918
EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/polygon_editor/auto_bake_delay", 1.5, "-1.0,10.0,0.01");
919919

920920
// Animation
921+
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/animation/default_fps_mode", 0, "Seconds,FPS");
922+
_initial_set("editors/animation/default_fps_compatibility", true);
921923
_initial_set("editors/animation/autorename_animation_tracks", true);
922924
_initial_set("editors/animation/confirm_insert_track", true, true);
923925
_initial_set("editors/animation/default_create_bezier_tracks", false, true);

editor/plugins/animation_player_editor_plugin.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,10 @@ void AnimationPlayerEditor::set_state(const Dictionary &p_state) {
923923
}
924924
}
925925

926+
void AnimationPlayerEditor::clear() {
927+
track_editor->clear();
928+
}
929+
926930
void AnimationPlayerEditor::_animation_resource_edit() {
927931
String current = _get_current();
928932
if (current != String()) {

editor/plugins/animation_player_editor_plugin.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ class AnimationPlayerEditor : public VBoxContainer {
265265
AnimationTrackEditor *get_track_editor() { return track_editor; }
266266
Dictionary get_state() const;
267267
void set_state(const Dictionary &p_state);
268+
void clear();
268269

269270
void ensure_visibility();
270271

@@ -297,6 +298,7 @@ class AnimationPlayerEditorPlugin : public EditorPlugin {
297298
public:
298299
virtual Dictionary get_state() const override { return anim_editor->get_state(); }
299300
virtual void set_state(const Dictionary &p_state) override { anim_editor->set_state(p_state); }
301+
virtual void clear() override { anim_editor->clear(); }
300302

301303
virtual String get_plugin_name() const override { return "Anim"; }
302304
bool has_main_screen() const override { return false; }

0 commit comments

Comments
 (0)