Merge pull request #579 from GriffinRichards/hover-te
Display tile ID when hovering over Tileset Editor layer view
This commit is contained in:
commit
9538097a6f
3 changed files with 76 additions and 40 deletions
|
@ -14,25 +14,33 @@ public:
|
||||||
this->primaryTileset = primaryTileset;
|
this->primaryTileset = primaryTileset;
|
||||||
this->secondaryTileset = secondaryTileset;
|
this->secondaryTileset = secondaryTileset;
|
||||||
this->clearLastModifiedCoords();
|
this->clearLastModifiedCoords();
|
||||||
|
this->clearLastHoveredCoords();
|
||||||
|
setAcceptHoverEvents(true);
|
||||||
}
|
}
|
||||||
void draw();
|
void draw();
|
||||||
void setTilesets(Tileset*, Tileset*);
|
void setTilesets(Tileset*, Tileset*);
|
||||||
void setMetatile(Metatile*);
|
void setMetatile(Metatile*);
|
||||||
void clearLastModifiedCoords();
|
void clearLastModifiedCoords();
|
||||||
|
void clearLastHoveredCoords();
|
||||||
bool showGrid;
|
bool showGrid;
|
||||||
private:
|
private:
|
||||||
Metatile* metatile;
|
Metatile* metatile;
|
||||||
Tileset *primaryTileset;
|
Tileset *primaryTileset;
|
||||||
Tileset *secondaryTileset;
|
Tileset *secondaryTileset;
|
||||||
QPoint prevChangedTile;
|
QPoint prevChangedPos;
|
||||||
void getBoundedCoords(QPointF, int*, int*);
|
QPoint prevHoveredPos;
|
||||||
|
QPoint getBoundedPos(const QPointF &);
|
||||||
signals:
|
signals:
|
||||||
void tileChanged(int, int);
|
void tileChanged(int, int);
|
||||||
void selectedTilesChanged(QPoint, int, int);
|
void selectedTilesChanged(QPoint, int, int);
|
||||||
|
void hoveredTileChanged(uint16_t);
|
||||||
|
void hoveredTileCleared();
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
||||||
void mouseMoveEvent(QGraphicsSceneMouseEvent*);
|
void mouseMoveEvent(QGraphicsSceneMouseEvent*);
|
||||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
|
||||||
|
void hoverMoveEvent(QGraphicsSceneHoverEvent*);
|
||||||
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent*);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // METATILELAYERSITEM_H
|
#endif // METATILELAYERSITEM_H
|
||||||
|
|
|
@ -3,22 +3,22 @@
|
||||||
#include "imageproviders.h"
|
#include "imageproviders.h"
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
void MetatileLayersItem::draw() {
|
static const QList<QPoint> tilePositions = {
|
||||||
static const QList<QPoint> tileCoords = QList<QPoint>{
|
|
||||||
QPoint(0, 0),
|
QPoint(0, 0),
|
||||||
QPoint(16, 0),
|
QPoint(1, 0),
|
||||||
QPoint(0, 16),
|
QPoint(0, 1),
|
||||||
QPoint(16, 16),
|
QPoint(1, 1),
|
||||||
QPoint(32, 0),
|
QPoint(2, 0),
|
||||||
QPoint(48, 0),
|
QPoint(3, 0),
|
||||||
QPoint(32, 16),
|
QPoint(2, 1),
|
||||||
QPoint(48, 16),
|
QPoint(3, 1),
|
||||||
QPoint(64, 0),
|
QPoint(4, 0),
|
||||||
QPoint(80, 0),
|
QPoint(5, 0),
|
||||||
QPoint(64, 16),
|
QPoint(4, 1),
|
||||||
QPoint(80, 16),
|
QPoint(5, 1),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void MetatileLayersItem::draw() {
|
||||||
const int numLayers = projectConfig.getNumLayersInMetatile();
|
const int numLayers = projectConfig.getNumLayersInMetatile();
|
||||||
QPixmap pixmap(numLayers * 32, 32);
|
QPixmap pixmap(numLayers * 32, 32);
|
||||||
QPainter painter(&pixmap);
|
QPainter painter(&pixmap);
|
||||||
|
@ -30,7 +30,7 @@ void MetatileLayersItem::draw() {
|
||||||
QImage tileImage = getPalettedTileImage(tile.tileId, this->primaryTileset, this->secondaryTileset, tile.palette, true)
|
QImage tileImage = getPalettedTileImage(tile.tileId, this->primaryTileset, this->secondaryTileset, tile.palette, true)
|
||||||
.mirrored(tile.xflip, tile.yflip)
|
.mirrored(tile.xflip, tile.yflip)
|
||||||
.scaled(16, 16);
|
.scaled(16, 16);
|
||||||
painter.drawImage(tileCoords.at(i), tileImage);
|
painter.drawImage(tilePositions.at(i) * 16, tileImage);
|
||||||
}
|
}
|
||||||
if (this->showGrid) {
|
if (this->showGrid) {
|
||||||
// Draw grid
|
// Draw grid
|
||||||
|
@ -47,6 +47,7 @@ void MetatileLayersItem::draw() {
|
||||||
void MetatileLayersItem::setMetatile(Metatile *metatile) {
|
void MetatileLayersItem::setMetatile(Metatile *metatile) {
|
||||||
this->metatile = metatile;
|
this->metatile = metatile;
|
||||||
this->clearLastModifiedCoords();
|
this->clearLastModifiedCoords();
|
||||||
|
this->clearLastHoveredCoords();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetatileLayersItem::setTilesets(Tileset *primaryTileset, Tileset *secondaryTileset) {
|
void MetatileLayersItem::setTilesets(Tileset *primaryTileset, Tileset *secondaryTileset) {
|
||||||
|
@ -54,6 +55,7 @@ void MetatileLayersItem::setTilesets(Tileset *primaryTileset, Tileset *secondary
|
||||||
this->secondaryTileset = secondaryTileset;
|
this->secondaryTileset = secondaryTileset;
|
||||||
this->draw();
|
this->draw();
|
||||||
this->clearLastModifiedCoords();
|
this->clearLastModifiedCoords();
|
||||||
|
this->clearLastHoveredCoords();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetatileLayersItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
void MetatileLayersItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
|
@ -64,11 +66,10 @@ void MetatileLayersItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
emit this->selectedTilesChanged(selectionOrigin, dimensions.x(), dimensions.y());
|
emit this->selectedTilesChanged(selectionOrigin, dimensions.x(), dimensions.y());
|
||||||
this->drawSelection();
|
this->drawSelection();
|
||||||
} else {
|
} else {
|
||||||
int x, y;
|
const QPoint pos = this->getBoundedPos(event->pos());
|
||||||
this->getBoundedCoords(event->pos(), &x, &y);
|
this->prevChangedPos = pos;
|
||||||
this->prevChangedTile.setX(x);
|
this->clearLastHoveredCoords();
|
||||||
this->prevChangedTile.setY(y);
|
emit this->tileChanged(pos.x(), pos.y());
|
||||||
emit this->tileChanged(x, y);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,12 +81,11 @@ void MetatileLayersItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
emit this->selectedTilesChanged(selectionOrigin, dimensions.x(), dimensions.y());
|
emit this->selectedTilesChanged(selectionOrigin, dimensions.x(), dimensions.y());
|
||||||
this->drawSelection();
|
this->drawSelection();
|
||||||
} else {
|
} else {
|
||||||
int x, y;
|
const QPoint pos = this->getBoundedPos(event->pos());
|
||||||
this->getBoundedCoords(event->pos(), &x, &y);
|
if (prevChangedPos != pos) {
|
||||||
if (prevChangedTile.x() != x || prevChangedTile.y() != y) {
|
this->prevChangedPos = pos;
|
||||||
this->prevChangedTile.setX(x);
|
this->clearLastHoveredCoords();
|
||||||
this->prevChangedTile.setY(y);
|
emit this->tileChanged(pos.x(), pos.y());
|
||||||
emit this->tileChanged(x, y);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,17 +101,40 @@ void MetatileLayersItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
this->draw();
|
this->draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetatileLayersItem::clearLastModifiedCoords() {
|
void MetatileLayersItem::hoverMoveEvent(QGraphicsSceneHoverEvent * event) {
|
||||||
this->prevChangedTile.setX(-1);
|
const QPoint pos = this->getBoundedPos(event->pos());
|
||||||
this->prevChangedTile.setY(-1);
|
if (pos == this->prevHoveredPos)
|
||||||
|
return;
|
||||||
|
this->prevHoveredPos = pos;
|
||||||
|
|
||||||
|
int tileIndex = tilePositions.indexOf(pos);
|
||||||
|
if (tileIndex < 0 || tileIndex >= this->metatile->tiles.length())
|
||||||
|
return;
|
||||||
|
|
||||||
|
emit this->hoveredTileChanged(this->metatile->tiles.at(tileIndex).tileId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetatileLayersItem::getBoundedCoords(QPointF pos, int *x, int *y) {
|
void MetatileLayersItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
|
||||||
int maxX = (projectConfig.getNumLayersInMetatile() * 2) - 1;
|
this->clearLastHoveredCoords();
|
||||||
*x = static_cast<int>(pos.x()) / 16;
|
emit this->hoveredTileCleared();
|
||||||
*y = static_cast<int>(pos.y()) / 16;
|
}
|
||||||
if (*x < 0) *x = 0;
|
|
||||||
if (*y < 0) *y = 0;
|
void MetatileLayersItem::clearLastModifiedCoords() {
|
||||||
if (*x > maxX) *x = maxX;
|
this->prevChangedPos = QPoint(-1, -1);
|
||||||
if (*y > 1) *y = 1;
|
}
|
||||||
|
|
||||||
|
void MetatileLayersItem::clearLastHoveredCoords() {
|
||||||
|
this->prevHoveredPos = QPoint(-1, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
QPoint MetatileLayersItem::getBoundedPos(const QPointF &pos) {
|
||||||
|
int x, y;
|
||||||
|
int maxX = (projectConfig.getNumLayersInMetatile() * 2) - 1;
|
||||||
|
x = static_cast<int>(pos.x()) / 16;
|
||||||
|
y = static_cast<int>(pos.y()) / 16;
|
||||||
|
if (x < 0) x = 0;
|
||||||
|
if (y < 0) y = 0;
|
||||||
|
if (x > maxX) x = maxX;
|
||||||
|
if (y > 1) y = 1;
|
||||||
|
return QPoint(x, y);
|
||||||
}
|
}
|
||||||
|
|
|
@ -206,6 +206,10 @@ void TilesetEditor::initMetatileLayersItem() {
|
||||||
this, &TilesetEditor::onMetatileLayerTileChanged);
|
this, &TilesetEditor::onMetatileLayerTileChanged);
|
||||||
connect(this->metatileLayersItem, &MetatileLayersItem::selectedTilesChanged,
|
connect(this->metatileLayersItem, &MetatileLayersItem::selectedTilesChanged,
|
||||||
this, &TilesetEditor::onMetatileLayerSelectionChanged);
|
this, &TilesetEditor::onMetatileLayerSelectionChanged);
|
||||||
|
connect(this->metatileLayersItem, &MetatileLayersItem::hoveredTileChanged,
|
||||||
|
this, &TilesetEditor::onHoveredTileChanged);
|
||||||
|
connect(this->metatileLayersItem, &MetatileLayersItem::hoveredTileCleared,
|
||||||
|
this, &TilesetEditor::onHoveredTileCleared);
|
||||||
|
|
||||||
bool showGrid = porymapConfig.getShowTilesetEditorLayerGrid();
|
bool showGrid = porymapConfig.getShowTilesetEditorLayerGrid();
|
||||||
this->ui->actionLayer_Grid->setChecked(showGrid);
|
this->ui->actionLayer_Grid->setChecked(showGrid);
|
||||||
|
@ -861,6 +865,7 @@ bool TilesetEditor::replaceMetatile(uint16_t metatileId, const Metatile * src, Q
|
||||||
this->metatileSelector->draw();
|
this->metatileSelector->draw();
|
||||||
this->metatileLayersItem->draw();
|
this->metatileLayersItem->draw();
|
||||||
this->metatileLayersItem->clearLastModifiedCoords();
|
this->metatileLayersItem->clearLastModifiedCoords();
|
||||||
|
this->metatileLayersItem->clearLastHoveredCoords();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue