diff --git a/include/ui/prefab.h b/include/ui/prefab.h index 70029a91..83656e08 100644 --- a/include/ui/prefab.h +++ b/include/ui/prefab.h @@ -22,6 +22,7 @@ class Prefab public: void initPrefabUI(MetatileSelector *selector, QWidget *prefabWidget, QLabel *emptyPrefabLabel, Map *map); void addPrefab(MetatileSelection selection, Map *map, QString name); + void updatePrefabUi(Map *map); private: MetatileSelector *selector; @@ -29,7 +30,6 @@ private: QLabel *emptyPrefabLabel; QList items; void loadPrefabs(); - void updatePrefabUi(Map *map); QList getPrefabsForTilesets(QString primaryTileset, QString secondaryTileset); }; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 9e16f763..e45f0bc0 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -667,6 +667,7 @@ bool MainWindow::setMap(QString map_name, bool scrollTreeView) { updateMapList(); Scripting::cb_MapOpened(map_name); + prefab.updatePrefabUi(editor->map); updateTilesetEditor(); return true; } @@ -1696,6 +1697,8 @@ void MainWindow::on_mapViewTab_tabBarClicked(int index) editor->setEditingMap(); } else if (index == 1) { editor->setEditingCollision(); + } else if (index == 2) { + editor->setEditingMap(); } editor->setCursorRectVisible(false); } @@ -2893,6 +2896,7 @@ void MainWindow::on_comboBox_PrimaryTileset_currentTextChanged(const QString &ti redrawMapScene(); on_horizontalSlider_MetatileZoom_valueChanged(ui->horizontalSlider_MetatileZoom->value()); updateTilesetEditor(); + prefab.updatePrefabUi(editor->map); markMapEdited(); } } @@ -2904,6 +2908,7 @@ void MainWindow::on_comboBox_SecondaryTileset_currentTextChanged(const QString & redrawMapScene(); on_horizontalSlider_MetatileZoom_valueChanged(ui->horizontalSlider_MetatileZoom->value()); updateTilesetEditor(); + prefab.updatePrefabUi(editor->map); markMapEdited(); } } diff --git a/src/ui/prefab.cpp b/src/ui/prefab.cpp index f8efe9b2..42979c7d 100644 --- a/src/ui/prefab.cpp +++ b/src/ui/prefab.cpp @@ -5,6 +5,7 @@ #include "parseutil.h" #include "currentselectedmetatilespixmapitem.h" #include "log.h" +#include "project.h" #include #include @@ -88,17 +89,16 @@ QList Prefab::getPrefabsForTilesets(QString primaryTileset, QString } void Prefab::initPrefabUI(MetatileSelector *selector, QWidget *prefabWidget, QLabel *emptyPrefabLabel, Map *map) { - logInfo("initPrefabUI"); this->selector = selector; this->prefabWidget = prefabWidget; this->emptyPrefabLabel = emptyPrefabLabel; this->loadPrefabs(); - logInfo("initPrefabUI loaded prefabs"); this->updatePrefabUi(map); - logInfo("initPrefabUI after updatePrefabUi"); } void Prefab::updatePrefabUi(Map *map) { + if (!this->selector) + return; // Cleanup the PrefabFrame to have a clean slate. auto layout = this->prefabWidget->layout(); while (layout && layout->count() > 1) { @@ -149,11 +149,23 @@ void Prefab::updatePrefabUi(Map *map) { } void Prefab::addPrefab(MetatileSelection selection, Map *map, QString name) { + bool usesPrimaryTileset = false; + bool usesSecondaryTileset = false; + for (auto metatile : selection.metatileItems) { + if (!metatile.enabled) + continue; + if (metatile.metatileId < Project::getNumMetatilesPrimary()) { + usesPrimaryTileset = true; + } else if (metatile.metatileId < Project::getNumMetatilesTotal()) { + usesSecondaryTileset = true; + } + } + this->items.append(PrefabItem{ QUuid::createUuid(), name, - map->layout->tileset_primary_label, - map->layout->tileset_secondary_label, + usesPrimaryTileset ? map->layout->tileset_primary_label : "", + usesSecondaryTileset ? map->layout->tileset_secondary_label: "", selection }); this->updatePrefabUi(map);