Few improvements for SpriteFrames Editor

This commit is contained in:
Danil Alexeev 2023-01-28 20:06:50 +03:00
parent 551f5191e5
commit ca7209aaef
No known key found for this signature in database
GPG key ID: 124453E157DA8DC7
2 changed files with 37 additions and 28 deletions

View file

@ -425,6 +425,7 @@ void SpriteFramesEditor::_notification(int p_what) {
_update_stop_icon();
autoplay->set_icon(get_theme_icon(SNAME("AutoPlay"), SNAME("EditorIcons")));
anim_loop->set_icon(get_theme_icon(SNAME("Loop"), SNAME("EditorIcons")));
play->set_icon(get_theme_icon(SNAME("PlayStart"), SNAME("EditorIcons")));
play_from->set_icon(get_theme_icon(SNAME("Play"), SNAME("EditorIcons")));
play_bw->set_icon(get_theme_icon(SNAME("PlayStartBackwards"), SNAME("EditorIcons")));
@ -1114,18 +1115,19 @@ void SpriteFramesEditor::_update_library(bool p_skip_selector) {
}
for (int i = 0; i < frames->get_frame_count(edited_anim); i++) {
String name;
String name = itos(i);
Ref<Texture2D> texture = frames->get_frame_texture(edited_anim, i);
float duration = frames->get_frame_duration(edited_anim, i);
String duration_string;
if (duration != 1.0f) {
duration_string = String::utf8(" [ ×") + String::num_real(frames->get_frame_duration(edited_anim, i)) + " ]";
}
if (texture.is_null()) {
name = itos(i) + ": " + TTR("(empty)") + duration_string;
} else {
name = itos(i) + ": " + texture->get_name() + duration_string;
texture = empty_icon;
name += ": " + TTR("(empty)");
} else if (!texture->get_name().is_empty()) {
name += ": " + texture->get_name();
}
if (duration != 1.0f) {
name += String::utf8(" [× ") + String::num(duration, 2) + "]";
}
frame_list->add_item(name, texture);
@ -1521,9 +1523,30 @@ SpriteFramesEditor::SpriteFramesEditor() {
delete_anim->set_disabled(true);
delete_anim->connect("pressed", callable_mp(this, &SpriteFramesEditor::_animation_remove));
hbc_animlist->add_child(memnew(VSeparator));
anim_speed = memnew(SpinBox);
anim_speed->set_suffix(TTR("FPS"));
anim_speed->set_min(0);
anim_speed->set_max(120);
anim_speed->set_step(0.01);
anim_speed->set_custom_arrow_step(1);
anim_speed->set_tooltip_text(TTR("Animation Speed"));
anim_speed->connect("value_changed", callable_mp(this, &SpriteFramesEditor::_animation_speed_changed));
hbc_animlist->add_child(anim_speed);
anim_loop = memnew(Button);
anim_loop->set_toggle_mode(true);
anim_loop->set_flat(true);
anim_loop->set_tooltip_text(TTR("Animation Looping"));
anim_loop->connect("pressed", callable_mp(this, &SpriteFramesEditor::_animation_loop_changed));
hbc_animlist->add_child(anim_loop);
autoplay_container = memnew(HBoxContainer);
hbc_animlist->add_child(autoplay_container);
autoplay_container->add_child(memnew(VSeparator));
autoplay = memnew(Button);
autoplay->set_flat(true);
autoplay->set_tooltip_text(TTR("Autoplay on Load"));
@ -1549,23 +1572,6 @@ SpriteFramesEditor::SpriteFramesEditor() {
delete_anim->set_shortcut_context(animations);
delete_anim->set_shortcut(ED_SHORTCUT("sprite_frames/delete_animation", TTR("Delete Animation"), Key::KEY_DELETE));
HBoxContainer *hbc_anim_speed = memnew(HBoxContainer);
hbc_anim_speed->add_child(memnew(Label(TTR("Speed:"))));
vbc_animlist->add_child(hbc_anim_speed);
anim_speed = memnew(SpinBox);
anim_speed->set_suffix(TTR("FPS"));
anim_speed->set_min(0);
anim_speed->set_max(120);
anim_speed->set_step(0.01);
anim_speed->set_h_size_flags(SIZE_EXPAND_FILL);
hbc_anim_speed->add_child(anim_speed);
anim_speed->connect("value_changed", callable_mp(this, &SpriteFramesEditor::_animation_speed_changed));
anim_loop = memnew(CheckButton);
anim_loop->set_text(TTR("Loop"));
vbc_animlist->add_child(anim_loop);
anim_loop->connect("pressed", callable_mp(this, &SpriteFramesEditor::_animation_loop_changed));
VBoxContainer *vbc = memnew(VBoxContainer);
add_child(vbc);
vbc->set_h_size_flags(SIZE_EXPAND_FILL);
@ -1667,6 +1673,7 @@ SpriteFramesEditor::SpriteFramesEditor() {
frame_duration->set_min(SPRITE_FRAME_MINIMUM_DURATION); // Avoid zero div.
frame_duration->set_max(10);
frame_duration->set_step(0.01);
frame_duration->set_custom_arrow_step(0.1);
frame_duration->set_allow_lesser(false);
frame_duration->set_allow_greater(true);
hbc->add_child(frame_duration);

View file

@ -73,6 +73,7 @@ class SpriteFramesEditor : public HSplitContainer {
Ref<Texture2D> autoplay_icon;
Ref<Texture2D> stop_icon;
Ref<Texture2D> pause_icon;
Ref<Texture2D> empty_icon = memnew(ImageTexture);
HBoxContainer *playback_container = nullptr;
Button *stop = nullptr;
@ -100,13 +101,14 @@ class SpriteFramesEditor : public HSplitContainer {
Button *add_anim = nullptr;
Button *delete_anim = nullptr;
SpinBox *anim_speed = nullptr;
Button *anim_loop = nullptr;
HBoxContainer *autoplay_container = nullptr;
Button *autoplay = nullptr;
LineEdit *anim_search_box = nullptr;
LineEdit *anim_search_box = nullptr;
Tree *animations = nullptr;
SpinBox *anim_speed = nullptr;
CheckButton *anim_loop = nullptr;
EditorFileDialog *file = nullptr;