mirror of
https://github.com/aseprite/aseprite.git
synced 2025-04-01 01:20:25 +00:00
Minor refactor "first visible index" -> "base index"
This commit is contained in:
parent
c2e5e69882
commit
a3286fc20a
@ -1023,9 +1023,11 @@ default_new_layer_name = New Layer
|
||||
new_tileset = New Tileset
|
||||
grid_width = Grid Width:
|
||||
grid_height = Grid Height:
|
||||
first_visible_index = First Visible Index:
|
||||
first_visible_index_tooltip = <<<END
|
||||
Change how you see the tile of index 1 (you can set it to 0 or any value).
|
||||
base_index = Base Index:
|
||||
base_tooltip = <<<END
|
||||
Visible aid to see the first tile with content from the tileset
|
||||
as index 1 (by default, one-based index) or other value.
|
||||
E.g. you can use 0 here for zero-based indexing.
|
||||
END
|
||||
|
||||
[new_sprite]
|
||||
|
@ -13,9 +13,9 @@
|
||||
<label text="@.grid_height" />
|
||||
<expr id="grid_height" text="" />
|
||||
|
||||
<label text="@.first_visible_index" />
|
||||
<expr id="first_visible_index" text="1" tooltip="@.first_visible_index_tooltip" />
|
||||
<booxfiller cell_hspan="2" />
|
||||
<label text="@.base_index" />
|
||||
<expr id="base_index" text="1" tooltip="@.base_tooltip" />
|
||||
<boxfiller cell_hspan="2" />
|
||||
</grid>
|
||||
</vbox>
|
||||
</gui>
|
||||
|
@ -374,9 +374,12 @@ the Tags chunk.
|
||||
DWORD Number of tiles
|
||||
WORD Tile Width
|
||||
WORD Tile Height
|
||||
SHORT Number to show in the screen from the tile with index 1 and
|
||||
so on (by default this is field is 1, so the data that is
|
||||
displayed is equivalent to the data in memory)
|
||||
SHORT Base Index: Number to show in the screen from the tile with
|
||||
index 1 and so on (by default this is field is 1, so the data
|
||||
that is displayed is equivalent to the data in memory). But it
|
||||
can be 0 to display zero-based indexing (this field isn't used
|
||||
for the representation of the data in the file, it's just for
|
||||
UI purposes).
|
||||
BYTE[14] Reserved
|
||||
STRING Name of the tileset
|
||||
+ If flag 1 is set
|
||||
|
@ -195,7 +195,7 @@ void NewLayerCommand::onExecute(Context* context)
|
||||
TilesetSelector::Info tilesetInfo;
|
||||
tilesetInfo.newTileset = true;
|
||||
tilesetInfo.grid = context->activeSite().grid();
|
||||
tilesetInfo.firstVisibleIndex = 1;
|
||||
tilesetInfo.baseIndex = 1;
|
||||
|
||||
#ifdef ENABLE_UI
|
||||
// If params specify to ask the user about the name...
|
||||
@ -268,7 +268,7 @@ void NewLayerCommand::onExecute(Context* context)
|
||||
tileset_index tsi;
|
||||
if (tilesetInfo.newTileset) {
|
||||
auto tileset = new Tileset(sprite, tilesetInfo.grid, 1);
|
||||
tileset->setFirstVisibleIndex(tilesetInfo.firstVisibleIndex);
|
||||
tileset->setBaseIndex(tilesetInfo.baseIndex);
|
||||
|
||||
auto addTileset = new cmd::AddTileset(sprite, tileset);
|
||||
tx(addTileset);
|
||||
|
@ -1283,7 +1283,7 @@ static void ase_file_write_tileset_chunk(FILE* f, FileOp* fop,
|
||||
fputl(tileset->size(), f);
|
||||
fputw(tileset->grid().tileSize().w, f);
|
||||
fputw(tileset->grid().tileSize().h, f);
|
||||
fputw(short(tileset->firstVisibleIndex()), f);
|
||||
fputw(short(tileset->baseIndex()), f);
|
||||
ase_file_write_padding(f, 14);
|
||||
ase_file_write_string(f, tileset->name()); // tileset name
|
||||
|
||||
|
@ -69,18 +69,18 @@ int Tileset_get_grid(lua_State* L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Tileset_get_firstVisibleIndex(lua_State* L)
|
||||
int Tileset_get_baseIndex(lua_State* L)
|
||||
{
|
||||
auto tileset = get_docobj<Tileset>(L, 1);
|
||||
lua_pushinteger(L, tileset->firstVisibleIndex());
|
||||
lua_pushinteger(L, tileset->baseIndex());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Tileset_set_firstVisibleIndex(lua_State* L)
|
||||
int Tileset_set_baseIndex(lua_State* L)
|
||||
{
|
||||
auto tileset = get_docobj<Tileset>(L, 1);
|
||||
int i = lua_tointeger(L, 2);
|
||||
tileset->setFirstVisibleIndex(i);
|
||||
tileset->setBaseIndex(i);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -96,7 +96,7 @@ const luaL_Reg Tileset_methods[] = {
|
||||
const Property Tileset_properties[] = {
|
||||
{ "name", Tileset_get_name, Tileset_set_name },
|
||||
{ "grid", Tileset_get_grid, nullptr },
|
||||
{ "firstVisibleIndex", Tileset_get_firstVisibleIndex, Tileset_set_firstVisibleIndex },
|
||||
{ "baseIndex", Tileset_get_baseIndex, Tileset_set_baseIndex },
|
||||
{ nullptr, nullptr, nullptr }
|
||||
};
|
||||
|
||||
|
@ -1162,7 +1162,7 @@ void Editor::drawTileNumbers(ui::Graphics* g, const Cel* cel)
|
||||
+ mainTilePosition();
|
||||
|
||||
int ti_offset =
|
||||
static_cast<LayerTilemap*>(cel->layer())->tileset()->firstVisibleIndex() - 1;
|
||||
static_cast<LayerTilemap*>(cel->layer())->tileset()->baseIndex() - 1;
|
||||
|
||||
const gfx::Rect rc = cel->bounds();
|
||||
const doc::Image* image = cel->image();
|
||||
|
@ -472,17 +472,17 @@ public:
|
||||
}
|
||||
else {
|
||||
// TODO could the site came from the Indicators or StatusBar itself
|
||||
int firstVisibleIndex = 1;
|
||||
int baseIndex = 1;
|
||||
Site site = UIContext::instance()->activeSite();
|
||||
if (site.tileset())
|
||||
firstVisibleIndex = site.tileset()->firstVisibleIndex();
|
||||
baseIndex = site.tileset()->baseIndex();
|
||||
|
||||
doc::tile_index ti = doc::tile_geti(tile);
|
||||
doc::tile_flags tf = doc::tile_getf(tile);
|
||||
if (firstVisibleIndex < 0)
|
||||
str += fmt::format("{}", ((int)ti) + firstVisibleIndex - 1);
|
||||
if (baseIndex < 0)
|
||||
str += fmt::format("{}", ((int)ti) + baseIndex - 1);
|
||||
else
|
||||
str += fmt::format("{}", ti + firstVisibleIndex - 1);
|
||||
str += fmt::format("{}", ti + baseIndex - 1);
|
||||
if (tf) {
|
||||
if (tf & doc::tile_f_flipx) str += " FlipX";
|
||||
if (tf & doc::tile_f_flipy) str += " FlipY";
|
||||
|
@ -145,11 +145,11 @@ void TileButton::onPaint(PaintEvent& ev)
|
||||
|
||||
// Draw text
|
||||
if (m_tile != doc::notile) {
|
||||
int firstVisibleIndex = 1;
|
||||
int baseIndex = 1;
|
||||
if (site.tileset())
|
||||
firstVisibleIndex = site.tileset()->firstVisibleIndex();
|
||||
baseIndex = site.tileset()->baseIndex();
|
||||
|
||||
std::string str = fmt::format("{}", doc::tile_geti(m_tile) + firstVisibleIndex - 1);
|
||||
std::string str = fmt::format("{}", doc::tile_geti(m_tile) + baseIndex - 1);
|
||||
setTextQuiet(str.c_str());
|
||||
|
||||
// TODO calc a proper color for the text
|
||||
|
@ -27,7 +27,7 @@ TilesetSelector::TilesetSelector(const doc::Sprite* sprite,
|
||||
|
||||
gridWidth()->setTextf("%d", info.grid.tileSize().w);
|
||||
gridHeight()->setTextf("%d", info.grid.tileSize().h);
|
||||
firstVisibleIndex()->setTextf("%d", info.firstVisibleIndex);
|
||||
baseIndex()->setTextf("%d", info.baseIndex);
|
||||
|
||||
doc::tileset_index tsi = 0;
|
||||
for (doc::Tileset* tileset : *sprite->tilesets()) {
|
||||
@ -60,7 +60,7 @@ TilesetSelector::Info TilesetSelector::getInfo()
|
||||
|
||||
info.newTileset = true;
|
||||
info.grid = doc::Grid::MakeRect(sz);
|
||||
info.firstVisibleIndex = firstVisibleIndex()->textInt();
|
||||
info.baseIndex = baseIndex()->textInt();
|
||||
}
|
||||
else {
|
||||
info.newTileset = false;
|
||||
|
@ -25,7 +25,7 @@ namespace app {
|
||||
struct Info {
|
||||
bool newTileset = true;
|
||||
doc::Grid grid;
|
||||
int firstVisibleIndex = 1;
|
||||
int baseIndex = 1;
|
||||
doc::tileset_index tsi = 0;
|
||||
};
|
||||
|
||||
|
@ -1068,7 +1068,7 @@ void AsepriteDecoder::readTilesetChunk(doc::Sprite* sprite,
|
||||
const doc::tile_index ntiles = read32();
|
||||
const int w = read16();
|
||||
const int h = read16();
|
||||
const int firstVisibleIndex = short(read16());
|
||||
const int baseIndex = short(read16());
|
||||
readPadding(14);
|
||||
const std::string name = readString();
|
||||
|
||||
@ -1083,7 +1083,7 @@ void AsepriteDecoder::readTilesetChunk(doc::Sprite* sprite,
|
||||
doc::Grid grid(gfx::Size(w, h));
|
||||
auto tileset = new doc::Tileset(sprite, grid, ntiles);
|
||||
tileset->setName(name);
|
||||
tileset->setFirstVisibleIndex(firstVisibleIndex);
|
||||
tileset->setBaseIndex(baseIndex);
|
||||
|
||||
if (flags & ASE_TILESET_FLAG_EXTERNAL_FILE) {
|
||||
const uint32_t extFileId = read32(); // filename ID in the external files chunk
|
||||
|
@ -45,8 +45,8 @@ namespace doc {
|
||||
const std::string& name() const { return m_name; }
|
||||
void setName(const std::string& name) { m_name = name; }
|
||||
|
||||
int firstVisibleIndex() const { return m_firstVisibleIndex; }
|
||||
void setFirstVisibleIndex(int index) { m_firstVisibleIndex = index; }
|
||||
int baseIndex() const { return m_baseIndex; }
|
||||
void setBaseIndex(int index) { m_baseIndex = index; }
|
||||
|
||||
int getMemSize() const override;
|
||||
|
||||
@ -124,7 +124,7 @@ namespace doc {
|
||||
Tiles m_tiles;
|
||||
TilesetHashTable m_hash;
|
||||
std::string m_name;
|
||||
int m_firstVisibleIndex = 1;
|
||||
int m_baseIndex = 1;
|
||||
struct External {
|
||||
std::string filename;
|
||||
tileset_index tileset;
|
||||
|
@ -71,7 +71,7 @@ Tileset* read_tileset(std::istream& is,
|
||||
if (isOldVersion)
|
||||
*isOldVersion = false;
|
||||
|
||||
tileset->setFirstVisibleIndex(1);
|
||||
tileset->setBaseIndex(1);
|
||||
}
|
||||
// Old tileset used in internal versions (this was added to recover
|
||||
// old files, maybe in a future we could remove this code)
|
||||
|
@ -19,14 +19,14 @@ void fix_old_tileset(
|
||||
// case we can use this tileset as a new tileset without any
|
||||
// conversion.
|
||||
if (tileset->size() > 0 && is_empty_image(tileset->get(0).get())) {
|
||||
tileset->setFirstVisibleIndex(1);
|
||||
tileset->setBaseIndex(1);
|
||||
}
|
||||
else {
|
||||
// Add the empty tile in the index = 0
|
||||
tileset->insert(0, tileset->makeEmptyTile());
|
||||
|
||||
// The tile 1 will be displayed as tile 0 in the editor
|
||||
tileset->setFirstVisibleIndex(0);
|
||||
tileset->setBaseIndex(0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ void fix_old_tilemap(
|
||||
const tile_t tileIDMask,
|
||||
const tile_t tileFlagsMask)
|
||||
{
|
||||
int delta = (tileset->firstVisibleIndex() == 0 ? 1: 0);
|
||||
int delta = (tileset->baseIndex() == 0 ? 1: 0);
|
||||
|
||||
// Convert old empty tile (0xffffffff) to new empty tile (index 0 = notile)
|
||||
transform_image<TilemapTraits>(
|
||||
|
Loading…
x
Reference in New Issue
Block a user