mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-29 21:33:12 +00:00
Merge branch 'fix-export-layers-same-name'
This commit is contained in:
commit
05dd5f8db7
@ -485,6 +485,7 @@
|
||||
<option id="filename" type="std::string" />
|
||||
<option id="resize_scale" type="double" default="1" />
|
||||
<option id="layer" type="std::string" />
|
||||
<option id="layer_index" type="int" default ="-1" />
|
||||
<option id="frame_tag" type="std::string" />
|
||||
<option id="ani_dir" type="doc::AniDir" default="doc::AniDir::FORWARD" />
|
||||
<option id="apply_pixel_ratio" type="bool" default="false" />
|
||||
@ -512,6 +513,7 @@
|
||||
<option id="ignore_empty" type="bool" default="false" />
|
||||
<option id="open_generated" type="bool" default="false" />
|
||||
<option id="layer" type="std::string" />
|
||||
<option id="layer_index" type="int" default ="-1" />
|
||||
<option id="frame_tag" type="std::string" />
|
||||
<option id="split_layers" type="bool" default="false" />
|
||||
<option id="split_tags" type="bool" default="false" />
|
||||
|
@ -76,6 +76,12 @@ struct ExportSpriteSheetParams : public NewParams {
|
||||
Param<bool> mergeDuplicates { this, false, "mergeDuplicates" };
|
||||
Param<bool> openGenerated { this, false, "openGenerated" };
|
||||
Param<std::string> layer { this, std::string(), "layer" };
|
||||
// TODO The layerIndex parameter is for internal use only, layers
|
||||
// are counted in the same order as they are displayed in the
|
||||
// Timeline or in the Export Sprite Sheet combobox. But this
|
||||
// index is different to the one specified in the .aseprite
|
||||
// file spec (where layers are counted from bottom to top).
|
||||
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 +188,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 +219,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 +384,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 +540,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 +725,11 @@ private:
|
||||
return layers()->getValue();
|
||||
}
|
||||
|
||||
int layerIndex() const {
|
||||
int i = layers()->getSelectedItemIndex() - kLayersComboboxExtraInitialItems;
|
||||
return i < 0 ? -1 : i;
|
||||
}
|
||||
|
||||
std::string tagValue() const {
|
||||
return frames()->getValue();
|
||||
}
|
||||
@ -1235,6 +1251,7 @@ void ExportSpriteSheetCommand::onExecute(Context* context)
|
||||
if (!params.ignoreEmpty.isSet()) params.ignoreEmpty( defPref.spriteSheet.ignoreEmpty());
|
||||
if (!params.openGenerated.isSet()) params.openGenerated( defPref.spriteSheet.openGenerated());
|
||||
if (!params.layer.isSet()) params.layer( defPref.spriteSheet.layer());
|
||||
if (!params.layerIndex.isSet()) params.layerIndex( defPref.spriteSheet.layerIndex());
|
||||
if (!params.tag.isSet()) params.tag( defPref.spriteSheet.frameTag());
|
||||
if (!params.splitLayers.isSet()) params.splitLayers( defPref.spriteSheet.splitLayers());
|
||||
if (!params.splitTags.isSet()) params.splitTags( defPref.spriteSheet.splitTags());
|
||||
@ -1281,6 +1298,7 @@ void ExportSpriteSheetCommand::onExecute(Context* context)
|
||||
docPref.spriteSheet.ignoreEmpty (params.ignoreEmpty());
|
||||
docPref.spriteSheet.openGenerated (params.openGenerated());
|
||||
docPref.spriteSheet.layer (params.layer());
|
||||
docPref.spriteSheet.layerIndex (params.layerIndex());
|
||||
docPref.spriteSheet.frameTag (params.tag());
|
||||
docPref.spriteSheet.splitLayers (params.splitLayers());
|
||||
docPref.spriteSheet.splitTags (params.splitTags());
|
||||
|
@ -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(), m_docPref.saveCopy.layerIndex());
|
||||
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());
|
||||
@ -98,6 +98,7 @@ void ExportFileWindow::savePref()
|
||||
m_docPref.saveCopy.filename(outputFilenameValue());
|
||||
m_docPref.saveCopy.resizeScale(resizeValue());
|
||||
m_docPref.saveCopy.layer(layersValue());
|
||||
m_docPref.saveCopy.layerIndex(layersIndex());
|
||||
m_docPref.saveCopy.aniDir(aniDirValue());
|
||||
m_docPref.saveCopy.frameTag(framesValue());
|
||||
m_docPref.saveCopy.applyPixelRatio(applyPixelRatio());
|
||||
@ -121,6 +122,12 @@ std::string ExportFileWindow::layersValue() const
|
||||
return layers()->getValue();
|
||||
}
|
||||
|
||||
int ExportFileWindow::layersIndex() const
|
||||
{
|
||||
int i = layers()->getSelectedItemIndex() - kLayersComboboxExtraInitialItems;
|
||||
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);
|
||||
@ -67,11 +67,16 @@ void fill_layers_combobox(const doc::Sprite* sprite, ui::ComboBox* layers, const
|
||||
if (defLayer == kSelectedLayers)
|
||||
layers->setSelectedItemIndex(i);
|
||||
|
||||
assert(layers->getItemCount() == kLayersComboboxExtraInitialItems);
|
||||
static_assert(kLayersComboboxExtraInitialItems == 2,
|
||||
"Update kLayersComboboxExtraInitialItems value to match the number of initial items in layers combobox");
|
||||
|
||||
doc::LayerList layersList = sprite->allLayers();
|
||||
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-kLayersComboboxExtraInitialItems)
|
||||
layers->setSelectedItemIndex(i);
|
||||
}
|
||||
}
|
||||
@ -112,6 +117,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 +130,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;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2019 Igara Studio S.A.
|
||||
// Copyright (C) 2019-2022 Igara Studio S.A.
|
||||
// Copyright (C) 2016-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -35,6 +35,8 @@ namespace app {
|
||||
extern const char* kSelectedLayers;
|
||||
extern const char* kSelectedFrames;
|
||||
|
||||
constexpr const int kLayersComboboxExtraInitialItems = 2;
|
||||
|
||||
class LayerListItem : public ui::ListItem {
|
||||
public:
|
||||
LayerListItem(doc::Layer* layer);
|
||||
@ -52,12 +54,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