Explorar el Código

Merge pull request #1 from yenatch/master

sync with source
Garak hace 6 años
padre
commit
43119f2b43
No account linked to committer's email address
Se han modificado 18 ficheros con 1113 adiciones y 362 borrados
  1. 155
    29
      editor.cpp
  2. 34
    2
      editor.h
  3. 208
    0
      event.cpp
  4. 30
    1
      event.h
  5. 50
    20
      mainwindow.cpp
  6. 6
    2
      mainwindow.h
  7. 196
    18
      mainwindow.ui
  8. 23
    107
      map.cpp
  9. 6
    16
      map.h
  10. 0
    6
      metatile.cpp
  11. 0
    16
      metatile.h
  12. 103
    0
      neweventtoolbutton.cpp
  13. 35
    0
      neweventtoolbutton.h
  14. 4
    4
      pretmap.pro
  15. 131
    139
      project.cpp
  16. 2
    1
      project.h
  17. 111
    0
      tileset.cpp
  18. 19
    1
      tileset.h

+ 155
- 29
editor.cpp Ver fichero

@@ -1,4 +1,5 @@
1 1
 #include "editor.h"
2
+#include "event.h"
2 3
 #include <QCheckBox>
3 4
 #include <QPainter>
4 5
 #include <QMouseEvent>
@@ -301,8 +302,12 @@ void Editor::onConnectionDirectionChanged(QString newDirection) {
301 302
     ui->comboBox_ConnectionDirection->blockSignals(false);
302 303
 }
303 304
 
305
+void Editor::onBorderMetatilesChanged() {
306
+    displayMapBorder();
307
+}
308
+
304 309
 void Editor::setConnectionsVisibility(bool visible) {
305
-    for (QGraphicsPixmapItem* item : map->connection_items) {
310
+    for (QGraphicsPixmapItem* item : connection_items) {
306 311
         item->setVisible(visible);
307 312
         item->setActive(visible);
308 313
     }
@@ -344,8 +349,13 @@ void Editor::mouseEvent_collision(QGraphicsSceneMouseEvent *event, CollisionPixm
344 349
 }
345 350
 
346 351
 void Editor::displayMap() {
347
-    scene = new QGraphicsScene;
352
+    if (!scene)
353
+        scene = new QGraphicsScene;
348 354
 
355
+    if (map_item && scene) {
356
+        scene->removeItem(map_item);
357
+        delete map_item;
358
+    }
349 359
     map_item = new MapPixmapItem(map);
350 360
     connect(map_item, SIGNAL(mouseEvent(QGraphicsSceneMouseEvent*,MapPixmapItem*)),
351 361
             this, SLOT(mouseEvent_map(QGraphicsSceneMouseEvent*,MapPixmapItem*)));
@@ -353,6 +363,10 @@ void Editor::displayMap() {
353 363
     map_item->draw(true);
354 364
     scene->addItem(map_item);
355 365
 
366
+    if (collision_item && scene) {
367
+        scene->removeItem(collision_item);
368
+        delete collision_item;
369
+    }
356 370
     collision_item = new CollisionPixmapItem(map);
357 371
     connect(collision_item, SIGNAL(mouseEvent(QGraphicsSceneMouseEvent*,CollisionPixmapItem*)),
358 372
             this, SLOT(mouseEvent_collision(QGraphicsSceneMouseEvent*,CollisionPixmapItem*)));
@@ -360,19 +374,6 @@ void Editor::displayMap() {
360 374
     collision_item->draw(true);
361 375
     scene->addItem(collision_item);
362 376
 
363
-    events_group = new EventGroup;
364
-    scene->addItem(events_group);
365
-
366
-    if (map_item) {
367
-        map_item->setVisible(false);
368
-    }
369
-    if (collision_item) {
370
-        collision_item->setVisible(false);
371
-    }
372
-    if (events_group) {
373
-        events_group->setVisible(false);
374
-    }
375
-
376 377
     int tw = 16;
377 378
     int th = 16;
378 379
     scene->setSceneRect(
@@ -383,22 +384,57 @@ void Editor::displayMap() {
383 384
     );
384 385
 
385 386
     displayMetatiles();
387
+    displayBorderMetatiles();
386 388
     displayCollisionMetatiles();
387 389
     displayElevationMetatiles();
388 390
     displayMapEvents();
389 391
     displayMapConnections();
390 392
     displayMapBorder();
391 393
     displayMapGrid();
394
+
395
+    if (map_item) {
396
+        map_item->setVisible(false);
397
+    }
398
+    if (collision_item) {
399
+        collision_item->setVisible(false);
400
+    }
401
+    if (events_group) {
402
+        events_group->setVisible(false);
403
+    }
392 404
 }
393 405
 
394 406
 void Editor::displayMetatiles() {
407
+    if (metatiles_item && metatiles_item->scene()) {
408
+        metatiles_item->scene()->removeItem(metatiles_item);
409
+        delete metatiles_item;
410
+    }
411
+
395 412
     scene_metatiles = new QGraphicsScene;
396 413
     metatiles_item = new MetatilesPixmapItem(map);
397 414
     metatiles_item->draw();
398 415
     scene_metatiles->addItem(metatiles_item);
399 416
 }
400 417
 
418
+void Editor::displayBorderMetatiles() {
419
+    if (selected_border_metatiles_item && selected_border_metatiles_item->scene()) {
420
+        selected_border_metatiles_item->scene()->removeItem(selected_border_metatiles_item);
421
+        delete selected_border_metatiles_item;
422
+    }
423
+
424
+    scene_selected_border_metatiles = new QGraphicsScene;
425
+    selected_border_metatiles_item = new BorderMetatilesPixmapItem(map);
426
+    selected_border_metatiles_item->draw();
427
+    scene_selected_border_metatiles->addItem(selected_border_metatiles_item);
428
+
429
+    connect(selected_border_metatiles_item, SIGNAL(borderMetatilesChanged()), this, SLOT(onBorderMetatilesChanged()));
430
+}
431
+
401 432
 void Editor::displayCollisionMetatiles() {
433
+    if (collision_metatiles_item && collision_metatiles_item->scene()) {
434
+        collision_metatiles_item->scene()->removeItem(collision_metatiles_item);
435
+        delete collision_metatiles_item;
436
+    }
437
+
402 438
     scene_collision_metatiles = new QGraphicsScene;
403 439
     collision_metatiles_item = new CollisionMetatilesPixmapItem(map);
404 440
     collision_metatiles_item->draw();
@@ -406,6 +442,11 @@ void Editor::displayCollisionMetatiles() {
406 442
 }
407 443
 
408 444
 void Editor::displayElevationMetatiles() {
445
+    if (elevation_metatiles_item && elevation_metatiles_item->scene()) {
446
+        elevation_metatiles_item->scene()->removeItem(elevation_metatiles_item);
447
+        delete elevation_metatiles_item;
448
+    }
449
+
409 450
     scene_elevation_metatiles = new QGraphicsScene;
410 451
     elevation_metatiles_item = new ElevationMetatilesPixmapItem(map);
411 452
     elevation_metatiles_item->draw();
@@ -413,10 +454,22 @@ void Editor::displayElevationMetatiles() {
413 454
 }
414 455
 
415 456
 void Editor::displayMapEvents() {
416
-    for (QGraphicsItem *child : events_group->childItems()) {
417
-        events_group->removeFromGroup(child);
457
+    if (events_group) {
458
+        for (QGraphicsItem *child : events_group->childItems()) {
459
+            events_group->removeFromGroup(child);
460
+            delete child;
461
+        }
462
+
463
+        if (events_group->scene()) {
464
+            events_group->scene()->removeItem(events_group);
465
+        }
466
+
467
+        delete events_group;
418 468
     }
419 469
 
470
+    events_group = new EventGroup;
471
+    scene->addItem(events_group);
472
+
420 473
     QList<Event *> events = map->getAllEvents();
421 474
     project->loadEventPixmaps(events);
422 475
     for (Event *event : events) {
@@ -436,12 +489,18 @@ DraggablePixmapItem *Editor::addMapEvent(Event *event) {
436 489
 }
437 490
 
438 491
 void Editor::displayMapConnections() {
439
-    for (QGraphicsPixmapItem* item : map->connection_items) {
492
+    for (QGraphicsPixmapItem* item : connection_items) {
493
+        if (item->scene()) {
494
+            item->scene()->removeItem(item);
495
+        }
440 496
         delete item;
441 497
     }
442
-    map->connection_items.clear();
498
+    connection_items.clear();
443 499
 
444 500
     for (ConnectionPixmapItem* item : connection_edit_items) {
501
+        if (item->scene()) {
502
+            item->scene()->removeItem(item);
503
+        }
445 504
         delete item;
446 505
     }
447 506
     selected_connection_item = NULL;
@@ -483,7 +542,7 @@ void Editor::createConnectionItem(Connection* connection, bool hide) {
483 542
     item->setX(x);
484 543
     item->setY(y);
485 544
     scene->addItem(item);
486
-    map->connection_items.append(item);
545
+    connection_items.append(item);
487 546
     item->setVisible(!hide);
488 547
 
489 548
     ConnectionPixmapItem *connection_edit_item = new ConnectionPixmapItem(pixmap, connection, x, y, map->getWidth(), map->getHeight());
@@ -498,6 +557,14 @@ void Editor::createConnectionItem(Connection* connection, bool hide) {
498 557
 }
499 558
 
500 559
 void Editor::displayMapBorder() {
560
+    for (QGraphicsPixmapItem* item : borderItems) {
561
+        if (item->scene()) {
562
+            item->scene()->removeItem(item);
563
+        }
564
+        delete item;
565
+    }
566
+    borderItems.clear();
567
+
501 568
     QPixmap pixmap = map->renderBorder();
502 569
     for (int y = -6; y < map->getHeight() + 6; y += 2)
503 570
     for (int x = -6; x < map->getWidth() + 6; x += 2) {
@@ -511,18 +578,29 @@ void Editor::displayMapBorder() {
511 578
 }
512 579
 
513 580
 void Editor::displayMapGrid() {
581
+    for (QGraphicsLineItem* item : gridLines) {
582
+        if (item && item->scene()) {
583
+            item->scene()->removeItem(item);
584
+        }
585
+        delete item;
586
+    }
587
+    gridLines.clear();
588
+    ui->checkBox_ToggleGrid->disconnect();
589
+
514 590
     int pixelWidth = map->getWidth() * 16;
515 591
     int pixelHeight = map->getHeight() * 16;
516 592
     for (int i = 0; i <= map->getWidth(); i++) {
517 593
         int x = i * 16;
518 594
         QGraphicsLineItem *line = scene->addLine(x, 0, x, pixelHeight);
519 595
         line->setVisible(ui->checkBox_ToggleGrid->isChecked());
596
+        gridLines.append(line);
520 597
         connect(ui->checkBox_ToggleGrid, &QCheckBox::toggled, [=](bool checked){line->setVisible(checked);});
521 598
     }
522 599
     for (int j = 0; j <= map->getHeight(); j++) {
523 600
         int y = j * 16;
524 601
         QGraphicsLineItem *line = scene->addLine(0, y, pixelWidth, y);
525 602
         line->setVisible(ui->checkBox_ToggleGrid->isChecked());
603
+        gridLines.append(line);
526 604
         connect(ui->checkBox_ToggleGrid, &QCheckBox::toggled, [=](bool checked){line->setVisible(checked);});
527 605
     }
528 606
 }
@@ -665,8 +743,11 @@ void Editor::removeCurrentConnection() {
665 743
     connection_edit_items.removeOne(selected_connection_item);
666 744
     removeMirroredConnection(selected_connection_item->connection);
667 745
 
668
-    scene->removeItem(selected_connection_item);
669
-    delete selected_connection_item;
746
+    if (selected_connection_item && selected_connection_item->scene()) {
747
+        selected_connection_item->scene()->removeItem(selected_connection_item);
748
+        delete selected_connection_item;
749
+    }
750
+
670 751
     selected_connection_item = NULL;
671 752
     setConnectionEditControlsEnabled(false);
672 753
     ui->spinBox_ConnectionOffset->setValue(0);
@@ -723,6 +804,20 @@ void Editor::updateDiveEmergeMap(QString mapName, QString direction) {
723 804
     ui->label_NumConnections->setText(QString::number(map->connections.length()));
724 805
 }
725 806
 
807
+void Editor::updatePrimaryTileset(QString tilesetLabel)
808
+{
809
+    map->layout->tileset_primary_label = tilesetLabel;
810
+    map->layout->tileset_primary = project->getTileset(tilesetLabel);
811
+    emit tilesetChanged(map->name);
812
+}
813
+
814
+void Editor::updateSecondaryTileset(QString tilesetLabel)
815
+{
816
+    map->layout->tileset_secondary_label = tilesetLabel;
817
+    map->layout->tileset_secondary = project->getTileset(tilesetLabel);
818
+    emit tilesetChanged(map->name);
819
+}
820
+
726 821
 void MetatilesPixmapItem::paintTileChanged(Map *map) {
727 822
     draw();
728 823
 }
@@ -792,6 +887,43 @@ void MetatilesPixmapItem::updateSelection(QPointF pos, Qt::MouseButton button) {
792 887
     }
793 888
 }
794 889
 
890
+void BorderMetatilesPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
891
+    QPointF pos = event->pos();
892
+    int x = ((int)pos.x()) / 16;
893
+    int y = ((int)pos.y()) / 16;
894
+
895
+    for (int i = 0; i < map->paint_tile_width && (i + x) < 2; i++) {
896
+        for (int j = 0; j < map->paint_tile_height && (j + y) < 2; j++) {
897
+            int blockIndex = (j + y) * 2 + (i + x);
898
+            int tile = map->getSelectedBlockIndex(map->paint_tile_index + i + (j * 8));
899
+            (*map->layout->border->blocks)[blockIndex].tile = tile;
900
+        }
901
+    }
902
+
903
+    draw();
904
+    emit borderMetatilesChanged();
905
+}
906
+
907
+void BorderMetatilesPixmapItem::draw() {
908
+    QImage image(32, 32, QImage::Format_RGBA8888);
909
+    QPainter painter(&image);
910
+    QList<Block> *blocks = map->layout->border->blocks;
911
+
912
+    for (int i = 0; i < 2; i++)
913
+    for (int j = 0; j < 2; j++)
914
+    {
915
+        int x = i * 16;
916
+        int y = j * 16;
917
+        int index = j * 2 + i;
918
+        QImage metatile_image = Metatile::getMetatileImage(blocks->value(index).tile, map->layout->tileset_primary, map->layout->tileset_secondary);
919
+        QPoint metatile_origin = QPoint(x, y);
920
+        painter.drawImage(metatile_origin, metatile_image);
921
+    }
922
+
923
+    painter.end();
924
+    setPixmap(QPixmap::fromImage(image));
925
+}
926
+
795 927
 void MovementPermissionsPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent* event) {
796 928
     QPointF pos = event->pos();
797 929
     int x = ((int)pos.x()) / 16;
@@ -1298,15 +1430,10 @@ void Editor::selectMapEvent(DraggablePixmapItem *object, bool toggle) {
1298 1430
     }
1299 1431
 }
1300 1432
 
1301
-DraggablePixmapItem* Editor::addNewEvent() {
1302
-    return addNewEvent("object");
1303
-}
1304
-
1305 1433
 DraggablePixmapItem* Editor::addNewEvent(QString event_type) {
1306 1434
     if (project && map) {
1307
-        Event *event = new Event;
1435
+        Event *event = Event::createNewEvent(event_type, map->name);
1308 1436
         event->put("map_name", map->name);
1309
-        event->put("event_type", event_type);
1310 1437
         map->addEvent(event);
1311 1438
         project->loadEventPixmaps(map->getAllEvents());
1312 1439
         DraggablePixmapItem *object = addMapEvent(event);
@@ -1325,7 +1452,6 @@ void Editor::deleteEvent(Event *event) {
1325 1452
     //updateSelectedObjects();
1326 1453
 }
1327 1454
 
1328
-
1329 1455
 // dunno how to detect bubbling. QMouseEvent::isAccepted seems to always be true
1330 1456
 // check if selected_events changed instead. this has the side effect of deselecting
1331 1457
 // when you click on a selected event, since selected_events doesn't change.

+ 34
- 2
editor.h Ver fichero

@@ -16,6 +16,7 @@ class MapPixmapItem;
16 16
 class CollisionPixmapItem;
17 17
 class ConnectionPixmapItem;
18 18
 class MetatilesPixmapItem;
19
+class BorderMetatilesPixmapItem;
19 20
 class CollisionMetatilesPixmapItem;
20 21
 class ElevationMetatilesPixmapItem;
21 22
 
@@ -36,6 +37,7 @@ public:
36 37
     void setMap(QString map_name);
37 38
     void displayMap();
38 39
     void displayMetatiles();
40
+    void displayBorderMetatiles();
39 41
     void displayCollisionMetatiles();
40 42
     void displayElevationMetatiles();
41 43
     void displayMapEvents();
@@ -57,12 +59,14 @@ public:
57 59
     void updateDiveMap(QString mapName);
58 60
     void updateEmergeMap(QString mapName);
59 61
     void setSelectedConnectionFromMap(QString mapName);
62
+    void updatePrimaryTileset(QString tilesetLabel);
63
+    void updateSecondaryTileset(QString tilesetLabel);
60 64
 
61 65
     DraggablePixmapItem *addMapEvent(Event *event);
62 66
     void selectMapEvent(DraggablePixmapItem *object);
63 67
     void selectMapEvent(DraggablePixmapItem *object, bool toggle);
64
-    DraggablePixmapItem *addNewEvent();
65 68
     DraggablePixmapItem *addNewEvent(QString event_type);
69
+    Event* createNewEvent(QString event_type);
66 70
     void deleteEvent(Event *);
67 71
     void updateSelectedEvents();
68 72
     void redrawObject(DraggablePixmapItem *item);
@@ -72,15 +76,19 @@ public:
72 76
     QGraphicsPixmapItem *current_view = NULL;
73 77
     MapPixmapItem *map_item = NULL;
74 78
     ConnectionPixmapItem* selected_connection_item = NULL;
79
+    QList<QGraphicsPixmapItem*> connection_items;
75 80
     QList<ConnectionPixmapItem*> connection_edit_items;
76 81
     CollisionPixmapItem *collision_item = NULL;
77 82
     QGraphicsItemGroup *events_group = NULL;
78 83
     QList<QGraphicsPixmapItem*> borderItems;
84
+    QList<QGraphicsLineItem*> gridLines;
79 85
 
80 86
     QGraphicsScene *scene_metatiles = NULL;
87
+    QGraphicsScene *scene_selected_border_metatiles = NULL;
81 88
     QGraphicsScene *scene_collision_metatiles = NULL;
82 89
     QGraphicsScene *scene_elevation_metatiles = NULL;
83 90
     MetatilesPixmapItem *metatiles_item = NULL;
91
+    BorderMetatilesPixmapItem *selected_border_metatiles_item = NULL;
84 92
     CollisionMetatilesPixmapItem *collision_metatiles_item = NULL;
85 93
     ElevationMetatilesPixmapItem *elevation_metatiles_item = NULL;
86 94
 
@@ -108,6 +116,13 @@ private:
108 116
     void updateMirroredConnectionDirection(Connection*, QString);
109 117
     void updateMirroredConnectionMap(Connection*, QString);
110 118
     void updateMirroredConnection(Connection*, QString, QString, bool isDelete = false);
119
+    Event* createNewObjectEvent();
120
+    Event* createNewWarpEvent();
121
+    Event* createNewCoordScriptEvent();
122
+    Event* createNewCoordWeatherEvent();
123
+    Event* createNewSignEvent();
124
+    Event* createNewHiddenItemEvent();
125
+    Event* createNewSecretBaseEvent();
111 126
 
112 127
 private slots:
113 128
     void mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item);
@@ -116,11 +131,13 @@ private slots:
116 131
     void onConnectionItemSelected(ConnectionPixmapItem* connectionItem);
117 132
     void onConnectionItemDoubleClicked(ConnectionPixmapItem* connectionItem);
118 133
     void onConnectionDirectionChanged(QString newDirection);
134
+    void onBorderMetatilesChanged();
119 135
 
120 136
 signals:
121 137
     void objectsChanged();
122 138
     void selectedObjectsChanged();
123 139
     void loadMapRequested(QString, QString);
140
+    void tilesetChanged(QString);
124 141
 };
125 142
 
126 143
 
@@ -166,7 +183,7 @@ public:
166 183
         emit spriteChanged(event->pixmap);
167 184
     }
168 185
     void bind(QComboBox *combo, QString key) {
169
-        connect(combo, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::activated),
186
+        connect(combo, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentTextChanged),
170 187
                 this, [this, key](QString value){
171 188
             this->event->put(key, value);
172 189
         });
@@ -344,6 +361,21 @@ protected:
344 361
     void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
345 362
 };
346 363
 
364
+class BorderMetatilesPixmapItem : public QObject, public QGraphicsPixmapItem {
365
+    Q_OBJECT
366
+public:
367
+    BorderMetatilesPixmapItem(Map *map_) {
368
+        map = map_;
369
+        setAcceptHoverEvents(true);
370
+    }
371
+    Map* map = NULL;
372
+    virtual void draw();
373
+signals:
374
+    void borderMetatilesChanged();
375
+protected:
376
+    void mousePressEvent(QGraphicsSceneMouseEvent*);
377
+};
378
+
347 379
 class MovementPermissionsPixmapItem : public MetatilesPixmapItem {
348 380
     Q_OBJECT
349 381
 public:

+ 208
- 0
event.cpp Ver fichero

@@ -1,5 +1,213 @@
1 1
 #include "event.h"
2 2
 
3
+QString EventType::Object = "event_object";
4
+QString EventType::Warp = "event_warp";
5
+QString EventType::CoordScript = "event_trap";
6
+QString EventType::CoordWeather = "event_trap_weather";
7
+QString EventType::Sign = "event_sign";
8
+QString EventType::HiddenItem = "event_hidden_item";
9
+QString EventType::SecretBase = "event_secret_base";
10
+
3 11
 Event::Event()
4 12
 {
5 13
 }
14
+
15
+Event* Event::createNewEvent(QString event_type, QString map_name)
16
+{
17
+    Event *event;
18
+    if (event_type == EventType::Object) {
19
+        event = createNewObjectEvent();
20
+    } else if (event_type == EventType::Warp) {
21
+        event = createNewWarpEvent(map_name);
22
+    } else if (event_type == EventType::CoordScript) {
23
+        event = createNewCoordScriptEvent();
24
+    } else if (event_type == EventType::CoordWeather) {
25
+        event = createNewCoordWeatherEvent();
26
+    } else if (event_type == EventType::Sign) {
27
+        event = createNewSignEvent();
28
+    } else if (event_type == EventType::HiddenItem) {
29
+        event = createNewHiddenItemEvent();
30
+    } else if (event_type == EventType::SecretBase) {
31
+        event = createNewSecretBaseEvent();
32
+    }
33
+
34
+    event->setX(0);
35
+    event->setY(0);
36
+    event->put("elevation", 3);
37
+    return event;
38
+}
39
+
40
+Event* Event::createNewObjectEvent()
41
+{
42
+    Event *event = new Event;
43
+    event->put("event_group_type", "object_event_group");
44
+    event->put("event_type", EventType::Object);
45
+    event->put("sprite", "EVENT_OBJ_GFX_BOY_1");
46
+    event->put("behavior", "1");
47
+    event->put("radius_x", 0);
48
+    event->put("radius_y", 0);
49
+    event->put("script_label", "NULL");
50
+    event->put("event_flag", "0");
51
+    event->put("replacement", "0");
52
+    event->put("trainer_see_type", "0");
53
+    event->put("sight_radius_tree_id", 0);
54
+    return event;
55
+}
56
+
57
+Event* Event::createNewWarpEvent(QString map_name)
58
+{
59
+    Event *event = new Event;
60
+    event->put("event_group_type", "warp_event_group");
61
+    event->put("event_type", EventType::Warp);
62
+    event->put("destination_warp", 0);
63
+    event->put("destination_map_name", map_name);
64
+    return event;
65
+}
66
+
67
+Event* Event::createNewCoordScriptEvent()
68
+{
69
+    Event *event = new Event;
70
+    event->put("event_group_type", "coord_event_group");
71
+    event->put("event_type", EventType::CoordScript);
72
+    event->put("script_label", "NULL");
73
+    event->put("script_var", "VAR_TEMP_0");
74
+    event->put("script_var_value", "0");
75
+    return event;
76
+}
77
+
78
+Event* Event::createNewCoordWeatherEvent()
79
+{
80
+    Event *event = new Event;
81
+    event->put("event_group_type", "coord_event_group");
82
+    event->put("event_type", EventType::CoordWeather);
83
+    event->put("weather", "COORD_EVENT_WEATHER_SUNNY");
84
+    return event;
85
+}
86
+
87
+Event* Event::createNewSignEvent()
88
+{
89
+    Event *event = new Event;
90
+    event->put("event_group_type", "bg_event_group");
91
+    event->put("event_type", EventType::Sign);
92
+    event->put("player_facing_direction", "0");
93
+    event->put("script_label", "NULL");
94
+    return event;
95
+}
96
+
97
+Event* Event::createNewHiddenItemEvent()
98
+{
99
+    Event *event = new Event;
100
+    event->put("event_group_type", "bg_event_group");
101
+    event->put("event_type", EventType::HiddenItem);
102
+    event->put("item", "ITEM_POTION");
103
+    event->put("flag", "FLAG_HIDDEN_ITEM_0");
104
+    return event;
105
+}
106
+
107
+Event* Event::createNewSecretBaseEvent()
108
+{
109
+    Event *event = new Event;
110
+    event->put("event_group_type", "bg_event_group");
111
+    event->put("event_type", EventType::SecretBase);
112
+    event->put("secret_base_map", "SECRET_BASE_RED_CAVE2_1");
113
+    return event;
114
+}
115
+
116
+QString Event::buildObjectEventMacro(int item_index)
117
+{
118
+    int radius_x = this->getInt("radius_x");
119
+    int radius_y = this->getInt("radius_y");
120
+    uint16_t x = this->getInt("x");
121
+    uint16_t y = this->getInt("y");
122
+
123
+    QString text = "";
124
+    text += QString("\tobject_event %1").arg(item_index + 1);
125
+    text += QString(", %1").arg(this->get("sprite"));
126
+    text += QString(", %1").arg(this->get("replacement"));
127
+    text += QString(", %1").arg(x);
128
+    text += QString(", %1").arg(y);
129
+    text += QString(", %1").arg(this->get("elevation"));
130
+    text += QString(", %1").arg(this->get("behavior"));
131
+    text += QString(", %1").arg(radius_x);
132
+    text += QString(", %1").arg(radius_y);
133
+    text += QString(", %1").arg(this->get("trainer_see_type"));
134
+    text += QString(", %1").arg(this->get("sight_radius_tree_id"));
135
+    text += QString(", %1").arg(this->get("script_label"));
136
+    text += QString(", %1").arg(this->get("event_flag"));
137
+    text += "\n";
138
+    return text;
139
+}
140
+
141
+QString Event::buildWarpEventMacro(QMap<QString, QString> *mapNamesToMapConstants)
142
+{
143
+    QString text = "";
144
+    text += QString("\twarp_def %1").arg(this->get("x"));
145
+    text += QString(", %1").arg(this->get("y"));
146
+    text += QString(", %1").arg(this->get("elevation"));
147
+    text += QString(", %1").arg(this->get("destination_warp"));
148
+    text += QString(", %1").arg(mapNamesToMapConstants->value(this->get("destination_map_name")));
149
+    text += "\n";
150
+    return text;
151
+}
152
+
153
+QString Event::buildCoordScriptEventMacro()
154
+{
155
+    QString text = "";
156
+    text += QString("\tcoord_event %1").arg(this->get("x"));
157
+    text += QString(", %1").arg(this->get("y"));
158
+    text += QString(", %1").arg(this->get("elevation"));
159
+    text += QString(", 0");
160
+    text += QString(", %1").arg(this->get("script_var"));
161
+    text += QString(", %1").arg(this->get("script_var_value"));
162
+    text += QString(", 0");
163
+    text += QString(", %1").arg(this->get("script_label"));
164
+    text += "\n";
165
+    return text;
166
+}
167
+
168
+QString Event::buildCoordWeatherEventMacro()
169
+{
170
+    QString text = "";
171
+    text += QString("\tcoord_weather_event %1").arg(this->get("x"));
172
+    text += QString(", %1").arg(this->get("y"));
173
+    text += QString(", %1").arg(this->get("elevation"));
174
+    text += QString(", %1").arg(this->get("weather"));
175
+    text += "\n";
176
+    return text;
177
+}
178
+
179
+QString Event::buildSignEventMacro()
180
+{
181
+    QString text = "";
182
+    text += QString("\tbg_event %1").arg(this->get("x"));
183
+    text += QString(", %1").arg(this->get("y"));
184
+    text += QString(", %1").arg(this->get("elevation"));
185
+    text += QString(", %1").arg(this->get("player_facing_direction"));
186
+    text += QString(", 0");
187
+    text += QString(", %1").arg(this->get("script_label"));
188
+    text += "\n";
189
+    return text;
190
+}
191
+
192
+QString Event::buildHiddenItemEventMacro()
193
+{
194
+    QString text = "";
195
+    text += QString("\tbg_hidden_item_event %1").arg(this->get("x"));
196
+    text += QString(", %1").arg(this->get("y"));
197
+    text += QString(", %1").arg(this->get("elevation"));
198
+    text += QString(", %1").arg(this->get("item"));
199
+    text += QString(", %1").arg(this->get("flag"));
200
+    text += "\n";
201
+    return text;
202
+}
203
+
204
+QString Event::buildSecretBaseEventMacro()
205
+{
206
+    QString text = "";
207
+    text += QString("\tbg_secret_base_event %1").arg(this->get("x"));
208
+    text += QString(", %1").arg(this->get("y"));
209
+    text += QString(", %1").arg(this->get("elevation"));
210
+    text += QString(", %1").arg(this->get("secret_base_map"));
211
+    text += "\n";
212
+    return text;
213
+}

+ 30
- 1
event.h Ver fichero

@@ -4,12 +4,24 @@
4 4
 #include <QString>
5 5
 #include <QPixmap>
6 6
 #include <QMap>
7
+#include <QDebug>
8
+
9
+class EventType
10
+{
11
+public:
12
+    static QString Object;
13
+    static QString Warp;
14
+    static QString CoordScript;
15
+    static QString CoordWeather;
16
+    static QString Sign;
17
+    static QString HiddenItem;
18
+    static QString SecretBase;
19
+};
7 20
 
8 21
 class Event
9 22
 {
10 23
 public:
11 24
     Event();
12
-
13 25
 public:
14 26
     int x() {
15 27
         return getInt("x");
@@ -39,6 +51,23 @@ public:
39 51
         values.insert(key, value);
40 52
     }
41 53
 
54
+    static Event* createNewEvent(QString, QString);
55
+    static Event* createNewObjectEvent();
56
+    static Event* createNewWarpEvent(QString);
57
+    static Event* createNewCoordScriptEvent();
58
+    static Event* createNewCoordWeatherEvent();
59
+    static Event* createNewSignEvent();
60
+    static Event* createNewHiddenItemEvent();
61
+    static Event* createNewSecretBaseEvent();
62
+
63
+    QString buildObjectEventMacro(int);
64
+    QString buildWarpEventMacro(QMap<QString, QString>*);
65
+    QString buildCoordScriptEventMacro();
66
+    QString buildCoordWeatherEventMacro();
67
+    QString buildSignEventMacro();
68
+    QString buildHiddenItemEventMacro();
69
+    QString buildSecretBaseEventMacro();
70
+
42 71
     QMap<QString, QString> values;
43 72
     QPixmap pixmap;
44 73
 };

+ 50
- 20
mainwindow.cpp Ver fichero

@@ -24,12 +24,17 @@ MainWindow::MainWindow(QWidget *parent) :
24 24
     QCoreApplication::setApplicationName("pretmap");
25 25
 
26 26
     ui->setupUi(this);
27
+
28
+    ui->newEventToolButton->initButton();
29
+    connect(ui->newEventToolButton, SIGNAL(newEventAdded(QString)), this, SLOT(addNewEvent(QString)));
30
+
27 31
     new QShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Z), this, SLOT(redo()));
28 32
 
29 33
     editor = new Editor(ui);
30 34
     connect(editor, SIGNAL(objectsChanged()), this, SLOT(updateSelectedObjects()));
31 35
     connect(editor, SIGNAL(selectedObjectsChanged()), this, SLOT(updateSelectedObjects()));
32 36
     connect(editor, SIGNAL(loadMapRequested(QString, QString)), this, SLOT(onLoadMapRequested(QString, QString)));
37
+    connect(editor, SIGNAL(tilesetChanged(QString)), this, SLOT(onTilesetChanged(QString)));
33 38
 
34 39
     on_toolButton_Paint_clicked();
35 40
 
@@ -162,6 +167,9 @@ void MainWindow::setMap(QString map_name) {
162 167
     //ui->graphicsView_Metatiles->setSceneRect(editor->scene_metatiles->sceneRect());
163 168
     ui->graphicsView_Metatiles->setFixedSize(editor->metatiles_item->pixmap().width() + 2, editor->metatiles_item->pixmap().height() + 2);
164 169
 
170
+    ui->graphicsView_BorderMetatile->setScene(editor->scene_selected_border_metatiles);
171
+    ui->graphicsView_BorderMetatile->setFixedSize(editor->selected_border_metatiles_item->pixmap().width() + 2, editor->selected_border_metatiles_item->pixmap().height() + 2);
172
+
165 173
     ui->graphicsView_Collision->setScene(editor->scene_collision_metatiles);
166 174
     //ui->graphicsView_Collision->setSceneRect(editor->scene_collision_metatiles->sceneRect());
167 175
     ui->graphicsView_Collision->setFixedSize(editor->collision_metatiles_item->pixmap().width() + 2, editor->collision_metatiles_item->pixmap().height() + 2);
@@ -199,6 +207,8 @@ void MainWindow::displayMapProperties() {
199 207
     ui->comboBox_Weather->clear();
200 208
     ui->comboBox_Type->clear();
201 209
     ui->comboBox_BattleScene->clear();
210
+    ui->comboBox_PrimaryTileset->clear();
211
+    ui->comboBox_SecondaryTileset->clear();
202 212
     ui->checkBox_ShowLocation->setChecked(false);
203 213
     if (!editor || !editor->map || !editor->project) {
204 214
         ui->frame_3->setEnabled(false);
@@ -215,6 +225,12 @@ void MainWindow::displayMapProperties() {
215 225
     ui->comboBox_Location->addItems(project->getLocations());
216 226
     ui->comboBox_Location->setCurrentText(map->location);
217 227
 
228
+    QMap<QString, QStringList> tilesets = project->getTilesets();
229
+    ui->comboBox_PrimaryTileset->addItems(tilesets.value("primary"));
230
+    ui->comboBox_PrimaryTileset->setCurrentText(map->layout->tileset_primary_label);
231
+    ui->comboBox_SecondaryTileset->addItems(tilesets.value("secondary"));
232
+    ui->comboBox_SecondaryTileset->setCurrentText(map->layout->tileset_secondary_label);
233
+
218 234
     ui->comboBox_Visibility->addItems(project->getVisibilities());
219 235
     ui->comboBox_Visibility->setCurrentText(map->visibility);
220 236
 
@@ -405,6 +421,11 @@ void MainWindow::onAddNewMapToGroupClick(QAction* triggeredAction)
405 421
     setMap(newMapName);
406 422
 }
407 423
 
424
+void MainWindow::onTilesetChanged(QString mapName)
425
+{
426
+    setMap(mapName);
427
+}
428
+
408 429
 void MainWindow::on_mapList_activated(const QModelIndex &index)
409 430
 {
410 431
     QVariant data = index.data(Qt::UserRole);
@@ -503,14 +524,12 @@ void MainWindow::on_actionRedo_triggered()
503 524
     redo();
504 525
 }
505 526
 
506
-void MainWindow::on_toolButton_newObject_clicked()
527
+void MainWindow::addNewEvent(QString event_type)
507 528
 {
508 529
     if (editor) {
509
-        DraggablePixmapItem *object = editor->addNewEvent();
530
+        DraggablePixmapItem *object = editor->addNewEvent(event_type);
510 531
         if (object) {
511
-            //if (editor->selected_events->length()) {
512
-                editor->selectMapEvent(object, true);
513
-            //}
532
+            editor->selectMapEvent(object, false);
514 533
         }
515 534
         updateSelectedObjects();
516 535
     }
@@ -554,12 +573,13 @@ void MainWindow::updateSelectedObjects() {
554 573
         font.setCapitalization(QFont::Capitalize);
555 574
         frame->ui->label_name->setFont(font);
556 575
         QString event_type = item->event->get("event_type");
576
+        QString event_group_type = item->event->get("event_group_type");
557 577
         QString map_name = item->event->get("map_name");
558 578
         frame->ui->label_name->setText(
559
-            QString("%1 %2 %3")
579
+            QString("%1: %2 %3")
580
+                .arg(editor->project->getMap(map_name)->events.value(event_group_type).indexOf(item->event) + 1)
560 581
                 .arg(map_name)
561 582
                 .arg(event_type)
562
-                .arg(editor->project->getMap(map_name)->events.value(event_type).indexOf(item->event) + 1)
563 583
         );
564 584
 
565 585
         frame->ui->label_spritePixmap->setPixmap(item->event->pixmap);
@@ -574,13 +594,13 @@ void MainWindow::updateSelectedObjects() {
574 594
         field_labels["behavior"] = "Behavior";
575 595
         field_labels["radius_x"] = "Movement Radius X";
576 596
         field_labels["radius_y"] = "Movement Radius Y";
577
-        field_labels["property"] = "Property";
578
-        field_labels["sight_radius"] = "Sight Radius";
597
+        field_labels["trainer_see_type"] = "Trainer See Type";
598
+        field_labels["sight_radius_tree_id"] = "Sight Radius / Berry Tree ID";
579 599
         field_labels["destination_warp"] = "Destination Warp";
580 600
         field_labels["destination_map_name"] = "Destination Map";
581 601
         field_labels["script_var"] = "Var";
582 602
         field_labels["script_var_value"] = "Var Value";
583
-        field_labels["type"] = "Type";
603
+        field_labels["player_facing_direction"] = "Player Facing Direction";
584 604
         field_labels["item"] = "Item";
585 605
         field_labels["item_unknown5"] = "Unknown 5";
586 606
         field_labels["item_unknown6"] = "Unknown 6";
@@ -590,7 +610,7 @@ void MainWindow::updateSelectedObjects() {
590 610
 
591 611
         QStringList fields;
592 612
 
593
-        if (event_type == "object") {
613
+        if (event_type == EventType::Object) {
594 614
 
595 615
             frame->ui->sprite->setVisible(true);
596 616
             frame->ui->comboBox_sprite->addItems(event_obj_gfx_constants.keys());
@@ -613,30 +633,30 @@ void MainWindow::updateSelectedObjects() {
613 633
             fields << "script_label";
614 634
             fields << "event_flag";
615 635
             fields << "replacement";
616
-            fields << "property";
617
-            fields << "sight_radius";
636
+            fields << "trainer_see_type";
637
+            fields << "sight_radius_tree_id";
618 638
         }
619
-        else if (event_type == "warp") {
639
+        else if (event_type == EventType::Warp) {
620 640
             fields << "destination_warp";
621 641
             fields << "destination_map_name";
622 642
         }
623
-        else if (event_type == "trap") {
643
+        else if (event_type == EventType::CoordScript) {
624 644
             fields << "script_label";
625 645
             fields << "script_var";
626 646
             fields << "script_var_value";
627 647
         }
628
-        else if (event_type == "trap_weather") {
648
+        else if (event_type == EventType::CoordWeather) {
629 649
             fields << "weather";
630 650
         }
631
-        else if (event_type == "sign") {
632
-            fields << "type";
651
+        else if (event_type == EventType::Sign) {
652
+            fields << "player_facing_direction";
633 653
             fields << "script_label";
634 654
         }
635
-        else if (event_type == "event_hidden_item") {
655
+        else if (event_type == EventType::HiddenItem) {
636 656
             fields << "item";
637 657
             fields << "flag";
638 658
         }
639
-        else if (event_type == "event_secret_base") {
659
+        else if (event_type == EventType::SecretBase) {
640 660
             fields << "secret_base_map";
641 661
         }
642 662
 
@@ -808,3 +828,13 @@ void MainWindow::on_comboBox_EmergeMap_currentTextChanged(const QString &mapName
808 828
 {
809 829
     editor->updateEmergeMap(mapName);
810 830
 }
831
+
832
+void MainWindow::on_comboBox_PrimaryTileset_activated(const QString &tilesetLabel)
833
+{
834
+    editor->updatePrimaryTileset(tilesetLabel);
835
+}
836
+
837
+void MainWindow::on_comboBox_SecondaryTileset_activated(const QString &tilesetLabel)
838
+{
839
+    editor->updateSecondaryTileset(tilesetLabel);
840
+}

+ 6
- 2
mainwindow.h Ver fichero

@@ -56,10 +56,9 @@ private slots:
56 56
 
57 57
     void on_actionRedo_triggered();
58 58
 
59
-    void on_toolButton_newObject_clicked();
60
-
61 59
     void on_toolButton_deleteObject_clicked();
62 60
 
61
+    void addNewEvent(QString);
63 62
     void updateSelectedObjects();
64 63
 
65 64
     void on_toolButton_Paint_clicked();
@@ -72,6 +71,7 @@ private slots:
72 71
 
73 72
     void onOpenMapListContextMenu(const QPoint &point);
74 73
     void onAddNewMapToGroupClick(QAction* triggeredAction);
74
+    void onTilesetChanged(QString);
75 75
 
76 76
     void on_action_Export_Map_Image_triggered();
77 77
 
@@ -89,6 +89,10 @@ private slots:
89 89
 
90 90
     void on_comboBox_EmergeMap_currentTextChanged(const QString &mapName);
91 91
 
92
+    void on_comboBox_PrimaryTileset_activated(const QString &arg1);
93
+
94
+    void on_comboBox_SecondaryTileset_activated(const QString &arg1);
95
+
92 96
 private:
93 97
     Ui::MainWindow *ui;
94 98
     QStandardItemModel *mapListModel;

+ 196
- 18
mainwindow.ui Ver fichero

@@ -290,7 +290,7 @@
290 290
                     <rect>
291 291
                      <x>0</x>
292 292
                      <y>0</y>
293
-                     <width>614</width>
293
+                     <width>436</width>
294 294
                      <height>621</height>
295 295
                     </rect>
296 296
                    </property>
@@ -451,9 +451,146 @@
451 451
                   <number>0</number>
452 452
                  </property>
453 453
                  <item row="0" column="0">
454
+                  <widget class="QFrame" name="frame_Tilesets">
455
+                   <property name="sizePolicy">
456
+                    <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
457
+                     <horstretch>0</horstretch>
458
+                     <verstretch>0</verstretch>
459
+                    </sizepolicy>
460
+                   </property>
461
+                   <property name="frameShape">
462
+                    <enum>QFrame::StyledPanel</enum>
463
+                   </property>
464
+                   <property name="frameShadow">
465
+                    <enum>QFrame::Raised</enum>
466
+                   </property>
467
+                   <layout class="QFormLayout" name="formLayout">
468
+                    <item row="0" column="0">
469
+                     <widget class="QLabel" name="label_PrimaryTileset">
470
+                      <property name="text">
471
+                       <string>Primary Tileset</string>
472
+                      </property>
473
+                     </widget>
474
+                    </item>
475
+                    <item row="0" column="1">
476
+                     <widget class="QComboBox" name="comboBox_PrimaryTileset">
477
+                      <property name="editable">
478
+                       <bool>true</bool>
479
+                      </property>
480
+                     </widget>
481
+                    </item>
482
+                    <item row="1" column="0">
483
+                     <widget class="QLabel" name="label_SecondaryTileset">
484
+                      <property name="text">
485
+                       <string>Secondary Tileset</string>
486
+                      </property>
487
+                     </widget>
488
+                    </item>
489
+                    <item row="1" column="1">
490
+                     <widget class="QComboBox" name="comboBox_SecondaryTileset">
491
+                      <property name="editable">
492
+                       <bool>true</bool>
493
+                      </property>
494
+                     </widget>
495
+                    </item>
496
+                   </layout>
497
+                  </widget>
498
+                 </item>
499
+                 <item row="1" column="0">
500
+                  <widget class="QFrame" name="frame_10">
501
+                   <property name="sizePolicy">
502
+                    <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
503
+                     <horstretch>0</horstretch>
504
+                     <verstretch>0</verstretch>
505
+                    </sizepolicy>
506
+                   </property>
507
+                   <property name="frameShape">
508
+                    <enum>QFrame::NoFrame</enum>
509
+                   </property>
510
+                   <property name="frameShadow">
511
+                    <enum>QFrame::Raised</enum>
512
+                   </property>
513
+                   <layout class="QHBoxLayout" name="horizontalLayout_5">
514
+                    <property name="spacing">
515
+                     <number>6</number>
516
+                    </property>
517
+                    <property name="sizeConstraint">
518
+                     <enum>QLayout::SetDefaultConstraint</enum>
519
+                    </property>
520
+                    <item>
521
+                     <spacer name="horizontalSpacer_13">
522
+                      <property name="orientation">
523
+                       <enum>Qt::Horizontal</enum>
524
+                      </property>
525
+                      <property name="sizeHint" stdset="0">
526
+                       <size>
527
+                        <width>40</width>
528
+                        <height>20</height>
529
+                       </size>
530
+                      </property>
531
+                     </spacer>
532
+                    </item>
533
+                    <item>
534
+                     <widget class="QLabel" name="label_16">
535
+                      <property name="sizePolicy">
536
+                       <sizepolicy hsizetype="Preferred" vsizetype="Minimum">
537
+                        <horstretch>0</horstretch>
538
+                        <verstretch>0</verstretch>
539
+                       </sizepolicy>
540
+                      </property>
541
+                      <property name="text">
542
+                       <string>Border</string>
543
+                      </property>
544
+                     </widget>
545
+                    </item>
546
+                    <item>
547
+                     <widget class="QGraphicsView" name="graphicsView_BorderMetatile">
548
+                      <property name="sizePolicy">
549
+                       <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
550
+                        <horstretch>0</horstretch>
551
+                        <verstretch>0</verstretch>
552
+                       </sizepolicy>
553
+                      </property>
554
+                      <property name="maximumSize">
555
+                       <size>
556
+                        <width>16777215</width>
557
+                        <height>48</height>
558
+                       </size>
559
+                      </property>
560
+                      <property name="frameShape">
561
+                       <enum>QFrame::StyledPanel</enum>
562
+                      </property>
563
+                      <property name="frameShadow">
564
+                       <enum>QFrame::Sunken</enum>
565
+                      </property>
566
+                      <property name="verticalScrollBarPolicy">
567
+                       <enum>Qt::ScrollBarAsNeeded</enum>
568
+                      </property>
569
+                     </widget>
570
+                    </item>
571
+                    <item>
572
+                     <spacer name="horizontalSpacer_12">
573
+                      <property name="orientation">
574
+                       <enum>Qt::Horizontal</enum>
575
+                      </property>
576
+                      <property name="sizeType">
577
+                       <enum>QSizePolicy::Expanding</enum>
578
+                      </property>
579
+                      <property name="sizeHint" stdset="0">
580
+                       <size>
581
+                        <width>40</width>
582
+                        <height>20</height>
583
+                       </size>
584
+                      </property>
585
+                     </spacer>
586
+                    </item>
587
+                   </layout>
588
+                  </widget>
589
+                 </item>
590
+                 <item row="2" column="0">
454 591
                   <widget class="QScrollArea" name="scrollArea_2">
455 592
                    <property name="sizePolicy">
456
-                    <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
593
+                    <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
457 594
                      <horstretch>0</horstretch>
458 595
                      <verstretch>0</verstretch>
459 596
                     </sizepolicy>
@@ -470,6 +607,9 @@
470 607
                    <property name="widgetResizable">
471 608
                     <bool>true</bool>
472 609
                    </property>
610
+                   <property name="alignment">
611
+                    <set>Qt::AlignHCenter|Qt::AlignTop</set>
612
+                   </property>
473 613
                    <widget class="QWidget" name="scrollAreaWidgetContents_2">
474 614
                     <property name="enabled">
475 615
                      <bool>true</bool>
@@ -478,8 +618,8 @@
478 618
                      <rect>
479 619
                       <x>0</x>
480 620
                       <y>0</y>
481
-                      <width>180</width>
482
-                      <height>629</height>
621
+                      <width>358</width>
622
+                      <height>497</height>
483 623
                      </rect>
484 624
                     </property>
485 625
                     <property name="sizePolicy">
@@ -488,7 +628,10 @@
488 628
                       <verstretch>0</verstretch>
489 629
                      </sizepolicy>
490 630
                     </property>
491
-                    <layout class="QGridLayout" name="gridLayout_5" rowstretch="0" columnstretch="0">
631
+                    <layout class="QGridLayout" name="gridLayout_5">
632
+                     <property name="sizeConstraint">
633
+                      <enum>QLayout::SetDefaultConstraint</enum>
634
+                     </property>
492 635
                      <property name="leftMargin">
493 636
                       <number>0</number>
494 637
                      </property>
@@ -501,16 +644,26 @@
501 644
                      <property name="bottomMargin">
502 645
                       <number>0</number>
503 646
                      </property>
504
-                     <property name="spacing">
505
-                      <number>0</number>
506
-                     </property>
507
-                     <item row="0" column="0">
647
+                     <item row="1" column="1">
648
+                      <spacer name="verticalSpacer_5">
649
+                       <property name="orientation">
650
+                        <enum>Qt::Vertical</enum>
651
+                       </property>
652
+                       <property name="sizeHint" stdset="0">
653
+                        <size>
654
+                         <width>20</width>
655
+                         <height>40</height>
656
+                        </size>
657
+                       </property>
658
+                      </spacer>
659
+                     </item>
660
+                     <item row="0" column="1">
508 661
                       <widget class="QGraphicsView" name="graphicsView_Metatiles">
509 662
                        <property name="enabled">
510 663
                         <bool>true</bool>
511 664
                        </property>
512 665
                        <property name="sizePolicy">
513
-                        <sizepolicy hsizetype="Ignored" vsizetype="Ignored">
666
+                        <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
514 667
                          <horstretch>0</horstretch>
515 668
                          <verstretch>0</verstretch>
516 669
                         </sizepolicy>
@@ -526,6 +679,32 @@
526 679
                        </property>
527 680
                       </widget>
528 681
                      </item>
682
+                     <item row="0" column="0">
683
+                      <spacer name="horizontalSpacer_14">
684
+                       <property name="orientation">
685
+                        <enum>Qt::Horizontal</enum>
686
+                       </property>
687
+                       <property name="sizeHint" stdset="0">
688
+                        <size>
689
+                         <width>40</width>
690
+                         <height>20</height>
691
+                        </size>
692
+                       </property>
693
+                      </spacer>
694
+                     </item>
695
+                     <item row="0" column="2">
696
+                      <spacer name="horizontalSpacer_15">
697
+                       <property name="orientation">
698
+                        <enum>Qt::Horizontal</enum>
699
+                       </property>
700
+                       <property name="sizeHint" stdset="0">
701
+                        <size>
702
+                         <width>40</width>
703
+                         <height>20</height>
704
+                        </size>
705
+                       </property>
706
+                      </spacer>
707
+                     </item>
529 708
                     </layout>
530 709
                    </widget>
531 710
                   </widget>
@@ -904,13 +1083,7 @@
904 1083
                  <number>0</number>
905 1084
                 </property>
906 1085
                 <item>
907
-                 <widget class="QToolButton" name="toolButton_newObject">
908
-                  <property name="sizePolicy">
909
-                   <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
910
-                    <horstretch>0</horstretch>
911
-                    <verstretch>0</verstretch>
912
-                   </sizepolicy>
913
-                  </property>
1086
+                 <widget class="NewEventToolButton" name="newEventToolButton">
914 1087
                   <property name="minimumSize">
915 1088
                    <size>
916 1089
                     <width>40</width>
@@ -918,7 +1091,7 @@
918 1091
                    </size>
919 1092
                   </property>
920 1093
                   <property name="text">
921
-                   <string>New</string>
1094
+                   <string>New Object</string>
922 1095
                   </property>
923 1096
                   <property name="icon">
924 1097
                    <iconset resource="resources/images.qrc">
@@ -1794,6 +1967,11 @@
1794 1967
    <extends>QGraphicsView</extends>
1795 1968
    <header>graphicsview.h</header>
1796 1969
   </customwidget>
1970
+  <customwidget>
1971
+   <class>NewEventToolButton</class>
1972
+   <extends>QToolButton</extends>
1973
+   <header>neweventtoolbutton.h</header>
1974
+  </customwidget>
1797 1975
  </customwidgets>
1798 1976
  <resources>
1799 1977
   <include location="resources/images.qrc"/>

+ 23
- 107
map.cpp Ver fichero

@@ -31,41 +31,32 @@ QString Map::mapConstantFromName(QString mapName) {
31 31
     return constantName;
32 32
 }
33 33
 
34
-int Map::getWidth() {
35
-    return layout->width.toInt(nullptr, 0);
34
+QString Map::objectEventsLabelFromName(QString mapName)
35
+{
36
+    return QString("%1_EventObjects").arg(mapName);
36 37
 }
37 38
 
38
-int Map::getHeight() {
39
-    return layout->height.toInt(nullptr, 0);
39
+QString Map::warpEventsLabelFromName(QString mapName)
40
+{
41
+    return QString("%1_MapWarps").arg(mapName);
40 42
 }
41 43
 
42
-Tileset* Map::getBlockTileset(int metatile_index) {
43
-    int primary_size = 0x200;
44
-    if (metatile_index < primary_size) {
45
-        return layout->tileset_primary;
46
-    } else {
47
-        return layout->tileset_secondary;
48
-    }
44
+QString Map::coordEventsLabelFromName(QString mapName)
45
+{
46
+    return QString("%1_MapCoordEvents").arg(mapName);
49 47
 }
50 48
 
51
-QList<QList<QRgb>> Map::getBlockPalettes(int metatile_index) {
52
-    QList<QList<QRgb>> palettes;
53
-    for (int i = 0; i < 6; i++) {
54
-        palettes.append(layout->tileset_primary->palettes->at(i));
55
-    }
56
-    for (int i = 6; i < layout->tileset_secondary->palettes->length(); i++) {
57
-        palettes.append(layout->tileset_secondary->palettes->at(i));
58
-    }
59
-    return palettes;
49
+QString Map::bgEventsLabelFromName(QString mapName)
50
+{
51
+    return QString("%1_MapBGEvents").arg(mapName);
60 52
 }
61 53
 
62
-int Map::getBlockIndex(int index) {
63
-    int primary_size = 0x200;
64
-    if (index < primary_size) {
65
-        return index;
66
-    } else {
67
-        return index - primary_size;
68
-    }
54
+int Map::getWidth() {
55
+    return layout->width.toInt(nullptr, 0);
56
+}
57
+
58
+int Map::getHeight() {
59
+    return layout->height.toInt(nullptr, 0);
69 60
 }
70 61
 
71 62
 int Map::getSelectedBlockIndex(int index) {
@@ -84,25 +75,6 @@ int Map::getDisplayedBlockIndex(int index) {
84 75
     }
85 76
 }
86 77
 
87
-QImage Map::getMetatileTile(int tile) {
88
-    Tileset *tileset = getBlockTileset(tile);
89
-    int local_index = getBlockIndex(tile);
90
-    if (!tileset || !tileset->tiles) {
91
-        return QImage();
92
-    }
93
-    return tileset->tiles->value(local_index, QImage());
94
-}
95
-
96
-Metatile* Map::getMetatile(int index) {
97
-    Tileset *tileset = getBlockTileset(index);
98
-    int local_index = getBlockIndex(index);
99
-    if (!tileset || !tileset->metatiles) {
100
-        return NULL;
101
-    }
102
-    Metatile *metatile = tileset->metatiles->value(local_index, NULL);
103
-    return metatile;
104
-}
105
-
106 78
 QImage Map::getCollisionMetatileImage(Block block) {
107 79
     return getCollisionMetatileImage(block.collision);
108 80
 }
@@ -146,57 +118,6 @@ QImage Map::getElevationMetatileImage(int elevation) {
146 118
     return metatile_image;
147 119
 }
148 120
 
149
-QImage Map::getMetatileImage(int tile) {
150
-
151
-    QImage metatile_image(16, 16, QImage::Format_RGBA8888);
152
-
153
-    Metatile* metatile = getMetatile(tile);
154
-    if (!metatile || !metatile->tiles) {
155
-        metatile_image.fill(0xffffffff);
156
-        return metatile_image;
157
-    }
158
-
159
-    Tileset* blockTileset = getBlockTileset(tile);
160
-    if (!blockTileset) {
161
-        metatile_image.fill(0xffffffff);
162
-        return metatile_image;
163
-    }
164
-    QList<QList<QRgb>> palettes = getBlockPalettes(tile);
165
-
166
-    QPainter metatile_painter(&metatile_image);
167
-    for (int layer = 0; layer < 2; layer++)
168
-    for (int y = 0; y < 2; y++)
169
-    for (int x = 0; x < 2; x++) {
170
-        Tile tile_ = metatile->tiles->value((y * 2) + x + (layer * 4));
171
-        QImage tile_image = getMetatileTile(tile_.tile);
172
-        if (tile_image.isNull()) {
173
-            // Some metatiles specify tiles that are outside the valid range.
174
-            // These are treated as completely transparent, so they can be skipped without
175
-            // being drawn.
176
-            continue;
177
-        }
178
-
179
-        // Colorize the metatile tiles with its palette.
180
-        QList<QRgb> palette = palettes.value(tile_.palette);
181
-        for (int j = 0; j < palette.length(); j++) {
182
-            tile_image.setColor(j, palette.value(j));
183
-        }
184
-
185
-        // The top layer of the metatile has its last color displayed at transparent.
186
-        if (layer > 0) {
187
-            QColor color(tile_image.color(15));
188
-            color.setAlpha(0);
189
-            tile_image.setColor(15, color.rgba());
190
-        }
191
-
192
-        QPoint origin = QPoint(x*8, y*8);
193
-        metatile_painter.drawImage(origin, tile_image.mirrored(tile_.xflip == 1, tile_.yflip == 1));
194
-    }
195
-    metatile_painter.end();
196
-
197
-    return metatile_image;
198
-}
199
-
200 121
 bool Map::blockChanged(int i, Blockdata *cache) {
201 122
     if (cache == NULL || cache == nullptr) {
202 123
         return true;
@@ -275,7 +196,7 @@ QPixmap Map::renderCollision(bool ignoreCache) {
275 196
         }
276 197
         changed_any = true;
277 198
         Block block = layout->blockdata->blocks->value(i);
278
-        QImage metatile_image = getMetatileImage(block.tile);
199
+        QImage metatile_image = Metatile::getMetatileImage(block.tile, layout->tileset_primary, layout->tileset_secondary);
279 200
         QImage collision_metatile_image = getCollisionMetatileImage(block);
280 201
         QImage elevation_metatile_image = getElevationMetatileImage(block);
281 202
         int map_y = width_ ? i / width_ : 0;
@@ -344,7 +265,7 @@ QPixmap Map::render(bool ignoreCache = false) {
344 265
         }
345 266
         changed_any = true;
346 267
         Block block = layout->blockdata->blocks->value(i);
347
-        QImage metatile_image = getMetatileImage(block.tile);
268
+        QImage metatile_image = Metatile::getMetatileImage(block.tile, layout->tileset_primary, layout->tileset_secondary);
348 269
         int map_y = width_ ? i / width_ : 0;
349 270
         int map_x = width_ ? i % width_ : 0;
350 271
         QPoint metatile_origin = QPoint(map_x * 16, map_y * 16);
@@ -377,7 +298,7 @@ QPixmap Map::renderBorder() {
377 298
         }
378 299
         changed_any = true;
379 300
         Block block = layout->border->blocks->value(i);
380
-        QImage metatile_image = getMetatileImage(block.tile);
301
+        QImage metatile_image = Metatile::getMetatileImage(block.tile, layout->tileset_primary, layout->tileset_secondary);
381 302
         int map_y = i / width_;
382 303
         int map_x = i % width_;
383 304
         painter.drawImage(QPoint(map_x * 16, map_y * 16), metatile_image);
@@ -493,7 +414,7 @@ QPixmap Map::renderMetatiles() {
493 414
         if (i >= primary_length) {
494 415
             tile += 0x200 - primary_length;
495 416
         }
496
-        QImage metatile_image = getMetatileImage(tile);
417
+        QImage metatile_image = Metatile::getMetatileImage(tile, layout->tileset_primary, layout->tileset_secondary);
497 418
         int map_y = i / width_;
498 419
         int map_x = i % width_;
499 420
         QPoint metatile_origin = QPoint(map_x * 16, map_y * 16);
@@ -733,11 +654,6 @@ QList<Event *> Map::getAllEvents() {
733 654
     return all;
734 655
 }
735 656
 
736
-QList<Event *> Map::getEventsByType(QString type)
737
-{
738
-    return events.value(type);
739
-}
740
-
741 657
 void Map::removeEvent(Event *event) {
742 658
     for (QString key : events.keys()) {
743 659
         events[key].removeAll(event);
@@ -745,7 +661,7 @@ void Map::removeEvent(Event *event) {
745 661
 }
746 662
 
747 663
 void Map::addEvent(Event *event) {
748
-    events[event->get("event_type")].append(event);
664
+    events[event->get("event_group_type")].append(event);
749 665
 }
750 666
 
751 667
 bool Map::hasUnsavedChanges() {

+ 6
- 16
map.h Ver fichero

@@ -129,15 +129,14 @@ public:
129 129
 public:
130 130
     void setName(QString mapName);
131 131
     static QString mapConstantFromName(QString mapName);
132
+    static QString objectEventsLabelFromName(QString mapName);
133
+    static QString warpEventsLabelFromName(QString mapName);
134
+    static QString coordEventsLabelFromName(QString mapName);
135
+    static QString bgEventsLabelFromName(QString mapName);
132 136
     int getWidth();
133 137
     int getHeight();
134
-    Tileset* getBlockTileset(int);
135
-    int getBlockIndex(int layout_id);
136
-    int getSelectedBlockIndex(int layout_id);
137
-    int getDisplayedBlockIndex(int layout_id);
138
-    Metatile* getMetatile(int);
139
-    QImage getMetatileImage(int);
140
-    QImage getMetatileTile(int);
138
+    int getSelectedBlockIndex(int);
139
+    int getDisplayedBlockIndex(int);
141 140
     QPixmap render(bool ignoreCache);
142 141
     QPixmap renderMetatiles();
143 142
 
@@ -188,19 +187,12 @@ public:
188 187
     void redo();
189 188
     void commit();
190 189
 
191
-    QString object_events_label;
192
-    QString warps_label;
193
-    QString coord_events_label;
194
-    QString bg_events_label;
195
-
196 190
     QList<Event*> getAllEvents();
197
-    QList<Event*> getEventsByType(QString type);
198 191
     void removeEvent(Event *event);
199 192
     void addEvent(Event *event);
200 193
     QMap<QString, QList<Event*>> events;
201 194
 
202 195
     QList<Connection*> connections;
203
-    QList<QGraphicsPixmapItem*> connection_items;
204 196
     QPixmap renderConnection(Connection);
205 197
 
206 198
     QPixmap renderBorder();
@@ -216,8 +208,6 @@ public:
216 208
     void hoveredElevationTileChanged(int elevation);
217 209
     void clearHoveredElevationTile();
218 210
 
219
-    QList<QList<QRgb> > getBlockPalettes(int metatile_index);
220
-
221 211
 signals:
222 212
     void paintTileChanged(Map *map);
223 213
     void paintCollisionChanged(Map *map);

+ 0
- 6
metatile.cpp Ver fichero

@@ -1,6 +0,0 @@
1
-#include "metatile.h"
2
-
3
-Metatile::Metatile()
4
-{
5
-    tiles = new QList<Tile>;
6
-}

+ 0
- 16
metatile.h Ver fichero

@@ -1,16 +0,0 @@
1
-#ifndef METATILE_H
2
-#define METATILE_H
3
-
4
-#include "tile.h"
5
-#include <QList>
6
-
7
-class Metatile
8
-{
9
-public:
10
-    Metatile();
11
-public:
12
-    QList<Tile> *tiles = NULL;
13
-    int attr;
14
-};
15
-
16
-#endif // METATILE_H

+ 103
- 0
neweventtoolbutton.cpp Ver fichero

@@ -0,0 +1,103 @@
1
+#include "neweventtoolbutton.h"
2
+#include <QMenu>
3
+#include <QDebug>
4
+
5
+// Custom QToolButton which has a context menu that expands to allow
6
+// selection of different types of map events.
7
+NewEventToolButton::NewEventToolButton(QWidget *parent) :
8
+    QToolButton(parent)
9
+{
10
+    setPopupMode(QToolButton::MenuButtonPopup);
11
+    QObject::connect(this, SIGNAL(triggered(QAction*)),
12
+                     this, SLOT(setDefaultAction(QAction*)));
13
+}
14
+
15
+void NewEventToolButton::initButton()
16
+{
17
+    // Add a context menu to select different types of map events.
18
+    this->newObjectAction = new QAction("New Object", this);
19
+    this->newObjectAction->setIcon(QIcon(":/icons/add.ico"));
20
+    connect(this->newObjectAction, SIGNAL(triggered(bool)), this, SLOT(newObject()));
21
+
22
+    this->newWarpAction = new QAction("New Warp", this);
23
+    this->newWarpAction->setIcon(QIcon(":/icons/add.ico"));
24
+    connect(this->newWarpAction, SIGNAL(triggered(bool)), this, SLOT(newWarp()));
25
+
26
+    this->newCoordScriptAction = new QAction("New Coord Script", this);
27
+    this->newCoordScriptAction->setIcon(QIcon(":/icons/add.ico"));
28
+    connect(this->newCoordScriptAction, SIGNAL(triggered(bool)), this, SLOT(newCoordScript()));
29
+
30
+    this->newCoordWeatherAction = new QAction("New Coord Weather", this);
31
+    this->newCoordWeatherAction->setIcon(QIcon(":/icons/add.ico"));
32
+    connect(this->newCoordWeatherAction, SIGNAL(triggered(bool)), this, SLOT(newCoordWeather()));
33
+
34
+    this->newSignAction = new QAction("New Sign", this);
35
+    this->newSignAction->setIcon(QIcon(":/icons/add.ico"));
36
+    connect(this->newSignAction, SIGNAL(triggered(bool)), this, SLOT(newSign()));
37
+
38
+    this->newHiddenItemAction = new QAction("New Hidden Item", this);
39
+    this->newHiddenItemAction->setIcon(QIcon(":/icons/add.ico"));
40
+    connect(this->newHiddenItemAction, SIGNAL(triggered(bool)), this, SLOT(newHiddenItem()));
41
+
42
+    this->newSecretBaseAction = new QAction("New Secret Base", this);
43
+    this->newSecretBaseAction->setIcon(QIcon(":/icons/add.ico"));
44
+    connect(this->newSecretBaseAction, SIGNAL(triggered(bool)), this, SLOT(newSecretBase()));
45
+
46
+    QMenu *alignMenu = new QMenu();
47
+    alignMenu->addAction(this->newObjectAction);
48
+    alignMenu->addAction(this->newWarpAction);
49
+    alignMenu->addAction(this->newCoordScriptAction);
50
+    alignMenu->addAction(this->newCoordWeatherAction);
51
+    alignMenu->addAction(this->newSignAction);
52
+    alignMenu->addAction(this->newHiddenItemAction);
53
+    alignMenu->addAction(this->newSecretBaseAction);
54
+    this->setMenu(alignMenu);
55
+    this->setDefaultAction(this->newObjectAction);
56
+}
57
+
58
+QString NewEventToolButton::getSelectedEventType()
59
+{
60
+    return this->selectedEventType;
61
+}
62
+
63
+void NewEventToolButton::newObject()
64
+{
65
+    this->selectedEventType = EventType::Object;
66
+    emit newEventAdded(this->selectedEventType);
67
+}
68
+
69
+void NewEventToolButton::newWarp()
70
+{
71
+    this->selectedEventType = EventType::Warp;
72
+    emit newEventAdded(this->selectedEventType);
73
+}
74
+
75
+void NewEventToolButton::newCoordScript()
76
+{
77
+    this->selectedEventType = EventType::CoordScript;
78
+    emit newEventAdded(this->selectedEventType);
79
+}
80
+
81
+void NewEventToolButton::newCoordWeather()
82
+{
83
+    this->selectedEventType = EventType::CoordWeather;
84
+    emit newEventAdded(this->selectedEventType);
85
+}
86
+
87
+void NewEventToolButton::newSign()
88
+{
89
+    this->selectedEventType = EventType::Sign;
90
+    emit newEventAdded(this->selectedEventType);
91
+}
92
+
93
+void NewEventToolButton::newHiddenItem()
94
+{
95
+    this->selectedEventType = EventType::HiddenItem;
96
+    emit newEventAdded(this->selectedEventType);
97
+}
98
+
99
+void NewEventToolButton::newSecretBase()
100
+{
101
+    this->selectedEventType = EventType::SecretBase;
102
+    emit newEventAdded(this->selectedEventType);
103
+}

+ 35
- 0
neweventtoolbutton.h Ver fichero

@@ -0,0 +1,35 @@
1
+#ifndef NEWEVENTTOOLBUTTON_H
2
+#define NEWEVENTTOOLBUTTON_H
3
+
4
+#include "event.h"
5
+#include <QToolButton>
6
+
7
+class NewEventToolButton : public QToolButton
8
+{
9
+    Q_OBJECT
10
+public:
11
+    explicit NewEventToolButton(QWidget *parent = 0);
12
+    void initButton();
13
+    QString getSelectedEventType();
14
+public slots:
15
+    void newObject();
16
+    void newWarp();
17
+    void newCoordScript();
18
+    void newCoordWeather();
19
+    void newSign();
20
+    void newHiddenItem();
21
+    void newSecretBase();
22
+signals:
23
+    void newEventAdded(QString);
24
+private:
25
+    QString selectedEventType;
26
+    QAction *newObjectAction;
27
+    QAction *newWarpAction;
28
+    QAction *newCoordScriptAction;
29
+    QAction *newCoordWeatherAction;
30
+    QAction *newSignAction;
31
+    QAction *newHiddenItemAction;
32
+    QAction *newSecretBaseAction;
33
+};
34
+
35
+#endif // NEWEVENTTOOLBUTTON_H

+ 4
- 4
pretmap.pro Ver fichero

@@ -19,13 +19,13 @@ SOURCES += main.cpp\
19 19
     blockdata.cpp \
20 20
     block.cpp \
21 21
     tileset.cpp \
22
-    metatile.cpp \
23 22
     tile.cpp \
24 23
     event.cpp \
25 24
     editor.cpp \
26 25
     objectpropertiesframe.cpp \
27 26
     graphicsview.cpp \
28
-    parseutil.cpp
27
+    parseutil.cpp \
28
+    neweventtoolbutton.cpp
29 29
 
30 30
 HEADERS  += mainwindow.h \
31 31
     project.h \
@@ -33,13 +33,13 @@ HEADERS  += mainwindow.h \
33 33
     blockdata.h \
34 34
     block.h \
35 35
     tileset.h \
36
-    metatile.h \
37 36
     tile.h \
38 37
     event.h \
39 38
     editor.h \
40 39
     objectpropertiesframe.h \
41 40
     graphicsview.h \
42
-    parseutil.h
41
+    parseutil.h \
42
+    neweventtoolbutton.h
43 43
 
44 44
 FORMS    += mainwindow.ui \
45 45
     objectpropertiesframe.ui

+ 131
- 139
project.cpp Ver fichero

@@ -2,7 +2,6 @@
2 2
 #include "project.h"
3 3
 #include "tile.h"
4 4
 #include "tileset.h"
5
-#include "metatile.h"
6 5
 #include "event.h"
7 6
 
8 7
 #include <QDebug>
@@ -65,7 +64,6 @@ void Project::loadMapConnections(Map *map) {
65 64
     }
66 65
 
67 66
     map->connections.clear();
68
-    map->connection_items.clear();
69 67
     if (!map->connections_label.isNull()) {
70 68
         QString path = root + QString("/data/maps/%1/connections.inc").arg(map->name);
71 69
         QString text = readTextFile(path);
@@ -355,7 +353,7 @@ void Project::readMapLayout(Map* map) {
355 353
         map->layout = mapLayouts[map->layout_label];
356 354
     }
357 355
 
358
-    getTilesets(map);
356
+    loadMapTilesets(map);
359 357
     loadBlockdata(map);
360 358
     loadMapBorder(map);
361 359
 }
@@ -495,7 +493,7 @@ void Project::saveMapConstantsHeader() {
495 493
     saveTextFile(root + "/include/constants/maps.h", text);
496 494
 }
497 495
 
498
-void Project::getTilesets(Map* map) {
496
+void Project::loadMapTilesets(Map* map) {
499 497
     if (map->layout->has_unsaved_changes) {
500 498
         return;
501 499
     }
@@ -956,7 +954,7 @@ Map* Project::addNewMapToGroup(QString mapName, int groupNum) {
956 954
     mapNamesToMapConstants->insert(map->name, map->constantName);
957 955
     setNewMapHeader(map, mapLayoutsTable.size() + 1);
958 956
     setNewMapLayout(map);
959
-    getTilesets(map);
957
+    loadMapTilesets(map);
960 958
     setNewMapBlockdata(map);
961 959
     setNewMapBorder(map);
962 960
     setNewMapEvents(map);
@@ -1002,6 +1000,47 @@ QStringList Project::getVisibilities() {
1002 1000
     return names;
1003 1001
 }
1004 1002
 
1003
+QMap<QString, QStringList> Project::getTilesets() {
1004
+    QMap<QString, QStringList> allTilesets;
1005
+    QStringList primaryTilesets;
1006
+    QStringList secondaryTilesets;
1007
+    allTilesets.insert("primary", primaryTilesets);
1008
+    allTilesets.insert("secondary", secondaryTilesets);
1009
+    QString headers_text = readTextFile(root + "/data/tilesets/headers.inc");
1010
+    QList<QStringList>* commands = parseAsm(headers_text);
1011
+    int i = 0;
1012
+    while (i < commands->length()) {
1013
+        if (commands->at(i).length() != 2)
1014
+            continue;
1015
+
1016
+        if (commands->at(i).at(0) == ".label") {
1017
+            QString tilesetLabel = commands->at(i).at(1);
1018
+            // Advance to command specifying whether or not it is a secondary tileset
1019
+            i += 2;
1020
+            if (commands->at(i).at(0) != ".byte") {
1021
+                qDebug() << "Unexpected command found for secondary tileset flag. Expected '.byte', but found: " << commands->at(i).at(0);
1022
+                continue;
1023
+            }
1024
+
1025
+            QString secondaryTilesetValue = commands->at(i).at(1);
1026
+            if (secondaryTilesetValue != "TRUE" && secondaryTilesetValue != "FALSE" && secondaryTilesetValue != "0" && secondaryTilesetValue != "1") {
1027
+                qDebug() << "Unexpected secondary tileset flag found. Expected \"TRUE\", \"FALSE\", \"0\", or \"1\", but found: " << secondaryTilesetValue;
1028
+                continue;
1029
+            }
1030
+
1031
+            bool isSecondaryTileset = (secondaryTilesetValue == "TRUE" || secondaryTilesetValue == "1");
1032
+            if (isSecondaryTileset)
1033
+                allTilesets["secondary"].append(tilesetLabel);
1034
+            else
1035
+                allTilesets["primary"].append(tilesetLabel);
1036
+        }
1037
+
1038
+        i++;
1039
+    }
1040
+
1041
+    return allTilesets;
1042
+}
1043
+
1005 1044
 QStringList Project::getWeathers() {
1006 1045
     // TODO
1007 1046
     QStringList names;
@@ -1152,17 +1191,17 @@ void Project::loadEventPixmaps(QList<Event*> objects) {
1152 1191
             continue;
1153 1192
         }
1154 1193
         QString event_type = object->get("event_type");
1155
-        if (event_type == "object") {
1194
+        if (event_type == EventType::Object) {
1156 1195
             object->pixmap = QPixmap(":/images/Entities_16x16.png").copy(0, 0, 16, 16);
1157
-        } else if (event_type == "warp") {
1196
+        } else if (event_type == EventType::Warp) {
1158 1197
             object->pixmap = QPixmap(":/images/Entities_16x16.png").copy(16, 0, 16, 16);
1159
-        } else if (event_type == "trap" || event_type == "trap_weather") {
1198
+        } else if (event_type == EventType::CoordScript || event_type == EventType::CoordWeather) {
1160 1199
             object->pixmap = QPixmap(":/images/Entities_16x16.png").copy(32, 0, 16, 16);
1161
-        } else if (event_type == "sign" || event_type == "event_hidden_item" || event_type == "event_secret_base") {
1200
+        } else if (event_type == EventType::Sign || event_type == EventType::HiddenItem || event_type == EventType::SecretBase) {
1162 1201
             object->pixmap = QPixmap(":/images/Entities_16x16.png").copy(48, 0, 16, 16);
1163 1202
         }
1164 1203
 
1165
-        if (event_type == "object") {
1204
+        if (event_type == EventType::Object) {
1166 1205
             int sprite_id = constants.value(object->get("sprite"));
1167 1206
 
1168 1207
             QString info_label = pointers.value(sprite_id).replace("&", "");
@@ -1178,117 +1217,74 @@ void Project::loadEventPixmaps(QList<Event*> objects) {
1178 1217
                     object->pixmap = pixmap;
1179 1218
                 }
1180 1219
             }
1181
-
1182 1220
         }
1183 1221
     }
1184
-
1185 1222
 }
1186 1223
 
1187 1224
 void Project::saveMapEvents(Map *map) {
1188 1225
     QString path = root + QString("/data/maps/%1/events.inc").arg(map->name);
1189 1226
     QString text = "";
1190
-
1191
-    if (map->events["object"].length() > 0) {
1192
-        text += QString("%1::\n").arg(map->object_events_label);
1193
-        for (int i = 0; i < map->events["object"].length(); i++) {
1194
-            Event *object_event = map->events["object"].value(i);
1195
-            int radius_x = object_event->getInt("radius_x");
1196
-            int radius_y = object_event->getInt("radius_y");
1197
-            uint16_t x = object_event->getInt("x");
1198
-            uint16_t y = object_event->getInt("y");
1199
-
1200
-            text += QString("\tobject_event %1").arg(i + 1);
1201
-            text += QString(", %1").arg(object_event->get("sprite"));
1202
-            text += QString(", %1").arg(object_event->get("replacement"));
1203
-            text += QString(", %1").arg(x);
1204
-            text += QString(", %1").arg(y);
1205
-            text += QString(", %1").arg(object_event->get("elevation"));
1206
-            text += QString(", %1").arg(object_event->get("behavior"));
1207
-            text += QString(", %1").arg(radius_x);
1208
-            text += QString(", %1").arg(radius_y);
1209
-            text += QString(", %1").arg(object_event->get("property"));
1210
-            text += QString(", %1").arg(object_event->get("sight_radius"));
1211
-            text += QString(", %1").arg(object_event->get("script_label"));
1212
-            text += QString(", %1").arg(object_event->get("event_flag"));
1213
-            text += "\n";
1227
+    QString objectEventsLabel = "0x0";
1228
+    QString warpEventsLabel = "0x0";
1229
+    QString coordEventsLabel = "0x0";
1230
+    QString bgEventsLabel = "0x0";
1231
+
1232
+    if (map->events["object_event_group"].length() > 0) {
1233
+        objectEventsLabel = Map::objectEventsLabelFromName(map->name);
1234
+        text += QString("%1::\n").arg(objectEventsLabel);
1235
+        for (int i = 0; i < map->events["object_event_group"].length(); i++) {
1236
+            Event *object_event = map->events["object_event_group"].value(i);
1237
+            text += object_event->buildObjectEventMacro(i);
1214 1238
         }
1215 1239
         text += "\n";
1216 1240
     }
1217 1241
 
1218
-    if (map->events["warp"].length() > 0) {
1219
-        text += QString("%1::\n").arg(map->warps_label);
1220
-        for (Event *warp : map->events["warp"]) {
1221
-            text += QString("\twarp_def %1").arg(warp->get("x"));
1222
-            text += QString(", %1").arg(warp->get("y"));
1223
-            text += QString(", %1").arg(warp->get("elevation"));
1224
-            text += QString(", %1").arg(warp->get("destination_warp"));
1225
-            text += QString(", %1").arg(mapNamesToMapConstants->value(warp->get("destination_map_name")));
1226
-            text += "\n";
1242
+    if (map->events["warp_event_group"].length() > 0) {
1243
+        warpEventsLabel = Map::warpEventsLabelFromName(map->name);
1244
+        text += QString("%1::\n").arg(warpEventsLabel);
1245
+        for (Event *warp : map->events["warp_event_group"]) {
1246
+            text += warp->buildWarpEventMacro(mapNamesToMapConstants);
1227 1247
         }
1228 1248
         text += "\n";
1229 1249
     }
1230 1250
 
1231
-    if (map->events["trap"].length() + map->events["trap_weather"].length() > 0) {
1232
-        text += QString("%1::\n").arg(map->coord_events_label);
1233
-        for (Event *coords : map->events["trap"]) {
1234
-            text += QString("\tcoord_event %1").arg(coords->get("x"));
1235
-            text += QString(", %1").arg(coords->get("y"));
1236
-            text += QString(", %1").arg(coords->get("elevation"));
1237
-            text += QString(", 0");
1238
-            text += QString(", %1").arg(coords->get("script_var"));
1239
-            text += QString(", %1").arg(coords->get("script_var_value"));
1240
-            text += QString(", 0");
1241
-            text += QString(", %1").arg(coords->get("script_label"));
1242
-            text += "\n";
1243
-        }
1244
-        for (Event *coords : map->events["trap_weather"]) {
1245
-            text += QString("\tcoord_weather_event %1").arg(coords->get("x"));
1246
-            text += QString(", %1").arg(coords->get("y"));
1247
-            text += QString(", %1").arg(coords->get("elevation"));
1248
-            text += QString(", %1").arg(coords->get("weather"));
1249
-            text += "\n";
1251
+    if (map->events["coord_event_group"].length() > 0) {
1252
+        coordEventsLabel = Map::coordEventsLabelFromName(map->name);
1253
+        text += QString("%1::\n").arg(coordEventsLabel);
1254
+        for (Event *event : map->events["coord_event_group"]) {
1255
+            QString event_type = event->get("event_type");
1256
+            if (event_type == EventType::CoordScript) {
1257
+                text += event->buildCoordScriptEventMacro();
1258
+            } else if (event_type == EventType::CoordWeather) {
1259
+                text += event->buildCoordWeatherEventMacro();
1260
+            }
1250 1261
         }
1251 1262
         text += "\n";
1252 1263
     }
1253 1264
 
1254
-    if (map->events["sign"].length() +
1255
-        map->events["event_hidden_item"].length() +
1256
-        map->events["event_secret_base"].length() > 0)
1265
+    if (map->events["bg_event_group"].length() > 0)
1257 1266
     {
1258
-        text += QString("%1::\n").arg(map->bg_events_label);
1259
-        for (Event *sign : map->events["sign"]) {
1260
-            text += QString("\tbg_event %1").arg(sign->get("x"));
1261
-            text += QString(", %1").arg(sign->get("y"));
1262
-            text += QString(", %1").arg(sign->get("elevation"));
1263
-            text += QString(", %1").arg(sign->get("type"));
1264
-            text += QString(", 0");
1265
-            text += QString(", %1").arg(sign->get("script_label"));
1266
-            text += "\n";
1267
-        }
1268
-        for (Event *item : map->events["event_hidden_item"]) {
1269
-            text += QString("\tbg_hidden_item_event %1").arg(item->get("x"));
1270
-            text += QString(", %1").arg(item->get("y"));
1271
-            text += QString(", %1").arg(item->get("elevation"));
1272
-            text += QString(", %1").arg(item->get("item"));
1273
-            text += QString(", %1").arg(item->get("flag"));
1274
-            text += "\n";
1275
-        }
1276
-        for (Event *item : map->events["event_secret_base"]) {
1277
-            text += QString("\tbg_secret_base_event %1").arg(item->get("x"));
1278
-            text += QString(", %1").arg(item->get("y"));
1279
-            text += QString(", %1").arg(item->get("elevation"));
1280
-            text += QString(", %1").arg(item->get("secret_base_map"));
1281
-            text += "\n";
1267
+        bgEventsLabel = Map::bgEventsLabelFromName(map->name);
1268
+        text += QString("%1::\n").arg(bgEventsLabel);
1269
+        for (Event *event : map->events["bg_event_group"]) {
1270
+            QString event_type = event->get("event_type");
1271
+            if (event_type == EventType::Sign) {
1272
+                text += event->buildSignEventMacro();
1273
+            } else if (event_type == EventType::HiddenItem) {
1274
+                text += event->buildHiddenItemEventMacro();
1275
+            } else if (event_type == EventType::SecretBase) {
1276
+                text += event->buildSecretBaseEventMacro();
1277
+            }
1282 1278
         }
1283 1279
         text += "\n";
1284 1280
     }
1285 1281
 
1286 1282
     text += QString("%1::\n").arg(map->events_label);
1287 1283
     text += QString("\tmap_events %1, %2, %3, %4\n")
1288
-            .arg(map->object_events_label)
1289
-            .arg(map->warps_label)
1290
-            .arg(map->coord_events_label)
1291
-            .arg(map->bg_events_label);
1284
+            .arg(objectEventsLabel)
1285
+            .arg(warpEventsLabel)
1286
+            .arg(coordEventsLabel)
1287
+            .arg(bgEventsLabel);
1292 1288
 
1293 1289
     saveTextFile(path, text);
1294 1290
 }
@@ -1306,13 +1302,13 @@ void Project::readMapEvents(Map *map) {
1306 1302
     }
1307 1303
 
1308 1304
     QStringList *labels = getLabelValues(parseAsm(text), map->events_label);
1309
-    map->object_events_label = labels->value(0);
1310
-    map->warps_label = labels->value(1);
1311
-    map->coord_events_label = labels->value(2);
1312
-    map->bg_events_label = labels->value(3);
1305
+    QString objectEventsLabel = labels->value(0);
1306
+    QString warpEventsLabel = labels->value(1);
1307
+    QString coordEventsLabel = labels->value(2);
1308
+    QString bgEventsLabel = labels->value(3);
1313 1309
 
1314
-    QList<QStringList> *object_events = getLabelMacros(parseAsm(text), map->object_events_label);
1315
-    map->events["object"].clear();
1310
+    QList<QStringList> *object_events = getLabelMacros(parseAsm(text), objectEventsLabel);
1311
+    map->events["object_event_group"].clear();
1316 1312
     for (QStringList command : *object_events) {
1317 1313
         if (command.value(0) == "object_event") {
1318 1314
             Event *object = new Event;
@@ -1326,18 +1322,18 @@ void Project::readMapEvents(Map *map) {
1326 1322
             object->put("behavior", command.value(i++));
1327 1323
             object->put("radius_x", command.value(i++).toInt(nullptr, 0));
1328 1324
             object->put("radius_y", command.value(i++).toInt(nullptr, 0));
1329
-            object->put("property", command.value(i++));
1330
-            object->put("sight_radius", command.value(i++));
1325
+            object->put("trainer_see_type", command.value(i++));
1326
+            object->put("sight_radius_tree_id", command.value(i++));
1331 1327
             object->put("script_label", command.value(i++));
1332 1328
             object->put("event_flag", command.value(i++));
1333
-
1334
-            object->put("event_type", "object");
1335
-            map->events["object"].append(object);
1329
+            object->put("event_group_type", "object_event_group");
1330
+            object->put("event_type", EventType::Object);
1331
+            map->events["object_event_group"].append(object);
1336 1332
         }
1337 1333
     }
1338 1334
 
1339
-    QList<QStringList> *warps = getLabelMacros(parseAsm(text), map->warps_label);
1340
-    map->events["warp"].clear();
1335
+    QList<QStringList> *warps = getLabelMacros(parseAsm(text), warpEventsLabel);
1336
+    map->events["warp_event_group"].clear();
1341 1337
     for (QStringList command : *warps) {
1342 1338
         if (command.value(0) == "warp_def") {
1343 1339
             Event *warp = new Event;
@@ -1352,17 +1348,17 @@ void Project::readMapEvents(Map *map) {
1352 1348
             QString mapConstant = command.value(i++);
1353 1349
             if (mapConstantsToMapNames->contains(mapConstant)) {
1354 1350
                 warp->put("destination_map_name", mapConstantsToMapNames->value(mapConstant));
1355
-                warp->put("event_type", "warp");
1356
-                map->events["warp"].append(warp);
1351
+                warp->put("event_group_type", "warp_event_group");
1352
+                warp->put("event_type", EventType::Warp);
1353
+                map->events["warp_event_group"].append(warp);
1357 1354
             } else {
1358 1355
                 qDebug() << QString("Destination map constant '%1' is invalid for warp").arg(mapConstant);
1359 1356
             }
1360 1357
         }
1361 1358
     }
1362 1359
 
1363
-    QList<QStringList> *coords = getLabelMacros(parseAsm(text), map->coord_events_label);
1364
-    map->events["trap"].clear();
1365
-    map->events["trap_weather"].clear();
1360
+    QList<QStringList> *coords = getLabelMacros(parseAsm(text), coordEventsLabel);
1361
+    map->events["coord_event_group"].clear();
1366 1362
     for (QStringList command : *coords) {
1367 1363
         if (command.value(0) == "coord_event") {
1368 1364
             Event *coord = new Event;
@@ -1383,8 +1379,9 @@ void Project::readMapEvents(Map *map) {
1383 1379
             //coord_unknown3
1384 1380
             //coord_unknown4
1385 1381
 
1386
-            coord->put("event_type", "trap");
1387
-            map->events["trap"].append(coord);
1382
+            coord->put("event_group_type", "coord_event_group");
1383
+            coord->put("event_type", EventType::CoordScript);
1384
+            map->events["coord_event_group"].append(coord);
1388 1385
         } else if (command.value(0) == "coord_weather_event") {
1389 1386
             Event *coord = new Event;
1390 1387
             coord->put("map_name", map->name);
@@ -1393,15 +1390,14 @@ void Project::readMapEvents(Map *map) {
1393 1390
             coord->put("y", command.value(i++));
1394 1391
             coord->put("elevation", command.value(i++));
1395 1392
             coord->put("weather", command.value(i++));
1396
-            coord->put("event_type", "trap_weather");
1397
-            map->events["trap_weather"].append(coord);
1393
+            coord->put("event_group_type", "coord_event_group");
1394
+            coord->put("event_type", EventType::CoordWeather);
1395
+            map->events["coord_event_group"].append(coord);
1398 1396
         }
1399 1397
     }
1400 1398
 
1401
-    QList<QStringList> *bgs = getLabelMacros(parseAsm(text), map->bg_events_label);
1402
-    map->events["sign"].clear();
1403
-    map->events["event_hidden_item"].clear();
1404
-    map->events["event_secret_base"].clear();
1399
+    QList<QStringList> *bgs = getLabelMacros(parseAsm(text), bgEventsLabel);
1400
+    map->events["bg_event_group"].clear();
1405 1401
     for (QStringList command : *bgs) {
1406 1402
         if (command.value(0) == "bg_event") {
1407 1403
             Event *bg = new Event;
@@ -1410,12 +1406,13 @@ void Project::readMapEvents(Map *map) {
1410 1406
             bg->put("x", command.value(i++));
1411 1407
             bg->put("y", command.value(i++));
1412 1408
             bg->put("elevation", command.value(i++));
1413
-            bg->put("type", command.value(i++));
1409
+            bg->put("player_facing_direction", command.value(i++));
1414 1410
             i++;
1415 1411
             bg->put("script_label", command.value(i++));
1416 1412
             //sign_unknown7
1417
-            bg->put("event_type", "sign");
1418
-            map->events["sign"].append(bg);
1413
+            bg->put("event_group_type", "bg_event_group");
1414
+            bg->put("event_type", EventType::Sign);
1415
+            map->events["bg_event_group"].append(bg);
1419 1416
         } else if (command.value(0) == "bg_hidden_item_event") {
1420 1417
             Event *bg = new Event;
1421 1418
             bg->put("map_name", map->name);
@@ -1425,8 +1422,9 @@ void Project::readMapEvents(Map *map) {
1425 1422
             bg->put("elevation", command.value(i++));
1426 1423
             bg->put("item", command.value(i++));
1427 1424
             bg->put("flag", command.value(i++));
1428
-            bg->put("event_type", "event_hidden_item");
1429
-            map->events["event_hidden_item"].append(bg);
1425
+            bg->put("event_group_type", "bg_event_group");
1426
+            bg->put("event_type", EventType::HiddenItem);
1427
+            map->events["bg_event_group"].append(bg);
1430 1428
         } else if (command.value(0) == "bg_secret_base_event") {
1431 1429
             Event *bg = new Event;
1432 1430
             bg->put("map_name", map->name);
@@ -1435,24 +1433,18 @@ void Project::readMapEvents(Map *map) {
1435 1433
             bg->put("y", command.value(i++));
1436 1434
             bg->put("elevation", command.value(i++));
1437 1435
             bg->put("secret_base_map", command.value(i++));
1438
-            bg->put("event_type", "event_secret_base");
1439
-            map->events["event_secret_base"].append(bg);
1436
+            bg->put("event_group_type", "bg_event_group");
1437
+            bg->put("event_type", EventType::SecretBase);
1438
+            map->events["bg_event_group"].append(bg);
1440 1439
         }
1441 1440
     }
1442 1441
 }
1443 1442
 
1444 1443
 void Project::setNewMapEvents(Map *map) {
1445
-    map->object_events_label = "0x0";
1446
-    map->warps_label = "0x0";
1447
-    map->coord_events_label = "0x0";
1448
-    map->bg_events_label = "0x0";
1449
-    map->events["object"].clear();
1450
-    map->events["warp"].clear();
1451
-    map->events["trap"].clear();
1452
-    map->events["trap_weather"].clear();
1453
-    map->events["sign"].clear();
1454
-    map->events["event_hidden_item"].clear();
1455
-    map->events["event_secret_base"].clear();
1444
+    map->events["object_event_group"].clear();
1445
+    map->events["warp_event_group"].clear();
1446
+    map->events["coord_event_group"].clear();
1447
+    map->events["bg_event_group"].clear();
1456 1448
 }
1457 1449
 
1458 1450
 QStringList Project::readCArray(QString text, QString label) {

+ 2
- 1
project.h Ver fichero

@@ -57,7 +57,7 @@ public:
57 57
     QStringList* readLayoutValues(QString layoutName);
58 58
     void readMapLayout(Map*);
59 59
     void readMapsWithConnections();
60
-    void getTilesets(Map*);
60
+    void loadMapTilesets(Map*);
61 61
     void loadTilesetAssets(Tileset*);
62 62
 
63 63
     void saveBlockdata(Map*);
@@ -74,6 +74,7 @@ public:
74 74
     QStringList getSongNames();
75 75
     QStringList getLocations();
76 76
     QStringList getVisibilities();
77
+    QMap<QString, QStringList> getTilesets();
77 78
     QStringList getWeathers();
78 79
     QStringList getMapTypes();
79 80
     QStringList getBattleScenes();

+ 111
- 0
tileset.cpp Ver fichero

@@ -1,6 +1,117 @@
1 1
 #include "tileset.h"
2 2
 
3
+#include <QPainter>
4
+#include <QImage>
5
+#include <QDebug>
6
+
3 7
 Tileset::Tileset()
4 8
 {
5 9
 
6 10
 }
11
+
12
+Metatile::Metatile()
13
+{
14
+    tiles = new QList<Tile>;
15
+}
16
+
17
+QImage Metatile::getMetatileImage(int tile, Tileset *primaryTileset, Tileset *secondaryTileset) {
18
+    QImage metatile_image(16, 16, QImage::Format_RGBA8888);
19
+
20
+    Metatile* metatile = Metatile::getMetatile(tile, primaryTileset, secondaryTileset);
21
+    if (!metatile || !metatile->tiles) {
22
+        metatile_image.fill(0xffffffff);
23
+        return metatile_image;
24
+    }
25
+
26
+    Tileset* blockTileset = Metatile::getBlockTileset(tile, primaryTileset, secondaryTileset);
27
+    if (!blockTileset) {
28
+        metatile_image.fill(0xffffffff);
29
+        return metatile_image;
30
+    }
31
+    QList<QList<QRgb>> palettes = Metatile::getBlockPalettes(primaryTileset, secondaryTileset);
32
+
33
+    QPainter metatile_painter(&metatile_image);
34
+    for (int layer = 0; layer < 2; layer++)
35
+    for (int y = 0; y < 2; y++)
36
+    for (int x = 0; x < 2; x++) {
37
+        Tile tile_ = metatile->tiles->value((y * 2) + x + (layer * 4));
38
+        QImage tile_image = Metatile::getMetatileTile(tile_.tile, primaryTileset, secondaryTileset);
39
+        if (tile_image.isNull()) {
40
+            // Some metatiles specify tiles that are outside the valid range.
41
+            // These are treated as completely transparent, so they can be skipped without
42
+            // being drawn.
43
+            continue;
44
+        }
45
+
46
+        // Colorize the metatile tiles with its palette.
47
+        if (tile_.palette < palettes.length()) {
48
+            QList<QRgb> palette = palettes.value(tile_.palette);
49
+            for (int j = 0; j < palette.length(); j++) {
50
+                tile_image.setColor(j, palette.value(j));
51
+            }
52
+        } else {
53
+            qDebug() << "Tile is referring to invalid palette number: " << tile_.palette;
54
+        }
55
+
56
+        // The top layer of the metatile has its last color displayed at transparent.
57
+        if (layer > 0) {
58
+            QColor color(tile_image.color(15));
59
+            color.setAlpha(0);
60
+            tile_image.setColor(15, color.rgba());
61
+        }
62
+
63
+        QPoint origin = QPoint(x*8, y*8);
64
+        metatile_painter.drawImage(origin, tile_image.mirrored(tile_.xflip == 1, tile_.yflip == 1));
65
+    }
66
+    metatile_painter.end();
67
+
68
+    return metatile_image;
69
+}
70
+
71
+Metatile* Metatile::getMetatile(int index, Tileset *primaryTileset, Tileset *secondaryTileset) {
72
+    Tileset *tileset = Metatile::getBlockTileset(index, primaryTileset, secondaryTileset);
73
+    int local_index = Metatile::getBlockIndex(index);
74
+    if (!tileset || !tileset->metatiles) {
75
+        return NULL;
76
+    }
77
+    Metatile *metatile = tileset->metatiles->value(local_index, NULL);
78
+    return metatile;
79
+}
80
+
81
+QImage Metatile::getMetatileTile(int tile, Tileset *primaryTileset, Tileset *secondaryTileset) {
82
+    Tileset *tileset = Metatile::getBlockTileset(tile, primaryTileset, secondaryTileset);
83
+    int local_index = Metatile::getBlockIndex(tile);
84
+    if (!tileset || !tileset->tiles) {
85
+        return QImage();
86
+    }
87
+    return tileset->tiles->value(local_index, QImage());
88
+}
89
+
90
+Tileset* Metatile::getBlockTileset(int metatile_index, Tileset *primaryTileset, Tileset *secondaryTileset) {
91
+    int primary_size = 0x200;
92
+    if (metatile_index < primary_size) {
93
+        return primaryTileset;
94
+    } else {
95
+        return secondaryTileset;
96
+    }
97
+}
98
+
99
+int Metatile::getBlockIndex(int index) {
100
+    int primary_size = 0x200;
101
+    if (index < primary_size) {
102
+        return index;
103
+    } else {
104
+        return index - primary_size;
105
+    }
106
+}
107
+
108
+QList<QList<QRgb>> Metatile::getBlockPalettes(Tileset *primaryTileset, Tileset *secondaryTileset) {
109
+    QList<QList<QRgb>> palettes;
110
+    for (int i = 0; i < 6; i++) {
111
+        palettes.append(primaryTileset->palettes->at(i));
112
+    }
113
+    for (int i = 6; i < 12; i++) {
114
+        palettes.append(secondaryTileset->palettes->at(i));
115
+    }
116
+    return palettes;
117
+}

+ 19
- 1
tileset.h Ver fichero

@@ -1,9 +1,11 @@
1 1
 #ifndef TILESET_H
2 2
 #define TILESET_H
3 3
 
4
-#include "metatile.h"
4
+#include "tile.h"
5 5
 #include <QImage>
6 6
 
7
+class Metatile;
8
+
7 9
 class Tileset
8 10
 {
9 11
 public:
@@ -24,4 +26,20 @@ public:
24 26
     QList<QList<QRgb>> *palettes = NULL;
25 27
 };
26 28
 
29
+class Metatile
30
+{
31
+public:
32
+    Metatile();
33
+public:
34
+    QList<Tile> *tiles = NULL;
35
+    int attr;
36
+
37
+    static QImage getMetatileImage(int, Tileset*, Tileset*);
38
+    static Metatile* getMetatile(int, Tileset*, Tileset*);
39
+    static QImage getMetatileTile(int, Tileset*, Tileset*);
40
+    static Tileset* getBlockTileset(int, Tileset*, Tileset*);
41
+    static int getBlockIndex(int);
42
+    static QList<QList<QRgb>> getBlockPalettes(Tileset*, Tileset*);
43
+};
44
+
27 45
 #endif // TILESET_H