Keep tileset editor in sync with currently opened map
This commit is contained in:
parent
8d38783833
commit
0c7ecebe0b
6 changed files with 36 additions and 8 deletions
|
@ -157,6 +157,7 @@ private:
|
|||
void initEditor();
|
||||
void loadUserSettings();
|
||||
void openRecentProject();
|
||||
void updateTilesetEditor();
|
||||
};
|
||||
|
||||
enum MapListUserRoles {
|
||||
|
|
|
@ -18,6 +18,7 @@ class TilesetEditor : public QMainWindow
|
|||
public:
|
||||
explicit TilesetEditor(Project*, QString, QString, QWidget *parent = nullptr);
|
||||
~TilesetEditor();
|
||||
void setTilesets(QString, QString);
|
||||
|
||||
private slots:
|
||||
void onHoveredMetatileChanged(uint16_t);
|
||||
|
|
|
@ -33,6 +33,7 @@ private:
|
|||
void updateSelectedMetatile();
|
||||
uint16_t getMetatileId(int x, int y);
|
||||
QPoint getMetatileIdCoords(uint16_t);
|
||||
uint16_t getValidMetatileId(uint16_t);
|
||||
|
||||
signals:
|
||||
void hoveredMetatileChanged(uint16_t);
|
||||
|
|
|
@ -196,6 +196,7 @@ void MainWindow::setMap(QString map_name, bool scrollTreeView) {
|
|||
|
||||
setRecentMap(map_name);
|
||||
updateMapList();
|
||||
updateTilesetEditor();
|
||||
}
|
||||
|
||||
void MainWindow::redrawMapScene()
|
||||
|
@ -529,6 +530,12 @@ void MainWindow::onTilesetChanged(QString mapName)
|
|||
setMap(mapName);
|
||||
}
|
||||
|
||||
void MainWindow::updateTilesetEditor() {
|
||||
if (this->tilesetEditor) {
|
||||
this->tilesetEditor->setTilesets(editor->ui->comboBox_PrimaryTileset->currentText(), editor->ui->comboBox_SecondaryTileset->currentText());
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::currentMetatilesSelectionChanged()
|
||||
{
|
||||
ui->graphicsView_currentMetatileSelection->setFixedSize(editor->scene_current_metatile_selection_item->pixmap().width() + 2, editor->scene_current_metatile_selection_item->pixmap().height() + 2);
|
||||
|
|
|
@ -41,6 +41,21 @@ TilesetEditor::~TilesetEditor()
|
|||
delete ui;
|
||||
}
|
||||
|
||||
void TilesetEditor::setTilesets(QString primaryTilesetLabel, QString secondaryTilesetLabel) {
|
||||
delete this->primaryTileset;
|
||||
delete this->secondaryTileset;
|
||||
Tileset *primaryTileset = project->getTileset(primaryTilesetLabel);
|
||||
Tileset *secondaryTileset = project->getTileset(secondaryTilesetLabel);
|
||||
this->primaryTileset = primaryTileset->copy();
|
||||
this->secondaryTileset = secondaryTileset->copy();
|
||||
|
||||
this->metatileSelector->setTilesets(this->primaryTileset, this->secondaryTileset);
|
||||
this->tileSelector->setTilesets(this->primaryTileset, this->secondaryTileset);
|
||||
this->metatileLayersItem->setTilesets(this->primaryTileset, this->secondaryTileset);
|
||||
this->metatileSelector->select(this->metatileSelector->getSelectedMetatile());
|
||||
this->drawSelectedTile();
|
||||
}
|
||||
|
||||
void TilesetEditor::initMetatileSelector()
|
||||
{
|
||||
this->metatileSelector = new TilesetEditorMetatileSelector(this->primaryTileset, this->secondaryTileset);
|
||||
|
|
|
@ -32,6 +32,7 @@ void TilesetEditorMetatileSelector::draw() {
|
|||
}
|
||||
|
||||
void TilesetEditorMetatileSelector::select(uint16_t metatileId) {
|
||||
metatileId = this->getValidMetatileId(metatileId);
|
||||
QPoint coords = this->getMetatileIdCoords(metatileId);
|
||||
SelectablePixmapItem::select(coords.x(), coords.y(), 0, 0);
|
||||
this->selectedMetatile = metatileId;
|
||||
|
@ -95,17 +96,19 @@ void TilesetEditorMetatileSelector::hoverLeaveEvent(QGraphicsSceneHoverEvent*) {
|
|||
}
|
||||
|
||||
QPoint TilesetEditorMetatileSelector::getMetatileIdCoords(uint16_t metatileId) {
|
||||
if (metatileId >= Project::getNumMetatilesTotal()
|
||||
|| (metatileId < Project::getNumMetatilesPrimary() && metatileId >= this->primaryTileset->metatiles->length())
|
||||
|| (metatileId < Project::getNumMetatilesTotal() && metatileId >= Project::getNumMetatilesPrimary() + this->secondaryTileset->metatiles->length()))
|
||||
{
|
||||
// Invalid metatile id.
|
||||
return QPoint(0, 0);
|
||||
}
|
||||
|
||||
int index = metatileId < Project::getNumMetatilesPrimary()
|
||||
? metatileId
|
||||
: metatileId - Project::getNumMetatilesPrimary() + this->primaryTileset->metatiles->length();
|
||||
return QPoint(index % this->numMetatilesWide, index / this->numMetatilesWide);
|
||||
}
|
||||
|
||||
uint16_t TilesetEditorMetatileSelector::getValidMetatileId(uint16_t metatileId) {
|
||||
if (metatileId >= Project::getNumMetatilesTotal()
|
||||
|| (metatileId < Project::getNumMetatilesPrimary() && metatileId >= this->primaryTileset->metatiles->length())
|
||||
|| (metatileId < Project::getNumMetatilesTotal() && metatileId >= Project::getNumMetatilesPrimary() + this->secondaryTileset->metatiles->length()))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return metatileId;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue