Просмотр исходного кода

Add tileset comboboxes, and make metatile area scrollable

Marcus Huderle 6 лет назад
Родитель
Сommit
37529d37ec
4 измененных файлов: 234 добавлений и 91 удалений
  1. 6
    0
      mainwindow.cpp
  2. 182
    87
      mainwindow.ui
  3. 44
    3
      project.cpp
  4. 2
    1
      project.h

+ 6
- 0
mainwindow.cpp Просмотреть файл

@@ -222,6 +222,12 @@ void MainWindow::displayMapProperties() {
222 222
     ui->comboBox_Location->addItems(project->getLocations());
223 223
     ui->comboBox_Location->setCurrentText(map->location);
224 224
 
225
+    QMap<QString, QStringList> tilesets = project->getTilesets();
226
+    ui->comboBox_PrimaryTileset->addItems(tilesets.value("primary"));
227
+    ui->comboBox_PrimaryTileset->setCurrentText(map->layout->tileset_primary_label);
228
+    ui->comboBox_SecondaryTileset->addItems(tilesets.value("secondary"));
229
+    ui->comboBox_SecondaryTileset->setCurrentText(map->layout->tileset_secondary_label);
230
+
225 231
     ui->comboBox_Visibility->addItems(project->getVisibilities());
226 232
     ui->comboBox_Visibility->setCurrentText(map->visibility);
227 233
 

+ 182
- 87
mainwindow.ui Просмотреть файл

@@ -290,7 +290,7 @@
290 290
                     <rect>
291 291
                      <x>0</x>
292 292
                      <y>0</y>
293
-                     <width>475</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>
@@ -479,7 +619,7 @@
479 619
                       <x>0</x>
480 620
                       <y>0</y>
481 621
                       <width>358</width>
482
-                      <height>612</height>
622
+                      <height>497</height>
483 623
                      </rect>
484 624
                     </property>
485 625
                     <property name="sizePolicy">
@@ -488,7 +628,7 @@
488 628
                       <verstretch>0</verstretch>
489 629
                      </sizepolicy>
490 630
                     </property>
491
-                    <layout class="QGridLayout" name="gridLayout_5" rowstretch="0,0" columnstretch="0">
631
+                    <layout class="QGridLayout" name="gridLayout_5">
492 632
                      <property name="sizeConstraint">
493 633
                       <enum>QLayout::SetDefaultConstraint</enum>
494 634
                      </property>
@@ -504,97 +644,26 @@
504 644
                      <property name="bottomMargin">
505 645
                       <number>0</number>
506 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 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 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 659
                      </item>
591
-                     <item row="1" column="0">
660
+                     <item row="0" column="1">
592 661
                       <widget class="QGraphicsView" name="graphicsView_Metatiles">
593 662
                        <property name="enabled">
594 663
                         <bool>true</bool>
595 664
                        </property>
596 665
                        <property name="sizePolicy">
597
-                        <sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
666
+                        <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
598 667
                          <horstretch>0</horstretch>
599 668
                          <verstretch>0</verstretch>
600 669
                         </sizepolicy>
@@ -610,6 +679,32 @@
610 679
                        </property>
611 680
                       </widget>
612 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 708
                     </layout>
614 709
                    </widget>
615 710
                   </widget>

+ 44
- 3
project.cpp Просмотреть файл

@@ -354,7 +354,7 @@ void Project::readMapLayout(Map* map) {
354 354
         map->layout = mapLayouts[map->layout_label];
355 355
     }
356 356
 
357
-    getTilesets(map);
357
+    getMapTilesets(map);
358 358
     loadBlockdata(map);
359 359
     loadMapBorder(map);
360 360
 }
@@ -494,7 +494,7 @@ void Project::saveMapConstantsHeader() {
494 494
     saveTextFile(root + "/include/constants/maps.h", text);
495 495
 }
496 496
 
497
-void Project::getTilesets(Map* map) {
497
+void Project::getMapTilesets(Map* map) {
498 498
     if (map->layout->has_unsaved_changes) {
499 499
         return;
500 500
     }
@@ -955,7 +955,7 @@ Map* Project::addNewMapToGroup(QString mapName, int groupNum) {
955 955
     mapNamesToMapConstants->insert(map->name, map->constantName);
956 956
     setNewMapHeader(map, mapLayoutsTable.size() + 1);
957 957
     setNewMapLayout(map);
958
-    getTilesets(map);
958
+    getMapTilesets(map);
959 959
     setNewMapBlockdata(map);
960 960
     setNewMapBorder(map);
961 961
     setNewMapEvents(map);
@@ -1001,6 +1001,47 @@ QStringList Project::getVisibilities() {
1001 1001
     return names;
1002 1002
 }
1003 1003
 
1004
+QMap<QString, QStringList> Project::getTilesets() {
1005
+    QMap<QString, QStringList> allTilesets;
1006
+    QStringList primaryTilesets;
1007
+    QStringList secondaryTilesets;
1008
+    allTilesets.insert("primary", primaryTilesets);
1009
+    allTilesets.insert("secondary", secondaryTilesets);
1010
+    QString headers_text = readTextFile(root + "/data/tilesets/headers.inc");
1011
+    QList<QStringList>* commands = parseAsm(headers_text);
1012
+    int i = 0;
1013
+    while (i < commands->length()) {
1014
+        if (commands->at(i).length() != 2)
1015
+            continue;
1016
+
1017
+        if (commands->at(i).at(0) == ".label") {
1018
+            QString tilesetLabel = commands->at(i).at(1);
1019
+            // Advance to command specifying whether or not it is a secondary tileset
1020
+            i += 2;
1021
+            if (commands->at(i).at(0) != ".byte") {
1022
+                qDebug() << "Unexpected command found for secondary tileset flag. Expected '.byte', but found: " << commands->at(i).at(0);
1023
+                continue;
1024
+            }
1025
+
1026
+            QString secondaryTilesetValue = commands->at(i).at(1);
1027
+            if (secondaryTilesetValue != "TRUE" && secondaryTilesetValue != "FALSE" && secondaryTilesetValue != "0" && secondaryTilesetValue != "1") {
1028
+                qDebug() << "Unexpected secondary tileset flag found. Expected \"TRUE\", \"FALSE\", \"0\", or \"1\", but found: " << secondaryTilesetValue;
1029
+                continue;
1030
+            }
1031
+
1032
+            bool isSecondaryTileset = (secondaryTilesetValue == "TRUE" || secondaryTilesetValue == "1");
1033
+            if (isSecondaryTileset)
1034
+                allTilesets["secondary"].append(tilesetLabel);
1035
+            else
1036
+                allTilesets["primary"].append(tilesetLabel);
1037
+        }
1038
+
1039
+        i++;
1040
+    }
1041
+
1042
+    return allTilesets;
1043
+}
1044
+
1004 1045
 QStringList Project::getWeathers() {
1005 1046
     // TODO
1006 1047
     QStringList names;

+ 2
- 1
project.h Просмотреть файл

@@ -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 getMapTilesets(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();