Browse Source

Allow collision and elevation tiles to handle hover events individually

Marcus Huderle 6 years ago
parent
commit
2dfcab7a47
4 changed files with 51 additions and 2 deletions
  1. 25
    0
      editor.cpp
  2. 6
    2
      editor.h
  3. 16
    0
      map.cpp
  4. 4
    0
      map.h

+ 25
- 0
editor.cpp View File

295
     mousePressEvent(event);
295
     mousePressEvent(event);
296
 }
296
 }
297
 
297
 
298
+void CollisionMetatilesPixmapItem::updateCurHoveredMetatile(QPointF pos) {
299
+    int x = ((int)pos.x()) / 16;
300
+    int y = ((int)pos.y()) / 16;
301
+    int width = pixmap().width() / 16;
302
+    int height = pixmap().height() / 16;
303
+    if (x < 0 || x >= width || y < 0 || y >= height) {
304
+        map->clearHoveredCollisionTile();
305
+    } else {
306
+        int collision = y * width + x;
307
+        map->hoveredCollisionTileChanged(collision);
308
+    }
309
+}
310
+
311
+void ElevationMetatilesPixmapItem::updateCurHoveredMetatile(QPointF pos) {
312
+    int x = ((int)pos.x()) / 16;
313
+    int y = ((int)pos.y()) / 16;
314
+    int width = pixmap().width() / 16;
315
+    int height = pixmap().height() / 16;
316
+    if (x < 0 || x >= width || y < 0 || y >= height) {
317
+        map->clearHoveredElevationTile();
318
+    } else {
319
+        int elevation = y * width + x;
320
+        map->hoveredElevationTileChanged(elevation);
321
+    }
322
+}
298
 
323
 
299
 void MapPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
324
 void MapPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
300
     if (map) {
325
     if (map) {

+ 6
- 2
editor.h View File

247
     Map* map = NULL;
247
     Map* map = NULL;
248
     virtual void pick(uint);
248
     virtual void pick(uint);
249
     virtual void draw();
249
     virtual void draw();
250
-private:
251
-    void updateCurHoveredMetatile(QPointF pos);
250
+protected:
251
+    virtual void updateCurHoveredMetatile(QPointF pos);
252
 private slots:
252
 private slots:
253
     void paintTileChanged(Map *map);
253
     void paintTileChanged(Map *map);
254
 protected:
254
 protected:
272
     virtual void draw() {
272
     virtual void draw() {
273
         setPixmap(map->renderCollisionMetatiles());
273
         setPixmap(map->renderCollisionMetatiles());
274
     }
274
     }
275
+protected:
276
+    virtual void updateCurHoveredMetatile(QPointF pos);
275
 private slots:
277
 private slots:
276
     void paintCollisionChanged(Map *map) {
278
     void paintCollisionChanged(Map *map) {
277
         draw();
279
         draw();
291
     virtual void draw() {
293
     virtual void draw() {
292
         setPixmap(map->renderElevationMetatiles());
294
         setPixmap(map->renderElevationMetatiles());
293
     }
295
     }
296
+protected:
297
+    virtual void updateCurHoveredMetatile(QPointF pos);
294
 private slots:
298
 private slots:
295
     void paintCollisionChanged(Map *map) {
299
     void paintCollisionChanged(Map *map) {
296
         draw();
300
         draw();

+ 16
- 0
map.cpp View File

754
 void Map::clearHoveredMetatile() {
754
 void Map::clearHoveredMetatile() {
755
     emit statusBarMessage(QString(""));
755
     emit statusBarMessage(QString(""));
756
 }
756
 }
757
+
758
+void Map::hoveredCollisionTileChanged(int collision) {
759
+    emit statusBarMessage(QString("Collision: %1").arg(collision));
760
+}
761
+
762
+void Map::clearHoveredCollisionTile() {
763
+    emit statusBarMessage(QString(""));
764
+}
765
+
766
+void Map::hoveredElevationTileChanged(int elevation) {
767
+    emit statusBarMessage(QString("Elevation: %1").arg(elevation));
768
+}
769
+
770
+void Map::clearHoveredElevationTile() {
771
+    emit statusBarMessage(QString(""));
772
+}

+ 4
- 0
map.h View File

186
     void clearHoveredTile();
186
     void clearHoveredTile();
187
     void hoveredMetatileChanged(int block);
187
     void hoveredMetatileChanged(int block);
188
     void clearHoveredMetatile();
188
     void clearHoveredMetatile();
189
+    void hoveredCollisionTileChanged(int collision);
190
+    void clearHoveredCollisionTile();
191
+    void hoveredElevationTileChanged(int elevation);
192
+    void clearHoveredElevationTile();
189
 
193
 
190
     QList<QList<QRgb> > getBlockPalettes(int metatile_index);
194
     QList<QList<QRgb> > getBlockPalettes(int metatile_index);
191
 
195