Skip to content

Commit

Permalink
Stop tileset editor from scrolling to map's selection when saving
Browse files Browse the repository at this point in the history
  • Loading branch information
GriffinRichards committed Jun 30, 2023
1 parent cdf4556 commit 0b293d2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The **"Breaking Changes"** listed below are changes that have been made in the d
- Fix default object sprites retaining dimensions and transparency of the previous sprite.
- Fix connections not being deleted when the map name text box is cleared.
- Fix the map border not updating when a tileset is changed.
- Stop the Tileset Editor from scrolling to the initially selected metatile when saving.

## [5.1.1] - 2023-02-20
### Added
Expand Down
1 change: 1 addition & 0 deletions include/ui/tileseteditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ private slots:
QGraphicsScene *selectedTileScene = nullptr;
QGraphicsPixmapItem *selectedTilePixmapItem = nullptr;
QGraphicsScene *metatileLayersScene = nullptr;
bool lockSelection = false;

signals:
void tilesetsSaved(QString, QString);
Expand Down
12 changes: 6 additions & 6 deletions src/ui/tileseteditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ void TilesetEditor::updateTilesets(QString primaryTilesetLabel, QString secondar
}

bool TilesetEditor::selectMetatile(uint16_t metatileId) {
if (!Tileset::metatileIsValid(metatileId, this->primaryTileset, this->secondaryTileset)) return false;
if (!Tileset::metatileIsValid(metatileId, this->primaryTileset, this->secondaryTileset) || this->lockSelection)
return false;
this->metatileSelector->select(metatileId);
QPoint pos = this->metatileSelector->getMetatileIdCoordsOnWidget(metatileId);
this->ui->scrollArea_Metatiles->ensureVisible(pos.x(), pos.y());
Expand Down Expand Up @@ -592,18 +593,17 @@ void TilesetEditor::on_comboBox_terrainType_activated(int terrainType)

void TilesetEditor::on_actionSave_Tileset_triggered()
{
// need this temporary metatile ID to reset selection after saving
// when the tilesetsSaved signal is sent, it will be reset to the current map metatile
uint16_t reselectMetatileID = this->metatileSelector->getSelectedMetatileId();

// Need this temporary flag to stop selection resetting after saving.
// This is a workaround; redrawing the map's metatile selector shouldn't emit the same signal as when it's selected.
this->lockSelection = true;
this->project->saveTilesets(this->primaryTileset, this->secondaryTileset);
emit this->tilesetsSaved(this->primaryTileset->name, this->secondaryTileset->name);
this->metatileSelector->select(reselectMetatileID);
if (this->paletteEditor) {
this->paletteEditor->setTilesets(this->primaryTileset, this->secondaryTileset);
}
this->ui->statusbar->showMessage(QString("Saved primary and secondary Tilesets!"), 5000);
this->hasUnsavedChanges = false;
this->lockSelection = false;
}

void TilesetEditor::on_actionImport_Primary_Tiles_triggered()
Expand Down

0 comments on commit 0b293d2

Please sign in to comment.