Skip to content

Commit 56d1a0d

Browse files
Fix exported metatile image scaling, remove hardcoded cell sizes
1 parent bbe34e4 commit 56d1a0d

11 files changed

+62
-59
lines changed

forms/tileseteditor.ui

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>733</width>
9+
<width>748</width>
1010
<height>784</height>
1111
</rect>
1212
</property>
@@ -267,16 +267,10 @@
267267
<verstretch>0</verstretch>
268268
</sizepolicy>
269269
</property>
270-
<property name="minimumSize">
271-
<size>
272-
<width>66</width>
273-
<height>34</height>
274-
</size>
275-
</property>
276270
<property name="maximumSize">
277271
<size>
278-
<width>96</width>
279-
<height>34</height>
272+
<width>1</width>
273+
<height>1</height>
280274
</size>
281275
</property>
282276
<property name="verticalScrollBarPolicy">
@@ -561,8 +555,8 @@
561555
<rect>
562556
<x>0</x>
563557
<y>0</y>
564-
<width>445</width>
565-
<height>237</height>
558+
<width>499</width>
559+
<height>241</height>
566560
</rect>
567561
</property>
568562
<layout class="QGridLayout" name="gridLayout_2">
@@ -623,7 +617,7 @@
623617
<rect>
624618
<x>0</x>
625619
<y>0</y>
626-
<width>733</width>
620+
<width>748</width>
627621
<height>37</height>
628622
</rect>
629623
</property>

include/config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class PorymapConfig: public KeyValueConfigBase
8282
this->collisionOpacity = 50;
8383
this->collisionZoom = 30;
8484
this->metatilesZoom = 30;
85-
this->tilesetEditorMetatilesZoom = 30;
85+
this->tilesetEditorMetatilesZoom = 45;
8686
this->tilesetEditorTilesZoom = 30;
8787
this->showPlayerView = false;
8888
this->showCursorTile = true;

include/ui/metatilelayersitem.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,7 @@
99
class MetatileLayersItem: public SelectablePixmapItem {
1010
Q_OBJECT
1111
public:
12-
MetatileLayersItem(Metatile *metatile, Tileset *primaryTileset, Tileset *secondaryTileset): SelectablePixmapItem(16, 16, 6, 2) {
13-
this->metatile = metatile;
14-
this->primaryTileset = primaryTileset;
15-
this->secondaryTileset = secondaryTileset;
16-
this->clearLastModifiedCoords();
17-
this->clearLastHoveredCoords();
18-
setAcceptHoverEvents(true);
19-
}
12+
MetatileLayersItem(Metatile *metatile, Tileset *primaryTileset, Tileset *secondaryTileset);
2013
void draw();
2114
void setTilesets(Tileset*, Tileset*);
2215
void setMetatile(Metatile*);

include/ui/tilemaptileselector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class TilemapTileSelector: public SelectablePixmapItem {
136136
this->palette = PaletteUtil::parse(palFilepath, &err);
137137
}
138138
this->setPixmap(QPixmap::fromImage(this->tileset));
139-
this->numTilesWide = this->tileset.width() / 8;
139+
this->numTilesWide = this->tileset.width() / this->cellWidth;
140140
this->selectedTile = 0x00;
141141
setAcceptHoverEvents(true);
142142
}

src/ui/metatilelayersitem.cpp

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33
#include "imageproviders.h"
44
#include <QPainter>
55

6+
MetatileLayersItem::MetatileLayersItem(Metatile *metatile, Tileset *primaryTileset, Tileset *secondaryTileset)
7+
: SelectablePixmapItem(16, 16, 2 * projectConfig.getNumLayersInMetatile(), 2),
8+
metatile(metatile),
9+
primaryTileset(primaryTileset),
10+
secondaryTileset(secondaryTileset)
11+
{
12+
clearLastModifiedCoords();
13+
clearLastHoveredCoords();
14+
setAcceptHoverEvents(true);
15+
}
16+
617
static const QList<QPoint> tilePositions = {
718
QPoint(0, 0),
819
QPoint(1, 0),
@@ -20,23 +31,31 @@ static const QList<QPoint> tilePositions = {
2031

2132
void MetatileLayersItem::draw() {
2233
const int numLayers = projectConfig.getNumLayersInMetatile();
23-
QPixmap pixmap(numLayers * 32, 32);
34+
const int layerWidth = this->cellWidth * 2;
35+
const int layerHeight = this->cellHeight * 2;
36+
QPixmap pixmap(numLayers * layerWidth, layerHeight);
2437
QPainter painter(&pixmap);
2538

2639
// Draw tile images
2740
int numTiles = qMin(projectConfig.getNumTilesInMetatile(), this->metatile ? this->metatile->tiles.length() : 0);
2841
for (int i = 0; i < numTiles; i++) {
2942
Tile tile = this->metatile->tiles.at(i);
30-
QImage tileImage = getPalettedTileImage(tile.tileId, this->primaryTileset, this->secondaryTileset, tile.palette, true).scaled(16, 16);
43+
QImage tileImage = getPalettedTileImage(tile.tileId,
44+
this->primaryTileset,
45+
this->secondaryTileset,
46+
tile.palette,
47+
true
48+
).scaled(this->cellWidth, this->cellHeight);
3149
tile.flip(&tileImage);
32-
painter.drawImage(tilePositions.at(i) * 16, tileImage);
50+
QPoint pos = tilePositions.at(i);
51+
painter.drawImage(pos.x() * this->cellWidth, pos.y() * this->cellHeight, tileImage);
3352
}
3453
if (this->showGrid) {
3554
// Draw grid
3655
painter.setPen(Qt::white);
3756
for (int i = 1; i < numLayers; i++) {
38-
int x = i * 32;
39-
painter.drawLine(x, 0, x, 32);
57+
int x = i * layerWidth;
58+
painter.drawLine(x, 0, x, layerHeight);
4059
}
4160
}
4261

@@ -127,13 +146,8 @@ void MetatileLayersItem::clearLastHoveredCoords() {
127146
}
128147

129148
QPoint MetatileLayersItem::getBoundedPos(const QPointF &pos) {
130-
int x, y;
131-
int maxX = (projectConfig.getNumLayersInMetatile() * 2) - 1;
132-
x = static_cast<int>(pos.x()) / 16;
133-
y = static_cast<int>(pos.y()) / 16;
134-
if (x < 0) x = 0;
135-
if (y < 0) y = 0;
136-
if (x > maxX) x = maxX;
137-
if (y > 1) y = 1;
138-
return QPoint(x, y);
149+
int x = static_cast<int>(pos.x()) / this->cellWidth;
150+
int y = static_cast<int>(pos.y()) / this->cellHeight;
151+
return QPoint( qMax(0, qMin(x, this->maxSelectionWidth - 1)),
152+
qMax(0, qMin(y, this->maxSelectionHeight - 1)) );
139153
}

src/ui/metatileselector.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void MetatileSelector::updateBasePixmap() {
2121
if (length_ % this->numMetatilesWide != 0) {
2222
height_++;
2323
}
24-
QImage image(this->numMetatilesWide * 16, height_ * 16, QImage::Format_RGBA8888);
24+
QImage image(this->numMetatilesWide * this->cellWidth, height_ * this->cellHeight, QImage::Format_RGBA8888);
2525
image.fill(Qt::magenta);
2626
QPainter painter(&image);
2727
for (int i = 0; i < length_; i++) {
@@ -32,7 +32,7 @@ void MetatileSelector::updateBasePixmap() {
3232
QImage metatile_image = getMetatileImage(tile, this->primaryTileset, this->secondaryTileset, layout->metatileLayerOrder, layout->metatileLayerOpacity);
3333
int map_y = i / this->numMetatilesWide;
3434
int map_x = i % this->numMetatilesWide;
35-
QPoint metatile_origin = QPoint(map_x * 16, map_y * 16);
35+
QPoint metatile_origin = QPoint(map_x * this->cellWidth, map_y * this->cellHeight);
3636
painter.drawImage(metatile_origin, metatile_image);
3737
}
3838
painter.end();

src/ui/regionmapentriespixmapitem.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ void RegionMapEntriesPixmapItem::draw() {
1717
entry_w = entry.width, entry_h = entry.height;
1818
}
1919

20-
QImage image(region_map->tilemapWidth() * 8, region_map->tilemapHeight() * 8, QImage::Format_RGBA8888);
20+
QImage image(region_map->tilemapWidth() * this->cellWidth, region_map->tilemapHeight() * this->cellHeight, QImage::Format_RGBA8888);
2121

2222
QPainter painter(&image);
2323
for (int i = 0; i < region_map->tilemapSize(); i++) {
2424
QImage bottom_img = this->tile_selector->tileImg(region_map->getTile(i));
25-
QImage top_img(8, 8, QImage::Format_RGBA8888);
25+
QImage top_img(this->cellWidth, this->cellHeight, QImage::Format_RGBA8888);
2626
int x = i % region_map->tilemapWidth();
2727
int y = i / region_map->tilemapWidth();
2828
bool insideEntry = false;
@@ -40,7 +40,7 @@ void RegionMapEntriesPixmapItem::draw() {
4040
} else {
4141
top_img.fill(Qt::black);
4242
}
43-
QPoint pos = QPoint(x * 8, y * 8);
43+
QPoint pos = QPoint(x * this->cellWidth, y * this->cellHeight);
4444
painter.setOpacity(1);
4545
painter.drawImage(pos, bottom_img);
4646
painter.save();

src/ui/regionmaplayoutpixmapitem.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ void RegionMapLayoutPixmapItem::draw() {
88
QPainter painter(&image);
99
for (int i = 0; i < region_map->tilemapSize(); i++) {
1010
QImage bottom_img = this->tile_selector->tileImg(region_map->getTile(i));
11-
QImage top_img(8, 8, QImage::Format_RGBA8888);
11+
QImage top_img(this->cellWidth, this->cellHeight, QImage::Format_RGBA8888);
1212
if (region_map->squareHasMap(i)) {
1313
top_img.fill(Qt::gray);
1414
} else {
1515
top_img.fill(Qt::black);
1616
}
1717
int x = i % region_map->tilemapWidth();
1818
int y = i / region_map->tilemapWidth();
19-
QPoint pos = QPoint(x * 8, y * 8);
19+
QPoint pos = QPoint(x * this->cellWidth, y * this->cellHeight);
2020
painter.setOpacity(1);
2121
painter.drawImage(pos, bottom_img);
2222
painter.save();

src/ui/tilemaptileselector.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ void TilemapTileSelector::draw() {
77
this->pixelWidth = width_;
88
size_t height_ = this->tileset.height();
99
this->pixelHeight = height_;
10-
size_t ntiles_ = (width_/8) * (height_/8);
10+
size_t ntiles_ = (width_/this->cellWidth) * (height_/this->cellHeight);
1111

12-
this->numTilesWide = width_ / 8;
12+
this->numTilesWide = width_ / this->cellWidth;
1313
this->numTiles = ntiles_;
1414

1515
this->setPixmap(QPixmap::fromImage(this->setPalette(this->tile_palette)));
@@ -92,7 +92,7 @@ QImage TilemapTileSelector::tileImg(shared_ptr<TilemapTile> tile) {
9292
QImage tilesetImage = setPalette(tile->palette());
9393

9494
// take a tile from the tileset
95-
QImage img = tilesetImage.copy(pos.x() * 8, pos.y() * 8, 8, 8);
95+
QImage img = tilesetImage.copy(pos.x() * this->cellWidth, pos.y() * this->cellHeight, this->cellWidth, this->cellHeight);
9696

9797
// QImage::flip was introduced in 6.9.0 to replace QImage::mirrored.
9898
#if (QT_VERSION >= QT_VERSION_CHECK(6, 9, 0))

src/ui/tileseteditormetatileselector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <QPainter>
55

66
TilesetEditorMetatileSelector::TilesetEditorMetatileSelector(Tileset *primaryTileset, Tileset *secondaryTileset, Layout *layout)
7-
: SelectablePixmapItem(32, 32, 1, 1) {
7+
: SelectablePixmapItem(16, 16, 1, 1) {
88
this->primaryTileset = primaryTileset;
99
this->secondaryTileset = secondaryTileset;
1010
this->numMetatilesWide = 8;

0 commit comments

Comments
 (0)