Browse Source

Merge pull request #54 from huderlem/tilesets

Allow changing map tilesets
yenatch 6 years ago
parent
commit
8d2958c952
No account linked to committer's email address
9 changed files with 373 additions and 119 deletions
  1. 102
    22
      editor.cpp
  2. 5
    0
      editor.h
  3. 24
    0
      mainwindow.cpp
  4. 5
    0
      mainwindow.h
  5. 182
    87
      mainwindow.ui
  6. 0
    1
      map.h
  7. 44
    4
      project.cpp
  8. 2
    1
      project.h
  9. 9
    4
      tileset.cpp

+ 102
- 22
editor.cpp View File

306
 }
306
 }
307
 
307
 
308
 void Editor::setConnectionsVisibility(bool visible) {
308
 void Editor::setConnectionsVisibility(bool visible) {
309
-    for (QGraphicsPixmapItem* item : map->connection_items) {
309
+    for (QGraphicsPixmapItem* item : connection_items) {
310
         item->setVisible(visible);
310
         item->setVisible(visible);
311
         item->setActive(visible);
311
         item->setActive(visible);
312
     }
312
     }
348
 }
348
 }
349
 
349
 
350
 void Editor::displayMap() {
350
 void Editor::displayMap() {
351
-    scene = new QGraphicsScene;
351
+    if (!scene)
352
+        scene = new QGraphicsScene;
352
 
353
 
354
+    if (map_item && scene) {
355
+        scene->removeItem(map_item);
356
+        delete map_item;
357
+    }
353
     map_item = new MapPixmapItem(map);
358
     map_item = new MapPixmapItem(map);
354
     connect(map_item, SIGNAL(mouseEvent(QGraphicsSceneMouseEvent*,MapPixmapItem*)),
359
     connect(map_item, SIGNAL(mouseEvent(QGraphicsSceneMouseEvent*,MapPixmapItem*)),
355
             this, SLOT(mouseEvent_map(QGraphicsSceneMouseEvent*,MapPixmapItem*)));
360
             this, SLOT(mouseEvent_map(QGraphicsSceneMouseEvent*,MapPixmapItem*)));
357
     map_item->draw(true);
362
     map_item->draw(true);
358
     scene->addItem(map_item);
363
     scene->addItem(map_item);
359
 
364
 
365
+    if (collision_item && scene) {
366
+        scene->removeItem(collision_item);
367
+        delete collision_item;
368
+    }
360
     collision_item = new CollisionPixmapItem(map);
369
     collision_item = new CollisionPixmapItem(map);
361
     connect(collision_item, SIGNAL(mouseEvent(QGraphicsSceneMouseEvent*,CollisionPixmapItem*)),
370
     connect(collision_item, SIGNAL(mouseEvent(QGraphicsSceneMouseEvent*,CollisionPixmapItem*)),
362
             this, SLOT(mouseEvent_collision(QGraphicsSceneMouseEvent*,CollisionPixmapItem*)));
371
             this, SLOT(mouseEvent_collision(QGraphicsSceneMouseEvent*,CollisionPixmapItem*)));
364
     collision_item->draw(true);
373
     collision_item->draw(true);
365
     scene->addItem(collision_item);
374
     scene->addItem(collision_item);
366
 
375
 
367
-    events_group = new EventGroup;
368
-    scene->addItem(events_group);
369
-
370
-    if (map_item) {
371
-        map_item->setVisible(false);
372
-    }
373
-    if (collision_item) {
374
-        collision_item->setVisible(false);
375
-    }
376
-    if (events_group) {
377
-        events_group->setVisible(false);
378
-    }
379
-
380
     int tw = 16;
376
     int tw = 16;
381
     int th = 16;
377
     int th = 16;
382
     scene->setSceneRect(
378
     scene->setSceneRect(
394
     displayMapConnections();
390
     displayMapConnections();
395
     displayMapBorder();
391
     displayMapBorder();
396
     displayMapGrid();
392
     displayMapGrid();
393
+
394
+    if (map_item) {
395
+        map_item->setVisible(false);
396
+    }
397
+    if (collision_item) {
398
+        collision_item->setVisible(false);
399
+    }
400
+    if (events_group) {
401
+        events_group->setVisible(false);
402
+    }
397
 }
403
 }
398
 
404
 
399
 void Editor::displayMetatiles() {
405
 void Editor::displayMetatiles() {
406
+    if (metatiles_item && metatiles_item->scene()) {
407
+        metatiles_item->scene()->removeItem(metatiles_item);
408
+        delete metatiles_item;
409
+    }
410
+
400
     scene_metatiles = new QGraphicsScene;
411
     scene_metatiles = new QGraphicsScene;
401
     metatiles_item = new MetatilesPixmapItem(map);
412
     metatiles_item = new MetatilesPixmapItem(map);
402
     metatiles_item->draw();
413
     metatiles_item->draw();
404
 }
415
 }
405
 
416
 
406
 void Editor::displayBorderMetatiles() {
417
 void Editor::displayBorderMetatiles() {
418
+    if (selected_border_metatiles_item && selected_border_metatiles_item->scene()) {
419
+        selected_border_metatiles_item->scene()->removeItem(selected_border_metatiles_item);
420
+        delete selected_border_metatiles_item;
421
+    }
422
+
407
     scene_selected_border_metatiles = new QGraphicsScene;
423
     scene_selected_border_metatiles = new QGraphicsScene;
408
     selected_border_metatiles_item = new BorderMetatilesPixmapItem(map);
424
     selected_border_metatiles_item = new BorderMetatilesPixmapItem(map);
409
     selected_border_metatiles_item->draw();
425
     selected_border_metatiles_item->draw();
413
 }
429
 }
414
 
430
 
415
 void Editor::displayCollisionMetatiles() {
431
 void Editor::displayCollisionMetatiles() {
432
+    if (collision_metatiles_item && collision_metatiles_item->scene()) {
433
+        collision_metatiles_item->scene()->removeItem(collision_metatiles_item);
434
+        delete collision_metatiles_item;
435
+    }
436
+
416
     scene_collision_metatiles = new QGraphicsScene;
437
     scene_collision_metatiles = new QGraphicsScene;
417
     collision_metatiles_item = new CollisionMetatilesPixmapItem(map);
438
     collision_metatiles_item = new CollisionMetatilesPixmapItem(map);
418
     collision_metatiles_item->draw();
439
     collision_metatiles_item->draw();
420
 }
441
 }
421
 
442
 
422
 void Editor::displayElevationMetatiles() {
443
 void Editor::displayElevationMetatiles() {
444
+    if (elevation_metatiles_item && elevation_metatiles_item->scene()) {
445
+        elevation_metatiles_item->scene()->removeItem(elevation_metatiles_item);
446
+        delete elevation_metatiles_item;
447
+    }
448
+
423
     scene_elevation_metatiles = new QGraphicsScene;
449
     scene_elevation_metatiles = new QGraphicsScene;
424
     elevation_metatiles_item = new ElevationMetatilesPixmapItem(map);
450
     elevation_metatiles_item = new ElevationMetatilesPixmapItem(map);
425
     elevation_metatiles_item->draw();
451
     elevation_metatiles_item->draw();
427
 }
453
 }
428
 
454
 
429
 void Editor::displayMapEvents() {
455
 void Editor::displayMapEvents() {
430
-    for (QGraphicsItem *child : events_group->childItems()) {
431
-        events_group->removeFromGroup(child);
456
+    if (events_group) {
457
+        for (QGraphicsItem *child : events_group->childItems()) {
458
+            events_group->removeFromGroup(child);
459
+            delete child;
460
+        }
461
+
462
+        if (events_group->scene()) {
463
+            events_group->scene()->removeItem(events_group);
464
+        }
465
+
466
+        delete events_group;
432
     }
467
     }
433
 
468
 
469
+    events_group = new EventGroup;
470
+    scene->addItem(events_group);
471
+
434
     QList<Event *> events = map->getAllEvents();
472
     QList<Event *> events = map->getAllEvents();
435
     project->loadEventPixmaps(events);
473
     project->loadEventPixmaps(events);
436
     for (Event *event : events) {
474
     for (Event *event : events) {
450
 }
488
 }
451
 
489
 
452
 void Editor::displayMapConnections() {
490
 void Editor::displayMapConnections() {
453
-    for (QGraphicsPixmapItem* item : map->connection_items) {
491
+    for (QGraphicsPixmapItem* item : connection_items) {
492
+        if (item->scene()) {
493
+            item->scene()->removeItem(item);
494
+        }
454
         delete item;
495
         delete item;
455
     }
496
     }
456
-    map->connection_items.clear();
497
+    connection_items.clear();
457
 
498
 
458
     for (ConnectionPixmapItem* item : connection_edit_items) {
499
     for (ConnectionPixmapItem* item : connection_edit_items) {
500
+        if (item->scene()) {
501
+            item->scene()->removeItem(item);
502
+        }
459
         delete item;
503
         delete item;
460
     }
504
     }
461
     selected_connection_item = NULL;
505
     selected_connection_item = NULL;
497
     item->setX(x);
541
     item->setX(x);
498
     item->setY(y);
542
     item->setY(y);
499
     scene->addItem(item);
543
     scene->addItem(item);
500
-    map->connection_items.append(item);
544
+    connection_items.append(item);
501
     item->setVisible(!hide);
545
     item->setVisible(!hide);
502
 
546
 
503
     ConnectionPixmapItem *connection_edit_item = new ConnectionPixmapItem(pixmap, connection, x, y, map->getWidth(), map->getHeight());
547
     ConnectionPixmapItem *connection_edit_item = new ConnectionPixmapItem(pixmap, connection, x, y, map->getWidth(), map->getHeight());
512
 }
556
 }
513
 
557
 
514
 void Editor::displayMapBorder() {
558
 void Editor::displayMapBorder() {
559
+    for (QGraphicsPixmapItem* item : borderItems) {
560
+        if (item->scene()) {
561
+            item->scene()->removeItem(item);
562
+        }
563
+        delete item;
564
+    }
565
+    borderItems.clear();
566
+
515
     QPixmap pixmap = map->renderBorder();
567
     QPixmap pixmap = map->renderBorder();
516
     for (int y = -6; y < map->getHeight() + 6; y += 2)
568
     for (int y = -6; y < map->getHeight() + 6; y += 2)
517
     for (int x = -6; x < map->getWidth() + 6; x += 2) {
569
     for (int x = -6; x < map->getWidth() + 6; x += 2) {
525
 }
577
 }
526
 
578
 
527
 void Editor::displayMapGrid() {
579
 void Editor::displayMapGrid() {
580
+    for (QGraphicsLineItem* item : gridLines) {
581
+        if (item && item->scene()) {
582
+            item->scene()->removeItem(item);
583
+        }
584
+        delete item;
585
+    }
586
+    gridLines.clear();
587
+    ui->checkBox_ToggleGrid->disconnect();
588
+
528
     int pixelWidth = map->getWidth() * 16;
589
     int pixelWidth = map->getWidth() * 16;
529
     int pixelHeight = map->getHeight() * 16;
590
     int pixelHeight = map->getHeight() * 16;
530
     for (int i = 0; i <= map->getWidth(); i++) {
591
     for (int i = 0; i <= map->getWidth(); i++) {
531
         int x = i * 16;
592
         int x = i * 16;
532
         QGraphicsLineItem *line = scene->addLine(x, 0, x, pixelHeight);
593
         QGraphicsLineItem *line = scene->addLine(x, 0, x, pixelHeight);
533
         line->setVisible(ui->checkBox_ToggleGrid->isChecked());
594
         line->setVisible(ui->checkBox_ToggleGrid->isChecked());
595
+        gridLines.append(line);
534
         connect(ui->checkBox_ToggleGrid, &QCheckBox::toggled, [=](bool checked){line->setVisible(checked);});
596
         connect(ui->checkBox_ToggleGrid, &QCheckBox::toggled, [=](bool checked){line->setVisible(checked);});
535
     }
597
     }
536
     for (int j = 0; j <= map->getHeight(); j++) {
598
     for (int j = 0; j <= map->getHeight(); j++) {
537
         int y = j * 16;
599
         int y = j * 16;
538
         QGraphicsLineItem *line = scene->addLine(0, y, pixelWidth, y);
600
         QGraphicsLineItem *line = scene->addLine(0, y, pixelWidth, y);
539
         line->setVisible(ui->checkBox_ToggleGrid->isChecked());
601
         line->setVisible(ui->checkBox_ToggleGrid->isChecked());
602
+        gridLines.append(line);
540
         connect(ui->checkBox_ToggleGrid, &QCheckBox::toggled, [=](bool checked){line->setVisible(checked);});
603
         connect(ui->checkBox_ToggleGrid, &QCheckBox::toggled, [=](bool checked){line->setVisible(checked);});
541
     }
604
     }
542
 }
605
 }
679
     connection_edit_items.removeOne(selected_connection_item);
742
     connection_edit_items.removeOne(selected_connection_item);
680
     removeMirroredConnection(selected_connection_item->connection);
743
     removeMirroredConnection(selected_connection_item->connection);
681
 
744
 
682
-    scene->removeItem(selected_connection_item);
683
-    delete selected_connection_item;
745
+    if (selected_connection_item && selected_connection_item->scene()) {
746
+        selected_connection_item->scene()->removeItem(selected_connection_item);
747
+        delete selected_connection_item;
748
+    }
749
+
684
     selected_connection_item = NULL;
750
     selected_connection_item = NULL;
685
     setConnectionEditControlsEnabled(false);
751
     setConnectionEditControlsEnabled(false);
686
     ui->spinBox_ConnectionOffset->setValue(0);
752
     ui->spinBox_ConnectionOffset->setValue(0);
737
     ui->label_NumConnections->setText(QString::number(map->connections.length()));
803
     ui->label_NumConnections->setText(QString::number(map->connections.length()));
738
 }
804
 }
739
 
805
 
806
+void Editor::updatePrimaryTileset(QString tilesetLabel)
807
+{
808
+    map->layout->tileset_primary_label = tilesetLabel;
809
+    map->layout->tileset_primary = project->getTileset(tilesetLabel);
810
+    emit tilesetChanged(map->name);
811
+}
812
+
813
+void Editor::updateSecondaryTileset(QString tilesetLabel)
814
+{
815
+    map->layout->tileset_secondary_label = tilesetLabel;
816
+    map->layout->tileset_secondary = project->getTileset(tilesetLabel);
817
+    emit tilesetChanged(map->name);
818
+}
819
+
740
 void MetatilesPixmapItem::paintTileChanged(Map *map) {
820
 void MetatilesPixmapItem::paintTileChanged(Map *map) {
741
     draw();
821
     draw();
742
 }
822
 }

+ 5
- 0
editor.h View File

59
     void updateDiveMap(QString mapName);
59
     void updateDiveMap(QString mapName);
60
     void updateEmergeMap(QString mapName);
60
     void updateEmergeMap(QString mapName);
61
     void setSelectedConnectionFromMap(QString mapName);
61
     void setSelectedConnectionFromMap(QString mapName);
62
+    void updatePrimaryTileset(QString tilesetLabel);
63
+    void updateSecondaryTileset(QString tilesetLabel);
62
 
64
 
63
     DraggablePixmapItem *addMapEvent(Event *event);
65
     DraggablePixmapItem *addMapEvent(Event *event);
64
     void selectMapEvent(DraggablePixmapItem *object);
66
     void selectMapEvent(DraggablePixmapItem *object);
74
     QGraphicsPixmapItem *current_view = NULL;
76
     QGraphicsPixmapItem *current_view = NULL;
75
     MapPixmapItem *map_item = NULL;
77
     MapPixmapItem *map_item = NULL;
76
     ConnectionPixmapItem* selected_connection_item = NULL;
78
     ConnectionPixmapItem* selected_connection_item = NULL;
79
+    QList<QGraphicsPixmapItem*> connection_items;
77
     QList<ConnectionPixmapItem*> connection_edit_items;
80
     QList<ConnectionPixmapItem*> connection_edit_items;
78
     CollisionPixmapItem *collision_item = NULL;
81
     CollisionPixmapItem *collision_item = NULL;
79
     QGraphicsItemGroup *events_group = NULL;
82
     QGraphicsItemGroup *events_group = NULL;
80
     QList<QGraphicsPixmapItem*> borderItems;
83
     QList<QGraphicsPixmapItem*> borderItems;
84
+    QList<QGraphicsLineItem*> gridLines;
81
 
85
 
82
     QGraphicsScene *scene_metatiles = NULL;
86
     QGraphicsScene *scene_metatiles = NULL;
83
     QGraphicsScene *scene_selected_border_metatiles = NULL;
87
     QGraphicsScene *scene_selected_border_metatiles = NULL;
133
     void objectsChanged();
137
     void objectsChanged();
134
     void selectedObjectsChanged();
138
     void selectedObjectsChanged();
135
     void loadMapRequested(QString, QString);
139
     void loadMapRequested(QString, QString);
140
+    void tilesetChanged(QString);
136
 };
141
 };
137
 
142
 
138
 
143
 

+ 24
- 0
mainwindow.cpp View File

34
     connect(editor, SIGNAL(objectsChanged()), this, SLOT(updateSelectedObjects()));
34
     connect(editor, SIGNAL(objectsChanged()), this, SLOT(updateSelectedObjects()));
35
     connect(editor, SIGNAL(selectedObjectsChanged()), this, SLOT(updateSelectedObjects()));
35
     connect(editor, SIGNAL(selectedObjectsChanged()), this, SLOT(updateSelectedObjects()));
36
     connect(editor, SIGNAL(loadMapRequested(QString, QString)), this, SLOT(onLoadMapRequested(QString, QString)));
36
     connect(editor, SIGNAL(loadMapRequested(QString, QString)), this, SLOT(onLoadMapRequested(QString, QString)));
37
+    connect(editor, SIGNAL(tilesetChanged(QString)), this, SLOT(onTilesetChanged(QString)));
37
 
38
 
38
     on_toolButton_Paint_clicked();
39
     on_toolButton_Paint_clicked();
39
 
40
 
206
     ui->comboBox_Weather->clear();
207
     ui->comboBox_Weather->clear();
207
     ui->comboBox_Type->clear();
208
     ui->comboBox_Type->clear();
208
     ui->comboBox_BattleScene->clear();
209
     ui->comboBox_BattleScene->clear();
210
+    ui->comboBox_PrimaryTileset->clear();
211
+    ui->comboBox_SecondaryTileset->clear();
209
     ui->checkBox_ShowLocation->setChecked(false);
212
     ui->checkBox_ShowLocation->setChecked(false);
210
     if (!editor || !editor->map || !editor->project) {
213
     if (!editor || !editor->map || !editor->project) {
211
         ui->frame_3->setEnabled(false);
214
         ui->frame_3->setEnabled(false);
222
     ui->comboBox_Location->addItems(project->getLocations());
225
     ui->comboBox_Location->addItems(project->getLocations());
223
     ui->comboBox_Location->setCurrentText(map->location);
226
     ui->comboBox_Location->setCurrentText(map->location);
224
 
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
+
225
     ui->comboBox_Visibility->addItems(project->getVisibilities());
234
     ui->comboBox_Visibility->addItems(project->getVisibilities());
226
     ui->comboBox_Visibility->setCurrentText(map->visibility);
235
     ui->comboBox_Visibility->setCurrentText(map->visibility);
227
 
236
 
412
     setMap(newMapName);
421
     setMap(newMapName);
413
 }
422
 }
414
 
423
 
424
+void MainWindow::onTilesetChanged(QString mapName)
425
+{
426
+    setMap(mapName);
427
+}
428
+
415
 void MainWindow::on_mapList_activated(const QModelIndex &index)
429
 void MainWindow::on_mapList_activated(const QModelIndex &index)
416
 {
430
 {
417
     QVariant data = index.data(Qt::UserRole);
431
     QVariant data = index.data(Qt::UserRole);
814
 {
828
 {
815
     editor->updateEmergeMap(mapName);
829
     editor->updateEmergeMap(mapName);
816
 }
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
+}

+ 5
- 0
mainwindow.h View File

71
 
71
 
72
     void onOpenMapListContextMenu(const QPoint &point);
72
     void onOpenMapListContextMenu(const QPoint &point);
73
     void onAddNewMapToGroupClick(QAction* triggeredAction);
73
     void onAddNewMapToGroupClick(QAction* triggeredAction);
74
+    void onTilesetChanged(QString);
74
 
75
 
75
     void on_action_Export_Map_Image_triggered();
76
     void on_action_Export_Map_Image_triggered();
76
 
77
 
88
 
89
 
89
     void on_comboBox_EmergeMap_currentTextChanged(const QString &mapName);
90
     void on_comboBox_EmergeMap_currentTextChanged(const QString &mapName);
90
 
91
 
92
+    void on_comboBox_PrimaryTileset_activated(const QString &arg1);
93
+
94
+    void on_comboBox_SecondaryTileset_activated(const QString &arg1);
95
+
91
 private:
96
 private:
92
     Ui::MainWindow *ui;
97
     Ui::MainWindow *ui;
93
     QStandardItemModel *mapListModel;
98
     QStandardItemModel *mapListModel;

+ 182
- 87
mainwindow.ui View File

290
                     <rect>
290
                     <rect>
291
                      <x>0</x>
291
                      <x>0</x>
292
                      <y>0</y>
292
                      <y>0</y>
293
-                     <width>475</width>
293
+                     <width>436</width>
294
                      <height>621</height>
294
                      <height>621</height>
295
                     </rect>
295
                     </rect>
296
                    </property>
296
                    </property>
451
                   <number>0</number>
451
                   <number>0</number>
452
                  </property>
452
                  </property>
453
                  <item row="0" column="0">
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
                   <widget class="QScrollArea" name="scrollArea_2">
591
                   <widget class="QScrollArea" name="scrollArea_2">
455
                    <property name="sizePolicy">
592
                    <property name="sizePolicy">
456
-                    <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
593
+                    <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
457
                      <horstretch>0</horstretch>
594
                      <horstretch>0</horstretch>
458
                      <verstretch>0</verstretch>
595
                      <verstretch>0</verstretch>
459
                     </sizepolicy>
596
                     </sizepolicy>
470
                    <property name="widgetResizable">
607
                    <property name="widgetResizable">
471
                     <bool>true</bool>
608
                     <bool>true</bool>
472
                    </property>
609
                    </property>
610
+                   <property name="alignment">
611
+                    <set>Qt::AlignHCenter|Qt::AlignTop</set>
612
+                   </property>
473
                    <widget class="QWidget" name="scrollAreaWidgetContents_2">
613
                    <widget class="QWidget" name="scrollAreaWidgetContents_2">
474
                     <property name="enabled">
614
                     <property name="enabled">
475
                      <bool>true</bool>
615
                      <bool>true</bool>
479
                       <x>0</x>
619
                       <x>0</x>
480
                       <y>0</y>
620
                       <y>0</y>
481
                       <width>358</width>
621
                       <width>358</width>
482
-                      <height>612</height>
622
+                      <height>497</height>
483
                      </rect>
623
                      </rect>
484
                     </property>
624
                     </property>
485
                     <property name="sizePolicy">
625
                     <property name="sizePolicy">
488
                       <verstretch>0</verstretch>
628
                       <verstretch>0</verstretch>
489
                      </sizepolicy>
629
                      </sizepolicy>
490
                     </property>
630
                     </property>
491
-                    <layout class="QGridLayout" name="gridLayout_5" rowstretch="0,0" columnstretch="0">
631
+                    <layout class="QGridLayout" name="gridLayout_5">
492
                      <property name="sizeConstraint">
632
                      <property name="sizeConstraint">
493
                       <enum>QLayout::SetDefaultConstraint</enum>
633
                       <enum>QLayout::SetDefaultConstraint</enum>
494
                      </property>
634
                      </property>
504
                      <property name="bottomMargin">
644
                      <property name="bottomMargin">
505
                       <number>0</number>
645
                       <number>0</number>
506
                      </property>
646
                      </property>
507
-                     <property name="horizontalSpacing">
508
-                      <number>0</number>
509
-                     </property>
510
-                     <property name="verticalSpacing">
511
-                      <number>8</number>
512
-                     </property>
513
-                     <item row="0" column="0">
514
-                      <widget class="QFrame" name="frame_10">
515
-                       <property name="sizePolicy">
516
-                        <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
517
-                         <horstretch>0</horstretch>
518
-                         <verstretch>0</verstretch>
519
-                        </sizepolicy>
647
+                     <item row="1" column="1">
648
+                      <spacer name="verticalSpacer_5">
649
+                       <property name="orientation">
650
+                        <enum>Qt::Vertical</enum>
520
                        </property>
651
                        </property>
521
-                       <property name="frameShape">
522
-                        <enum>QFrame::NoFrame</enum>
652
+                       <property name="sizeHint" stdset="0">
653
+                        <size>
654
+                         <width>20</width>
655
+                         <height>40</height>
656
+                        </size>
523
                        </property>
657
                        </property>
524
-                       <property name="frameShadow">
525
-                        <enum>QFrame::Raised</enum>
526
-                       </property>
527
-                       <layout class="QHBoxLayout" name="horizontalLayout_5">
528
-                        <property name="spacing">
529
-                         <number>6</number>
530
-                        </property>
531
-                        <property name="sizeConstraint">
532
-                         <enum>QLayout::SetDefaultConstraint</enum>
533
-                        </property>
534
-                        <item>
535
-                         <widget class="QLabel" name="label_16">
536
-                          <property name="sizePolicy">
537
-                           <sizepolicy hsizetype="Preferred" vsizetype="Minimum">
538
-                            <horstretch>0</horstretch>
539
-                            <verstretch>0</verstretch>
540
-                           </sizepolicy>
541
-                          </property>
542
-                          <property name="text">
543
-                           <string>Border</string>
544
-                          </property>
545
-                         </widget>
546
-                        </item>
547
-                        <item>
548
-                         <widget class="QGraphicsView" name="graphicsView_BorderMetatile">
549
-                          <property name="sizePolicy">
550
-                           <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
551
-                            <horstretch>0</horstretch>
552
-                            <verstretch>0</verstretch>
553
-                           </sizepolicy>
554
-                          </property>
555
-                          <property name="maximumSize">
556
-                           <size>
557
-                            <width>16777215</width>
558
-                            <height>48</height>
559
-                           </size>
560
-                          </property>
561
-                          <property name="frameShape">
562
-                           <enum>QFrame::StyledPanel</enum>
563
-                          </property>
564
-                          <property name="frameShadow">
565
-                           <enum>QFrame::Sunken</enum>
566
-                          </property>
567
-                          <property name="verticalScrollBarPolicy">
568
-                           <enum>Qt::ScrollBarAsNeeded</enum>
569
-                          </property>
570
-                         </widget>
571
-                        </item>
572
-                        <item>
573
-                         <spacer name="horizontalSpacer_12">
574
-                          <property name="orientation">
575
-                           <enum>Qt::Horizontal</enum>
576
-                          </property>
577
-                          <property name="sizeType">
578
-                           <enum>QSizePolicy::Maximum</enum>
579
-                          </property>
580
-                          <property name="sizeHint" stdset="0">
581
-                           <size>
582
-                            <width>40</width>
583
-                            <height>20</height>
584
-                           </size>
585
-                          </property>
586
-                         </spacer>
587
-                        </item>
588
-                       </layout>
589
-                      </widget>
658
+                      </spacer>
590
                      </item>
659
                      </item>
591
-                     <item row="1" column="0">
660
+                     <item row="0" column="1">
592
                       <widget class="QGraphicsView" name="graphicsView_Metatiles">
661
                       <widget class="QGraphicsView" name="graphicsView_Metatiles">
593
                        <property name="enabled">
662
                        <property name="enabled">
594
                         <bool>true</bool>
663
                         <bool>true</bool>
595
                        </property>
664
                        </property>
596
                        <property name="sizePolicy">
665
                        <property name="sizePolicy">
597
-                        <sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
666
+                        <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
598
                          <horstretch>0</horstretch>
667
                          <horstretch>0</horstretch>
599
                          <verstretch>0</verstretch>
668
                          <verstretch>0</verstretch>
600
                         </sizepolicy>
669
                         </sizepolicy>
610
                        </property>
679
                        </property>
611
                       </widget>
680
                       </widget>
612
                      </item>
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>
613
                     </layout>
708
                     </layout>
614
                    </widget>
709
                    </widget>
615
                   </widget>
710
                   </widget>

+ 0
- 1
map.h View File

193
     QMap<QString, QList<Event*>> events;
193
     QMap<QString, QList<Event*>> events;
194
 
194
 
195
     QList<Connection*> connections;
195
     QList<Connection*> connections;
196
-    QList<QGraphicsPixmapItem*> connection_items;
197
     QPixmap renderConnection(Connection);
196
     QPixmap renderConnection(Connection);
198
 
197
 
199
     QPixmap renderBorder();
198
     QPixmap renderBorder();

+ 44
- 4
project.cpp View File

64
     }
64
     }
65
 
65
 
66
     map->connections.clear();
66
     map->connections.clear();
67
-    map->connection_items.clear();
68
     if (!map->connections_label.isNull()) {
67
     if (!map->connections_label.isNull()) {
69
         QString path = root + QString("/data/maps/%1/connections.inc").arg(map->name);
68
         QString path = root + QString("/data/maps/%1/connections.inc").arg(map->name);
70
         QString text = readTextFile(path);
69
         QString text = readTextFile(path);
354
         map->layout = mapLayouts[map->layout_label];
353
         map->layout = mapLayouts[map->layout_label];
355
     }
354
     }
356
 
355
 
357
-    getTilesets(map);
356
+    loadMapTilesets(map);
358
     loadBlockdata(map);
357
     loadBlockdata(map);
359
     loadMapBorder(map);
358
     loadMapBorder(map);
360
 }
359
 }
494
     saveTextFile(root + "/include/constants/maps.h", text);
493
     saveTextFile(root + "/include/constants/maps.h", text);
495
 }
494
 }
496
 
495
 
497
-void Project::getTilesets(Map* map) {
496
+void Project::loadMapTilesets(Map* map) {
498
     if (map->layout->has_unsaved_changes) {
497
     if (map->layout->has_unsaved_changes) {
499
         return;
498
         return;
500
     }
499
     }
955
     mapNamesToMapConstants->insert(map->name, map->constantName);
954
     mapNamesToMapConstants->insert(map->name, map->constantName);
956
     setNewMapHeader(map, mapLayoutsTable.size() + 1);
955
     setNewMapHeader(map, mapLayoutsTable.size() + 1);
957
     setNewMapLayout(map);
956
     setNewMapLayout(map);
958
-    getTilesets(map);
957
+    loadMapTilesets(map);
959
     setNewMapBlockdata(map);
958
     setNewMapBlockdata(map);
960
     setNewMapBorder(map);
959
     setNewMapBorder(map);
961
     setNewMapEvents(map);
960
     setNewMapEvents(map);
1001
     return names;
1000
     return names;
1002
 }
1001
 }
1003
 
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
+
1004
 QStringList Project::getWeathers() {
1044
 QStringList Project::getWeathers() {
1005
     // TODO
1045
     // TODO
1006
     QStringList names;
1046
     QStringList names;

+ 2
- 1
project.h View File

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

+ 9
- 4
tileset.cpp View File

2
 
2
 
3
 #include <QPainter>
3
 #include <QPainter>
4
 #include <QImage>
4
 #include <QImage>
5
+#include <QDebug>
5
 
6
 
6
 Tileset::Tileset()
7
 Tileset::Tileset()
7
 {
8
 {
43
         }
44
         }
44
 
45
 
45
         // Colorize the metatile tiles with its palette.
46
         // Colorize the metatile tiles with its palette.
46
-        QList<QRgb> palette = palettes.value(tile_.palette);
47
-        for (int j = 0; j < palette.length(); j++) {
48
-            tile_image.setColor(j, palette.value(j));
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;
49
         }
54
         }
50
 
55
 
51
         // The top layer of the metatile has its last color displayed at transparent.
56
         // The top layer of the metatile has its last color displayed at transparent.
105
     for (int i = 0; i < 6; i++) {
110
     for (int i = 0; i < 6; i++) {
106
         palettes.append(primaryTileset->palettes->at(i));
111
         palettes.append(primaryTileset->palettes->at(i));
107
     }
112
     }
108
-    for (int i = 6; i < secondaryTileset->palettes->length(); i++) {
113
+    for (int i = 6; i < 12; i++) {
109
         palettes.append(secondaryTileset->palettes->at(i));
114
         palettes.append(secondaryTileset->palettes->at(i));
110
     }
115
     }
111
     return palettes;
116
     return palettes;