Переглянути джерело

Merge pull request #39 from huderlem/fixMovement

Fix collision and elevation selections
yenatch 6 роки тому
джерело
коміт
aa6949237f
Аккаунт користувача з таким Email не знайдено
2 змінених файлів з 36 додано та 4 видалено
  1. 18
    0
      editor.cpp
  2. 18
    4
      editor.h

+ 18
- 0
editor.cpp Переглянути файл

@@ -332,6 +332,24 @@ void MetatilesPixmapItem::updateSelection(QPointF pos, Qt::MouseButton button) {
332 332
     }
333 333
 }
334 334
 
335
+void MovementPermissionsPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent* event) {
336
+    QPointF pos = event->pos();
337
+    int x = ((int)pos.x()) / 16;
338
+    int y = ((int)pos.y()) / 16;
339
+    int width = pixmap().width() / 16;
340
+    int height = pixmap().height() / 16;
341
+    if ((x >= 0 && x < width) && (y >=0 && y < height)) {
342
+        pick(y * width + x);
343
+    }
344
+}
345
+void MovementPermissionsPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event) {
346
+    updateCurHoveredMetatile(event->pos());
347
+    mousePressEvent(event);
348
+}
349
+void MovementPermissionsPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) {
350
+    mousePressEvent(event);
351
+}
352
+
335 353
 void CollisionMetatilesPixmapItem::updateCurHoveredMetatile(QPointF pos) {
336 354
     int x = ((int)pos.x()) / 16;
337 355
     int y = ((int)pos.y()) / 16;

+ 18
- 4
editor.h Переглянути файл

@@ -266,10 +266,24 @@ protected:
266 266
     void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
267 267
 };
268 268
 
269
-class CollisionMetatilesPixmapItem : public MetatilesPixmapItem {
269
+class MovementPermissionsPixmapItem : public MetatilesPixmapItem {
270 270
     Q_OBJECT
271 271
 public:
272
-    CollisionMetatilesPixmapItem(Map *map_): MetatilesPixmapItem(map_) {
272
+    MovementPermissionsPixmapItem(Map *map_): MetatilesPixmapItem(map_) {}
273
+    virtual void pick(uint collision) {
274
+        map->paint_collision = collision;
275
+        draw();
276
+    }
277
+protected:
278
+    void mousePressEvent(QGraphicsSceneMouseEvent*);
279
+    void mouseMoveEvent(QGraphicsSceneMouseEvent*);
280
+    void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
281
+};
282
+
283
+class CollisionMetatilesPixmapItem : public MovementPermissionsPixmapItem {
284
+    Q_OBJECT
285
+public:
286
+    CollisionMetatilesPixmapItem(Map *map_): MovementPermissionsPixmapItem(map_) {
273 287
         connect(map, SIGNAL(paintCollisionChanged(Map*)), this, SLOT(paintCollisionChanged(Map *)));
274 288
     }
275 289
     virtual void pick(uint collision) {
@@ -287,10 +301,10 @@ private slots:
287 301
     }
288 302
 };
289 303
 
290
-class ElevationMetatilesPixmapItem : public MetatilesPixmapItem {
304
+class ElevationMetatilesPixmapItem : public MovementPermissionsPixmapItem {
291 305
     Q_OBJECT
292 306
 public:
293
-    ElevationMetatilesPixmapItem(Map *map_): MetatilesPixmapItem(map_) {
307
+    ElevationMetatilesPixmapItem(Map *map_): MovementPermissionsPixmapItem(map_) {
294 308
         connect(map, SIGNAL(paintCollisionChanged(Map*)), this, SLOT(paintCollisionChanged(Map *)));
295 309
     }
296 310
     virtual void pick(uint elevation) {