mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-29 19:20:09 +00:00
Add option to change the "base index" from the layer properties
This commit is contained in:
parent
a3286fc20a
commit
505aa6119a
@ -380,7 +380,7 @@ NewLayer_BeforeActiveLayer = New {} Below
|
||||
NewLayer_Layer = Layer
|
||||
NewLayer_Group = Group
|
||||
NewLayer_ReferenceLayer = Reference Layer
|
||||
NewLayer_TilemapLayer = Tilemap Layer
|
||||
NewLayer_TilemapLayer = Tilemap
|
||||
NewLayer_FromClipboard = {} from Clipboard
|
||||
NewLayer_ViaCopy = {} via Copy
|
||||
NewLayer_ViaCut = {} via Cut
|
||||
@ -827,6 +827,7 @@ title = Layer Properties
|
||||
name = Name:
|
||||
mode = Mode:
|
||||
opacity = Opacity:
|
||||
tileset_tooltip = Tileset
|
||||
|
||||
[main_menu]
|
||||
file = &File
|
||||
@ -1030,6 +1031,9 @@ as index 1 (by default, one-based index) or other value.
|
||||
E.g. you can use 0 here for zero-based indexing.
|
||||
END
|
||||
|
||||
[tileset_selector_window]
|
||||
title = Tileset
|
||||
|
||||
[new_sprite]
|
||||
title = New Sprite
|
||||
size = Size:
|
||||
|
@ -10,7 +10,8 @@
|
||||
<button id="user_data" icon="icon_user_data" tooltip="@general.user_data" />
|
||||
|
||||
<label text="@.mode" />
|
||||
<combobox id="mode" cell_hspan="2" />
|
||||
<combobox id="mode" />
|
||||
<button id="tileset" icon="tiles" tooltip="@.tileset_tooltip" />
|
||||
|
||||
<label text="@.opacity" />
|
||||
<slider id="opacity" min="0" max="255" width="128" cell_align="horizontal" cell_hspan="2" />
|
||||
|
@ -488,6 +488,7 @@ add_library(app-lib
|
||||
cmd/set_tag_color.cpp
|
||||
cmd/set_tag_name.cpp
|
||||
cmd/set_tag_range.cpp
|
||||
cmd/set_tileset_base_index.cpp
|
||||
cmd/set_total_frames.cpp
|
||||
cmd/set_transparent_color.cpp
|
||||
cmd/set_user_data.cpp
|
||||
|
44
src/app/cmd/set_tileset_base_index.cpp
Normal file
44
src/app/cmd/set_tileset_base_index.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_base_index.h"
|
||||
|
||||
#include "app/doc.h"
|
||||
#include "app/doc_event.h"
|
||||
#include "doc/tileset.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
|
||||
SetTilesetBaseIndex::SetTilesetBaseIndex(Tileset* tileset, int baseIndex)
|
||||
: WithTileset(tileset)
|
||||
, m_oldBaseIndex(tileset->baseIndex())
|
||||
, m_newBaseIndex(baseIndex)
|
||||
{
|
||||
}
|
||||
|
||||
void SetTilesetBaseIndex::onExecute()
|
||||
{
|
||||
auto ts = tileset();
|
||||
ts->setBaseIndex(m_newBaseIndex);
|
||||
ts->incrementVersion();
|
||||
ts->sprite()->incrementVersion();
|
||||
}
|
||||
|
||||
void SetTilesetBaseIndex::onUndo()
|
||||
{
|
||||
auto ts = tileset();
|
||||
ts->setBaseIndex(m_oldBaseIndex);
|
||||
ts->incrementVersion();
|
||||
ts->sprite()->incrementVersion();
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
38
src/app/cmd/set_tileset_base_index.h
Normal file
38
src/app/cmd/set_tileset_base_index.h
Normal file
@ -0,0 +1,38 @@
|
||||
// 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_BASE_INDEX_H_INCLUDED
|
||||
#define APP_CMD_SET_TILESET_BASE_INDEX_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "app/cmd.h"
|
||||
#include "app/cmd/with_tileset.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class SetTilesetBaseIndex : public Cmd
|
||||
, public WithTileset {
|
||||
public:
|
||||
SetTilesetBaseIndex(Tileset* tileset, int baseIndex);
|
||||
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onUndo() override;
|
||||
size_t onMemSize() const override {
|
||||
return sizeof(*this);
|
||||
}
|
||||
|
||||
private:
|
||||
int m_oldBaseIndex;
|
||||
int m_newBaseIndex;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif
|
@ -13,6 +13,7 @@
|
||||
#include "app/cmd/set_layer_blend_mode.h"
|
||||
#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_user_data.h"
|
||||
#include "app/commands/command.h"
|
||||
#include "app/console.h"
|
||||
@ -21,18 +22,23 @@
|
||||
#include "app/doc_event.h"
|
||||
#include "app/modules/gui.h"
|
||||
#include "app/tx.h"
|
||||
#include "app/ui/main_window.h"
|
||||
#include "app/ui/separator_in_view.h"
|
||||
#include "app/ui/tileset_selector.h"
|
||||
#include "app/ui/timeline/timeline.h"
|
||||
#include "app/ui/user_data_view.h"
|
||||
#include "app/ui_context.h"
|
||||
#include "base/scoped_value.h"
|
||||
#include "doc/image.h"
|
||||
#include "doc/layer.h"
|
||||
#include "doc/layer_tilemap.h"
|
||||
#include "doc/sprite.h"
|
||||
#include "doc/tileset.h"
|
||||
#include "doc/user_data.h"
|
||||
#include "ui/ui.h"
|
||||
|
||||
#include "layer_properties.xml.h"
|
||||
#include "tileset_selector_window.xml.h"
|
||||
|
||||
namespace app {
|
||||
|
||||
@ -105,6 +111,7 @@ public:
|
||||
opacity()->Change.connect([this]{ onStartTimer(); });
|
||||
m_timer.Tick.connect([this]{ onCommitChange(); });
|
||||
userData()->Click.connect([this]{ onToggleUserData(); });
|
||||
tileset()->Click.connect([this]{ onTileset(); });
|
||||
|
||||
m_userDataView.entry()->Change.connect([this]{ onStartTimer(); });
|
||||
m_userDataView.color()->Change.connect([this]{ onStartTimer(); });
|
||||
@ -315,6 +322,47 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
void onTileset() {
|
||||
if (!m_layer || !m_layer->isTilemap())
|
||||
return;
|
||||
|
||||
auto tilemap = static_cast<LayerTilemap*>(m_layer);
|
||||
auto tileset = tilemap->tileset();
|
||||
|
||||
// Information about the tileset to be used for new tilemaps
|
||||
TilesetSelector::Info tilesetInfo;
|
||||
tilesetInfo.enabled = false;
|
||||
tilesetInfo.newTileset = false;
|
||||
tilesetInfo.grid = tileset->grid();
|
||||
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;
|
||||
|
||||
tilesetInfo = tilesetSel.getInfo();
|
||||
|
||||
// TODO add options to change the tileset index, grid size, etc.
|
||||
|
||||
if (tileset->baseIndex() != tilesetInfo.baseIndex) {
|
||||
try {
|
||||
ContextWriter writer(UIContext::instance());
|
||||
Tx tx(writer.context(), "Set Base Index");
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateFromLayer() {
|
||||
if (m_selfUpdate)
|
||||
return;
|
||||
@ -323,6 +371,7 @@ private:
|
||||
|
||||
base::ScopedValue<bool> switchSelf(m_selfUpdate, true, false);
|
||||
|
||||
const bool tilemapVisibility = (m_layer && m_layer->isTilemap());
|
||||
if (m_layer) {
|
||||
name()->setText(m_layer->name().c_str());
|
||||
name()->setEnabled(true);
|
||||
@ -345,10 +394,10 @@ private:
|
||||
mode()->setEnabled(false);
|
||||
opacity()->setEnabled(false);
|
||||
}
|
||||
|
||||
color_t c = m_layer->userData().color();
|
||||
m_userDataView.color()->setColor(Color::fromRgb(rgba_getr(c), rgba_getg(c), rgba_getb(c), rgba_geta(c)));
|
||||
m_userDataView.entry()->setText(m_layer->userData().text());
|
||||
|
||||
}
|
||||
else {
|
||||
name()->setText("No Layer");
|
||||
@ -357,6 +406,11 @@ private:
|
||||
opacity()->setEnabled(false);
|
||||
m_userDataView.setVisible(false, false);
|
||||
}
|
||||
|
||||
if (tileset()->isVisible() != tilemapVisibility) {
|
||||
tileset()->setVisible(tilemapVisibility);
|
||||
tileset()->parent()->layout();
|
||||
}
|
||||
}
|
||||
|
||||
Timer m_timer;
|
||||
|
@ -31,21 +31,33 @@ TilesetSelector::TilesetSelector(const doc::Sprite* sprite,
|
||||
|
||||
doc::tileset_index tsi = 0;
|
||||
for (doc::Tileset* tileset : *sprite->tilesets()) {
|
||||
tilesets()->addItem(
|
||||
new ListItem(
|
||||
fmt::format("Tileset #{0} ({1}x{2}): \"{3}\"",
|
||||
tsi,
|
||||
tileset->grid().tileSize().w,
|
||||
tileset->grid().tileSize().w,
|
||||
tileset->name())));
|
||||
auto item = new ListItem(
|
||||
fmt::format("Tileset #{0} ({1}x{2}): \"{3}\"",
|
||||
tsi,
|
||||
tileset->grid().tileSize().w,
|
||||
tileset->grid().tileSize().w,
|
||||
tileset->name()));
|
||||
tilesets()->addItem(item);
|
||||
|
||||
if (info.tsi == tsi)
|
||||
tilesets()->setSelectedItem(item);
|
||||
|
||||
++tsi;
|
||||
}
|
||||
|
||||
if (!info.enabled) {
|
||||
tilesets()->setEnabled(false);
|
||||
gridWidth()->setEnabled(false);
|
||||
gridHeight()->setEnabled(false);
|
||||
}
|
||||
|
||||
tilesets()->Change.connect(
|
||||
[this]() {
|
||||
[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();
|
||||
});
|
||||
}
|
||||
@ -60,12 +72,12 @@ TilesetSelector::Info TilesetSelector::getInfo()
|
||||
|
||||
info.newTileset = true;
|
||||
info.grid = doc::Grid::MakeRect(sz);
|
||||
info.baseIndex = baseIndex()->textInt();
|
||||
}
|
||||
else {
|
||||
info.newTileset = false;
|
||||
info.tsi = itemIndex-1;
|
||||
}
|
||||
info.baseIndex = baseIndex()->textInt();
|
||||
return info;
|
||||
}
|
||||
|
||||
|
@ -23,18 +23,17 @@ namespace app {
|
||||
class TilesetSelector : public app::gen::TilesetSelector {
|
||||
public:
|
||||
struct Info {
|
||||
bool enabled = true;
|
||||
bool newTileset = true;
|
||||
doc::Grid grid;
|
||||
int baseIndex = 1;
|
||||
doc::tileset_index tsi = 0;
|
||||
doc::tileset_index tsi = -1;
|
||||
};
|
||||
|
||||
TilesetSelector(const doc::Sprite* sprite,
|
||||
const TilesetSelector::Info& info);
|
||||
|
||||
Info getInfo();
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
} // namespace app
|
||||
|
Loading…
x
Reference in New Issue
Block a user