Add ability to export tileset tiles image
This commit is contained in:
parent
95f712ef6f
commit
f1caa03c6c
5 changed files with 115 additions and 6 deletions
|
@ -479,6 +479,9 @@
|
|||
<addaction name="actionImport_Secondary_Tiles"/>
|
||||
<addaction name="actionChange_Metatiles_Count"/>
|
||||
<addaction name="actionChange_Palettes"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionExport_Primary_Tiles_Image"/>
|
||||
<addaction name="actionExport_Secondary_Tiles_Image"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuEdit">
|
||||
<property name="title">
|
||||
|
@ -502,22 +505,22 @@
|
|||
</action>
|
||||
<action name="actionImport_Primary_Tiles">
|
||||
<property name="text">
|
||||
<string>Import Primary Tiles</string>
|
||||
<string>Import Primary Tiles...</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionImport_Secondary_Tiles">
|
||||
<property name="text">
|
||||
<string>Import Secondary Tiles</string>
|
||||
<string>Import Secondary Tiles...</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionChange_Metatiles_Count">
|
||||
<property name="text">
|
||||
<string>Change Number of Metatiles</string>
|
||||
<string>Change Number of Metatiles...</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionChange_Palettes">
|
||||
<property name="text">
|
||||
<string>Change Palettes</string>
|
||||
<string>Palette Editor</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionUndo">
|
||||
|
@ -536,6 +539,16 @@
|
|||
<string>Ctrl+Y</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionExport_Primary_Tiles_Image">
|
||||
<property name="text">
|
||||
<string>Export Primary Tiles Image...</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionExport_Secondary_Tiles_Image">
|
||||
<property name="text">
|
||||
<string>Export Secondary Tiles Image...</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
|
|
@ -76,6 +76,10 @@ private slots:
|
|||
|
||||
void on_comboBox_layerType_activated(int arg1);
|
||||
|
||||
void on_actionExport_Primary_Tiles_Image_triggered();
|
||||
|
||||
void on_actionExport_Secondary_Tiles_Image_triggered();
|
||||
|
||||
private:
|
||||
void closeEvent(QCloseEvent*);
|
||||
void initMetatileSelector();
|
||||
|
|
|
@ -25,6 +25,8 @@ public:
|
|||
QList<Tile> getSelectedTiles();
|
||||
void setExternalSelection(int, int, QList<Tile>);
|
||||
QPoint getTileCoordsOnWidget(uint16_t);
|
||||
QImage buildPrimaryTilesIndexedImage();
|
||||
QImage buildSecondaryTilesIndexedImage();
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
||||
|
|
|
@ -369,8 +369,8 @@ void TilesetEditor::importTilesetTiles(Tileset *tileset, bool primary) {
|
|||
}
|
||||
|
||||
// Validate total number of tiles in image.
|
||||
int numTilesWide = image.width() / 16;
|
||||
int numTilesHigh = image.height() / 16;
|
||||
int numTilesWide = image.width() / 8;
|
||||
int numTilesHigh = image.height() / 8;
|
||||
int totalTiles = numTilesHigh * numTilesWide;
|
||||
int maxAllowedTiles = primary ? Project::getNumTilesPrimary() : Project::getNumTilesTotal() - Project::getNumTilesPrimary();
|
||||
if (totalTiles > maxAllowedTiles) {
|
||||
|
@ -553,3 +553,25 @@ void TilesetEditor::on_actionRedo_triggered()
|
|||
this->metatileLayersItem->clearLastModifiedCoords();
|
||||
}
|
||||
}
|
||||
|
||||
void TilesetEditor::on_actionExport_Primary_Tiles_Image_triggered()
|
||||
{
|
||||
QString defaultName = QString("%1_Tiles_Pal%2").arg(this->primaryTileset->name).arg(this->paletteId);
|
||||
QString defaultFilepath = QString("%1/%2.png").arg(this->project->root).arg(defaultName);
|
||||
QString filepath = QFileDialog::getSaveFileName(this, "Export Primary Tiles Image", defaultFilepath, "Image Files (*.png)");
|
||||
if (!filepath.isEmpty()) {
|
||||
QImage image = this->tileSelector->buildPrimaryTilesIndexedImage();
|
||||
image.save(filepath);
|
||||
}
|
||||
}
|
||||
|
||||
void TilesetEditor::on_actionExport_Secondary_Tiles_Image_triggered()
|
||||
{
|
||||
QString defaultName = QString("%1_Tiles_Pal%2").arg(this->secondaryTileset->name).arg(this->paletteId);
|
||||
QString defaultFilepath = QString("%1/%2.png").arg(this->project->root).arg(defaultName);
|
||||
QString filepath = QFileDialog::getSaveFileName(this, "Export Secondary Tiles Image", defaultFilepath, "Image Files (*.png)");
|
||||
if (!filepath.isEmpty()) {
|
||||
QImage image = this->tileSelector->buildSecondaryTilesIndexedImage();
|
||||
image.save(filepath);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "imageproviders.h"
|
||||
#include "project.h"
|
||||
#include <QPainter>
|
||||
#include <QVector>
|
||||
|
||||
QPoint TilesetEditorTileSelector::getSelectionDimensions() {
|
||||
if (this->externalSelection) {
|
||||
|
@ -169,3 +170,70 @@ QPoint TilesetEditorTileSelector::getTileCoordsOnWidget(uint16_t tile) {
|
|||
pos.ry() = (pos.y() * this->cellHeight) + (this->cellHeight / 2);
|
||||
return pos;
|
||||
}
|
||||
|
||||
QImage TilesetEditorTileSelector::buildPrimaryTilesIndexedImage() {
|
||||
if (!this->primaryTileset || !this->primaryTileset->tiles
|
||||
|| !this->secondaryTileset || !this->secondaryTileset->tiles) {
|
||||
return QImage();
|
||||
}
|
||||
|
||||
int primaryLength = this->primaryTileset->tiles->length();
|
||||
int height = primaryLength / this->numTilesWide;
|
||||
QList<QRgb> palette = Tileset::getPalette(this->paletteId, this->primaryTileset, this->secondaryTileset);
|
||||
QImage image(this->numTilesWide * 8, height * 8, QImage::Format_RGBA8888);
|
||||
|
||||
QPainter painter(&image);
|
||||
for (uint16_t tile = 0; tile < primaryLength; tile++) {
|
||||
QImage tileImage;
|
||||
if (tile < primaryLength) {
|
||||
tileImage = getColoredTileImage(tile, this->primaryTileset, this->secondaryTileset, this->paletteId);
|
||||
} else {
|
||||
tileImage = QImage(8, 8, QImage::Format_RGBA8888);
|
||||
tileImage.fill(palette.at(0));
|
||||
}
|
||||
|
||||
int y = tile / this->numTilesWide;
|
||||
int x = tile % this->numTilesWide;
|
||||
QPoint origin = QPoint(x * 8, y * 8);
|
||||
painter.drawImage(origin, tileImage.mirrored(this->xFlip, this->yFlip));
|
||||
}
|
||||
|
||||
painter.end();
|
||||
|
||||
QVector<QRgb> colorTable = palette.toVector();
|
||||
return image.convertToFormat(QImage::Format::Format_Indexed8, colorTable);
|
||||
}
|
||||
|
||||
QImage TilesetEditorTileSelector::buildSecondaryTilesIndexedImage() {
|
||||
if (!this->primaryTileset || !this->primaryTileset->tiles
|
||||
|| !this->secondaryTileset || !this->secondaryTileset->tiles) {
|
||||
return QImage();
|
||||
}
|
||||
|
||||
int secondaryLength = this->secondaryTileset->tiles->length();
|
||||
int height = secondaryLength / this->numTilesWide;
|
||||
QList<QRgb> palette = Tileset::getPalette(this->paletteId, this->primaryTileset, this->secondaryTileset);
|
||||
QImage image(this->numTilesWide * 8, height * 8, QImage::Format_RGBA8888);
|
||||
|
||||
QPainter painter(&image);
|
||||
uint16_t primaryLength = static_cast<uint16_t>(Project::getNumTilesPrimary());
|
||||
for (uint16_t tile = 0; tile < secondaryLength; tile++) {
|
||||
QImage tileImage;
|
||||
if (tile < secondaryLength) {
|
||||
tileImage = getColoredTileImage(tile + primaryLength, this->primaryTileset, this->secondaryTileset, this->paletteId);
|
||||
} else {
|
||||
tileImage = QImage(8, 8, QImage::Format_RGBA8888);
|
||||
tileImage.fill(palette.at(0));
|
||||
}
|
||||
|
||||
int y = tile / this->numTilesWide;
|
||||
int x = tile % this->numTilesWide;
|
||||
QPoint origin = QPoint(x * 8, y * 8);
|
||||
painter.drawImage(origin, tileImage.mirrored(this->xFlip, this->yFlip));
|
||||
}
|
||||
|
||||
painter.end();
|
||||
|
||||
QVector<QRgb> colorTable = palette.toVector();
|
||||
return image.convertToFormat(QImage::Format::Format_Indexed8, colorTable);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue