diff --git a/forms/mainwindow.ui b/forms/mainwindow.ui
index 46e0117a..92d83cc9 100644
--- a/forms/mainwindow.ui
+++ b/forms/mainwindow.ui
@@ -645,7 +645,7 @@
- 0
+ 2
@@ -1291,6 +1291,38 @@
+ -
+
+
+ Stamp Layer
+
+
+
-
+
+
+ Top Layer
+
+
+ true
+
+
+ buttonGroup_stampLayer
+
+
+
+ -
+
+
+ Bottom Layer
+
+
+ buttonGroup_stampLayer
+
+
+
+
+
+
-
@@ -1371,7 +1403,7 @@
0
0
411
- 468
+ 392
@@ -1808,8 +1840,8 @@
0
0
- 83
- 16
+ 100
+ 30
@@ -1902,8 +1934,8 @@
0
0
- 83
- 16
+ 100
+ 30
@@ -1996,8 +2028,8 @@
0
0
- 83
- 16
+ 100
+ 30
@@ -2096,8 +2128,8 @@
0
0
- 83
- 16
+ 100
+ 30
@@ -2190,8 +2222,8 @@
0
0
- 83
- 16
+ 100
+ 30
@@ -3553,4 +3585,7 @@
+
+
+
diff --git a/include/editor.h b/include/editor.h
index 4ce947b7..f7bf11f2 100644
--- a/include/editor.h
+++ b/include/editor.h
@@ -156,6 +156,7 @@ public:
void scaleMapView(int);
void openInTextEditor(const QString &path, int lineNum = 0) const;
bool eventLimitReached(Event::Type type);
+ StampLayer getSelectedStampLayer();
public slots:
void openMapScripts() const;
diff --git a/include/ui/mappixmapitem.h b/include/ui/mappixmapitem.h
index 961d5f9d..e5aeabeb 100644
--- a/include/ui/mappixmapitem.h
+++ b/include/ui/mappixmapitem.h
@@ -59,7 +59,7 @@ public:
MapPixmapItem::Axis lockedAxis;
QPoint selection_origin;
QList selection;
- virtual void paint(QGraphicsSceneMouseEvent*);
+ virtual void paint(QGraphicsSceneMouseEvent*, StampLayer stampLayer);
virtual void floodFill(QGraphicsSceneMouseEvent*);
virtual void magicFill(QGraphicsSceneMouseEvent*);
void magicFill(int x, int y, uint16_t metatileId, bool fromScriptCall = false);
@@ -86,7 +86,7 @@ public:
void shift(int xDelta, int yDelta, bool fromScriptCall = false);
virtual void draw(bool ignoreCache = false);
void updateMetatileSelection(QGraphicsSceneMouseEvent *event);
- void paintNormal(int x, int y, bool fromScriptCall = false);
+ void paintNormal(int x, int y, StampLayer stampLayer, bool fromScriptCall = false);
void lockNondominantAxis(QGraphicsSceneMouseEvent *event);
QPoint adjustCoords(QPoint pos);
diff --git a/include/ui/paintselection.h b/include/ui/paintselection.h
index 0e6623a0..8a8038e2 100644
--- a/include/ui/paintselection.h
+++ b/include/ui/paintselection.h
@@ -8,6 +8,12 @@
#include
#include
+enum StampLayer {
+ STAMP_LAYER_BOTTOM,
+ STAMP_LAYER_MIDDLE,
+ STAMP_LAYER_TOP,
+};
+
struct MetatileSelectionItem
{
bool enabled;
@@ -25,7 +31,7 @@ class PaintSelection
{
public:
QPoint dimensions;
- virtual bool paintNormal(int, Block*, Map*, int layer) = 0;
+ virtual bool paintNormal(int, Block*, Map*, StampLayer stampLayer) = 0;
};
class MetatileSelection: public PaintSelection
@@ -38,7 +44,7 @@ public:
this->metatileItems = other.metatileItems;
this->collisionItems = other.collisionItems;
}
- bool paintNormal(int index, Block *block, Map*, int layer) override;
+ bool paintNormal(int index, Block *block, Map*, StampLayer stampLayer) override;
bool hasCollision = false;
QList metatileItems;
QList collisionItems;
@@ -48,7 +54,7 @@ class StampSelection: public PaintSelection
{
public:
StampSelection() {}
- bool paintNormal(int index, Block *block, Map*, int layer) override;
+ bool paintNormal(int index, Block *block, Map*, StampLayer stampLayer) override;
QList stampIds;
};
diff --git a/src/editor.cpp b/src/editor.cpp
index b6fd26b6..49391ad4 100644
--- a/src/editor.cpp
+++ b/src/editor.cpp
@@ -1178,6 +1178,16 @@ void Editor::setStraightPathCursorMode(QGraphicsSceneMouseEvent *event) {
}
}
+StampLayer Editor::getSelectedStampLayer() {
+ auto stampLayerButton = ui->buttonGroup_stampLayer->checkedButton();
+ if (stampLayerButton == ui->radioButton_stampTopLayer) {
+ return StampLayer::STAMP_LAYER_TOP;
+ } else if (stampLayerButton == ui->radioButton_stampBottomLayer) {
+ return StampLayer::STAMP_LAYER_BOTTOM;
+ }
+ return StampLayer::STAMP_LAYER_MIDDLE;
+}
+
void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item) {
// TODO: add event tab object painting tool buttons stuff here
if (item->paintingMode == MapPixmapItem::PaintMode::Disabled) {
@@ -1207,7 +1217,7 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item
item->lockNondominantAxis(event);
pos = item->adjustCoords(pos);
}
- item->paint(event);
+ item->paint(event, getSelectedStampLayer());
}
} else if (map_edit_mode == "select") {
item->select(event);
diff --git a/src/scriptapi/apimap.cpp b/src/scriptapi/apimap.cpp
index fde049db..7ad8f00c 100644
--- a/src/scriptapi/apimap.cpp
+++ b/src/scriptapi/apimap.cpp
@@ -77,7 +77,7 @@ void MainWindow::setBlock(int x, int y, int rawValue, bool forceRedraw, bool com
void MainWindow::setBlocksFromSelection(int x, int y, bool forceRedraw, bool commitChanges) {
if (this->editor && this->editor->map_item) {
- this->editor->map_item->paintNormal(x, y, true);
+ this->editor->map_item->paintNormal(x, y, StampLayer::STAMP_LAYER_BOTTOM, true);
this->tryCommitMapChanges(commitChanges);
this->tryRedrawMapArea(forceRedraw);
}
diff --git a/src/ui/mappixmapitem.cpp b/src/ui/mappixmapitem.cpp
index dbdac39e..41d749e9 100644
--- a/src/ui/mappixmapitem.cpp
+++ b/src/ui/mappixmapitem.cpp
@@ -7,7 +7,7 @@
#define SWAP(a, b) do { if (a != b) { a ^= b; b ^= a; a ^= b; } } while (0)
-void MapPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
+void MapPixmapItem::paint(QGraphicsSceneMouseEvent *event, StampLayer stampLayer) {
if (map) {
if (event->type() == QEvent::GraphicsSceneMouseRelease) {
actionId_++;
@@ -31,13 +31,13 @@ void MapPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
if (!shiftPressed && selectionDimensions.x() == 3 && selectionDimensions.y() == 3) {
paintSmartPath(pos.x(), pos.y());
} else {
- paintNormal(pos.x(), pos.y());
+ paintNormal(pos.x(), pos.y(), stampLayer);
}
} else {
if (shiftPressed && selectionDimensions.x() == 3 && selectionDimensions.y() == 3) {
paintSmartPath(pos.x(), pos.y());
} else {
- paintNormal(pos.x(), pos.y());
+ paintNormal(pos.x(), pos.y(), stampLayer);
}
}
}
@@ -110,7 +110,7 @@ PaintSelection* MapPixmapItem::getActiveSelection() {
}
}
-void MapPixmapItem::paintNormal(int x, int y, bool fromScriptCall) {
+void MapPixmapItem::paintNormal(int x, int y, StampLayer stampLayer, bool fromScriptCall) {
PaintSelection *selection = this->getActiveSelection();
int initialX = fromScriptCall ? x : this->paint_tile_initial_x;
int initialY = fromScriptCall ? y : this->paint_tile_initial_y;
@@ -137,7 +137,7 @@ void MapPixmapItem::paintNormal(int x, int y, bool fromScriptCall) {
Block block;
if (map->getBlock(actualX, actualY, &block)) {
int index = j * selectionWidth + i;
- if (selection->paintNormal(index, &block, map, 2)) {
+ if (selection->paintNormal(index, &block, map, stampLayer)) {
map->setBlock(actualX, actualY, block, !fromScriptCall);
}
}
diff --git a/src/ui/paintselection.cpp b/src/ui/paintselection.cpp
index bec5d8ea..1c946c69 100644
--- a/src/ui/paintselection.cpp
+++ b/src/ui/paintselection.cpp
@@ -3,7 +3,7 @@
#include "metatile.h"
#include "log.h"
-bool MetatileSelection::paintNormal(int index, Block *block, Map *map, int layer) {
+bool MetatileSelection::paintNormal(int index, Block *block, Map *map, StampLayer stampLayer) {
MetatileSelectionItem item = this->metatileItems.at(index);
if (!item.enabled)
return false;
@@ -17,71 +17,24 @@ bool MetatileSelection::paintNormal(int index, Block *block, Map *map, int layer
return true;
}
-void adjustMetatileForLayer(int layer, int *baseOffset, Metatile *metatile) {
- switch (metatile->layerType)
+int getLayerOffset(StampLayer stampLayer) {
+ switch (stampLayer)
{
+ case StampLayer::STAMP_LAYER_BOTTOM:
+ return 0;
+ case StampLayer::STAMP_LAYER_TOP:
+ return 4;
default:
- case METATILE_LAYER_MIDDLE_TOP:
- switch (layer)
- {
- case 0:
- *baseOffset = 0;
- metatile->layerType = METATILE_LAYER_BOTTOM_TOP;
- for (int i = 0; i < 4; i++) {
- metatile->tiles[i+4] = metatile->tiles[i];
- }
- break;
- case 1:
- *baseOffset = 0;
- break;
- case 2:
- *baseOffset = 4;
- break;
- }
- break;
- case METATILE_LAYER_BOTTOM_MIDDLE:
- switch (layer)
- {
- case 0:
- *baseOffset = 0;
- break;
- case 1:
- *baseOffset = 4;
- break;
- case 2:
- *baseOffset = 4;
- metatile->layerType = METATILE_LAYER_MIDDLE_TOP;
- for (int i = 0; i < 4; i++) {
- metatile->tiles[i] = metatile->tiles[i+4];
- }
- break;
- }
- break;
- case METATILE_LAYER_BOTTOM_TOP:
- switch (layer)
- {
- case 0:
- *baseOffset = 0;
- break;
- case 1:
- *baseOffset = 4;
- metatile->layerType = METATILE_LAYER_BOTTOM_MIDDLE;
- break;
- case 2:
- *baseOffset = 4;
- break;
- }
- break;
+ return 0;
}
}
-bool StampSelection::paintNormal(int index, Block *block, Map *map, int layer) {
+bool StampSelection::paintNormal(int index, Block *block, Map *map, StampLayer stampLayer) {
Tileset *primaryTileset = map->layout->tileset_primary;
Tileset *secondaryTileset = map->layout->tileset_secondary;
// 1. Build metatile by applying the stamp to the existing block.
Metatile metatile = *(Tileset::getMetatile(block->metatileId, map->layout->tileset_primary, map->layout->tileset_secondary));
- int baseOffset;
- adjustMetatileForLayer(layer, &baseOffset, &metatile);
+ int baseOffset = getLayerOffset(stampLayer);
metatile.tiles[baseOffset] = Tile(0x5, false, false, 2);
metatile.tiles[baseOffset + 1] = Tile(0x5, true, false, 2);
metatile.tiles[baseOffset + 2] = Tile(0x15, false, false, 2);