From e283fdfb595d34af3832e95c614e2a57743af00a Mon Sep 17 00:00:00 2001 From: "Silc Lizard (Tokage) Renew" <61938263+TokageItLab@users.noreply.github.com> Date: Sun, 17 Nov 2024 01:54:06 +0900 Subject: [PATCH] Fix spinner in AnimationTrackEdit in FPS mode --- doc/classes/EditorSpinSlider.xml | 5 +++++ editor/animation_track_editor.cpp | 22 +++++++++++----------- editor/animation_track_editor.h | 2 +- editor/gui/editor_spin_slider.cpp | 2 ++ 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/doc/classes/EditorSpinSlider.xml b/doc/classes/EditorSpinSlider.xml index 83c65b736e7..6cd375a46de 100644 --- a/doc/classes/EditorSpinSlider.xml +++ b/doc/classes/EditorSpinSlider.xml @@ -40,6 +40,11 @@ Emitted when the spinner/slider is ungrabbed. + + + Emitted when the updown button is pressed. + + Emitted when the value form gains focus. diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index 55ea7c0082a..b9833a8906b 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -7983,6 +7983,11 @@ AnimationTrackEditor::~AnimationTrackEditor() { // AnimationTrackKeyEditEditorPlugin. +void AnimationTrackKeyEditEditor::_time_edit_spun() { + _time_edit_entered(); + _time_edit_exited(); +} + void AnimationTrackKeyEditEditor::_time_edit_entered() { int key = animation->track_find_key(track, key_ofs, Animation::FIND_MODE_APPROX); if (key == -1) { @@ -8010,7 +8015,7 @@ void AnimationTrackKeyEditEditor::_time_edit_exited() { int existing = animation->track_find_key(track, new_time, Animation::FIND_MODE_APPROX); EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); - undo_redo->create_action(TTR("Animation Change Keyframe Time"), UndoRedo::MERGE_ENDS); + undo_redo->create_action(TTR("Animation Change Keyframe Time")); if (existing != -1) { undo_redo->add_do_method(animation.ptr(), "track_remove_key_at_time", track, animation->track_get_key_time(track, existing)); @@ -8057,6 +8062,7 @@ AnimationTrackKeyEditEditor::AnimationTrackKeyEditEditor(Ref p_animat spinner->set_min(0); spinner->set_allow_greater(true); spinner->set_allow_lesser(true); + add_child(spinner); if (use_fps) { spinner->set_step(FPS_DECIMAL); @@ -8065,14 +8071,13 @@ AnimationTrackKeyEditEditor::AnimationTrackKeyEditEditor(Ref p_animat fps = 1.0 / fps; } spinner->set_value(key_ofs * fps); + spinner->connect("updown_pressed", callable_mp(this, &AnimationTrackKeyEditEditor::_time_edit_spun), CONNECT_DEFERRED); } else { spinner->set_step(SECOND_DECIMAL); spinner->set_value(key_ofs); spinner->set_max(animation->get_length()); } - add_child(spinner); - spinner->connect("grabbed", callable_mp(this, &AnimationTrackKeyEditEditor::_time_edit_entered), CONNECT_DEFERRED); spinner->connect("ungrabbed", callable_mp(this, &AnimationTrackKeyEditEditor::_time_edit_exited), CONNECT_DEFERRED); spinner->connect("value_focus_entered", callable_mp(this, &AnimationTrackKeyEditEditor::_time_edit_entered), CONNECT_DEFERRED); @@ -9193,9 +9198,6 @@ void AnimationMultiMarkerKeyEdit::_get_property_list(List *p_list) // AnimationMarkerKeyEditEditorPlugin -void AnimationMarkerKeyEditEditor::_time_edit_entered() { -} - void AnimationMarkerKeyEditEditor::_time_edit_exited() { real_t new_time = spinner->get_value(); @@ -9214,7 +9216,7 @@ void AnimationMarkerKeyEditEditor::_time_edit_exited() { } EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); - undo_redo->create_action(TTR("Animation Change Marker Time"), UndoRedo::MERGE_ENDS); + undo_redo->create_action(TTR("Animation Change Marker Time")); Color color = animation->get_marker_color(marker_name); undo_redo->add_do_method(animation.ptr(), "add_marker", marker_name, new_time); @@ -9255,6 +9257,7 @@ AnimationMarkerKeyEditEditor::AnimationMarkerKeyEditEditor(Ref p_anim spinner->set_min(0); spinner->set_allow_greater(true); spinner->set_allow_lesser(true); + add_child(spinner); float time = animation->get_marker_time(marker_name); @@ -9265,17 +9268,14 @@ AnimationMarkerKeyEditEditor::AnimationMarkerKeyEditEditor(Ref p_anim fps = 1.0 / fps; } spinner->set_value(time * fps); + spinner->connect("updown_pressed", callable_mp(this, &AnimationMarkerKeyEditEditor::_time_edit_exited), CONNECT_DEFERRED); } else { spinner->set_step(SECOND_DECIMAL); spinner->set_value(time); spinner->set_max(animation->get_length()); } - add_child(spinner); - - spinner->connect("grabbed", callable_mp(this, &AnimationMarkerKeyEditEditor::_time_edit_entered), CONNECT_DEFERRED); spinner->connect("ungrabbed", callable_mp(this, &AnimationMarkerKeyEditEditor::_time_edit_exited), CONNECT_DEFERRED); - spinner->connect("value_focus_entered", callable_mp(this, &AnimationMarkerKeyEditEditor::_time_edit_entered), CONNECT_DEFERRED); spinner->connect("value_focus_exited", callable_mp(this, &AnimationMarkerKeyEditEditor::_time_edit_exited), CONNECT_DEFERRED); } diff --git a/editor/animation_track_editor.h b/editor/animation_track_editor.h index e7271f1941a..f17386b0c90 100644 --- a/editor/animation_track_editor.h +++ b/editor/animation_track_editor.h @@ -977,6 +977,7 @@ class AnimationTrackKeyEditEditor : public EditorProperty { Variant value; } key_data_cache; + void _time_edit_spun(); void _time_edit_entered(); void _time_edit_exited(); @@ -996,7 +997,6 @@ class AnimationMarkerKeyEditEditor : public EditorProperty { EditorSpinSlider *spinner = nullptr; - void _time_edit_entered(); void _time_edit_exited(); public: diff --git a/editor/gui/editor_spin_slider.cpp b/editor/gui/editor_spin_slider.cpp index 712e91facaf..aa9e9f841d3 100644 --- a/editor/gui/editor_spin_slider.cpp +++ b/editor/gui/editor_spin_slider.cpp @@ -67,6 +67,7 @@ void EditorSpinSlider::gui_input(const Ref &p_event) { } else { set_value(get_value() - get_step()); } + emit_signal("updown_pressed"); return; } _grab_start(); @@ -696,6 +697,7 @@ void EditorSpinSlider::_bind_methods() { ADD_SIGNAL(MethodInfo("grabbed")); ADD_SIGNAL(MethodInfo("ungrabbed")); + ADD_SIGNAL(MethodInfo("updown_pressed")); ADD_SIGNAL(MethodInfo("value_focus_entered")); ADD_SIGNAL(MethodInfo("value_focus_exited"));