diff --git a/forms/tileseteditor.ui b/forms/tileseteditor.ui
index 0eeffd04..3d7d733a 100644
--- a/forms/tileseteditor.ui
+++ b/forms/tileseteditor.ui
@@ -25,7 +25,7 @@
0
0
- 363
+ 308
539
@@ -207,7 +207,7 @@
0
0
- 363
+ 309
415
@@ -282,7 +282,65 @@
QFrame::Raised
-
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ QFrame::StyledPanel
+
+
+ QFrame::Raised
+
+
+
-
+
+
+ Bottom/Top
+
+
+
+ -
+
+
+
+ 64
+ 32
+
+
+
+
+ 64
+ 32
+
+
+
+ Qt::ScrollBarAlwaysOff
+
+
+ Qt::ScrollBarAlwaysOff
+
+
+
+ -
+
+
+ Metatile Behavior
+
+
+
+ -
+
+
+
+
+
+
diff --git a/include/ui/metatilelayersitem.h b/include/ui/metatilelayersitem.h
new file mode 100644
index 00000000..d2b7d243
--- /dev/null
+++ b/include/ui/metatilelayersitem.h
@@ -0,0 +1,29 @@
+#ifndef METATILELAYERSITEM_H
+#define METATILELAYERSITEM_H
+
+#include "tileset.h"
+#include
+#include
+
+class MetatileLayersItem : public QObject, public QGraphicsPixmapItem {
+ Q_OBJECT
+public:
+ MetatileLayersItem(Metatile *metatile, Tileset *primaryTileset, Tileset *secondaryTileset) {
+ this->metatile = metatile;
+ this->primaryTileset = primaryTileset;
+ this->secondaryTileset = secondaryTileset;
+ }
+ void draw();
+ void setTilesets(Tileset*, Tileset*);
+ void setMetatile(Metatile*);
+private:
+ Metatile* metatile;
+ Tileset *primaryTileset;
+ Tileset *secondaryTileset;
+signals:
+ void tileChanged(int);
+protected:
+ void mousePressEvent(QGraphicsSceneMouseEvent*);
+};
+
+#endif // METATILELAYERSITEM_H
diff --git a/include/ui/tileseteditor.h b/include/ui/tileseteditor.h
index 989fb717..084d3af1 100644
--- a/include/ui/tileseteditor.h
+++ b/include/ui/tileseteditor.h
@@ -5,6 +5,7 @@
#include "project.h"
#include "tileseteditormetatileselector.h"
#include "tileseteditortileselector.h"
+#include "metatilelayersitem.h"
namespace Ui {
class TilesetEditor;
@@ -25,6 +26,7 @@ private slots:
void onHoveredTileChanged(uint16_t);
void onHoveredTileCleared();
void onSelectedTileChanged(uint16_t);
+ void onMetatileLayerTileChanged(int);
void on_spinBox_paletteSelector_valueChanged(int arg1);
@@ -36,11 +38,14 @@ private:
void initMetatileSelector();
void initTileSelector();
void initSelectedTileItem();
+ void initMetatileLayersItem();
void drawSelectedTile();
Ui::TilesetEditor *ui;
- TilesetEditorMetatileSelector *metatileSelector;
- TilesetEditorTileSelector *tileSelector;
+ TilesetEditorMetatileSelector *metatileSelector = nullptr;
+ TilesetEditorTileSelector *tileSelector = nullptr;
+ MetatileLayersItem *metatileLayersItem = nullptr;
Project *project;
+ Metatile *metatile;
int paletteId;
bool tileXFlip;
bool tileYFlip;
@@ -50,6 +55,7 @@ private:
QGraphicsScene *tilesScene = nullptr;
QGraphicsScene *selectedTileScene = nullptr;
QGraphicsPixmapItem *selectedTilePixmapItem = nullptr;
+ QGraphicsScene *metatileLayersScene = nullptr;
};
#endif // TILESETEDITOR_H
diff --git a/porymap.pro b/porymap.pro
index 311630d9..b0ef9c13 100644
--- a/porymap.pro
+++ b/porymap.pro
@@ -34,6 +34,7 @@ SOURCES += src/core/block.cpp \
src/ui/imageproviders.cpp \
src/ui/mappixmapitem.cpp \
src/ui/mapsceneeventfilter.cpp \
+ src/ui/metatilelayersitem.cpp \
src/ui/metatileselector.cpp \
src/ui/movementpermissionsselector.cpp \
src/ui/neweventtoolbutton.cpp \
@@ -71,6 +72,7 @@ HEADERS += include/core/block.h \
include/ui/imageproviders.h \
include/ui/mappixmapitem.h \
include/ui/mapsceneeventfilter.h \
+ include/ui/metatilelayersitem.h \
include/ui/metatileselector.h \
include/ui/movementpermissionsselector.h \
include/ui/neweventtoolbutton.h \
diff --git a/src/ui/metatilelayersitem.cpp b/src/ui/metatilelayersitem.cpp
new file mode 100644
index 00000000..14e6d95c
--- /dev/null
+++ b/src/ui/metatilelayersitem.cpp
@@ -0,0 +1,48 @@
+#include "metatilelayersitem.h"
+#include "imageproviders.h"
+#include
+#include
+
+void MetatileLayersItem::draw() {
+ const QList tileCoords = QList{
+ QPoint(0, 0),
+ QPoint(16, 0),
+ QPoint(0, 16),
+ QPoint(16, 16),
+ QPoint(32, 0),
+ QPoint(48, 0),
+ QPoint(32, 16),
+ QPoint(48, 16),
+ };
+
+ QPixmap pixmap(64, 32);
+ QPainter painter(&pixmap);
+ for (int i = 0; i < 8; i++) {
+ Tile tile = this->metatile->tiles->at(i);
+ QImage tileImage = getColoredTileImage(tile.tile, this->primaryTileset, this->secondaryTileset, tile.palette)
+ .mirrored(tile.xflip, tile.yflip)
+ .scaled(16, 16);
+ painter.drawImage(tileCoords.at(i), tileImage);
+ }
+
+ this->setPixmap(pixmap);
+}
+
+void MetatileLayersItem::setMetatile(Metatile *metatile) {
+ this->metatile = metatile;
+}
+
+void MetatileLayersItem::setTilesets(Tileset *primaryTileset, Tileset *secondaryTileset) {
+ this->primaryTileset = primaryTileset;
+ this->secondaryTileset = secondaryTileset;
+ this->draw();
+}
+
+void MetatileLayersItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
+ QPointF pos = event->pos();
+ int x = static_cast(pos.x()) / 16;
+ int y = static_cast(pos.y()) / 16;
+ int tileIndex = (x / 2 * 4) + (y * 2) + (x % 2);
+ qDebug() << tileIndex;
+ emit this->tileChanged(tileIndex);
+}
diff --git a/src/ui/tileseteditor.cpp b/src/ui/tileseteditor.cpp
index f9774eed..8fcf9117 100644
--- a/src/ui/tileseteditor.cpp
+++ b/src/ui/tileseteditor.cpp
@@ -19,8 +19,10 @@ TilesetEditor::TilesetEditor(Project *project, QString primaryTilesetLabel, QStr
ui->spinBox_paletteSelector->setMinimum(0);
ui->spinBox_paletteSelector->setMaximum(Project::getNumPalettesTotal() - 1);
this->initMetatileSelector();
+ this->initMetatileLayersItem();
this->initTileSelector();
this->initSelectedTileItem();
+ this->metatileSelector->select(0);
}
TilesetEditor::~TilesetEditor()
@@ -42,7 +44,6 @@ void TilesetEditor::initMetatileSelector()
this->metatilesScene = new QGraphicsScene;
this->metatilesScene->addItem(this->metatileSelector);
- this->metatileSelector->select(0);
this->metatileSelector->draw();
this->ui->graphicsView_Metatiles->setScene(this->metatilesScene);
@@ -81,6 +82,7 @@ void TilesetEditor::drawSelectedTile() {
return;
}
+ this->selectedTileScene->clear();
Tileset *primaryTileset = this->project->getTileset(this->primaryTilesetLabel);
Tileset *secondaryTileset = this->project->getTileset(this->secondaryTilesetLabel);
QImage tileImage = getColoredTileImage(this->tileSelector->getSelectedTile(), primaryTileset, secondaryTileset, this->paletteId)
@@ -89,6 +91,19 @@ void TilesetEditor::drawSelectedTile() {
this->selectedTileScene->addItem(this->selectedTilePixmapItem);
}
+void TilesetEditor::initMetatileLayersItem() {
+ Tileset *primaryTileset = this->project->getTileset(this->primaryTilesetLabel);
+ Tileset *secondaryTileset = this->project->getTileset(this->secondaryTilesetLabel);
+ Metatile *metatile = Tileset::getMetatile(this->metatileSelector->getSelectedMetatile(), primaryTileset, secondaryTileset);
+ this->metatileLayersItem = new MetatileLayersItem(metatile, primaryTileset, secondaryTileset);
+ connect(this->metatileLayersItem, SIGNAL(tileChanged(int)),
+ this, SLOT(onMetatileLayerTileChanged(int)));
+
+ this->metatileLayersScene = new QGraphicsScene;
+ this->metatileLayersScene->addItem(this->metatileLayersItem);
+ this->ui->graphicsView_metatileLayers->setScene(this->metatileLayersScene);
+}
+
void TilesetEditor::onHoveredMetatileChanged(uint16_t metatileId) {
QString message = QString("Metatile: 0x%1")
.arg(QString("%1").arg(metatileId, 3, 16, QChar('0')).toUpper());
@@ -99,8 +114,12 @@ void TilesetEditor::onHoveredMetatileCleared() {
this->ui->statusbar->clearMessage();
}
-void TilesetEditor::onSelectedMetatileChanged(uint16_t) {
-
+void TilesetEditor::onSelectedMetatileChanged(uint16_t metatileId) {
+ Tileset *primaryTileset = this->project->getTileset(this->primaryTilesetLabel);
+ Tileset *secondaryTileset = this->project->getTileset(this->secondaryTilesetLabel);
+ this->metatile = Tileset::getMetatile(metatileId, primaryTileset, secondaryTileset);
+ this->metatileLayersItem->setMetatile(metatile);
+ this->metatileLayersItem->draw();
}
void TilesetEditor::onHoveredTileChanged(uint16_t tile) {
@@ -113,10 +132,21 @@ void TilesetEditor::onHoveredTileCleared() {
this->ui->statusbar->clearMessage();
}
-void TilesetEditor::onSelectedTileChanged(uint16_t) {
+void TilesetEditor::onSelectedTileChanged(uint16_t) {
this->drawSelectedTile();
}
+void TilesetEditor::onMetatileLayerTileChanged(int tileIndex) {
+ Tile tile = this->metatile->tiles->at(tileIndex);
+ tile.tile = this->tileSelector->getSelectedTile();
+ tile.xflip = this->tileXFlip;
+ tile.yflip = this->tileYFlip;
+ tile.palette = this->paletteId;
+ (*this->metatile->tiles)[tileIndex] = tile;
+ this->metatileSelector->draw();
+ this->metatileLayersItem->draw();
+}
+
void TilesetEditor::on_spinBox_paletteSelector_valueChanged(int paletteId)
{
this->paletteId = paletteId;