Add option to play/preview with subtags & repetitions

This commit is contained in:
David Capello 2022-10-20 14:41:24 -03:00
parent 4f96d37b1f
commit 9601c02812
10 changed files with 51 additions and 18 deletions

View File

@ -180,6 +180,7 @@
<option id="straight_line_preview" type="bool" default="true" />
<option id="play_once" type="bool" default="false" />
<option id="play_all" type="bool" default="false" />
<option id="play_subtags" type="bool" default="false" />
<!-- TODO this would be nice to be "true" but we have to fix
some performance issue rendering huge sprites with small
zoom levels -->
@ -211,6 +212,7 @@
<section id="preview" text="Preview">
<option id="play_once" type="bool" default="false" />
<option id="play_all" type="bool" default="false" />
<option id="play_subtags" type="bool" default="false" />
</section>
<section id="theme" text="Theme">
<option id="selected" type="std::string" default="&quot;default&quot;" />

View File

@ -1775,6 +1775,7 @@ title = Preview
speed_x = Speed x{}
play_once = Play Once
play_all_no_tags = Play All Frames (Ignore Tags)
play_subtags_and_repeats = Play Subtags & Repetitions
rewind_on_stop = Rewind on Stop
[recover_files]

View File

@ -1,4 +1,5 @@
// Aseprite
// Copyright (C) 2022 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -62,7 +63,8 @@ void PlayAnimationCommand::onExecute(Context* context)
current_editor->stop();
else
current_editor->play(Preferences::instance().editor.playOnce(),
Preferences::instance().editor.playAll());
Preferences::instance().editor.playAll(),
Preferences::instance().editor.playSubtags());
}
//////////////////////////////////////////////////////////////////////

View File

@ -2754,7 +2754,8 @@ void Editor::startZoomingState(ui::MouseMessage* msg)
}
void Editor::play(const bool playOnce,
const bool playAll)
const bool playAll,
const bool playSubtags)
{
ASSERT(m_state);
if (!m_state)
@ -2764,7 +2765,9 @@ void Editor::play(const bool playOnce,
stop();
m_isPlaying = true;
setState(EditorStatePtr(new PlayState(playOnce, playAll)));
setState(EditorStatePtr(new PlayState(playOnce,
playAll,
playSubtags)));
}
void Editor::stop()
@ -2792,6 +2795,7 @@ bool Editor::isPlaying() const
void Editor::showAnimationSpeedMultiplierPopup(Option<bool>& playOnce,
Option<bool>& playAll,
Option<bool>& playSubtags,
const bool withStopBehaviorOptions)
{
const double options[] = { 0.25, 0.5, 1.0, 1.5, 2.0, 3.0 };
@ -2828,6 +2832,17 @@ void Editor::showAnimationSpeedMultiplierPopup(Option<bool>& playOnce,
menu.addChild(item);
}
// Play subtags & repeats
{
MenuItem* item = new MenuItem(Strings::preview_play_subtags_and_repeats());
item->Click.connect(
[&playSubtags]() {
playSubtags(!playSubtags());
});
item->setSelected(playSubtags());
menu.addChild(item);
}
if (withStopBehaviorOptions) {
MenuItem* item = new MenuItem(Strings::preview_rewind_on_stop());
item->Click.connect(
@ -2846,7 +2861,8 @@ void Editor::showAnimationSpeedMultiplierPopup(Option<bool>& playOnce,
// Re-play
stop();
play(playOnce(),
playAll());
playAll(),
playSubtags());
}
}

View File

@ -274,13 +274,15 @@ namespace app {
// Animation control
void play(const bool playOnce,
const bool playAll);
const bool playAll,
const bool playSubtags);
void stop();
bool isPlaying() const;
// Shows a popup menu to change the editor animation speed.
void showAnimationSpeedMultiplierPopup(Option<bool>& playOnce,
Option<bool>& playAll,
Option<bool>& playSubtags,
const bool withStopBehaviorOptions);
double getAnimationSpeedMultiplier() const;
void setAnimationSpeedMultiplier(double speed);

View File

@ -31,10 +31,12 @@ namespace app {
using namespace ui;
PlayState::PlayState(const bool playOnce,
const bool playAll)
const bool playAll,
const bool playSubtags)
: m_editor(nullptr)
, m_playOnce(playOnce)
, m_playAll(playAll)
, m_playSubtags(playSubtags)
, m_toScroll(false)
, m_playTimer(10)
, m_nextFrameTime(-1)
@ -83,13 +85,14 @@ void PlayState::onEnterState(Editor* editor)
m_editor->setFrame(frame);
}
m_playback = doc::Playback(m_editor->sprite(),
TagsList(), // TODO add support to follow subtags
m_editor->frame(),
m_playOnce ? doc::Playback::PlayOnce:
m_playAll ? doc::Playback::PlayWithoutTagsInLoop:
doc::Playback::PlayInLoop,
m_tag);
m_playback = doc::Playback(
m_editor->sprite(),
m_playSubtags ? m_editor->sprite()->tags().getInternalList() : TagsList(),
m_editor->frame(),
m_playOnce ? doc::Playback::PlayOnce :
m_playAll ? doc::Playback::PlayWithoutTagsInLoop :
doc::Playback::PlayInLoop,
m_tag);
m_toScroll = false;
m_nextFrameTime = getNextFrameTime();

View File

@ -27,7 +27,8 @@ namespace app {
class PlayState : public StateWithWheelBehavior {
public:
PlayState(const bool playOnce,
const bool playAll);
const bool playAll,
const bool playSubtags);
doc::Tag* playingTag() const;
@ -54,6 +55,7 @@ namespace app {
doc::Playback m_playback;
bool m_playOnce;
bool m_playAll;
bool m_playSubtags;
bool m_toScroll;
ui::Timer m_playTimer;

View File

@ -317,7 +317,8 @@ void PreviewEditorWindow::onPlayClicked()
if (m_playButton->isPlaying()) {
m_refFrame = miniEditor->frame();
miniEditor->play(Preferences::instance().preview.playOnce(),
Preferences::instance().preview.playAll());
Preferences::instance().preview.playAll(),
Preferences::instance().preview.playSubtags());
}
else {
miniEditor->stop();
@ -337,6 +338,7 @@ void PreviewEditorWindow::onPopupSpeed()
miniEditor->showAnimationSpeedMultiplierPopup(
pref.preview.playOnce,
pref.preview.playAll,
pref.preview.playSubtags,
false);
m_aniSpeed = miniEditor->getAnimationSpeedMultiplier();
}
@ -513,7 +515,8 @@ void PreviewEditorWindow::adjustPlayingTag()
miniEditor->setFrame(m_refFrame = editor->frame());
miniEditor->play(Preferences::instance().preview.playOnce(),
Preferences::instance().preview.playAll());
Preferences::instance().preview.playAll(),
Preferences::instance().preview.playSubtags());
}
} // namespace app

View File

@ -95,7 +95,8 @@ void AniControls::onRightClick(Item* item)
if (item == getItem(ACTION_PLAY) && current_editor)
current_editor->showAnimationSpeedMultiplierPopup(
Preferences::instance().editor.playOnce,
Preferences::instance().editor.playAll, true);
Preferences::instance().editor.playAll,
Preferences::instance().editor.playSubtags, true);
}
const char* AniControls::getCommandId(int index) const

View File

@ -513,7 +513,8 @@ void Timeline::setFrame(frame_t frame, bool byUser)
if (isPlaying)
m_editor->play(false,
Preferences::instance().editor.playAll());
Preferences::instance().editor.playAll(),
Preferences::instance().editor.playSubtags());
}
}