Properly filter available prefabs based on current map's tilesets
This commit is contained in:
parent
4232410a79
commit
32cba33326
3 changed files with 23 additions and 6 deletions
|
@ -22,6 +22,7 @@ class Prefab
|
||||||
public:
|
public:
|
||||||
void initPrefabUI(MetatileSelector *selector, QWidget *prefabWidget, QLabel *emptyPrefabLabel, Map *map);
|
void initPrefabUI(MetatileSelector *selector, QWidget *prefabWidget, QLabel *emptyPrefabLabel, Map *map);
|
||||||
void addPrefab(MetatileSelection selection, Map *map, QString name);
|
void addPrefab(MetatileSelection selection, Map *map, QString name);
|
||||||
|
void updatePrefabUi(Map *map);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MetatileSelector *selector;
|
MetatileSelector *selector;
|
||||||
|
@ -29,7 +30,6 @@ private:
|
||||||
QLabel *emptyPrefabLabel;
|
QLabel *emptyPrefabLabel;
|
||||||
QList<PrefabItem> items;
|
QList<PrefabItem> items;
|
||||||
void loadPrefabs();
|
void loadPrefabs();
|
||||||
void updatePrefabUi(Map *map);
|
|
||||||
QList<PrefabItem> getPrefabsForTilesets(QString primaryTileset, QString secondaryTileset);
|
QList<PrefabItem> getPrefabsForTilesets(QString primaryTileset, QString secondaryTileset);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -667,6 +667,7 @@ bool MainWindow::setMap(QString map_name, bool scrollTreeView) {
|
||||||
updateMapList();
|
updateMapList();
|
||||||
|
|
||||||
Scripting::cb_MapOpened(map_name);
|
Scripting::cb_MapOpened(map_name);
|
||||||
|
prefab.updatePrefabUi(editor->map);
|
||||||
updateTilesetEditor();
|
updateTilesetEditor();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1696,6 +1697,8 @@ void MainWindow::on_mapViewTab_tabBarClicked(int index)
|
||||||
editor->setEditingMap();
|
editor->setEditingMap();
|
||||||
} else if (index == 1) {
|
} else if (index == 1) {
|
||||||
editor->setEditingCollision();
|
editor->setEditingCollision();
|
||||||
|
} else if (index == 2) {
|
||||||
|
editor->setEditingMap();
|
||||||
}
|
}
|
||||||
editor->setCursorRectVisible(false);
|
editor->setCursorRectVisible(false);
|
||||||
}
|
}
|
||||||
|
@ -2893,6 +2896,7 @@ void MainWindow::on_comboBox_PrimaryTileset_currentTextChanged(const QString &ti
|
||||||
redrawMapScene();
|
redrawMapScene();
|
||||||
on_horizontalSlider_MetatileZoom_valueChanged(ui->horizontalSlider_MetatileZoom->value());
|
on_horizontalSlider_MetatileZoom_valueChanged(ui->horizontalSlider_MetatileZoom->value());
|
||||||
updateTilesetEditor();
|
updateTilesetEditor();
|
||||||
|
prefab.updatePrefabUi(editor->map);
|
||||||
markMapEdited();
|
markMapEdited();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2904,6 +2908,7 @@ void MainWindow::on_comboBox_SecondaryTileset_currentTextChanged(const QString &
|
||||||
redrawMapScene();
|
redrawMapScene();
|
||||||
on_horizontalSlider_MetatileZoom_valueChanged(ui->horizontalSlider_MetatileZoom->value());
|
on_horizontalSlider_MetatileZoom_valueChanged(ui->horizontalSlider_MetatileZoom->value());
|
||||||
updateTilesetEditor();
|
updateTilesetEditor();
|
||||||
|
prefab.updatePrefabUi(editor->map);
|
||||||
markMapEdited();
|
markMapEdited();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "parseutil.h"
|
#include "parseutil.h"
|
||||||
#include "currentselectedmetatilespixmapitem.h"
|
#include "currentselectedmetatilespixmapitem.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include "project.h"
|
||||||
|
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
@ -88,17 +89,16 @@ QList<PrefabItem> Prefab::getPrefabsForTilesets(QString primaryTileset, QString
|
||||||
}
|
}
|
||||||
|
|
||||||
void Prefab::initPrefabUI(MetatileSelector *selector, QWidget *prefabWidget, QLabel *emptyPrefabLabel, Map *map) {
|
void Prefab::initPrefabUI(MetatileSelector *selector, QWidget *prefabWidget, QLabel *emptyPrefabLabel, Map *map) {
|
||||||
logInfo("initPrefabUI");
|
|
||||||
this->selector = selector;
|
this->selector = selector;
|
||||||
this->prefabWidget = prefabWidget;
|
this->prefabWidget = prefabWidget;
|
||||||
this->emptyPrefabLabel = emptyPrefabLabel;
|
this->emptyPrefabLabel = emptyPrefabLabel;
|
||||||
this->loadPrefabs();
|
this->loadPrefabs();
|
||||||
logInfo("initPrefabUI loaded prefabs");
|
|
||||||
this->updatePrefabUi(map);
|
this->updatePrefabUi(map);
|
||||||
logInfo("initPrefabUI after updatePrefabUi");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Prefab::updatePrefabUi(Map *map) {
|
void Prefab::updatePrefabUi(Map *map) {
|
||||||
|
if (!this->selector)
|
||||||
|
return;
|
||||||
// Cleanup the PrefabFrame to have a clean slate.
|
// Cleanup the PrefabFrame to have a clean slate.
|
||||||
auto layout = this->prefabWidget->layout();
|
auto layout = this->prefabWidget->layout();
|
||||||
while (layout && layout->count() > 1) {
|
while (layout && layout->count() > 1) {
|
||||||
|
@ -149,11 +149,23 @@ void Prefab::updatePrefabUi(Map *map) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Prefab::addPrefab(MetatileSelection selection, Map *map, QString name) {
|
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{
|
this->items.append(PrefabItem{
|
||||||
QUuid::createUuid(),
|
QUuid::createUuid(),
|
||||||
name,
|
name,
|
||||||
map->layout->tileset_primary_label,
|
usesPrimaryTileset ? map->layout->tileset_primary_label : "",
|
||||||
map->layout->tileset_secondary_label,
|
usesSecondaryTileset ? map->layout->tileset_secondary_label: "",
|
||||||
selection
|
selection
|
||||||
});
|
});
|
||||||
this->updatePrefabUi(map);
|
this->updatePrefabUi(map);
|
||||||
|
|
Loading…
Reference in a new issue