diff --git a/editor.cpp b/editor.cpp index 7ae693c5..6fb302ca 100755 --- a/editor.cpp +++ b/editor.cpp @@ -257,6 +257,25 @@ void MetatilesPixmapItem::pick(uint tile) { emit map->paintTileChanged(map); } +void MetatilesPixmapItem::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->clearHoveredMetatile(); + } else { + int block = y * width + x; + map->hoveredMetatileChanged(block); + } +} + +void MetatilesPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { + updateCurHoveredMetatile(event->pos()); +} +void MetatilesPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { + map->clearHoveredMetatile(); +} void MetatilesPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { QPointF pos = event->pos(); int x = ((int)pos.x()) / 16; @@ -269,12 +288,38 @@ void MetatilesPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { } } void MetatilesPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { + updateCurHoveredMetatile(event->pos()); mousePressEvent(event); } 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) { @@ -368,10 +413,29 @@ void MapPixmapItem::redo() { } } +void MapPixmapItem::updateCurHoveredTile(QPointF pos) { + int x = ((int)pos.x()) / 16; + int y = ((int)pos.y()) / 16; + int blockIndex = y * map->getWidth() + x; + if (x < 0 || x >= map->getWidth() || y < 0 || y >= map->getHeight()) { + map->clearHoveredTile(); + } else { + int tile = map->blockdata->blocks->at(blockIndex).tile; + map->hoveredTileChanged(x, y, tile); + } +} + +void MapPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { + updateCurHoveredTile(event->pos()); +} +void MapPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { + map->clearHoveredTile(); +} void MapPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { emit mouseEvent(event, this); } void MapPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { + updateCurHoveredTile(event->pos()); emit mouseEvent(event, this); } void MapPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { diff --git a/editor.h b/editor.h index e099809c..76e1d65a 100755 --- a/editor.h +++ b/editor.h @@ -185,6 +185,7 @@ public: Map *map = NULL; MapPixmapItem(Map *map_) { map = map_; + setAcceptHoverEvents(true); } bool active; bool right_click; @@ -198,10 +199,15 @@ public: virtual void redo(); virtual void draw(); +private: + void updateCurHoveredTile(QPointF pos); + signals: void mouseEvent(QGraphicsSceneMouseEvent *, MapPixmapItem *); protected: + void hoverMoveEvent(QGraphicsSceneHoverEvent*); + void hoverLeaveEvent(QGraphicsSceneHoverEvent*); void mousePressEvent(QGraphicsSceneMouseEvent*); void mouseMoveEvent(QGraphicsSceneMouseEvent*); void mouseReleaseEvent(QGraphicsSceneMouseEvent*); @@ -235,14 +241,19 @@ public: } MetatilesPixmapItem(Map *map_) { map = map_; + setAcceptHoverEvents(true); connect(map, SIGNAL(paintTileChanged(Map*)), this, SLOT(paintTileChanged(Map *))); } Map* map = NULL; virtual void pick(uint); virtual void draw(); +protected: + virtual void updateCurHoveredMetatile(QPointF pos); private slots: void paintTileChanged(Map *map); protected: + void hoverMoveEvent(QGraphicsSceneHoverEvent*); + void hoverLeaveEvent(QGraphicsSceneHoverEvent*); void mousePressEvent(QGraphicsSceneMouseEvent*); void mouseMoveEvent(QGraphicsSceneMouseEvent*); void mouseReleaseEvent(QGraphicsSceneMouseEvent*); @@ -261,6 +272,8 @@ public: virtual void draw() { setPixmap(map->renderCollisionMetatiles()); } +protected: + virtual void updateCurHoveredMetatile(QPointF pos); private slots: void paintCollisionChanged(Map *map) { draw(); @@ -280,6 +293,8 @@ public: virtual void draw() { setPixmap(map->renderElevationMetatiles()); } +protected: + virtual void updateCurHoveredMetatile(QPointF pos); private slots: void paintCollisionChanged(Map *map) { draw(); diff --git a/mainwindow.cpp b/mainwindow.cpp index fd5bebc5..79e1e13e 100755 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -48,10 +48,17 @@ MainWindow::~MainWindow() delete ui; } +void MainWindow::setStatusBarMessage(QString message, int timeout/* = 0*/) { + statusBar()->showMessage(message, timeout); +} + void MainWindow::openProject(QString dir) { if (dir.isNull()) { return; } + + setStatusBarMessage(QString("Opening project %1").arg(dir)); + bool already_open = ( (editor != NULL && editor != nullptr) && (editor->project != NULL && editor->project != nullptr) @@ -69,6 +76,8 @@ void MainWindow::openProject(QString dir) { loadDataStructures(); populateMapList(); } + + setStatusBarMessage(QString("Opened project %1").arg(dir)); } QString MainWindow::getDefaultMap() { @@ -169,6 +178,7 @@ void MainWindow::setMap(QString map_name) { setWindowTitle(map_name + " - " + editor->project->getProjectTitle() + " - pretmap"); connect(editor->map, SIGNAL(mapChanged(Map*)), this, SLOT(onMapChanged(Map *))); + connect(editor->map, SIGNAL(statusBarMessage(QString)), this, SLOT(setStatusBarMessage(QString))); setRecentMap(map_name); updateMapList(); diff --git a/mainwindow.h b/mainwindow.h index 34c94d63..67d18aa9 100755 --- a/mainwindow.h +++ b/mainwindow.h @@ -25,6 +25,9 @@ public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); +public slots: + void setStatusBarMessage(QString message, int timeout = 0); + private slots: void on_action_Open_Project_triggered(); void on_mapList_activated(const QModelIndex &index); diff --git a/mainwindow.ui b/mainwindow.ui index 67baef37..a3f7a857 100755 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -1217,14 +1217,6 @@ - - - TopToolBarArea - - - false - - diff --git a/map.cpp b/map.cpp index 03156002..15587df8 100755 --- a/map.cpp +++ b/map.cpp @@ -734,3 +734,39 @@ void Map::addEvent(Event *event) { bool Map::hasUnsavedChanges() { return !history.isSaved() || !isPersistedToFile; } + +void Map::hoveredTileChanged(int x, int y, int block) { + emit statusBarMessage(QString("X: %1, Y: %2, Block: 0x%3") + .arg(x) + .arg(y) + .arg(QString("%1").arg(block, 3, 16, QChar('0')).toUpper())); +} + +void Map::clearHoveredTile() { + emit statusBarMessage(QString("")); +} + +void Map::hoveredMetatileChanged(int block) { + emit statusBarMessage(QString("Block: 0x%1") + .arg(QString("%1").arg(block, 3, 16, QChar('0')).toUpper())); +} + +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("")); +} diff --git a/map.h b/map.h index c49d833e..1421d07c 100755 --- a/map.h +++ b/map.h @@ -182,6 +182,14 @@ public: void cacheBorder(); bool hasUnsavedChanges(); + void hoveredTileChanged(int x, int y, int block); + void clearHoveredTile(); + void hoveredMetatileChanged(int block); + void clearHoveredMetatile(); + void hoveredCollisionTileChanged(int collision); + void clearHoveredCollisionTile(); + void hoveredElevationTileChanged(int elevation); + void clearHoveredElevationTile(); QList > getBlockPalettes(int metatile_index); @@ -189,6 +197,7 @@ signals: void paintTileChanged(Map *map); void paintCollisionChanged(Map *map); void mapChanged(Map *map); + void statusBarMessage(QString); public slots: };