Procházet zdrojové kódy

Allow collision and elevation tiles to handle hover events individually

Marcus Huderle před 6 roky
rodič
revize
2dfcab7a47
4 změnil soubory, kde provedl 51 přidání a 2 odebrání
  1. 25
    0
      editor.cpp
  2. 6
    2
      editor.h
  3. 16
    0
      map.cpp
  4. 4
    0
      map.h

+ 25
- 0
editor.cpp Zobrazit soubor

@@ -295,6 +295,31 @@ void MetatilesPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
295 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 324
 void MapPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
300 325
     if (map) {

+ 6
- 2
editor.h Zobrazit soubor

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

+ 16
- 0
map.cpp Zobrazit soubor

@@ -754,3 +754,19 @@ void Map::hoveredMetatileChanged(int block) {
754 754
 void Map::clearHoveredMetatile() {
755 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 Zobrazit soubor

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