Add metatile layer item
This commit is contained in:
parent
ffd769f7ed
commit
322238c7b8
6 changed files with 182 additions and 9 deletions
|
@ -25,7 +25,7 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>363</width>
|
||||
<width>308</width>
|
||||
<height>539</height>
|
||||
</rect>
|
||||
</property>
|
||||
|
@ -207,7 +207,7 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>363</width>
|
||||
<width>309</width>
|
||||
<height>415</height>
|
||||
</rect>
|
||||
</property>
|
||||
|
@ -282,7 +282,65 @@
|
|||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout"/>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QFrame" name="frame_6">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Bottom/Top</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QGraphicsView" name="graphicsView_metatileLayers">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>64</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>64</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="verticalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
<property name="horizontalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Metatile Behavior</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QComboBox" name="comboBox_metatileBehaviors"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
|
29
include/ui/metatilelayersitem.h
Normal file
29
include/ui/metatilelayersitem.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
#ifndef METATILELAYERSITEM_H
|
||||
#define METATILELAYERSITEM_H
|
||||
|
||||
#include "tileset.h"
|
||||
#include <QGraphicsPixmapItem>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
|
||||
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
|
|
@ -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
|
||||
|
|
|
@ -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 \
|
||||
|
|
48
src/ui/metatilelayersitem.cpp
Normal file
48
src/ui/metatilelayersitem.cpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
#include "metatilelayersitem.h"
|
||||
#include "imageproviders.h"
|
||||
#include <QPainter>
|
||||
#include <QDebug>
|
||||
|
||||
void MetatileLayersItem::draw() {
|
||||
const QList<QPoint> tileCoords = QList<QPoint>{
|
||||
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<int>(pos.x()) / 16;
|
||||
int y = static_cast<int>(pos.y()) / 16;
|
||||
int tileIndex = (x / 2 * 4) + (y * 2) + (x % 2);
|
||||
qDebug() << tileIndex;
|
||||
emit this->tileChanged(tileIndex);
|
||||
}
|
|
@ -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) {
|
||||
|
@ -117,6 +136,17 @@ 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;
|
||||
|
|
Loading…
Reference in a new issue