[lua] Add new 'beforepaintemptytilemap' app event

Now a tileManagementPlugin can customize the creation of empty tiles
when the user starts drawing on an empty cel.

To implement: https://github.com/aseprite/Attachment-System/issues/119
Related to: https://github.com/aseprite/Attachment-System/issues/127
This commit is contained in:
David Capello 2023-05-18 12:40:12 -03:00
parent d329f38075
commit c26351712a
3 changed files with 34 additions and 4 deletions

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018-2022 Igara Studio S.A.
// Copyright (C) 2018-2023 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -127,6 +127,12 @@ namespace app {
obs::signal<void()> ColorSpaceChange;
obs::signal<void()> PalettePresetsChange;
// Signal triggered for TileManagementPlugin that want to create a
// tile on-the-fly when the active tilemap cel is empty (it's like
// a way to customize the "tilemap/tileset", instead of
// Manual/Auto/Semi, the plugin can offer a custom behavior).
obs::signal<void()> BeforePaintEmptyTilemap;
private:
class CoreModules;
class LoadLanguage;

View File

@ -158,6 +158,7 @@ public:
BgColorChange,
BeforeCommand,
AfterCommand,
BeforePaintEmptyTilemap,
};
AppEvents() {
@ -174,6 +175,8 @@ public:
return BeforeCommand;
else if (std::strcmp(eventName, "aftercommand") == 0)
return AfterCommand;
else if (std::strcmp(eventName, "beforepaintemptytilemap") == 0)
return BeforePaintEmptyTilemap;
else
return Unknown;
}
@ -181,7 +184,8 @@ public:
private:
void onAddFirstListener(EventType eventType) override {
auto ctx = App::instance()->context();
auto app = App::instance();
auto ctx = app->context();
auto& pref = Preferences::instance();
switch (eventType) {
case SiteChange:
@ -203,6 +207,10 @@ private:
m_afterCmdConn = ctx->AfterCommandExecution
.connect(&AppEvents::onAfterCommand, this);
break;
case BeforePaintEmptyTilemap:
m_beforePaintConn = app->BeforePaintEmptyTilemap
.connect(&AppEvents::onBeforePaintEmptyTilemap, this);
break;
}
}
@ -223,6 +231,9 @@ private:
case AfterCommand:
m_afterCmdConn.disconnect();
break;
case BeforePaintEmptyTilemap:
m_beforePaintConn.disconnect();
break;
}
}
@ -253,6 +264,10 @@ private:
{ "params", ev.params() } });
}
void onBeforePaintEmptyTilemap() {
call(BeforePaintEmptyTilemap);
}
// ContextObserver impl
void onActiveSiteChange(const Site& site) override {
const bool fromUndo = (site.document() &&
@ -264,6 +279,7 @@ private:
obs::scoped_connection m_bgConn;
obs::scoped_connection m_beforeCmdConn;
obs::scoped_connection m_afterCmdConn;
obs::scoped_connection m_beforePaintConn;
};
class SpriteEvents : public Events

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018-2022 Igara Studio S.A.
// Copyright (C) 2018-2023 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -645,7 +645,15 @@ DrawingState* StandbyState::startDrawingState(
if (editor->layer()->isTilemap() &&
editor->sprite()->hasTileManagementPlugin() &&
!editor->layer()->cel(editor->frame())) {
return nullptr;
// Trigger event so the plugin can create a cel on-the-fly
App::instance()->BeforePaintEmptyTilemap();
if (!editor->layer() ||
!editor->layer()->cel(editor->frame())) {
return nullptr;
}
// In other case, it looks like PaintEmptyTilemap event created
// the cel...
}
// We need to clear and redraw the brush boundaries after the
// first mouse pressed/point shape if drawn. This is to avoid