mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-14 04:19:12 +00:00
Use layer index to avoid conflicts when exporting sprites with layers that have the same name (fix #2656)
This commit is contained in:
parent
03148f9c7c
commit
acdb501fc8
@ -76,6 +76,7 @@ struct ExportSpriteSheetParams : public NewParams {
|
||||
Param<bool> mergeDuplicates { this, false, "mergeDuplicates" };
|
||||
Param<bool> openGenerated { this, false, "openGenerated" };
|
||||
Param<std::string> layer { this, std::string(), "layer" };
|
||||
Param<int> layerIndex { this, -1, "layerIndex" };
|
||||
Param<std::string> tag { this, std::string(), "tag" };
|
||||
Param<bool> splitLayers { this, false, "splitLayers" };
|
||||
Param<bool> splitTags { this, false, "splitTags" };
|
||||
@ -182,6 +183,7 @@ Doc* generate_sprite_sheet_from_params(
|
||||
const SpriteSheetDataFormat dataFormat = params.dataFormat();
|
||||
const std::string filenameFormat = params.filenameFormat();
|
||||
const std::string layerName = params.layer();
|
||||
const int layerIndex = params.layerIndex();
|
||||
const std::string tagName = params.tag();
|
||||
const int borderPadding = std::clamp(params.borderPadding(), 0, 100);
|
||||
const int shapePadding = std::clamp(params.shapePadding(), 0, 100);
|
||||
@ -212,13 +214,16 @@ Doc* generate_sprite_sheet_from_params(
|
||||
// If the user choose to render selected layers only, we can
|
||||
// temporaly make them visible and hide the other ones.
|
||||
RestoreVisibleLayers layersVisibility;
|
||||
calculate_visible_layers(site, layerName, layersVisibility);
|
||||
calculate_visible_layers(site, layerName, layerIndex, layersVisibility);
|
||||
|
||||
SelectedLayers selLayers;
|
||||
if (layerName != kSelectedLayers) {
|
||||
// TODO add a getLayerByName
|
||||
int i = sprite->allLayersCount();
|
||||
for (const Layer* layer : sprite->allLayers()) {
|
||||
if (layer->name() == layerName) {
|
||||
i--;
|
||||
if (layer->name() == layerName && layerIndex == -1 ||
|
||||
layer->name() == layerName && layerIndex == i) {
|
||||
selLayers.insert(const_cast<Layer*>(layer));
|
||||
break;
|
||||
}
|
||||
@ -374,7 +379,7 @@ public:
|
||||
}
|
||||
|
||||
fill_layers_combobox(
|
||||
m_sprite, layers(), params.layer());
|
||||
m_sprite, layers(), params.layer(), params.layerIndex());
|
||||
|
||||
fill_frames_combobox(
|
||||
m_sprite, frames(), params.tag());
|
||||
@ -530,6 +535,7 @@ public:
|
||||
params.ignoreEmpty (ignoreEmptyValue());
|
||||
params.openGenerated (openGeneratedValue());
|
||||
params.layer (layerValue());
|
||||
params.layerIndex (layerIndex());
|
||||
params.tag (tagValue());
|
||||
params.splitLayers (splitLayersValue());
|
||||
params.splitTags (splitTagsValue());
|
||||
@ -714,6 +720,11 @@ private:
|
||||
return layers()->getValue();
|
||||
}
|
||||
|
||||
int layerIndex() const {
|
||||
int i = layers()->getSelectedItemIndex() - 2;
|
||||
return i < 0 ? -1 : i;
|
||||
}
|
||||
|
||||
std::string tagValue() const {
|
||||
return frames()->getValue();
|
||||
}
|
||||
|
@ -343,6 +343,7 @@ void SaveFileCopyAsCommand::onExecute(Context* context)
|
||||
Doc* doc = context->activeDocument();
|
||||
std::string outputFilename = params().filename();
|
||||
std::string layers = kAllLayers;
|
||||
int layersIndex = -1;
|
||||
std::string frames = kAllFrames;
|
||||
bool applyPixelRatio = false;
|
||||
double scale = params().scale();
|
||||
@ -408,6 +409,7 @@ void SaveFileCopyAsCommand::onExecute(Context* context)
|
||||
win.savePref();
|
||||
|
||||
layers = win.layersValue();
|
||||
layersIndex = win.layersIndex();
|
||||
frames = win.framesValue();
|
||||
scale = win.resizeValue();
|
||||
applyPixelRatio = win.applyPixelRatio();
|
||||
@ -464,6 +466,7 @@ void SaveFileCopyAsCommand::onExecute(Context* context)
|
||||
// Selected layers to export
|
||||
calculate_visible_layers(site,
|
||||
layers,
|
||||
layersIndex,
|
||||
layersVisibility);
|
||||
|
||||
// m_selFrames is not empty if fromFrame/toFrame parameters are
|
||||
|
@ -52,7 +52,7 @@ ExportFileWindow::ExportFileWindow(const Doc* doc)
|
||||
|
||||
// Default export configuration
|
||||
setResizeScale(m_docPref.saveCopy.resizeScale());
|
||||
fill_layers_combobox(m_doc->sprite(), layers(), m_docPref.saveCopy.layer());
|
||||
fill_layers_combobox(m_doc->sprite(), layers(), m_docPref.saveCopy.layer(), -1);
|
||||
fill_frames_combobox(m_doc->sprite(), frames(), m_docPref.saveCopy.frameTag());
|
||||
fill_anidir_combobox(anidir(), m_docPref.saveCopy.aniDir());
|
||||
pixelRatio()->setSelected(m_docPref.saveCopy.applyPixelRatio());
|
||||
@ -121,6 +121,12 @@ std::string ExportFileWindow::layersValue() const
|
||||
return layers()->getValue();
|
||||
}
|
||||
|
||||
int ExportFileWindow::layersIndex() const
|
||||
{
|
||||
int i = layers()->getSelectedItemIndex() - 2;
|
||||
return i < 0 ? -1 : i;
|
||||
}
|
||||
|
||||
std::string ExportFileWindow::framesValue() const
|
||||
{
|
||||
return frames()->getValue();
|
||||
|
@ -29,6 +29,7 @@ namespace app {
|
||||
std::string outputFilenameValue() const;
|
||||
double resizeValue() const;
|
||||
std::string layersValue() const;
|
||||
int layersIndex() const;
|
||||
std::string framesValue() const;
|
||||
doc::AniDir aniDirValue() const;
|
||||
bool applyPixelRatio() const;
|
||||
|
@ -57,7 +57,7 @@ FrameListItem::FrameListItem(doc::Tag* tag)
|
||||
setValue(m_tag->name());
|
||||
}
|
||||
|
||||
void fill_layers_combobox(const doc::Sprite* sprite, ui::ComboBox* layers, const std::string& defLayer)
|
||||
void fill_layers_combobox(const doc::Sprite* sprite, ui::ComboBox* layers, const std::string& defLayer, const int defLayerIndex)
|
||||
{
|
||||
int i = layers->addItem("Visible layers");
|
||||
dynamic_cast<ui::ListItem*>(layers->getItem(i))->setValue(kAllLayers);
|
||||
@ -71,7 +71,8 @@ void fill_layers_combobox(const doc::Sprite* sprite, ui::ComboBox* layers, const
|
||||
for (auto it=layersList.rbegin(), end=layersList.rend(); it!=end; ++it) {
|
||||
doc::Layer* layer = *it;
|
||||
i = layers->addItem(new LayerListItem(layer));
|
||||
if (defLayer == layer->name())
|
||||
if (defLayer == layer->name() && defLayerIndex == -1 ||
|
||||
defLayer == layer->name() && defLayerIndex == i-2)
|
||||
layers->setSelectedItemIndex(i);
|
||||
}
|
||||
}
|
||||
@ -112,6 +113,7 @@ void fill_anidir_combobox(ui::ComboBox* anidir, doc::AniDir defAnidir)
|
||||
|
||||
void calculate_visible_layers(const Site& site,
|
||||
const std::string& layersValue,
|
||||
const int layersIndex,
|
||||
RestoreVisibleLayers& layersVisibility)
|
||||
{
|
||||
if (layersValue == kSelectedLayers) {
|
||||
@ -124,10 +126,13 @@ void calculate_visible_layers(const Site& site,
|
||||
layersVisibility.showLayer(const_cast<Layer*>(site.layer()));
|
||||
}
|
||||
}
|
||||
else if (layersValue != kAllFrames) {
|
||||
else if (layersValue != kAllLayers) {
|
||||
int i = site.sprite()->allLayersCount();
|
||||
// TODO add a getLayerByName
|
||||
for (doc::Layer* layer : site.sprite()->allLayers()) {
|
||||
if (layer->name() == layersValue) {
|
||||
i--;
|
||||
if (layer->name() == layersValue && layersIndex == -1 ||
|
||||
layer->name() == layersValue && layersIndex == i) {
|
||||
layersVisibility.showLayer(layer);
|
||||
break;
|
||||
}
|
||||
|
@ -52,12 +52,13 @@ namespace app {
|
||||
doc::Tag* m_tag;
|
||||
};
|
||||
|
||||
void fill_layers_combobox(const doc::Sprite* sprite, ui::ComboBox* layers, const std::string& defLayer);
|
||||
void fill_layers_combobox(const doc::Sprite* sprite, ui::ComboBox* layers, const std::string& defLayer, const int defLayerIndex);
|
||||
void fill_frames_combobox(const doc::Sprite* sprite, ui::ComboBox* frames, const std::string& defFrame);
|
||||
void fill_anidir_combobox(ui::ComboBox* anidir, doc::AniDir defAnidir);
|
||||
|
||||
void calculate_visible_layers(const Site& site,
|
||||
const std::string& layersValue,
|
||||
const int layersIndex,
|
||||
RestoreVisibleLayers& layersVisibility);
|
||||
|
||||
doc::Tag* calculate_selected_frames(const Site& site,
|
||||
|
Loading…
x
Reference in New Issue
Block a user