Fix spinner in AnimationTrackEdit in FPS mode

This commit is contained in:
Silc Lizard (Tokage) Renew 2024-11-17 01:54:06 +09:00
parent 5efd124ca1
commit e283fdfb59
4 changed files with 19 additions and 12 deletions

View File

@ -40,6 +40,11 @@
Emitted when the spinner/slider is ungrabbed.
</description>
</signal>
<signal name="updown_pressed">
<description>
Emitted when the updown button is pressed.
</description>
</signal>
<signal name="value_focus_entered">
<description>
Emitted when the value form gains focus.

View File

@ -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<Animation> 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<Animation> 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<PropertyInfo> *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<Animation> 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<Animation> 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);
}

View File

@ -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:

View File

@ -67,6 +67,7 @@ void EditorSpinSlider::gui_input(const Ref<InputEvent> &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"));