Allow collision and elevation tiles to handle hover events individually

This commit is contained in:
Marcus Huderle 2018-03-04 10:49:44 -08:00
parent 4f838b979c
commit 2dfcab7a47
4 changed files with 51 additions and 2 deletions

View file

@ -295,6 +295,31 @@ void MetatilesPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
mousePressEvent(event);
}
void CollisionMetatilesPixmapItem::updateCurHoveredMetatile(QPointF pos) {
int x = ((int)pos.x()) / 16;
int y = ((int)pos.y()) / 16;
int width = pixmap().width() / 16;
int height = pixmap().height() / 16;
if (x < 0 || x >= width || y < 0 || y >= height) {
map->clearHoveredCollisionTile();
} else {
int collision = y * width + x;
map->hoveredCollisionTileChanged(collision);
}
}
void ElevationMetatilesPixmapItem::updateCurHoveredMetatile(QPointF pos) {
int x = ((int)pos.x()) / 16;
int y = ((int)pos.y()) / 16;
int width = pixmap().width() / 16;
int height = pixmap().height() / 16;
if (x < 0 || x >= width || y < 0 || y >= height) {
map->clearHoveredElevationTile();
} else {
int elevation = y * width + x;
map->hoveredElevationTileChanged(elevation);
}
}
void MapPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
if (map) {

View file

@ -247,8 +247,8 @@ public:
Map* map = NULL;
virtual void pick(uint);
virtual void draw();
private:
void updateCurHoveredMetatile(QPointF pos);
protected:
virtual void updateCurHoveredMetatile(QPointF pos);
private slots:
void paintTileChanged(Map *map);
protected:
@ -272,6 +272,8 @@ public:
virtual void draw() {
setPixmap(map->renderCollisionMetatiles());
}
protected:
virtual void updateCurHoveredMetatile(QPointF pos);
private slots:
void paintCollisionChanged(Map *map) {
draw();
@ -291,6 +293,8 @@ public:
virtual void draw() {
setPixmap(map->renderElevationMetatiles());
}
protected:
virtual void updateCurHoveredMetatile(QPointF pos);
private slots:
void paintCollisionChanged(Map *map) {
draw();

16
map.cpp
View file

@ -754,3 +754,19 @@ void Map::hoveredMetatileChanged(int block) {
void Map::clearHoveredMetatile() {
emit statusBarMessage(QString(""));
}
void Map::hoveredCollisionTileChanged(int collision) {
emit statusBarMessage(QString("Collision: %1").arg(collision));
}
void Map::clearHoveredCollisionTile() {
emit statusBarMessage(QString(""));
}
void Map::hoveredElevationTileChanged(int elevation) {
emit statusBarMessage(QString("Elevation: %1").arg(elevation));
}
void Map::clearHoveredElevationTile() {
emit statusBarMessage(QString(""));
}

4
map.h
View file

@ -186,6 +186,10 @@ public:
void clearHoveredTile();
void hoveredMetatileChanged(int block);
void clearHoveredMetatile();
void hoveredCollisionTileChanged(int collision);
void clearHoveredCollisionTile();
void hoveredElevationTileChanged(int elevation);
void clearHoveredElevationTile();
QList<QList<QRgb> > getBlockPalettes(int metatile_index);