mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-02 13:14:01 +00:00
Add option to specify/modify the tileset name
This commit is contained in:
parent
0cf28840b5
commit
26b75bdb57
@ -1024,6 +1024,8 @@ default_new_layer_name = New Layer
|
|||||||
new_tileset = New Tileset
|
new_tileset = New Tileset
|
||||||
grid_width = Grid Width:
|
grid_width = Grid Width:
|
||||||
grid_height = Grid Height:
|
grid_height = Grid Height:
|
||||||
|
name = Name:
|
||||||
|
default_name = Tileset
|
||||||
base_index = Base Index:
|
base_index = Base Index:
|
||||||
base_tooltip = <<<END
|
base_tooltip = <<<END
|
||||||
Visible aid to see the first tile with content from the tileset
|
Visible aid to see the first tile with content from the tileset
|
||||||
|
@ -6,10 +6,12 @@
|
|||||||
<listitem text="@.new_tileset" value="-1" />
|
<listitem text="@.new_tileset" value="-1" />
|
||||||
</combobox>
|
</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" />
|
<label text="@.grid_width" />
|
||||||
<expr id="grid_width" text="" />
|
<expr id="grid_width" text="" />
|
||||||
|
|
||||||
<label text="@.grid_height" />
|
<label text="@.grid_height" />
|
||||||
<expr id="grid_height" text="" />
|
<expr id="grid_height" text="" />
|
||||||
|
|
||||||
|
@ -489,6 +489,7 @@ add_library(app-lib
|
|||||||
cmd/set_tag_name.cpp
|
cmd/set_tag_name.cpp
|
||||||
cmd/set_tag_range.cpp
|
cmd/set_tag_range.cpp
|
||||||
cmd/set_tileset_base_index.cpp
|
cmd/set_tileset_base_index.cpp
|
||||||
|
cmd/set_tileset_name.cpp
|
||||||
cmd/set_total_frames.cpp
|
cmd/set_total_frames.cpp
|
||||||
cmd/set_transparent_color.cpp
|
cmd/set_transparent_color.cpp
|
||||||
cmd/set_user_data.cpp
|
cmd/set_user_data.cpp
|
||||||
|
44
src/app/cmd/set_tileset_name.cpp
Normal file
44
src/app/cmd/set_tileset_name.cpp
Normal 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
|
40
src/app/cmd/set_tileset_name.h
Normal file
40
src/app/cmd/set_tileset_name.h
Normal 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
|
@ -14,6 +14,7 @@
|
|||||||
#include "app/cmd/set_layer_name.h"
|
#include "app/cmd/set_layer_name.h"
|
||||||
#include "app/cmd/set_layer_opacity.h"
|
#include "app/cmd/set_layer_opacity.h"
|
||||||
#include "app/cmd/set_tileset_base_index.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/cmd/set_user_data.h"
|
||||||
#include "app/commands/command.h"
|
#include "app/commands/command.h"
|
||||||
#include "app/console.h"
|
#include "app/console.h"
|
||||||
@ -336,32 +337,35 @@ private:
|
|||||||
tilesetInfo.enabled = false;
|
tilesetInfo.enabled = false;
|
||||||
tilesetInfo.newTileset = false;
|
tilesetInfo.newTileset = false;
|
||||||
tilesetInfo.grid = tileset->grid();
|
tilesetInfo.grid = tileset->grid();
|
||||||
|
tilesetInfo.name = tileset->name();
|
||||||
tilesetInfo.baseIndex = tileset->baseIndex();
|
tilesetInfo.baseIndex = tileset->baseIndex();
|
||||||
tilesetInfo.tsi = tilemap->tilesetIndex();
|
tilesetInfo.tsi = tilemap->tilesetIndex();
|
||||||
|
|
||||||
gen::TilesetSelectorWindow window;
|
try {
|
||||||
TilesetSelector tilesetSel(tilemap->sprite(), tilesetInfo);
|
gen::TilesetSelectorWindow window;
|
||||||
window.tilesetOptions()->addChild(&tilesetSel);
|
TilesetSelector tilesetSel(tilemap->sprite(), tilesetInfo);
|
||||||
window.openWindowInForeground();
|
window.tilesetOptions()->addChild(&tilesetSel);
|
||||||
if (window.closer() != window.ok())
|
window.openWindowInForeground();
|
||||||
return;
|
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->name() != tilesetInfo.name ||
|
||||||
|
tileset->baseIndex() != tilesetInfo.baseIndex) {
|
||||||
if (tileset->baseIndex() != tilesetInfo.baseIndex) {
|
|
||||||
try {
|
|
||||||
ContextWriter writer(UIContext::instance());
|
ContextWriter writer(UIContext::instance());
|
||||||
Tx tx(writer.context(), "Set Base Index");
|
Tx tx(writer.context(), "Set Tileset Properties");
|
||||||
tx(new cmd::SetTilesetBaseIndex(tileset, tilesetInfo.baseIndex));
|
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
|
// TODO catch the tileset base index modification from the editor
|
||||||
App::instance()->mainWindow()->invalidate();
|
App::instance()->mainWindow()->invalidate();
|
||||||
tx.commit();
|
tx.commit();
|
||||||
}
|
}
|
||||||
catch (const std::exception& e) {
|
}
|
||||||
Console::showException(e);
|
catch (const std::exception& e) {
|
||||||
}
|
Console::showException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,6 +85,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
void adjustRefCelBounds(Cel* cel, gfx::RectF bounds);
|
void adjustRefCelBounds(Cel* cel, gfx::RectF bounds);
|
||||||
std::string getUniqueLayerName(const Sprite* sprite) const;
|
std::string getUniqueLayerName(const Sprite* sprite) const;
|
||||||
|
std::string getUniqueTilesetName(const Sprite* sprite) const;
|
||||||
int getMaxLayerNum(const Layer* layer) const;
|
int getMaxLayerNum(const Layer* layer) const;
|
||||||
std::string layerPrefix() const;
|
std::string layerPrefix() const;
|
||||||
|
|
||||||
@ -269,6 +270,7 @@ void NewLayerCommand::onExecute(Context* context)
|
|||||||
if (tilesetInfo.newTileset) {
|
if (tilesetInfo.newTileset) {
|
||||||
auto tileset = new Tileset(sprite, tilesetInfo.grid, 1);
|
auto tileset = new Tileset(sprite, tilesetInfo.grid, 1);
|
||||||
tileset->setBaseIndex(tilesetInfo.baseIndex);
|
tileset->setBaseIndex(tilesetInfo.baseIndex);
|
||||||
|
tileset->setName(tilesetInfo.name);
|
||||||
|
|
||||||
auto addTileset = new cmd::AddTileset(sprite, tileset);
|
auto addTileset = new cmd::AddTileset(sprite, tileset);
|
||||||
tx(addTileset);
|
tx(addTileset);
|
||||||
@ -515,6 +517,13 @@ std::string NewLayerCommand::getUniqueLayerName(const Sprite* sprite) const
|
|||||||
getMaxLayerNum(sprite->root())+1);
|
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
|
int NewLayerCommand::getMaxLayerNum(const Layer* layer) const
|
||||||
{
|
{
|
||||||
std::string prefix = layerPrefix();
|
std::string prefix = layerPrefix();
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include "app/ui/tileset_selector.h"
|
#include "app/ui/tileset_selector.h"
|
||||||
|
|
||||||
|
#include "app/i18n/strings.h"
|
||||||
#include "doc/sprite.h"
|
#include "doc/sprite.h"
|
||||||
#include "doc/tilesets.h"
|
#include "doc/tilesets.h"
|
||||||
#include "fmt/format.h"
|
#include "fmt/format.h"
|
||||||
@ -25,6 +26,7 @@ TilesetSelector::TilesetSelector(const doc::Sprite* sprite,
|
|||||||
{
|
{
|
||||||
initTheme();
|
initTheme();
|
||||||
|
|
||||||
|
name()->setText(info.name);
|
||||||
gridWidth()->setTextf("%d", info.grid.tileSize().w);
|
gridWidth()->setTextf("%d", info.grid.tileSize().w);
|
||||||
gridHeight()->setTextf("%d", info.grid.tileSize().h);
|
gridHeight()->setTextf("%d", info.grid.tileSize().h);
|
||||||
baseIndex()->setTextf("%d", info.baseIndex);
|
baseIndex()->setTextf("%d", info.baseIndex);
|
||||||
@ -45,21 +47,36 @@ TilesetSelector::TilesetSelector(const doc::Sprite* sprite,
|
|||||||
++tsi;
|
++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);
|
tilesets()->setEnabled(false);
|
||||||
gridWidth()->setEnabled(false);
|
gridWidth()->setEnabled(false);
|
||||||
gridHeight()->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()
|
TilesetSelector::Info TilesetSelector::getInfo()
|
||||||
@ -77,6 +94,7 @@ TilesetSelector::Info TilesetSelector::getInfo()
|
|||||||
info.newTileset = false;
|
info.newTileset = false;
|
||||||
info.tsi = itemIndex-1;
|
info.tsi = itemIndex-1;
|
||||||
}
|
}
|
||||||
|
info.name = name()->text();
|
||||||
info.baseIndex = baseIndex()->textInt();
|
info.baseIndex = baseIndex()->textInt();
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
#include "doc/grid.h"
|
#include "doc/grid.h"
|
||||||
#include "doc/tile.h"
|
#include "doc/tile.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "tileset_selector.xml.h"
|
#include "tileset_selector.xml.h"
|
||||||
|
|
||||||
namespace doc {
|
namespace doc {
|
||||||
@ -25,6 +27,7 @@ namespace app {
|
|||||||
struct Info {
|
struct Info {
|
||||||
bool enabled = true;
|
bool enabled = true;
|
||||||
bool newTileset = true;
|
bool newTileset = true;
|
||||||
|
std::string name;
|
||||||
doc::Grid grid;
|
doc::Grid grid;
|
||||||
int baseIndex = 1;
|
int baseIndex = 1;
|
||||||
doc::tileset_index tsi = -1;
|
doc::tileset_index tsi = -1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user