Skip to content

Commit 0b397d9

Browse files
committed
Add editor setting for FPS mode and compat
1 parent ee4acfb commit 0b397d9

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
@@ -520,6 +520,12 @@
520520
<member name="editors/animation/default_create_reset_tracks" type="bool" setter="" getter="">
521521
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.
522522
</member>
523+
<member name="editors/animation/default_fps_compatibility" type="bool" setter="" getter="">
524+
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.
525+
</member>
526+
<member name="editors/animation/default_fps_mode" type="int" setter="" getter="">
527+
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.
528+
</member>
523529
<member name="editors/animation/onion_layers_future_color" type="Color" setter="" getter="">
524530
The modulate color to use for "future" frames displayed in the animation editor's onion skinning feature.
525531
</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
@@ -916,6 +916,7 @@ class AnimationTrackEditor : public VBoxContainer {
916916

917917
Dictionary get_state() const;
918918
void set_state(const Dictionary &p_state);
919+
void clear();
919920

920921
void cleanup();
921922

editor/editor_settings.cpp

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

901901
// Animation
902+
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/animation/default_fps_mode", 0, "Seconds,FPS");
903+
_initial_set("editors/animation/default_fps_compatibility", true);
902904
_initial_set("editors/animation/autorename_animation_tracks", true);
903905
_initial_set("editors/animation/confirm_insert_track", true, true);
904906
_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
@@ -266,6 +266,7 @@ class AnimationPlayerEditor : public VBoxContainer {
266266
AnimationTrackEditor *get_track_editor() { return track_editor; }
267267
Dictionary get_state() const;
268268
void set_state(const Dictionary &p_state);
269+
void clear();
269270

270271
void ensure_visibility();
271272

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

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

0 commit comments

Comments
 (0)