Fix playback of same tag when adding new frames (fix https://community.aseprite.org/t/6486)

This commit is contained in:
David Capello 2020-07-27 18:17:48 -03:00
parent 0c0510b3b1
commit 2a48c688e2
9 changed files with 79 additions and 25 deletions

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019 Igara Studio S.A.
// Copyright (C) 2019-2020 Igara Studio S.A.
// Copyright (C) 2001-2015 David Capello
//
// This program is distributed under the terms of
@ -11,7 +11,11 @@
#include "app/cmd/set_tag_range.h"
#include "app/doc.h"
#include "app/doc_event.h"
#include "doc/sprite.h"
#include "doc/tag.h"
#include "doc/tags.h"
namespace app {
namespace cmd {
@ -37,5 +41,16 @@ void SetTagRange::onUndo()
tag()->incrementVersion();
}
void SetTagRange::onFireNotifications()
{
Tag* tag = this->tag();
Sprite* sprite = tag->owner()->sprite();
Doc* doc = static_cast<Doc*>(sprite->document());
DocEvent ev(doc);
ev.sprite(sprite);
ev.tag(tag);
doc->notify_observers<DocEvent&>(&DocObserver::onTagChange, ev);
}
} // namespace cmd
} // namespace app

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019 Igara Studio S.A.
// Copyright (C) 2019-2020 Igara Studio S.A.
// Copyright (C) 2001-2015 David Capello
//
// This program is distributed under the terms of
@ -25,6 +25,7 @@ namespace cmd {
protected:
void onExecute() override;
void onUndo() override;
void onFireNotifications() override;
size_t onMemSize() const override {
return sizeof(*this);
}

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018-2019 Igara Studio S.A.
// Copyright (C) 2018-2020 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -73,6 +73,9 @@ namespace app {
virtual void onSelectionChanged(DocEvent& ev) { }
virtual void onSelectionBoundariesChanged(DocEvent& ev) { }
// Tags
virtual void onTagChange(DocEvent& ev) { }
// Slices
virtual void onSliceNameChange(DocEvent& ev) { }

View File

@ -417,6 +417,12 @@ void DocView::onRemoveFrame(DocEvent& ev)
}
}
void DocView::onTagChange(DocEvent& ev)
{
if (m_previewDelegate)
m_previewDelegate->onTagChangeEditor(m_editor, ev);
}
void DocView::onAddCel(DocEvent& ev)
{
UIContext::instance()->notifyActiveSiteChanged();

View File

@ -30,6 +30,7 @@ namespace app {
virtual void onScrollOtherEditor(Editor* editor) = 0;
virtual void onDisposeOtherEditor(Editor* editor) = 0;
virtual void onPreviewOtherEditor(Editor* editor) = 0;
virtual void onTagChangeEditor(Editor* editor, DocEvent& ev) = 0;
};
class DocView : public ui::Box,
@ -75,6 +76,7 @@ namespace app {
void onAddLayer(DocEvent& ev) override;
void onAddFrame(DocEvent& ev) override;
void onRemoveFrame(DocEvent& ev) override;
void onTagChange(DocEvent& ev) override;
void onAddCel(DocEvent& ev) override;
void onRemoveCel(DocEvent& ev) override;
void onTotalFramesChanged(DocEvent& ev) override;

View File

@ -51,6 +51,11 @@ PlayState::PlayState(const bool playOnce,
&PlayState::onBeforeCommandExecution, this);
}
Tag* PlayState::playingTag() const
{
return m_tag;
}
void PlayState::onEnterState(Editor* editor)
{
StateWithWheelBehavior::onEnterState(editor);

View File

@ -1,4 +1,5 @@
// Aseprite
// Copyright (C) 2020 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
@ -27,6 +28,8 @@ namespace app {
PlayState(const bool playOnce,
const bool playAll);
doc::Tag* playingTag() const;
void onEnterState(Editor* editor) override;
LeaveAction onLeaveState(Editor* editor, EditorState* newState) override;
bool onMouseDown(Editor* editor, ui::MouseMessage* msg) override;

View File

@ -13,6 +13,7 @@
#include "app/app.h"
#include "app/doc.h"
#include "app/doc_event.h"
#include "app/ini_file.h"
#include "app/loop_tag.h"
#include "app/modules/editors.h"
@ -22,6 +23,7 @@
#include "app/ui/editor/editor_customization_delegate.h"
#include "app/ui/editor/editor_view.h"
#include "app/ui/editor/navigate_state.h"
#include "app/ui/editor/play_state.h"
#include "app/ui/skin/skin_theme.h"
#include "app/ui/status_bar.h"
#include "app/ui/toolbar.h"
@ -396,28 +398,7 @@ void PreviewEditorWindow::updateUsingEditor(Editor* editor)
miniEditor->setFrame(editor->frame());
}
else {
if (miniEditor->isPlaying()) {
doc::Tag* tag = editor
->getCustomizationDelegate()
->getTagProvider()
->getTagByFrame(editor->frame(), true);
doc::Tag* playingTag = editor
->getCustomizationDelegate()
->getTagProvider()
->getTagByFrame(m_refFrame, true);
if (tag == playingTag)
return;
miniEditor->stop();
}
if (!miniEditor->isPlaying())
miniEditor->setFrame(m_refFrame = editor->frame());
miniEditor->play(Preferences::instance().preview.playOnce(),
Preferences::instance().preview.playAll());
adjustPlayingTag();
}
}
@ -478,6 +459,11 @@ void PreviewEditorWindow::onPreviewOtherEditor(Editor* editor)
updateUsingEditor(editor);
}
void PreviewEditorWindow::onTagChangeEditor(Editor* editor, DocEvent& ev)
{
adjustPlayingTag();
}
void PreviewEditorWindow::hideWindow()
{
destroyDocView();
@ -495,4 +481,34 @@ void PreviewEditorWindow::destroyDocView()
}
}
void PreviewEditorWindow::adjustPlayingTag()
{
Editor* editor = m_relatedEditor;
Editor* miniEditor = m_docView->editor();
ASSERT(editor);
ASSERT(miniEditor);
if (miniEditor->isPlaying()) {
doc::Tag* tag = editor
->getCustomizationDelegate()
->getTagProvider()
->getTagByFrame(editor->frame(), true);
auto playState = dynamic_cast<PlayState*>(miniEditor->getState().get());
doc::Tag* playingTag = (playState ? playState->playingTag(): nullptr);
if (tag == playingTag)
return;
miniEditor->stop();
}
if (!miniEditor->isPlaying())
miniEditor->setFrame(m_refFrame = editor->frame());
miniEditor->play(Preferences::instance().preview.playOnce(),
Preferences::instance().preview.playAll());
}
} // namespace app

View File

@ -1,4 +1,5 @@
// Aseprite
// Copyright (C) 2020 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -42,6 +43,7 @@ namespace app {
void onScrollOtherEditor(Editor* editor) override;
void onDisposeOtherEditor(Editor* editor) override;
void onPreviewOtherEditor(Editor* editor) override;
void onTagChangeEditor(Editor* editor, DocEvent& ev) override;
protected:
bool onProcessMessage(ui::Message* msg) override;
@ -59,6 +61,7 @@ namespace app {
void hideWindow();
void destroyDocView();
void saveScrollPref();
void adjustPlayingTag();
bool m_isEnabled;
DocView* m_docView;