mirror of
https://github.com/aseprite/aseprite.git
synced 2024-10-03 21:46:20 +00:00
Fix unexpected behavior during multiple cel selection + cel property changes (fix aseprite/aseprite#3886)
Prior to this fix, if a field was modified, all fields were overwritten with the values from the Cel Properties dialog.
This commit is contained in:
parent
daf3e70e9d
commit
0c3d78b4ce
@ -44,6 +44,13 @@ using namespace ui;
|
|||||||
class CelPropertiesWindow;
|
class CelPropertiesWindow;
|
||||||
static CelPropertiesWindow* g_window = nullptr;
|
static CelPropertiesWindow* g_window = nullptr;
|
||||||
|
|
||||||
|
struct CelPropsLastValues {
|
||||||
|
int opacity = 0;
|
||||||
|
int zIndex = 0;
|
||||||
|
color_t color = 0;
|
||||||
|
std::string text = "";
|
||||||
|
};
|
||||||
|
|
||||||
class CelPropertiesWindow : public app::gen::CelProperties,
|
class CelPropertiesWindow : public app::gen::CelProperties,
|
||||||
public ContextObserver,
|
public ContextObserver,
|
||||||
public DocObserver {
|
public DocObserver {
|
||||||
@ -197,10 +204,16 @@ private:
|
|||||||
const int newZIndex = std::clamp<int>(zindexValue(),
|
const int newZIndex = std::clamp<int>(zindexValue(),
|
||||||
std::numeric_limits<int16_t>::min(),
|
std::numeric_limits<int16_t>::min(),
|
||||||
std::numeric_limits<int16_t>::max());
|
std::numeric_limits<int16_t>::max());
|
||||||
const UserData newUserData= m_userDataView.userData();
|
UserData newUserData= m_userDataView.userData();
|
||||||
|
|
||||||
|
const bool opacityChanged = newOpacity != m_lastValues.opacity;
|
||||||
|
const bool zIndexChanged = newZIndex != m_lastValues.zIndex;
|
||||||
|
const bool colorChanged = newUserData.color() != m_lastValues.color;
|
||||||
|
const bool textChanged = newUserData.text() != m_lastValues.text;
|
||||||
|
|
||||||
const int count = countCels();
|
const int count = countCels();
|
||||||
|
|
||||||
if ((count > 1) ||
|
if ((count > 0) ||
|
||||||
(count == 1 && m_cel && (newOpacity != m_cel->opacity() ||
|
(count == 1 && m_cel && (newOpacity != m_cel->opacity() ||
|
||||||
newZIndex != m_cel->zIndex() ||
|
newZIndex != m_cel->zIndex() ||
|
||||||
newUserData != m_cel->data()->userData()))) {
|
newUserData != m_cel->data()->userData()))) {
|
||||||
@ -224,11 +237,17 @@ private:
|
|||||||
// For each unique cel (don't repeat on links)
|
// For each unique cel (don't repeat on links)
|
||||||
for (Cel* cel : sprite->uniqueCels(range.selectedFrames())) {
|
for (Cel* cel : sprite->uniqueCels(range.selectedFrames())) {
|
||||||
if (range.contains(cel->layer())) {
|
if (range.contains(cel->layer())) {
|
||||||
if (!cel->layer()->isBackground() && newOpacity != cel->opacity()) {
|
if (opacityChanged &&
|
||||||
|
!cel->layer()->isBackground() &&
|
||||||
|
newOpacity != cel->opacity()) {
|
||||||
tx(new cmd::SetCelOpacity(cel, newOpacity));
|
tx(new cmd::SetCelOpacity(cel, newOpacity));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newUserData != cel->data()->userData()) {
|
if (newUserData != cel->data()->userData()) {
|
||||||
|
if (!colorChanged)
|
||||||
|
newUserData.setColor(cel->data()->userData().color());
|
||||||
|
if (!textChanged)
|
||||||
|
newUserData.setText(cel->data()->userData().text());
|
||||||
tx(new cmd::SetUserData(cel->data(), newUserData, m_document));
|
tx(new cmd::SetUserData(cel->data(), newUserData, m_document));
|
||||||
|
|
||||||
// Redraw timeline because the cel's user data/color
|
// Redraw timeline because the cel's user data/color
|
||||||
@ -241,6 +260,7 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// For all cels (repeat links)
|
// For all cels (repeat links)
|
||||||
|
if (newZIndex != m_lastValues.zIndex) {
|
||||||
for (Cel* cel : sprite->cels(range.selectedFrames())) {
|
for (Cel* cel : sprite->cels(range.selectedFrames())) {
|
||||||
if (range.contains(cel->layer())) {
|
if (range.contains(cel->layer())) {
|
||||||
if (newZIndex != cel->zIndex()) {
|
if (newZIndex != cel->zIndex()) {
|
||||||
@ -249,6 +269,12 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_lastValues.opacity = newOpacity;
|
||||||
|
m_lastValues.zIndex = newZIndex;
|
||||||
|
m_lastValues.color = newUserData.color();
|
||||||
|
m_lastValues.text = newUserData.text();
|
||||||
|
|
||||||
if (redrawTimeline)
|
if (redrawTimeline)
|
||||||
App::instance()->timeline()->invalidate();
|
App::instance()->timeline()->invalidate();
|
||||||
@ -315,6 +341,12 @@ private:
|
|||||||
int bgCount = 0;
|
int bgCount = 0;
|
||||||
int count = countCels(&bgCount);
|
int count = countCels(&bgCount);
|
||||||
|
|
||||||
|
// Dafault cel values when the active cel is empty
|
||||||
|
m_lastValues.opacity = 0;
|
||||||
|
m_lastValues.zIndex = 0;
|
||||||
|
m_lastValues.color = 0;
|
||||||
|
m_lastValues.text = "";
|
||||||
|
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
if (m_cel) {
|
if (m_cel) {
|
||||||
opacity()->setValue(m_cel->opacity());
|
opacity()->setValue(m_cel->opacity());
|
||||||
@ -322,10 +354,21 @@ private:
|
|||||||
color_t c = m_cel->data()->userData().color();
|
color_t c = m_cel->data()->userData().color();
|
||||||
m_userDataView.color()->setColor(Color::fromRgb(rgba_getr(c), rgba_getg(c), rgba_getb(c), rgba_geta(c)));
|
m_userDataView.color()->setColor(Color::fromRgb(rgba_getr(c), rgba_getg(c), rgba_getb(c), rgba_geta(c)));
|
||||||
m_userDataView.entry()->setText(m_cel->data()->userData().text());
|
m_userDataView.entry()->setText(m_cel->data()->userData().text());
|
||||||
|
// Set last filled values in CelPropertiesWindow
|
||||||
|
m_lastValues.opacity = m_cel->opacity();
|
||||||
|
m_lastValues.zIndex = m_cel->zIndex();
|
||||||
|
m_lastValues.color = m_cel->data()->userData().color();
|
||||||
|
m_lastValues.text = m_cel->data()->userData().text();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
opacity()->setValue(0);
|
||||||
|
zindex()->setText("0");
|
||||||
}
|
}
|
||||||
opacity()->setEnabled(bgCount < count);
|
opacity()->setEnabled(bgCount < count);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
opacity()->setValue(0);
|
||||||
|
zindex()->setText("0");
|
||||||
opacity()->setEnabled(false);
|
opacity()->setEnabled(false);
|
||||||
m_userDataView.setVisible(false, false);
|
m_userDataView.setVisible(false, false);
|
||||||
}
|
}
|
||||||
@ -338,6 +381,7 @@ private:
|
|||||||
DocRange m_range;
|
DocRange m_range;
|
||||||
bool m_selfUpdate = false;
|
bool m_selfUpdate = false;
|
||||||
UserDataView m_userDataView;
|
UserDataView m_userDataView;
|
||||||
|
CelPropsLastValues m_lastValues;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CelPropertiesCommand : public Command {
|
class CelPropertiesCommand : public Command {
|
||||||
|
Loading…
Reference in New Issue
Block a user