Add convenience functions for triple layer metatiles
This commit is contained in:
parent
eb8b9b0352
commit
3181523799
11 changed files with 42 additions and 38 deletions
|
@ -238,6 +238,8 @@ public:
|
||||||
bool getCreateMapTextFileEnabled();
|
bool getCreateMapTextFileEnabled();
|
||||||
void setTripleLayerMetatilesEnabled(bool enable);
|
void setTripleLayerMetatilesEnabled(bool enable);
|
||||||
bool getTripleLayerMetatilesEnabled();
|
bool getTripleLayerMetatilesEnabled();
|
||||||
|
int getNumLayersInMetatile();
|
||||||
|
int getNumTilesInMetatile();
|
||||||
void setNewMapMetatileId(int metatileId);
|
void setNewMapMetatileId(int metatileId);
|
||||||
int getNewMapMetatileId();
|
int getNewMapMetatileId();
|
||||||
void setNewMapElevation(int elevation);
|
void setNewMapElevation(int elevation);
|
||||||
|
|
|
@ -36,6 +36,7 @@ public:
|
||||||
Metatile();
|
Metatile();
|
||||||
Metatile(const Metatile &other) = default;
|
Metatile(const Metatile &other) = default;
|
||||||
Metatile &operator=(const Metatile &other) = default;
|
Metatile &operator=(const Metatile &other) = default;
|
||||||
|
Metatile(const int numTiles);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QList<Tile> tiles;
|
QList<Tile> tiles;
|
||||||
|
|
|
@ -7,8 +7,8 @@
|
||||||
class TilesetEditorTileSelector: public SelectablePixmapItem {
|
class TilesetEditorTileSelector: public SelectablePixmapItem {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
TilesetEditorTileSelector(Tileset *primaryTileset, Tileset *secondaryTileset, bool isTripleLayer)
|
TilesetEditorTileSelector(Tileset *primaryTileset, Tileset *secondaryTileset, int numLayers)
|
||||||
: SelectablePixmapItem(16, 16, isTripleLayer ? 6 : 4, 2) {
|
: SelectablePixmapItem(16, 16, numLayers * 2, 2) {
|
||||||
this->primaryTileset = primaryTileset;
|
this->primaryTileset = primaryTileset;
|
||||||
this->secondaryTileset = secondaryTileset;
|
this->secondaryTileset = secondaryTileset;
|
||||||
this->numTilesWide = 16;
|
this->numTilesWide = 16;
|
||||||
|
|
|
@ -795,6 +795,14 @@ bool ProjectConfig::getTripleLayerMetatilesEnabled() {
|
||||||
return this->enableTripleLayerMetatiles;
|
return this->enableTripleLayerMetatiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ProjectConfig::getNumLayersInMetatile() {
|
||||||
|
return this->enableTripleLayerMetatiles ? 3 : 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ProjectConfig::getNumTilesInMetatile() {
|
||||||
|
return this->enableTripleLayerMetatiles ? 12 : 8;
|
||||||
|
}
|
||||||
|
|
||||||
void ProjectConfig::setNewMapMetatileId(int metatileId) {
|
void ProjectConfig::setNewMapMetatileId(int metatileId) {
|
||||||
this->newMapMetatileId = metatileId;
|
this->newMapMetatileId = metatileId;
|
||||||
this->save();
|
this->save();
|
||||||
|
|
|
@ -10,6 +10,19 @@ Metatile::Metatile() :
|
||||||
unusedAttributes(0)
|
unusedAttributes(0)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
Metatile::Metatile(const int numTiles) :
|
||||||
|
behavior(0),
|
||||||
|
layerType(0),
|
||||||
|
encounterType(0),
|
||||||
|
terrainType(0),
|
||||||
|
unusedAttributes(0)
|
||||||
|
{
|
||||||
|
Tile tile = Tile();
|
||||||
|
for (int i = 0; i < numTiles; i++) {
|
||||||
|
this->tiles.append(tile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int Metatile::getIndexInTileset(int metatileId) {
|
int Metatile::getIndexInTileset(int metatileId) {
|
||||||
if (metatileId < Project::getNumMetatilesPrimary()) {
|
if (metatileId < Project::getNumMetatilesPrimary()) {
|
||||||
return metatileId;
|
return metatileId;
|
||||||
|
|
|
@ -1307,8 +1307,8 @@ void MainWindow::on_actionNew_Tileset_triggered() {
|
||||||
int numMetaTiles = createTilesetDialog->isSecondary ? (Project::getNumTilesTotal() - Project::getNumTilesPrimary()) : Project::getNumTilesPrimary();
|
int numMetaTiles = createTilesetDialog->isSecondary ? (Project::getNumTilesTotal() - Project::getNumTilesPrimary()) : Project::getNumTilesPrimary();
|
||||||
QImage tilesImage(":/images/blank_tileset.png");
|
QImage tilesImage(":/images/blank_tileset.png");
|
||||||
editor->project->loadTilesetTiles(&newSet, tilesImage);
|
editor->project->loadTilesetTiles(&newSet, tilesImage);
|
||||||
|
int tilesPerMetatile = projectConfig.getNumTilesInMetatile();
|
||||||
for(int i = 0; i < numMetaTiles; ++i) {
|
for(int i = 0; i < numMetaTiles; ++i) {
|
||||||
int tilesPerMetatile = projectConfig.getTripleLayerMetatilesEnabled() ? 12 : 8;
|
|
||||||
Metatile *mt = new Metatile();
|
Metatile *mt = new Metatile();
|
||||||
for(int j = 0; j < tilesPerMetatile; ++j){
|
for(int j = 0; j < tilesPerMetatile; ++j){
|
||||||
Tile tile(0, false, false, 0);
|
Tile tile(0, false, false, 0);
|
||||||
|
|
|
@ -1079,7 +1079,7 @@ void Project::saveTilesetMetatiles(Tileset *tileset) {
|
||||||
QFile metatiles_file(tileset->metatiles_path);
|
QFile metatiles_file(tileset->metatiles_path);
|
||||||
if (metatiles_file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
|
if (metatiles_file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
|
||||||
QByteArray data;
|
QByteArray data;
|
||||||
int numTiles = projectConfig.getTripleLayerMetatilesEnabled() ? 12 : 8;
|
int numTiles = projectConfig.getNumTilesInMetatile();
|
||||||
for (Metatile *metatile : tileset->metatiles) {
|
for (Metatile *metatile : tileset->metatiles) {
|
||||||
for (int i = 0; i < numTiles; i++) {
|
for (int i = 0; i < numTiles; i++) {
|
||||||
uint16_t tile = metatile->tiles.at(i).rawValue();
|
uint16_t tile = metatile->tiles.at(i).rawValue();
|
||||||
|
@ -1591,7 +1591,7 @@ void Project::loadTilesetMetatiles(Tileset* tileset) {
|
||||||
QFile metatiles_file(tileset->metatiles_path);
|
QFile metatiles_file(tileset->metatiles_path);
|
||||||
if (metatiles_file.open(QIODevice::ReadOnly)) {
|
if (metatiles_file.open(QIODevice::ReadOnly)) {
|
||||||
QByteArray data = metatiles_file.readAll();
|
QByteArray data = metatiles_file.readAll();
|
||||||
int tilesPerMetatile = projectConfig.getTripleLayerMetatilesEnabled() ? 12 : 8;
|
int tilesPerMetatile = projectConfig.getNumTilesInMetatile();
|
||||||
int bytesPerMetatile = 2 * tilesPerMetatile;
|
int bytesPerMetatile = 2 * tilesPerMetatile;
|
||||||
int num_metatiles = data.length() / bytesPerMetatile;
|
int num_metatiles = data.length() / bytesPerMetatile;
|
||||||
QList<Metatile*> metatiles;
|
QList<Metatile*> metatiles;
|
||||||
|
|
|
@ -691,7 +691,7 @@ void MainWindow::setMetatileAttributes(int metatileId, int attributes) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int MainWindow::calculateTileBounds(int * tileStart, int * tileEnd) {
|
int MainWindow::calculateTileBounds(int * tileStart, int * tileEnd) {
|
||||||
int maxNumTiles = projectConfig.getTripleLayerMetatilesEnabled() ? 12 : 8;
|
int maxNumTiles = projectConfig.getNumTilesInMetatile();
|
||||||
if (*tileEnd >= maxNumTiles || *tileEnd < 0)
|
if (*tileEnd >= maxNumTiles || *tileEnd < 0)
|
||||||
*tileEnd = maxNumTiles - 1;
|
*tileEnd = maxNumTiles - 1;
|
||||||
if (*tileStart >= maxNumTiles || *tileStart < 0)
|
if (*tileStart >= maxNumTiles || *tileStart < 0)
|
||||||
|
|
|
@ -70,7 +70,6 @@ void Scripting::populateGlobalObject(MainWindow *mainWindow) {
|
||||||
int numTilesTotal = Project::getNumTilesTotal();
|
int numTilesTotal = Project::getNumTilesTotal();
|
||||||
int numMetatilesPrimary = Project::getNumMetatilesPrimary();
|
int numMetatilesPrimary = Project::getNumMetatilesPrimary();
|
||||||
int numMetatilesTotal = Project::getNumMetatilesTotal();
|
int numMetatilesTotal = Project::getNumMetatilesTotal();
|
||||||
bool tripleLayerEnabled = projectConfig.getTripleLayerMetatilesEnabled();
|
|
||||||
|
|
||||||
// Invisibly create an "About" window to read Porymap version
|
// Invisibly create an "About" window to read Porymap version
|
||||||
AboutPorymap *about = new AboutPorymap(mainWindow);
|
AboutPorymap *about = new AboutPorymap(mainWindow);
|
||||||
|
@ -85,8 +84,8 @@ void Scripting::populateGlobalObject(MainWindow *mainWindow) {
|
||||||
constants.setProperty("max_secondary_tiles", numTilesTotal - numTilesPrimary);
|
constants.setProperty("max_secondary_tiles", numTilesTotal - numTilesPrimary);
|
||||||
constants.setProperty("max_primary_metatiles", numMetatilesPrimary);
|
constants.setProperty("max_primary_metatiles", numMetatilesPrimary);
|
||||||
constants.setProperty("max_secondary_metatiles", numMetatilesTotal - numMetatilesPrimary);
|
constants.setProperty("max_secondary_metatiles", numMetatilesTotal - numMetatilesPrimary);
|
||||||
constants.setProperty("layers_per_metatile", tripleLayerEnabled ? 3 : 2);
|
constants.setProperty("layers_per_metatile", projectConfig.getNumLayersInMetatile());
|
||||||
constants.setProperty("tiles_per_metatile", tripleLayerEnabled ? 12 : 8);
|
constants.setProperty("tiles_per_metatile", projectConfig.getNumTilesInMetatile());
|
||||||
constants.setProperty("base_game_version", projectConfig.getBaseGameVersionString());
|
constants.setProperty("base_game_version", projectConfig.getBaseGameVersionString());
|
||||||
|
|
||||||
instance->engine->globalObject().setProperty("constants", constants);
|
instance->engine->globalObject().setProperty("constants", constants);
|
||||||
|
|
|
@ -19,11 +19,9 @@ void MetatileLayersItem::draw() {
|
||||||
QPoint(80, 16),
|
QPoint(80, 16),
|
||||||
};
|
};
|
||||||
|
|
||||||
bool isTripleLayerMetatile = projectConfig.getTripleLayerMetatilesEnabled();
|
int numTiles = projectConfig.getNumTilesInMetatile();
|
||||||
int width = isTripleLayerMetatile ? 96 : 64;
|
QPixmap pixmap(numTiles * 8, 32);
|
||||||
QPixmap pixmap(width, 32);
|
|
||||||
QPainter painter(&pixmap);
|
QPainter painter(&pixmap);
|
||||||
int numTiles = isTripleLayerMetatile ? 12 : 8;
|
|
||||||
for (int i = 0; i < numTiles; i++) {
|
for (int i = 0; i < numTiles; i++) {
|
||||||
Tile tile = this->metatile->tiles.at(i);
|
Tile tile = this->metatile->tiles.at(i);
|
||||||
QImage tileImage = getPalettedTileImage(tile.tileId, this->primaryTileset, this->secondaryTileset, tile.palette, true)
|
QImage tileImage = getPalettedTileImage(tile.tileId, this->primaryTileset, this->secondaryTileset, tile.palette, true)
|
||||||
|
@ -98,8 +96,7 @@ void MetatileLayersItem::clearLastModifiedCoords() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetatileLayersItem::getBoundedCoords(QPointF pos, int *x, int *y) {
|
void MetatileLayersItem::getBoundedCoords(QPointF pos, int *x, int *y) {
|
||||||
bool isTripleLayerMetatile = projectConfig.getTripleLayerMetatilesEnabled();
|
int maxX = (projectConfig.getNumLayersInMetatile() * 2) - 1;
|
||||||
int maxX = isTripleLayerMetatile ? 5 : 3;
|
|
||||||
*x = static_cast<int>(pos.x()) / 16;
|
*x = static_cast<int>(pos.x()) / 16;
|
||||||
*y = static_cast<int>(pos.y()) / 16;
|
*y = static_cast<int>(pos.y()) / 16;
|
||||||
if (*x < 0) *x = 0;
|
if (*x < 0) *x = 0;
|
||||||
|
|
|
@ -192,8 +192,7 @@ void TilesetEditor::initMetatileLayersItem() {
|
||||||
|
|
||||||
void TilesetEditor::initTileSelector()
|
void TilesetEditor::initTileSelector()
|
||||||
{
|
{
|
||||||
this->tileSelector = new TilesetEditorTileSelector(this->primaryTileset, this->secondaryTileset,
|
this->tileSelector = new TilesetEditorTileSelector(this->primaryTileset, this->secondaryTileset, projectConfig.getNumLayersInMetatile());
|
||||||
projectConfig.getTripleLayerMetatilesEnabled());
|
|
||||||
connect(this->tileSelector, &TilesetEditorTileSelector::hoveredTileChanged,
|
connect(this->tileSelector, &TilesetEditorTileSelector::hoveredTileChanged,
|
||||||
this, &TilesetEditor::onHoveredTileChanged);
|
this, &TilesetEditor::onHoveredTileChanged);
|
||||||
connect(this->tileSelector, &TilesetEditorTileSelector::hoveredTileCleared,
|
connect(this->tileSelector, &TilesetEditorTileSelector::hoveredTileCleared,
|
||||||
|
@ -398,8 +397,7 @@ void TilesetEditor::onMetatileLayerTileChanged(int x, int y) {
|
||||||
QPoint dimensions = this->tileSelector->getSelectionDimensions();
|
QPoint dimensions = this->tileSelector->getSelectionDimensions();
|
||||||
QList<Tile> tiles = this->tileSelector->getSelectedTiles();
|
QList<Tile> tiles = this->tileSelector->getSelectedTiles();
|
||||||
int selectedTileIndex = 0;
|
int selectedTileIndex = 0;
|
||||||
bool isTripleLayerMetatile = projectConfig.getTripleLayerMetatilesEnabled();
|
int maxTileIndex = projectConfig.getNumTilesInMetatile();
|
||||||
int maxTileIndex = isTripleLayerMetatile ? 12: 8;
|
|
||||||
for (int j = 0; j < dimensions.y(); j++) {
|
for (int j = 0; j < dimensions.y(); j++) {
|
||||||
for (int i = 0; i < dimensions.x(); i++) {
|
for (int i = 0; i < dimensions.x(); i++) {
|
||||||
int tileIndex = ((x + i) / 2 * 4) + ((y + j) * 2) + ((x + i) % 2);
|
int tileIndex = ((x + i) / 2 * 4) + ((y + j) * 2) + ((x + i) % 2);
|
||||||
|
@ -430,8 +428,7 @@ void TilesetEditor::onMetatileLayerSelectionChanged(QPoint selectionOrigin, int
|
||||||
QList<int> tileIdxs;
|
QList<int> tileIdxs;
|
||||||
int x = selectionOrigin.x();
|
int x = selectionOrigin.x();
|
||||||
int y = selectionOrigin.y();
|
int y = selectionOrigin.y();
|
||||||
bool isTripleLayerMetatile = projectConfig.getTripleLayerMetatilesEnabled();
|
int maxTileIndex = projectConfig.getNumTilesInMetatile();
|
||||||
int maxTileIndex = isTripleLayerMetatile ? 12: 8;
|
|
||||||
for (int j = 0; j < height; j++) {
|
for (int j = 0; j < height; j++) {
|
||||||
for (int i = 0; i < width; i++) {
|
for (int i = 0; i < width; i++) {
|
||||||
int tileIndex = ((x + i) / 2 * 4) + ((y + j) * 2) + ((x + i) % 2);
|
int tileIndex = ((x + i) / 2 * 4) + ((y + j) * 2) + ((x + i) % 2);
|
||||||
|
@ -759,28 +756,18 @@ void TilesetEditor::on_actionChange_Metatiles_Count_triggered()
|
||||||
if (dialog.exec() == QDialog::Accepted) {
|
if (dialog.exec() == QDialog::Accepted) {
|
||||||
int numPrimaryMetatiles = primarySpinBox->value();
|
int numPrimaryMetatiles = primarySpinBox->value();
|
||||||
int numSecondaryMetatiles = secondarySpinBox->value();
|
int numSecondaryMetatiles = secondarySpinBox->value();
|
||||||
int numTiles = projectConfig.getTripleLayerMetatilesEnabled() ? 12 : 8;
|
int numTiles = projectConfig.getNumTilesInMetatile();
|
||||||
while (this->primaryTileset->metatiles.length() > numPrimaryMetatiles) {
|
while (this->primaryTileset->metatiles.length() > numPrimaryMetatiles) {
|
||||||
delete this->primaryTileset->metatiles.takeLast();
|
delete this->primaryTileset->metatiles.takeLast();
|
||||||
}
|
}
|
||||||
while (this->primaryTileset->metatiles.length() < numPrimaryMetatiles) {
|
while (this->primaryTileset->metatiles.length() < numPrimaryMetatiles) {
|
||||||
Tile tile(0, false, false, 0);
|
this->primaryTileset->metatiles.append(new Metatile(numTiles));
|
||||||
Metatile *metatile = new Metatile();
|
|
||||||
for (int i = 0; i < numTiles; i++) {
|
|
||||||
metatile->tiles.append(tile);
|
|
||||||
}
|
|
||||||
this->primaryTileset->metatiles.append(metatile);
|
|
||||||
}
|
}
|
||||||
while (this->secondaryTileset->metatiles.length() > numSecondaryMetatiles) {
|
while (this->secondaryTileset->metatiles.length() > numSecondaryMetatiles) {
|
||||||
delete this->secondaryTileset->metatiles.takeLast();
|
delete this->secondaryTileset->metatiles.takeLast();
|
||||||
}
|
}
|
||||||
while (this->secondaryTileset->metatiles.length() < numSecondaryMetatiles) {
|
while (this->secondaryTileset->metatiles.length() < numSecondaryMetatiles) {
|
||||||
Tile tile(0, false, false, 0);
|
this->secondaryTileset->metatiles.append(new Metatile(numTiles));
|
||||||
Metatile *metatile = new Metatile();
|
|
||||||
for (int i = 0; i < numTiles; i++) {
|
|
||||||
metatile->tiles.append(tile);
|
|
||||||
}
|
|
||||||
this->secondaryTileset->metatiles.append(metatile);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this->metatileSelector->updateSelectedMetatile();
|
this->metatileSelector->updateSelectedMetatile();
|
||||||
|
@ -852,10 +839,7 @@ void TilesetEditor::on_actionRedo_triggered()
|
||||||
|
|
||||||
void TilesetEditor::on_actionCut_triggered()
|
void TilesetEditor::on_actionCut_triggered()
|
||||||
{
|
{
|
||||||
int numTiles = projectConfig.getTripleLayerMetatilesEnabled() ? 12 : 8;
|
Metatile * empty = new Metatile(projectConfig.getNumTilesInMetatile());
|
||||||
Metatile * empty = new Metatile();
|
|
||||||
for (int i = 0; i < numTiles; i++)
|
|
||||||
empty->tiles.append(Tile());
|
|
||||||
this->copyMetatile(true);
|
this->copyMetatile(true);
|
||||||
this->pasteMetatile(empty);
|
this->pasteMetatile(empty);
|
||||||
delete empty;
|
delete empty;
|
||||||
|
|
Loading…
Reference in a new issue