From f026df1ff21fa1c89f2cd150a55573c7616e5bc9 Mon Sep 17 00:00:00 2001 From: kobewi Date: Tue, 22 Oct 2024 13:43:42 +0200 Subject: [PATCH] Add editor setting for default animation step --- doc/classes/EditorSettings.xml | 3 +++ editor/editor_settings.cpp | 2 ++ editor/plugins/animation_player_editor_plugin.cpp | 2 ++ scene/resources/animation.h | 3 ++- 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/doc/classes/EditorSettings.xml b/doc/classes/EditorSettings.xml index a5097521dc4..460f52d16f0 100644 --- a/doc/classes/EditorSettings.xml +++ b/doc/classes/EditorSettings.xml @@ -492,6 +492,9 @@ If [code]true[/code], display a confirmation dialog when adding a new track to an animation by pressing the "key" icon next to a property. Holding Shift will bypass the dialog. If [code]false[/code], the behavior is reversed, i.e. the dialog only appears when Shift is held. + + Default step used when creating new [Animation] in Animation tab. Only affects the first animation in [AnimationPlayer], subsequent animations will use step from the previous ones. + If [code]true[/code], create a Bezier track instead of a standard track when pressing the "key" icon next to a property. Bezier tracks provide more control over animation curves, but are more difficult to adjust quickly. diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index 12a7c3a2ff8..c52b4a755d9 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -54,6 +54,7 @@ #include "scene/main/node.h" #include "scene/main/scene_tree.h" #include "scene/main/window.h" +#include "scene/resources/animation.h" // PRIVATE METHODS @@ -882,6 +883,7 @@ void EditorSettings::_load_defaults(Ref p_extra_config) { EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/polygon_editor/auto_bake_delay", 1.5, "-1.0,10.0,0.01"); // Animation + _initial_set("editors/animation/default_animation_step", Animation::DEFAULT_STEP); _initial_set("editors/animation/autorename_animation_tracks", true); _initial_set("editors/animation/confirm_insert_track", true, true); _initial_set("editors/animation/default_create_bezier_tracks", false, true); diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp index 1581e7cc66c..9e30adb128c 100644 --- a/editor/plugins/animation_player_editor_plugin.cpp +++ b/editor/plugins/animation_player_editor_plugin.cpp @@ -655,6 +655,8 @@ void AnimationPlayerEditor::_animation_name_edited() { if (current_anim.is_valid()) { new_anim->set_step(current_anim->get_step()); } + } else { + new_anim->set_step(EDITOR_GET("editors/animation/default_animation_step")); } String library_name; diff --git a/scene/resources/animation.h b/scene/resources/animation.h index 618dc9ca17c..35d7319b7ac 100644 --- a/scene/resources/animation.h +++ b/scene/resources/animation.h @@ -44,6 +44,7 @@ public: typedef uint32_t TypeHash; static inline String PARAMETERS_BASE_PATH = "parameters/"; + static inline constexpr real_t DEFAULT_STEP = 1.0 / 30; enum TrackType : uint8_t { TYPE_VALUE, // Set a value in a property, can be interpolated. @@ -284,7 +285,7 @@ private: _FORCE_INLINE_ void _track_get_key_indices_in_range(const Vector &p_array, double from_time, double to_time, List *p_indices, bool p_is_backward) const; double length = 1.0; - real_t step = 1.0 / 30; + real_t step = DEFAULT_STEP; LoopMode loop_mode = LOOP_NONE; bool capture_included = false; void _check_capture_included();