Allow collision and elevation tiles to handle hover events individually
This commit is contained in:
parent
4f838b979c
commit
2dfcab7a47
4 changed files with 51 additions and 2 deletions
25
editor.cpp
25
editor.cpp
|
@ -295,6 +295,31 @@ void MetatilesPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
mousePressEvent(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) {
|
void MapPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
|
||||||
if (map) {
|
if (map) {
|
||||||
|
|
8
editor.h
8
editor.h
|
@ -247,8 +247,8 @@ public:
|
||||||
Map* map = NULL;
|
Map* map = NULL;
|
||||||
virtual void pick(uint);
|
virtual void pick(uint);
|
||||||
virtual void draw();
|
virtual void draw();
|
||||||
private:
|
protected:
|
||||||
void updateCurHoveredMetatile(QPointF pos);
|
virtual void updateCurHoveredMetatile(QPointF pos);
|
||||||
private slots:
|
private slots:
|
||||||
void paintTileChanged(Map *map);
|
void paintTileChanged(Map *map);
|
||||||
protected:
|
protected:
|
||||||
|
@ -272,6 +272,8 @@ public:
|
||||||
virtual void draw() {
|
virtual void draw() {
|
||||||
setPixmap(map->renderCollisionMetatiles());
|
setPixmap(map->renderCollisionMetatiles());
|
||||||
}
|
}
|
||||||
|
protected:
|
||||||
|
virtual void updateCurHoveredMetatile(QPointF pos);
|
||||||
private slots:
|
private slots:
|
||||||
void paintCollisionChanged(Map *map) {
|
void paintCollisionChanged(Map *map) {
|
||||||
draw();
|
draw();
|
||||||
|
@ -291,6 +293,8 @@ public:
|
||||||
virtual void draw() {
|
virtual void draw() {
|
||||||
setPixmap(map->renderElevationMetatiles());
|
setPixmap(map->renderElevationMetatiles());
|
||||||
}
|
}
|
||||||
|
protected:
|
||||||
|
virtual void updateCurHoveredMetatile(QPointF pos);
|
||||||
private slots:
|
private slots:
|
||||||
void paintCollisionChanged(Map *map) {
|
void paintCollisionChanged(Map *map) {
|
||||||
draw();
|
draw();
|
||||||
|
|
16
map.cpp
16
map.cpp
|
@ -754,3 +754,19 @@ void Map::hoveredMetatileChanged(int block) {
|
||||||
void Map::clearHoveredMetatile() {
|
void Map::clearHoveredMetatile() {
|
||||||
emit statusBarMessage(QString(""));
|
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
4
map.h
|
@ -186,6 +186,10 @@ public:
|
||||||
void clearHoveredTile();
|
void clearHoveredTile();
|
||||||
void hoveredMetatileChanged(int block);
|
void hoveredMetatileChanged(int block);
|
||||||
void clearHoveredMetatile();
|
void clearHoveredMetatile();
|
||||||
|
void hoveredCollisionTileChanged(int collision);
|
||||||
|
void clearHoveredCollisionTile();
|
||||||
|
void hoveredElevationTileChanged(int elevation);
|
||||||
|
void clearHoveredElevationTile();
|
||||||
|
|
||||||
QList<QList<QRgb> > getBlockPalettes(int metatile_index);
|
QList<QList<QRgb> > getBlockPalettes(int metatile_index);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue