Add stamp layer buttons

This commit is contained in:
Marcus Huderle 2023-03-12 17:21:56 -05:00
parent 95a1da1930
commit 3ad9af34a6
8 changed files with 86 additions and 81 deletions

View file

@ -645,7 +645,7 @@
</size>
</property>
<property name="currentIndex">
<number>0</number>
<number>2</number>
</property>
<widget class="QWidget" name="tab_blocks">
<property name="sizePolicy">
@ -1291,6 +1291,38 @@
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_stampLayer">
<property name="title">
<string>Stamp Layer</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_16">
<item>
<widget class="QRadioButton" name="radioButton_stampTopLayer">
<property name="text">
<string>Top Layer</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup_stampLayer</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButton_stampBottomLayer">
<property name="text">
<string>Bottom Layer</string>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup_stampLayer</string>
</attribute>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_4">
<property name="title">
@ -1371,7 +1403,7 @@
<x>0</x>
<y>0</y>
<width>411</width>
<height>468</height>
<height>392</height>
</rect>
</property>
<property name="sizePolicy">
@ -1808,8 +1840,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>83</width>
<height>16</height>
<width>100</width>
<height>30</height>
</rect>
</property>
<property name="sizePolicy">
@ -1902,8 +1934,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>83</width>
<height>16</height>
<width>100</width>
<height>30</height>
</rect>
</property>
<property name="sizePolicy">
@ -1996,8 +2028,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>83</width>
<height>16</height>
<width>100</width>
<height>30</height>
</rect>
</property>
<property name="sizePolicy">
@ -2096,8 +2128,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>83</width>
<height>16</height>
<width>100</width>
<height>30</height>
</rect>
</property>
<property name="sizePolicy">
@ -2190,8 +2222,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>83</width>
<height>16</height>
<width>100</width>
<height>30</height>
</rect>
</property>
<property name="sizePolicy">
@ -3553,4 +3585,7 @@
<include location="../resources/images.qrc"/>
</resources>
<connections/>
<buttongroups>
<buttongroup name="buttonGroup_stampLayer"/>
</buttongroups>
</ui>

View file

@ -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;

View file

@ -59,7 +59,7 @@ public:
MapPixmapItem::Axis lockedAxis;
QPoint selection_origin;
QList<QPoint> 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);

View file

@ -8,6 +8,12 @@
#include <QList>
#include <QPoint>
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<MetatileSelectionItem> metatileItems;
QList<CollisionSelectionItem> 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<uint16_t> stampIds;
};

View file

@ -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);

View file

@ -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);
}

View file

@ -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);
}
}

View file

@ -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);