Browse Source

Add editor setting for FPS mode and compat

kobewi 7 months ago
parent
commit
0b397d979d

+ 6 - 0
doc/classes/EditorSettings.xml

@@ -520,6 +520,12 @@
 		<member name="editors/animation/default_create_reset_tracks" type="bool" setter="" getter="">
 		<member name="editors/animation/default_create_reset_tracks" type="bool" setter="" getter="">
 			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.
 			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.
 		</member>
 		</member>
+		<member name="editors/animation/default_fps_compatibility" type="bool" setter="" getter="">
+			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.
+		</member>
+		<member name="editors/animation/default_fps_mode" type="int" setter="" getter="">
+			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.
+		</member>
 		<member name="editors/animation/onion_layers_future_color" type="Color" setter="" getter="">
 		<member name="editors/animation/onion_layers_future_color" type="Color" setter="" getter="">
 			The modulate color to use for "future" frames displayed in the animation editor's onion skinning feature.
 			The modulate color to use for "future" frames displayed in the animation editor's onion skinning feature.
 		</member>
 		</member>

+ 18 - 10
editor/animation_track_editor.cpp

@@ -3894,6 +3894,7 @@ bool AnimationTrackEditor::has_keying() const {
 Dictionary AnimationTrackEditor::get_state() const {
 Dictionary AnimationTrackEditor::get_state() const {
 	Dictionary state;
 	Dictionary state;
 	state["fps_mode"] = timeline->is_using_fps();
 	state["fps_mode"] = timeline->is_using_fps();
+	state["fps_compat"] = fps_compat->is_pressed();
 	state["zoom"] = zoom->get_value();
 	state["zoom"] = zoom->get_value();
 	state["offset"] = timeline->get_value();
 	state["offset"] = timeline->get_value();
 	state["v_scroll"] = scroll->get_v_scroll_bar()->get_value();
 	state["v_scroll"] = scroll->get_v_scroll_bar()->get_value();
@@ -3909,27 +3910,34 @@ void AnimationTrackEditor::set_state(const Dictionary &p_state) {
 			snap_mode->select(0);
 			snap_mode->select(0);
 		}
 		}
 		_snap_mode_changed(snap_mode->get_selected());
 		_snap_mode_changed(snap_mode->get_selected());
-	} else {
-		snap_mode->select(0);
-		_snap_mode_changed(snap_mode->get_selected());
 	}
 	}
+
+	if (p_state.has("fps_compat")) {
+		fps_compat->set_pressed(p_state["fps_compat"]);
+	}
+
 	if (p_state.has("zoom")) {
 	if (p_state.has("zoom")) {
 		zoom->set_value(p_state["zoom"]);
 		zoom->set_value(p_state["zoom"]);
-	} else {
-		zoom->set_value(1.0);
 	}
 	}
+
 	if (p_state.has("offset")) {
 	if (p_state.has("offset")) {
 		timeline->set_value(p_state["offset"]);
 		timeline->set_value(p_state["offset"]);
-	} else {
-		timeline->set_value(0);
 	}
 	}
+
 	if (p_state.has("v_scroll")) {
 	if (p_state.has("v_scroll")) {
 		scroll->get_v_scroll_bar()->set_value(p_state["v_scroll"]);
 		scroll->get_v_scroll_bar()->set_value(p_state["v_scroll"]);
-	} else {
-		scroll->get_v_scroll_bar()->set_value(0);
 	}
 	}
 }
 }
 
 
+void AnimationTrackEditor::clear() {
+	snap_mode->select(EDITOR_GET("editors/animation/default_fps_mode"));
+	_snap_mode_changed(snap_mode->get_selected());
+	fps_compat->set_pressed(EDITOR_GET("editors/animation/default_fps_compatibility"));
+	zoom->set_value(1.0);
+	timeline->set_value(0);
+	scroll->get_v_scroll_bar()->set_value(0);
+}
+
 void AnimationTrackEditor::cleanup() {
 void AnimationTrackEditor::cleanup() {
 	set_animation(Ref<Animation>(), read_only);
 	set_animation(Ref<Animation>(), read_only);
 }
 }
@@ -7704,9 +7712,9 @@ AnimationTrackEditor::AnimationTrackEditor() {
 	snap_mode = memnew(OptionButton);
 	snap_mode = memnew(OptionButton);
 	snap_mode->add_item(TTR("Seconds"));
 	snap_mode->add_item(TTR("Seconds"));
 	snap_mode->add_item(TTR("FPS"));
 	snap_mode->add_item(TTR("FPS"));
+	snap_mode->set_disabled(true);
 	bottom_hf->add_child(snap_mode);
 	bottom_hf->add_child(snap_mode);
 	snap_mode->connect(SceneStringName(item_selected), callable_mp(this, &AnimationTrackEditor::_snap_mode_changed));
 	snap_mode->connect(SceneStringName(item_selected), callable_mp(this, &AnimationTrackEditor::_snap_mode_changed));
-	snap_mode->set_disabled(true);
 
 
 	bottom_hf->add_child(memnew(VSeparator));
 	bottom_hf->add_child(memnew(VSeparator));
 
 

+ 1 - 0
editor/animation_track_editor.h

@@ -916,6 +916,7 @@ public:
 
 
 	Dictionary get_state() const;
 	Dictionary get_state() const;
 	void set_state(const Dictionary &p_state);
 	void set_state(const Dictionary &p_state);
+	void clear();
 
 
 	void cleanup();
 	void cleanup();
 
 

+ 2 - 0
editor/editor_settings.cpp

@@ -899,6 +899,8 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
 	EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/polygon_editor/auto_bake_delay", 1.5, "-1.0,10.0,0.01");
 	EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/polygon_editor/auto_bake_delay", 1.5, "-1.0,10.0,0.01");
 
 
 	// Animation
 	// Animation
+	EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/animation/default_fps_mode", 0, "Seconds,FPS");
+	_initial_set("editors/animation/default_fps_compatibility", true);
 	_initial_set("editors/animation/autorename_animation_tracks", true);
 	_initial_set("editors/animation/autorename_animation_tracks", true);
 	_initial_set("editors/animation/confirm_insert_track", true, true);
 	_initial_set("editors/animation/confirm_insert_track", true, true);
 	_initial_set("editors/animation/default_create_bezier_tracks", false, true);
 	_initial_set("editors/animation/default_create_bezier_tracks", false, true);

+ 4 - 0
editor/plugins/animation_player_editor_plugin.cpp

@@ -923,6 +923,10 @@ void AnimationPlayerEditor::set_state(const Dictionary &p_state) {
 	}
 	}
 }
 }
 
 
+void AnimationPlayerEditor::clear() {
+	track_editor->clear();
+}
+
 void AnimationPlayerEditor::_animation_resource_edit() {
 void AnimationPlayerEditor::_animation_resource_edit() {
 	String current = _get_current();
 	String current = _get_current();
 	if (current != String()) {
 	if (current != String()) {

+ 2 - 0
editor/plugins/animation_player_editor_plugin.h

@@ -266,6 +266,7 @@ public:
 	AnimationTrackEditor *get_track_editor() { return track_editor; }
 	AnimationTrackEditor *get_track_editor() { return track_editor; }
 	Dictionary get_state() const;
 	Dictionary get_state() const;
 	void set_state(const Dictionary &p_state);
 	void set_state(const Dictionary &p_state);
+	void clear();
 
 
 	void ensure_visibility();
 	void ensure_visibility();
 
 
@@ -298,6 +299,7 @@ protected:
 public:
 public:
 	virtual Dictionary get_state() const override { return anim_editor->get_state(); }
 	virtual Dictionary get_state() const override { return anim_editor->get_state(); }
 	virtual void set_state(const Dictionary &p_state) override { anim_editor->set_state(p_state); }
 	virtual void set_state(const Dictionary &p_state) override { anim_editor->set_state(p_state); }
+	virtual void clear() override { anim_editor->clear(); }
 
 
 	virtual String get_plugin_name() const override { return "Anim"; }
 	virtual String get_plugin_name() const override { return "Anim"; }
 	bool has_main_screen() const override { return false; }
 	bool has_main_screen() const override { return false; }