Open tileset editor with selected metatile

This commit is contained in:
GriffinR 2020-07-01 14:01:18 -04:00 committed by huderlem
parent cc16440336
commit 08bc85dde0
5 changed files with 16 additions and 0 deletions

View file

@ -38,6 +38,7 @@ public:
~TilesetEditor();
void setTilesets(QString, QString);
void init(Project*, QString, QString);
void selectMetatile(uint16_t metatileId);
private slots:
void onHoveredMetatileChanged(uint16_t);

View file

@ -18,6 +18,7 @@ public:
void setTilesets(Tileset*, Tileset*);
uint16_t getSelectedMetatile();
void updateSelectedMetatile();
QPoint getMetatileIdCoordsOnWidget(uint16_t metatileId);
protected:
void mousePressEvent(QGraphicsSceneMouseEvent*);

View file

@ -2452,6 +2452,7 @@ void MainWindow::on_actionTileset_Editor_triggered()
} else {
this->tilesetEditor->activateWindow();
}
this->tilesetEditor->selectMetatile(this->editor->metatile_selector_item->getSelectedMetatiles()->at(0));
}
void MainWindow::on_toolButton_ExpandAll_clicked()

View file

@ -105,6 +105,12 @@ void TilesetEditor::init(Project *project, QString primaryTilesetLabel, QString
metatileHistory.push(commit);
}
void TilesetEditor::selectMetatile(uint16_t metatileId) {
this->metatileSelector->select(metatileId);
QPoint pos = this->metatileSelector->getMetatileIdCoordsOnWidget(metatileId);
this->ui->scrollArea_Metatiles->ensureVisible(pos.x(), pos.y());
}
void TilesetEditor::setTilesets(QString primaryTilesetLabel, QString secondaryTilesetLabel) {
delete this->primaryTileset;
delete this->secondaryTileset;

View file

@ -117,3 +117,10 @@ QPoint TilesetEditorMetatileSelector::getMetatileIdCoords(uint16_t metatileId) {
: metatileId - Project::getNumMetatilesPrimary() + this->primaryTileset->metatiles->length();
return QPoint(index % this->numMetatilesWide, index / this->numMetatilesWide);
}
QPoint TilesetEditorMetatileSelector::getMetatileIdCoordsOnWidget(uint16_t metatileId) {
QPoint pos = getMetatileIdCoords(metatileId);
pos.rx() = (pos.x() * this->cellWidth) + (this->cellWidth / 2);
pos.ry() = (pos.y() * this->cellHeight) + (this->cellHeight / 2);
return pos;
}