Fix tileset editor desyncing with API changes
This commit is contained in:
parent
ecfc521a87
commit
6682233079
3 changed files with 25 additions and 3 deletions
|
@ -47,6 +47,7 @@ public:
|
|||
bool selectMetatile(uint16_t metatileId);
|
||||
uint16_t getSelectedMetatileId();
|
||||
void setMetatileLabel(QString label);
|
||||
void queueMetatileReload(uint16_t metatileId);
|
||||
|
||||
QObjectList shortcutableObjects() const;
|
||||
|
||||
|
@ -166,6 +167,7 @@ private:
|
|||
QGraphicsPixmapItem *selectedTilePixmapItem = nullptr;
|
||||
QGraphicsScene *metatileLayersScene = nullptr;
|
||||
bool lockSelection = false;
|
||||
QSet<uint16_t> metatileReloadQueue;
|
||||
|
||||
signals:
|
||||
void tilesetsSaved(QString, QString);
|
||||
|
|
|
@ -585,10 +585,16 @@ void MainWindow::saveMetatileAttributesByMetatileId(int metatileId) {
|
|||
if (this->editor->project && tileset)
|
||||
this->editor->project->saveTilesetMetatileAttributes(tileset);
|
||||
|
||||
// If the Tileset Editor is currently displaying the updated metatile, refresh it
|
||||
if (this->tilesetEditor && this->tilesetEditor->getSelectedMetatileId() == metatileId)
|
||||
// If the tileset editor is open it needs to be refreshed with the new changes.
|
||||
// Rather than do a full refresh (which is costly) we tell the editor it will need
|
||||
// to reload the metatile from the project next time it's displayed.
|
||||
// If it's currently being displayed, trigger this reload immediately.
|
||||
if (this->tilesetEditor) {
|
||||
this->tilesetEditor->queueMetatileReload(metatileId);
|
||||
if (this->tilesetEditor->getSelectedMetatileId() == metatileId)
|
||||
this->tilesetEditor->onSelectedMetatileChanged(metatileId);
|
||||
}
|
||||
}
|
||||
|
||||
Metatile * MainWindow::getMetatile(int metatileId) {
|
||||
if (!this->editor || !this->editor->map || !this->editor->map->layout)
|
||||
|
|
|
@ -81,6 +81,7 @@ uint16_t TilesetEditor::getSelectedMetatileId() {
|
|||
}
|
||||
|
||||
void TilesetEditor::setTilesets(QString primaryTilesetLabel, QString secondaryTilesetLabel) {
|
||||
this->metatileReloadQueue.clear();
|
||||
Tileset *primaryTileset = project->getTileset(primaryTilesetLabel);
|
||||
Tileset *secondaryTileset = project->getTileset(secondaryTilesetLabel);
|
||||
if (this->primaryTileset) delete this->primaryTileset;
|
||||
|
@ -373,6 +374,15 @@ void TilesetEditor::onHoveredMetatileCleared() {
|
|||
|
||||
void TilesetEditor::onSelectedMetatileChanged(uint16_t metatileId) {
|
||||
this->metatile = Tileset::getMetatile(metatileId, this->primaryTileset, this->secondaryTileset);
|
||||
|
||||
// The scripting API allows users to change metatiles in the project, and these changes are saved to disk.
|
||||
// The Tileset Editor (if open) needs to reflect these changes when the metatile is next displayed.
|
||||
if (this->metatileReloadQueue.contains(metatileId)) {
|
||||
this->metatileReloadQueue.remove(metatileId);
|
||||
Metatile *updatedMetatile = Tileset::getMetatile(metatileId, this->map->layout->tileset_primary, this->map->layout->tileset_secondary);
|
||||
if (updatedMetatile) *this->metatile = *updatedMetatile;
|
||||
}
|
||||
|
||||
this->metatileLayersItem->setMetatile(metatile);
|
||||
this->metatileLayersItem->draw();
|
||||
this->ui->graphicsView_metatileLayers->setFixedSize(this->metatileLayersItem->pixmap().width() + 2, this->metatileLayersItem->pixmap().height() + 2);
|
||||
|
@ -387,6 +397,10 @@ void TilesetEditor::onSelectedMetatileChanged(uint16_t metatileId) {
|
|||
this->ui->comboBox_terrainType->setHexItem(this->metatile->terrainType());
|
||||
}
|
||||
|
||||
void TilesetEditor::queueMetatileReload(uint16_t metatileId) {
|
||||
this->metatileReloadQueue.insert(metatileId);
|
||||
}
|
||||
|
||||
void TilesetEditor::onHoveredTileChanged(uint16_t tile) {
|
||||
QString message = QString("Tile: 0x%1")
|
||||
.arg(QString("%1").arg(tile, 3, 16, QChar('0')).toUpper());
|
||||
|
|
Loading…
Reference in a new issue