find unused tiles
This commit is contained in:
parent
601e671fc8
commit
df724a4682
8 changed files with 147 additions and 12 deletions
|
@ -527,9 +527,11 @@
|
|||
<addaction name="actionImport_Primary_Metatiles"/>
|
||||
<addaction name="actionImport_Secondary_Metatiles"/>
|
||||
<addaction name="actionChange_Metatiles_Count"/>
|
||||
<addaction name="actionChange_Palettes"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionShow_Unused"/>
|
||||
<addaction name="actionShow_Counts"/>
|
||||
<addaction name="actionChange_Palettes"/>
|
||||
<addaction name="actionShow_UnusedTiles"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionExport_Primary_Tiles_Image"/>
|
||||
<addaction name="actionExport_Secondary_Tiles_Image"/>
|
||||
|
@ -582,6 +584,14 @@
|
|||
<string>Display Unused Metatiles</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionShow_UnusedTiles">
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Display Unused Tiles</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionShow_Counts">
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
|
|
|
@ -77,6 +77,7 @@ private slots:
|
|||
|
||||
void on_actionShow_Unused_toggled(bool checked);
|
||||
void on_actionShow_Counts_toggled(bool checked);
|
||||
void on_actionShow_UnusedTiles_toggled(bool checked);
|
||||
|
||||
void on_actionUndo_triggered();
|
||||
|
||||
|
@ -123,6 +124,7 @@ private:
|
|||
void saveMetatileLabel();
|
||||
void closeEvent(QCloseEvent*);
|
||||
void countMetatileUsage();
|
||||
void countTileUsage();
|
||||
|
||||
Ui::TilesetEditor *ui;
|
||||
History<MetatileHistoryItem*> metatileHistory;
|
||||
|
|
|
@ -17,7 +17,6 @@ public:
|
|||
void updateSelectedMetatile();
|
||||
QPoint getMetatileIdCoordsOnWidget(uint16_t metatileId);
|
||||
|
||||
//
|
||||
QVector<uint16_t> usedMetatiles;
|
||||
bool selectorShowUnused = false;
|
||||
bool selectorShowCounts = false;
|
||||
|
|
|
@ -31,6 +31,9 @@ public:
|
|||
QImage buildPrimaryTilesIndexedImage();
|
||||
QImage buildSecondaryTilesIndexedImage();
|
||||
|
||||
QVector<uint16_t> usedTiles;
|
||||
bool showUnused = false;
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent*);
|
||||
|
@ -59,6 +62,8 @@ private:
|
|||
QList<QRgb> getCurPaletteTable();
|
||||
QList<Tile> buildSelectedTiles(int, int, QList<Tile>);
|
||||
|
||||
void drawUnused();
|
||||
|
||||
signals:
|
||||
void hoveredTileChanged(uint16_t);
|
||||
void hoveredTileCleared();
|
||||
|
|
|
@ -1089,11 +1089,6 @@ void Project::saveTilesetPalettes(Tileset *tileset) {
|
|||
}
|
||||
|
||||
bool Project::loadLayoutTilesets(MapLayout *layout) {
|
||||
// TODO: investigate where to put this now
|
||||
// if (map->hasUnsavedChanges()) {
|
||||
// return true;
|
||||
// }
|
||||
|
||||
layout->tileset_primary = getTileset(layout->tileset_primary_label);
|
||||
if (!layout->tileset_primary) {
|
||||
QString defaultTileset = tilesetLabels["primary"].value(0, "gTileset_General");
|
||||
|
|
|
@ -288,6 +288,13 @@ void TilesetEditor::refresh() {
|
|||
}
|
||||
}
|
||||
|
||||
if (tileSelector) {
|
||||
if (tileSelector->showUnused) {
|
||||
countTileUsage();
|
||||
this->tileSelector->draw();
|
||||
}
|
||||
}
|
||||
|
||||
this->ui->graphicsView_Tiles->setSceneRect(0, 0, this->tileSelector->pixmap().width() + 2, this->tileSelector->pixmap().height() + 2);
|
||||
this->ui->graphicsView_Tiles->setFixedSize(this->tileSelector->pixmap().width() + 2, this->tileSelector->pixmap().height() + 2);
|
||||
this->ui->graphicsView_Metatiles->setSceneRect(0, 0, this->metatileSelector->pixmap().width() + 2, this->metatileSelector->pixmap().height() + 2);
|
||||
|
@ -933,6 +940,14 @@ void TilesetEditor::on_actionShow_Counts_toggled(bool checked) {
|
|||
this->metatileSelector->draw();
|
||||
}
|
||||
|
||||
void TilesetEditor::on_actionShow_UnusedTiles_toggled(bool checked) {
|
||||
this->tileSelector->showUnused = checked;
|
||||
|
||||
if (checked) countTileUsage();
|
||||
|
||||
this->tileSelector->draw();
|
||||
}
|
||||
|
||||
void TilesetEditor::countMetatileUsage() {
|
||||
// do not double count
|
||||
metatileSelector->usedMetatiles.fill(0);
|
||||
|
@ -973,3 +988,59 @@ void TilesetEditor::countMetatileUsage() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TilesetEditor::countTileUsage() {
|
||||
// check primary tiles
|
||||
this->tileSelector->usedTiles.resize(Project::getNumTilesTotal());
|
||||
this->tileSelector->usedTiles.fill(0);
|
||||
|
||||
QSet<Tileset*> primaryTilesets;
|
||||
QSet<Tileset*> secondaryTilesets;
|
||||
|
||||
for (auto layout : this->project->mapLayouts.values()) {
|
||||
if (layout->tileset_primary_label == this->primaryTileset->name
|
||||
|| layout->tileset_secondary_label == this->secondaryTileset->name) {
|
||||
this->project->loadLayoutTilesets(layout);
|
||||
// need to check metatiles
|
||||
if (layout->tileset_primary && layout->tileset_secondary) {
|
||||
primaryTilesets.insert(layout->tileset_primary);
|
||||
secondaryTilesets.insert(layout->tileset_secondary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check primary tilesets that are used with this secondary tileset for
|
||||
// reference to secondary tiles in primary metatiles
|
||||
for (Tileset *tileset : primaryTilesets) {
|
||||
for (Metatile *metatile : tileset->metatiles) {
|
||||
for (Tile tile : metatile->tiles) {
|
||||
if (tile.tile >= Project::getNumTilesPrimary())
|
||||
this->tileSelector->usedTiles[tile.tile]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// do the opposite for primary tiles in secondary metatiles
|
||||
for (Tileset *tileset : secondaryTilesets) {
|
||||
for (Metatile *metatile : tileset->metatiles) {
|
||||
for (Tile tile : metatile->tiles) {
|
||||
if (tile.tile < Project::getNumTilesPrimary())
|
||||
this->tileSelector->usedTiles[tile.tile]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check this primary tileset metatiles
|
||||
for (Metatile *metatile : this->primaryTileset->metatiles) {
|
||||
for (Tile tile : metatile->tiles) {
|
||||
this->tileSelector->usedTiles[tile.tile]++;
|
||||
}
|
||||
}
|
||||
|
||||
// and the secondary metatiles
|
||||
for (Metatile *metatile : this->secondaryTileset->metatiles) {
|
||||
for (Tile tile : metatile->tiles) {
|
||||
this->tileSelector->usedTiles[tile.tile]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -160,14 +160,14 @@ void TilesetEditorMetatileSelector::drawUnused() {
|
|||
|
||||
QPen whitePen(Qt::white);
|
||||
whitePen.setWidth(1);
|
||||
QPen redPen(Qt::magenta);
|
||||
redPen.setWidth(1);
|
||||
QPen pinkPen(Qt::magenta);
|
||||
pinkPen.setWidth(1);
|
||||
|
||||
QPainter oPainter(&redX);
|
||||
|
||||
oPainter.setPen(whitePen);
|
||||
oPainter.drawEllipse(QRect(1, 1, 30, 30));
|
||||
oPainter.setPen(redPen);
|
||||
oPainter.setPen(pinkPen);
|
||||
oPainter.drawEllipse(QRect(2, 2, 28, 28));
|
||||
oPainter.drawEllipse(QRect(3, 3, 26, 26));
|
||||
|
||||
|
@ -178,8 +178,8 @@ void TilesetEditorMetatileSelector::drawUnused() {
|
|||
oPainter.setPen(whitePen);
|
||||
oPainter.drawLine(0, 0, 31, 31);
|
||||
|
||||
redPen.setWidth(3);
|
||||
oPainter.setPen(redPen);
|
||||
pinkPen.setWidth(3);
|
||||
oPainter.setPen(pinkPen);
|
||||
oPainter.drawLine(2, 2, 29, 29);
|
||||
|
||||
oPainter.end();
|
||||
|
@ -188,6 +188,7 @@ void TilesetEditorMetatileSelector::drawUnused() {
|
|||
QPixmap metatilesPixmap = this->pixmap();
|
||||
|
||||
QPainter unusedPainter(&metatilesPixmap);
|
||||
unusedPainter.setOpacity(0.5);
|
||||
|
||||
for (int tile = 0; tile < this->usedMetatiles.size(); tile++) {
|
||||
if (!usedMetatiles[tile]) {
|
||||
|
|
|
@ -52,6 +52,8 @@ void TilesetEditorTileSelector::draw() {
|
|||
if (!this->externalSelection || (this->externalSelectionWidth == 1 && this->externalSelectionHeight == 1)) {
|
||||
this->drawSelection();
|
||||
}
|
||||
|
||||
if (showUnused) drawUnused();
|
||||
}
|
||||
|
||||
void TilesetEditorTileSelector::select(uint16_t tile) {
|
||||
|
@ -286,3 +288,53 @@ QImage TilesetEditorTileSelector::buildSecondaryTilesIndexedImage() {
|
|||
indexedImage.setColorTable(palette.toVector());
|
||||
return indexedImage;
|
||||
}
|
||||
|
||||
void TilesetEditorTileSelector::drawUnused() {
|
||||
// setup the circle with a line through it image to layer above unused metatiles
|
||||
QPixmap redX(16, 16);
|
||||
redX.fill(Qt::transparent);
|
||||
|
||||
QBitmap mask(16, 16);
|
||||
|
||||
QPen whitePen(Qt::white);
|
||||
whitePen.setWidth(1);
|
||||
QPen pinkPen(Qt::magenta);
|
||||
pinkPen.setWidth(1);
|
||||
|
||||
QPainter oPainter(&redX);
|
||||
|
||||
oPainter.setPen(whitePen);
|
||||
oPainter.drawEllipse(QRect(1, 1, 14, 14));
|
||||
oPainter.setPen(pinkPen);
|
||||
oPainter.drawEllipse(QRect(2, 2, 12, 12));
|
||||
oPainter.drawEllipse(QRect(3, 3, 10, 10));
|
||||
|
||||
oPainter.setPen(whitePen);
|
||||
oPainter.drawEllipse(QRect(4, 4, 8, 8));
|
||||
|
||||
whitePen.setWidth(3);
|
||||
oPainter.setPen(whitePen);
|
||||
oPainter.drawLine(0, 0, 15, 15);
|
||||
|
||||
pinkPen.setWidth(1);
|
||||
oPainter.setPen(pinkPen);
|
||||
oPainter.drawLine(2, 2, 13, 13);
|
||||
|
||||
oPainter.end();
|
||||
|
||||
// draw symbol on unused metatiles
|
||||
QPixmap tilesPixmap = this->pixmap();
|
||||
|
||||
QPainter unusedPainter(&tilesPixmap);
|
||||
unusedPainter.setOpacity(0.5);
|
||||
|
||||
for (int tile = 0; tile < this->usedTiles.size(); tile++) {
|
||||
if (!usedTiles[tile]) {
|
||||
unusedPainter.drawPixmap((tile % 16) * 16, (tile / 16) * 16, redX);
|
||||
}
|
||||
}
|
||||
|
||||
unusedPainter.end();
|
||||
|
||||
this->setPixmap(tilesPixmap);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue