From 8f5e447431b85a246d6caeffb34f40a0aa1750e2 Mon Sep 17 00:00:00 2001 From: Silc 'Tokage' Renew Date: Tue, 19 Nov 2019 14:39:10 +0100 Subject: [PATCH] Implement toggling pause / stop button to AnimationPlayerEditor --- .../animation_player_editor_plugin.cpp | 34 +++++++++++-------- .../plugins/animation_player_editor_plugin.h | 2 ++ 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp index 10f2ce25d907a7..47c3d310d47f72 100644 --- a/editor/plugins/animation_player_editor_plugin.cpp +++ b/editor/plugins/animation_player_editor_plugin.cpp @@ -94,6 +94,7 @@ void AnimationPlayerEditor::_notification(int p_what) { // Need the last frame after it stopped. frame->set_value(player->get_current_animation_position()); track_editor->set_anim_pos(player->get_current_animation_position()); + stop->set_icon(stop_icon); } last_active = player->is_playing(); @@ -126,6 +127,8 @@ void AnimationPlayerEditor::_notification(int p_what) { play_bw->set_icon(get_theme_icon(SNAME("PlayStartBackwards"), SNAME("EditorIcons"))); play_bw_from->set_icon(get_theme_icon(SNAME("PlayBackwards"), SNAME("EditorIcons"))); + stop_icon = get_theme_icon(SNAME("Stop"), SNAME("EditorIcons")); + pause_icon = get_theme_icon(SNAME("Pause"), SNAME("EditorIcons")); autoplay_icon = get_theme_icon(SNAME("AutoPlay"), SNAME("EditorIcons")); reset_icon = get_theme_icon(SNAME("Reload"), SNAME("EditorIcons")); { @@ -137,7 +140,7 @@ void AnimationPlayerEditor::_notification(int p_what) { autoplay_reset_img->blit_rect(reset_img, Rect2i(Point2i(), icon_size), Point2i(icon_size.x, 0)); autoplay_reset_icon = ImageTexture::create_from_image(autoplay_reset_img); } - stop->set_icon(get_theme_icon(SNAME("Stop"), SNAME("EditorIcons"))); + stop->set_icon(stop_icon); onion_toggle->set_icon(get_theme_icon(SNAME("Onion"), SNAME("EditorIcons"))); onion_skinning->set_icon(get_theme_icon(SNAME("GuiTabMenuHl"), SNAME("EditorIcons"))); @@ -204,7 +207,7 @@ void AnimationPlayerEditor::_play_pressed() { } //unstop - stop->set_pressed(false); + stop->set_icon(pause_icon); } void AnimationPlayerEditor::_play_from_pressed() { @@ -221,7 +224,7 @@ void AnimationPlayerEditor::_play_from_pressed() { } //unstop - stop->set_pressed(false); + stop->set_icon(pause_icon); } String AnimationPlayerEditor::_get_current() const { @@ -242,7 +245,7 @@ void AnimationPlayerEditor::_play_bw_pressed() { } //unstop - stop->set_pressed(false); + stop->set_icon(pause_icon); } void AnimationPlayerEditor::_play_bw_from_pressed() { @@ -259,7 +262,7 @@ void AnimationPlayerEditor::_play_bw_from_pressed() { } //unstop - stop->set_pressed(false); + stop->set_icon(pause_icon); } void AnimationPlayerEditor::_stop_pressed() { @@ -267,9 +270,16 @@ void AnimationPlayerEditor::_stop_pressed() { return; } - player->pause(); - play->set_pressed(false); - stop->set_pressed(true); + if (player->is_playing()) { + player->pause(); + } else { + String current = _get_current(); + player->stop(); + player->set_assigned_animation(current); + frame->set_value(0); + track_editor->set_anim_pos(0); + } + stop->set_icon(stop_icon); } void AnimationPlayerEditor::_animation_selected(int p_which) { @@ -798,12 +808,9 @@ void AnimationPlayerEditor::_update_animation() { updating = true; if (player->is_playing()) { - play->set_pressed(true); - stop->set_pressed(false); - + stop->set_icon(pause_icon); } else { - play->set_pressed(false); - stop->set_pressed(true); + stop->set_icon(stop_icon); } scale->set_text(String::num(player->get_speed_scale(), 2)); @@ -1663,7 +1670,6 @@ AnimationPlayerEditor::AnimationPlayerEditor(AnimationPlayerEditorPlugin *p_plug stop = memnew(Button); stop->set_flat(true); - stop->set_toggle_mode(true); hb->add_child(stop); stop->set_tooltip_text(TTR("Stop animation playback. (S)")); diff --git a/editor/plugins/animation_player_editor_plugin.h b/editor/plugins/animation_player_editor_plugin.h index 6c690c812c4900..327200506f90c4 100644 --- a/editor/plugins/animation_player_editor_plugin.h +++ b/editor/plugins/animation_player_editor_plugin.h @@ -101,6 +101,8 @@ class AnimationPlayerEditor : public VBoxContainer { OptionButton *library = nullptr; Label *name_title = nullptr; + Ref stop_icon; + Ref pause_icon; Ref autoplay_icon; Ref reset_icon; Ref autoplay_reset_icon;