Add option to specify/modify the tileset name

This commit is contained in:
David Capello 2020-11-10 17:48:09 -03:00
parent 0cf28840b5
commit 26b75bdb57
9 changed files with 152 additions and 29 deletions

View File

@ -1024,6 +1024,8 @@ default_new_layer_name = New Layer
new_tileset = New Tileset
grid_width = Grid Width:
grid_height = Grid Height:
name = Name:
default_name = Tileset
base_index = Base Index:
base_tooltip = <<<END
Visible aid to see the first tile with content from the tileset

View File

@ -6,10 +6,12 @@
<listitem text="@.new_tileset" value="-1" />
</combobox>
<grid id="grid_options" columns="4">
<grid columns="4" expansive="true">
<label text="@.name" />
<entry maxsize="256" id="name" text="" cell_hspan="3" />
<label text="@.grid_width" />
<expr id="grid_width" text="" />
<label text="@.grid_height" />
<expr id="grid_height" text="" />

View File

@ -489,6 +489,7 @@ add_library(app-lib
cmd/set_tag_name.cpp
cmd/set_tag_range.cpp
cmd/set_tileset_base_index.cpp
cmd/set_tileset_name.cpp
cmd/set_total_frames.cpp
cmd/set_transparent_color.cpp
cmd/set_user_data.cpp

View File

@ -0,0 +1,44 @@
// Aseprite
// Copyright (C) 2020 Igara Studio S.A.
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "app/cmd/set_tileset_name.h"
#include "app/doc.h"
#include "app/doc_event.h"
#include "doc/tileset.h"
namespace app {
namespace cmd {
SetTilesetName::SetTilesetName(Tileset* tileset, const std::string& name)
: WithTileset(tileset)
, m_oldName(tileset->name())
, m_newName(name)
{
}
void SetTilesetName::onExecute()
{
auto ts = tileset();
ts->setName(m_newName);
ts->incrementVersion();
ts->sprite()->incrementVersion();
}
void SetTilesetName::onUndo()
{
auto ts = tileset();
ts->setName(m_oldName);
ts->incrementVersion();
ts->sprite()->incrementVersion();
}
} // namespace cmd
} // namespace app

View File

@ -0,0 +1,40 @@
// Aseprite
// Copyright (C) 2020 Igara Studio S.A.
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
#ifndef APP_CMD_SET_TILESET_NAME_H_INCLUDED
#define APP_CMD_SET_TILESET_NAME_H_INCLUDED
#pragma once
#include "app/cmd.h"
#include "app/cmd/with_tileset.h"
#include <string>
namespace app {
namespace cmd {
using namespace doc;
class SetTilesetName : public Cmd
, public WithTileset {
public:
SetTilesetName(Tileset* tileset, const std::string& name);
protected:
void onExecute() override;
void onUndo() override;
size_t onMemSize() const override {
return sizeof(*this);
}
private:
std::string m_oldName;
std::string m_newName;
};
} // namespace cmd
} // namespace app
#endif

View File

@ -14,6 +14,7 @@
#include "app/cmd/set_layer_name.h"
#include "app/cmd/set_layer_opacity.h"
#include "app/cmd/set_tileset_base_index.h"
#include "app/cmd/set_tileset_name.h"
#include "app/cmd/set_user_data.h"
#include "app/commands/command.h"
#include "app/console.h"
@ -336,32 +337,35 @@ private:
tilesetInfo.enabled = false;
tilesetInfo.newTileset = false;
tilesetInfo.grid = tileset->grid();
tilesetInfo.name = tileset->name();
tilesetInfo.baseIndex = tileset->baseIndex();
tilesetInfo.tsi = tilemap->tilesetIndex();
gen::TilesetSelectorWindow window;
TilesetSelector tilesetSel(tilemap->sprite(), tilesetInfo);
window.tilesetOptions()->addChild(&tilesetSel);
window.openWindowInForeground();
if (window.closer() != window.ok())
return;
try {
gen::TilesetSelectorWindow window;
TilesetSelector tilesetSel(tilemap->sprite(), tilesetInfo);
window.tilesetOptions()->addChild(&tilesetSel);
window.openWindowInForeground();
if (window.closer() != window.ok())
return;
tilesetInfo = tilesetSel.getInfo();
tilesetInfo = tilesetSel.getInfo();
// TODO add options to change the tileset index, grid size, etc.
if (tileset->baseIndex() != tilesetInfo.baseIndex) {
try {
if (tileset->name() != tilesetInfo.name ||
tileset->baseIndex() != tilesetInfo.baseIndex) {
ContextWriter writer(UIContext::instance());
Tx tx(writer.context(), "Set Base Index");
tx(new cmd::SetTilesetBaseIndex(tileset, tilesetInfo.baseIndex));
Tx tx(writer.context(), "Set Tileset Properties");
if (tileset->name() != tilesetInfo.name)
tx(new cmd::SetTilesetName(tileset, tilesetInfo.name));
if (tileset->baseIndex() != tilesetInfo.baseIndex)
tx(new cmd::SetTilesetBaseIndex(tileset, tilesetInfo.baseIndex));
// TODO catch the tileset base index modification from the editor
App::instance()->mainWindow()->invalidate();
tx.commit();
}
catch (const std::exception& e) {
Console::showException(e);
}
}
catch (const std::exception& e) {
Console::showException(e);
}
}

View File

@ -85,6 +85,7 @@ protected:
private:
void adjustRefCelBounds(Cel* cel, gfx::RectF bounds);
std::string getUniqueLayerName(const Sprite* sprite) const;
std::string getUniqueTilesetName(const Sprite* sprite) const;
int getMaxLayerNum(const Layer* layer) const;
std::string layerPrefix() const;
@ -269,6 +270,7 @@ void NewLayerCommand::onExecute(Context* context)
if (tilesetInfo.newTileset) {
auto tileset = new Tileset(sprite, tilesetInfo.grid, 1);
tileset->setBaseIndex(tilesetInfo.baseIndex);
tileset->setName(tilesetInfo.name);
auto addTileset = new cmd::AddTileset(sprite, tileset);
tx(addTileset);
@ -515,6 +517,13 @@ std::string NewLayerCommand::getUniqueLayerName(const Sprite* sprite) const
getMaxLayerNum(sprite->root())+1);
}
std::string NewLayerCommand::getUniqueTilesetName(const Sprite* sprite) const
{
return fmt::format("{} {}",
Strings::instance()->tileset_selector_default_name(),
sprite->tilesets()->size()+1);
}
int NewLayerCommand::getMaxLayerNum(const Layer* layer) const
{
std::string prefix = layerPrefix();

View File

@ -10,6 +10,7 @@
#include "app/ui/tileset_selector.h"
#include "app/i18n/strings.h"
#include "doc/sprite.h"
#include "doc/tilesets.h"
#include "fmt/format.h"
@ -25,6 +26,7 @@ TilesetSelector::TilesetSelector(const doc::Sprite* sprite,
{
initTheme();
name()->setText(info.name);
gridWidth()->setTextf("%d", info.grid.tileSize().w);
gridHeight()->setTextf("%d", info.grid.tileSize().h);
baseIndex()->setTextf("%d", info.baseIndex);
@ -45,21 +47,36 @@ TilesetSelector::TilesetSelector(const doc::Sprite* sprite,
++tsi;
}
if (!info.enabled) {
if (info.enabled) {
tilesets()->Change.connect(
[this, sprite]() {
int index = tilesets()->getSelectedItemIndex();
bool editable = (index == 0);
if (index == 0) {
name()->setText("");
baseIndex()->setTextf("%d", 1);
}
else {
doc::Tileset* ts = sprite->tilesets()->get(index-1);
doc::Grid grid = ts->grid();
name()->setText(ts->name());
gridWidth()->setTextf("%d", grid.tileSize().w);
gridHeight()->setTextf("%d", grid.tileSize().h);
baseIndex()->setTextf("%d", ts->baseIndex());
}
name()->setEnabled(editable);
gridWidth()->setEnabled(editable);
gridHeight()->setEnabled(editable);
baseIndex()->setEnabled(editable);
});
}
else {
tilesets()->setEnabled(false);
gridWidth()->setEnabled(false);
gridHeight()->setEnabled(false);
}
tilesets()->Change.connect(
[this, sprite]() {
int index = tilesets()->getSelectedItemIndex();
gridOptions()->setVisible(index == 0);
gridOptions()->setVisible(index == 0);
baseIndex()->setTextf(
"%d", (index == 0 ? 1: sprite->tilesets()->get(index-1)->baseIndex()));
this->window()->layout();
});
}
TilesetSelector::Info TilesetSelector::getInfo()
@ -77,6 +94,7 @@ TilesetSelector::Info TilesetSelector::getInfo()
info.newTileset = false;
info.tsi = itemIndex-1;
}
info.name = name()->text();
info.baseIndex = baseIndex()->textInt();
return info;
}

View File

@ -11,6 +11,8 @@
#include "doc/grid.h"
#include "doc/tile.h"
#include <string>
#include "tileset_selector.xml.h"
namespace doc {
@ -25,6 +27,7 @@ namespace app {
struct Info {
bool enabled = true;
bool newTileset = true;
std::string name;
doc::Grid grid;
int baseIndex = 1;
doc::tileset_index tsi = -1;