mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-11 18:41:05 +00:00
[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:
parent
d329f38075
commit
c26351712a
@ -1,5 +1,5 @@
|
|||||||
// Aseprite
|
// Aseprite
|
||||||
// Copyright (C) 2018-2022 Igara Studio S.A.
|
// Copyright (C) 2018-2023 Igara Studio S.A.
|
||||||
// Copyright (C) 2001-2018 David Capello
|
// Copyright (C) 2001-2018 David Capello
|
||||||
//
|
//
|
||||||
// This program is distributed under the terms of
|
// This program is distributed under the terms of
|
||||||
@ -127,6 +127,12 @@ namespace app {
|
|||||||
obs::signal<void()> ColorSpaceChange;
|
obs::signal<void()> ColorSpaceChange;
|
||||||
obs::signal<void()> PalettePresetsChange;
|
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:
|
private:
|
||||||
class CoreModules;
|
class CoreModules;
|
||||||
class LoadLanguage;
|
class LoadLanguage;
|
||||||
|
@ -158,6 +158,7 @@ public:
|
|||||||
BgColorChange,
|
BgColorChange,
|
||||||
BeforeCommand,
|
BeforeCommand,
|
||||||
AfterCommand,
|
AfterCommand,
|
||||||
|
BeforePaintEmptyTilemap,
|
||||||
};
|
};
|
||||||
|
|
||||||
AppEvents() {
|
AppEvents() {
|
||||||
@ -174,6 +175,8 @@ public:
|
|||||||
return BeforeCommand;
|
return BeforeCommand;
|
||||||
else if (std::strcmp(eventName, "aftercommand") == 0)
|
else if (std::strcmp(eventName, "aftercommand") == 0)
|
||||||
return AfterCommand;
|
return AfterCommand;
|
||||||
|
else if (std::strcmp(eventName, "beforepaintemptytilemap") == 0)
|
||||||
|
return BeforePaintEmptyTilemap;
|
||||||
else
|
else
|
||||||
return Unknown;
|
return Unknown;
|
||||||
}
|
}
|
||||||
@ -181,7 +184,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
void onAddFirstListener(EventType eventType) override {
|
void onAddFirstListener(EventType eventType) override {
|
||||||
auto ctx = App::instance()->context();
|
auto app = App::instance();
|
||||||
|
auto ctx = app->context();
|
||||||
auto& pref = Preferences::instance();
|
auto& pref = Preferences::instance();
|
||||||
switch (eventType) {
|
switch (eventType) {
|
||||||
case SiteChange:
|
case SiteChange:
|
||||||
@ -203,6 +207,10 @@ private:
|
|||||||
m_afterCmdConn = ctx->AfterCommandExecution
|
m_afterCmdConn = ctx->AfterCommandExecution
|
||||||
.connect(&AppEvents::onAfterCommand, this);
|
.connect(&AppEvents::onAfterCommand, this);
|
||||||
break;
|
break;
|
||||||
|
case BeforePaintEmptyTilemap:
|
||||||
|
m_beforePaintConn = app->BeforePaintEmptyTilemap
|
||||||
|
.connect(&AppEvents::onBeforePaintEmptyTilemap, this);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,6 +231,9 @@ private:
|
|||||||
case AfterCommand:
|
case AfterCommand:
|
||||||
m_afterCmdConn.disconnect();
|
m_afterCmdConn.disconnect();
|
||||||
break;
|
break;
|
||||||
|
case BeforePaintEmptyTilemap:
|
||||||
|
m_beforePaintConn.disconnect();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,6 +264,10 @@ private:
|
|||||||
{ "params", ev.params() } });
|
{ "params", ev.params() } });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void onBeforePaintEmptyTilemap() {
|
||||||
|
call(BeforePaintEmptyTilemap);
|
||||||
|
}
|
||||||
|
|
||||||
// ContextObserver impl
|
// ContextObserver impl
|
||||||
void onActiveSiteChange(const Site& site) override {
|
void onActiveSiteChange(const Site& site) override {
|
||||||
const bool fromUndo = (site.document() &&
|
const bool fromUndo = (site.document() &&
|
||||||
@ -264,6 +279,7 @@ private:
|
|||||||
obs::scoped_connection m_bgConn;
|
obs::scoped_connection m_bgConn;
|
||||||
obs::scoped_connection m_beforeCmdConn;
|
obs::scoped_connection m_beforeCmdConn;
|
||||||
obs::scoped_connection m_afterCmdConn;
|
obs::scoped_connection m_afterCmdConn;
|
||||||
|
obs::scoped_connection m_beforePaintConn;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SpriteEvents : public Events
|
class SpriteEvents : public Events
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Aseprite
|
// Aseprite
|
||||||
// Copyright (C) 2018-2022 Igara Studio S.A.
|
// Copyright (C) 2018-2023 Igara Studio S.A.
|
||||||
// Copyright (C) 2001-2018 David Capello
|
// Copyright (C) 2001-2018 David Capello
|
||||||
//
|
//
|
||||||
// This program is distributed under the terms of
|
// This program is distributed under the terms of
|
||||||
@ -645,7 +645,15 @@ DrawingState* StandbyState::startDrawingState(
|
|||||||
if (editor->layer()->isTilemap() &&
|
if (editor->layer()->isTilemap() &&
|
||||||
editor->sprite()->hasTileManagementPlugin() &&
|
editor->sprite()->hasTileManagementPlugin() &&
|
||||||
!editor->layer()->cel(editor->frame())) {
|
!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
|
// We need to clear and redraw the brush boundaries after the
|
||||||
// first mouse pressed/point shape if drawn. This is to avoid
|
// first mouse pressed/point shape if drawn. This is to avoid
|
||||||
|
Loading…
x
Reference in New Issue
Block a user