Fix bug moving tiles out of the tileset range

This commit is contained in:
David Capello 2020-02-18 10:30:34 -03:00
parent 75f7346ef6
commit 9973258618
3 changed files with 21 additions and 3 deletions

View File

@ -781,7 +781,8 @@ void ColorBar::onRemapTilesButtonClick()
Remap remap(tileset->size());
for (tile_index ti=0; ti<remap.size(); ++ti) {
auto img = m_oldTileset->get(ti);
tile_index destTi = tileset->findTileIndex(img);
tile_index destTi = (img ? tileset->findTileIndex(img):
doc::tile_i_notile);
if (img && destTi != doc::tile_i_notile) {
COLOR_BAR_TRACE(" - Remap tile %d -> %d\n", ti, destTi);
remap.map(ti, destTi);

View File

@ -243,8 +243,19 @@ public:
if (!tileset)
return;
// Important: we create a copy because if we make the tileset
// bigger dropping tiles outside the tileset range, the tileset
// will be made bigger (see cmd::AddTile() inside
// move_tiles_in_tileset() function), a
// Doc::notifyTilesetChanged() will be generated, a
// ColorBar::onTilesetChanged() called, and finally we'll receive a
// PaletteView::deselect() that will clear the whole picks.
auto newPicks = picks;
paletteView->delegate()->onTilesViewDragAndDrop(
tileset, picks, currentEntry, beforeIndex, isCopy);
tileset, newPicks, currentEntry, beforeIndex, isCopy);
// Copy the new picks
picks = newPicks;
}
void showEntryInStatusBar(StatusBar* statusBar, int index) override {
statusBar->setStatusText(

View File

@ -140,9 +140,11 @@ void Tileset::insert(const tile_index ti,
void Tileset::erase(const tile_index ti)
{
ASSERT(ti >= 0 && ti < size());
removeFromHash(ti, true);
// TODO check why this doesn't work
//removeFromHash(ti, true);
m_tiles.erase(m_tiles.begin()+ti);
rehash();
}
ImageRef Tileset::makeEmptyTile()
@ -161,6 +163,10 @@ void Tileset::setExternal(const std::string& filename,
tile_index Tileset::findTileIndex(const ImageRef& tileImage)
{
ASSERT(tileImage);
if (!tileImage)
return tile_i_notile;
auto it = m_hash.find(tileImage);
if (it != m_hash.end())
return it->second;