Explorar el Código

Add menu to 'add event' button

Marcus Huderle hace 6 años
padre
commit
76649ea867
Se han modificado 11 ficheros con 197 adiciones y 42 borrados
  1. 1
    4
      editor.cpp
  2. 0
    1
      editor.h
  3. 8
    0
      event.cpp
  4. 12
    1
      event.h
  5. 13
    9
      mainwindow.cpp
  6. 1
    2
      mainwindow.h
  7. 8
    9
      mainwindow.ui
  8. 103
    0
      neweventtoolbutton.cpp
  9. 35
    0
      neweventtoolbutton.h
  10. 4
    2
      pretmap.pro
  11. 12
    14
      project.cpp

+ 1
- 4
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>
@@ -1297,10 +1298,6 @@ void Editor::selectMapEvent(DraggablePixmapItem *object, bool toggle) {
1297 1298
     }
1298 1299
 }
1299 1300
 
1300
-DraggablePixmapItem* Editor::addNewEvent() {
1301
-    return addNewEvent("object");
1302
-}
1303
-
1304 1301
 DraggablePixmapItem* Editor::addNewEvent(QString event_type) {
1305 1302
     if (project && map) {
1306 1303
         Event *event = new Event;

+ 0
- 1
editor.h Ver fichero

@@ -61,7 +61,6 @@ public:
61 61
     DraggablePixmapItem *addMapEvent(Event *event);
62 62
     void selectMapEvent(DraggablePixmapItem *object);
63 63
     void selectMapEvent(DraggablePixmapItem *object, bool toggle);
64
-    DraggablePixmapItem *addNewEvent();
65 64
     DraggablePixmapItem *addNewEvent(QString event_type);
66 65
     void deleteEvent(Event *);
67 66
     void updateSelectedEvents();

+ 8
- 0
event.cpp Ver fichero

@@ -1,5 +1,13 @@
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
 }

+ 12
- 1
event.h Ver fichero

@@ -5,11 +5,22 @@
5 5
 #include <QPixmap>
6 6
 #include <QMap>
7 7
 
8
+class EventType
9
+{
10
+public:
11
+    static QString Object;
12
+    static QString Warp;
13
+    static QString CoordScript;
14
+    static QString CoordWeather;
15
+    static QString Sign;
16
+    static QString HiddenItem;
17
+    static QString SecretBase;
18
+};
19
+
8 20
 class Event
9 21
 {
10 22
 public:
11 23
     Event();
12
-
13 24
 public:
14 25
     int x() {
15 26
         return getInt("x");

+ 13
- 9
mainwindow.cpp Ver fichero

@@ -24,6 +24,10 @@ 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);
@@ -503,10 +507,10 @@ void MainWindow::on_actionRedo_triggered()
503 507
     redo();
504 508
 }
505 509
 
506
-void MainWindow::on_toolButton_newObject_clicked()
510
+void MainWindow::addNewEvent(QString event_type)
507 511
 {
508 512
     if (editor) {
509
-        DraggablePixmapItem *object = editor->addNewEvent();
513
+        DraggablePixmapItem *object = editor->addNewEvent(event_type);
510 514
         if (object) {
511 515
             //if (editor->selected_events->length()) {
512 516
                 editor->selectMapEvent(object, true);
@@ -590,7 +594,7 @@ void MainWindow::updateSelectedObjects() {
590 594
 
591 595
         QStringList fields;
592 596
 
593
-        if (event_type == "object") {
597
+        if (event_type == EventType::Object) {
594 598
 
595 599
             frame->ui->sprite->setVisible(true);
596 600
             frame->ui->comboBox_sprite->addItems(event_obj_gfx_constants.keys());
@@ -616,27 +620,27 @@ void MainWindow::updateSelectedObjects() {
616 620
             fields << "property";
617 621
             fields << "sight_radius";
618 622
         }
619
-        else if (event_type == "warp") {
623
+        else if (event_type == EventType::Warp) {
620 624
             fields << "destination_warp";
621 625
             fields << "destination_map_name";
622 626
         }
623
-        else if (event_type == "trap") {
627
+        else if (event_type == EventType::CoordScript) {
624 628
             fields << "script_label";
625 629
             fields << "script_var";
626 630
             fields << "script_var_value";
627 631
         }
628
-        else if (event_type == "trap_weather") {
632
+        else if (event_type == EventType::CoordWeather) {
629 633
             fields << "weather";
630 634
         }
631
-        else if (event_type == "sign") {
635
+        else if (event_type == EventType::Sign) {
632 636
             fields << "type";
633 637
             fields << "script_label";
634 638
         }
635
-        else if (event_type == "event_hidden_item") {
639
+        else if (event_type == EventType::HiddenItem) {
636 640
             fields << "item";
637 641
             fields << "flag";
638 642
         }
639
-        else if (event_type == "event_secret_base") {
643
+        else if (event_type == EventType::SecretBase) {
640 644
             fields << "secret_base_map";
641 645
         }
642 646
 

+ 1
- 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();

+ 8
- 9
mainwindow.ui Ver fichero

@@ -60,7 +60,7 @@
60 60
         </sizepolicy>
61 61
        </property>
62 62
        <property name="currentIndex">
63
-        <number>0</number>
63
+        <number>1</number>
64 64
        </property>
65 65
        <property name="tabsClosable">
66 66
         <bool>false</bool>
@@ -904,13 +904,7 @@
904 904
                  <number>0</number>
905 905
                 </property>
906 906
                 <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>
907
+                 <widget class="NewEventToolButton" name="newEventToolButton">
914 908
                   <property name="minimumSize">
915 909
                    <size>
916 910
                     <width>40</width>
@@ -918,7 +912,7 @@
918 912
                    </size>
919 913
                   </property>
920 914
                   <property name="text">
921
-                   <string>New</string>
915
+                   <string>New Object</string>
922 916
                   </property>
923 917
                   <property name="icon">
924 918
                    <iconset resource="resources/images.qrc">
@@ -1794,6 +1788,11 @@
1794 1788
    <extends>QGraphicsView</extends>
1795 1789
    <header>graphicsview.h</header>
1796 1790
   </customwidget>
1791
+  <customwidget>
1792
+   <class>NewEventToolButton</class>
1793
+   <extends>QToolButton</extends>
1794
+   <header>neweventtoolbutton.h</header>
1795
+  </customwidget>
1797 1796
  </customwidgets>
1798 1797
  <resources>
1799 1798
   <include location="resources/images.qrc"/>

+ 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
- 2
pretmap.pro Ver fichero

@@ -25,7 +25,8 @@ SOURCES += main.cpp\
25 25
     editor.cpp \
26 26
     objectpropertiesframe.cpp \
27 27
     graphicsview.cpp \
28
-    parseutil.cpp
28
+    parseutil.cpp \
29
+    neweventtoolbutton.cpp
29 30
 
30 31
 HEADERS  += mainwindow.h \
31 32
     project.h \
@@ -39,7 +40,8 @@ HEADERS  += mainwindow.h \
39 40
     editor.h \
40 41
     objectpropertiesframe.h \
41 42
     graphicsview.h \
42
-    parseutil.h
43
+    parseutil.h \
44
+    neweventtoolbutton.h
43 45
 
44 46
 FORMS    += mainwindow.ui \
45 47
     objectpropertiesframe.ui

+ 12
- 14
project.cpp Ver fichero

@@ -1152,17 +1152,17 @@ void Project::loadEventPixmaps(QList<Event*> objects) {
1152 1152
             continue;
1153 1153
         }
1154 1154
         QString event_type = object->get("event_type");
1155
-        if (event_type == "object") {
1155
+        if (event_type == EventType::Object) {
1156 1156
             object->pixmap = QPixmap(":/images/Entities_16x16.png").copy(0, 0, 16, 16);
1157
-        } else if (event_type == "warp") {
1157
+        } else if (event_type == EventType::Warp) {
1158 1158
             object->pixmap = QPixmap(":/images/Entities_16x16.png").copy(16, 0, 16, 16);
1159
-        } else if (event_type == "trap" || event_type == "trap_weather") {
1159
+        } else if (event_type == EventType::CoordScript || event_type == EventType::CoordWeather) {
1160 1160
             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") {
1161
+        } else if (event_type == EventType::Sign || event_type == EventType::HiddenItem || event_type == EventType::SecretBase) {
1162 1162
             object->pixmap = QPixmap(":/images/Entities_16x16.png").copy(48, 0, 16, 16);
1163 1163
         }
1164 1164
 
1165
-        if (event_type == "object") {
1165
+        if (event_type == EventType::Object) {
1166 1166
             int sprite_id = constants.value(object->get("sprite"));
1167 1167
 
1168 1168
             QString info_label = pointers.value(sprite_id).replace("&", "");
@@ -1178,10 +1178,8 @@ void Project::loadEventPixmaps(QList<Event*> objects) {
1178 1178
                     object->pixmap = pixmap;
1179 1179
                 }
1180 1180
             }
1181
-
1182 1181
         }
1183 1182
     }
1184
-
1185 1183
 }
1186 1184
 
1187 1185
 void Project::saveMapEvents(Map *map) {
@@ -1331,7 +1329,7 @@ void Project::readMapEvents(Map *map) {
1331 1329
             object->put("script_label", command.value(i++));
1332 1330
             object->put("event_flag", command.value(i++));
1333 1331
 
1334
-            object->put("event_type", "object");
1332
+            object->put("event_type", EventType::Object);
1335 1333
             map->events["object"].append(object);
1336 1334
         }
1337 1335
     }
@@ -1352,7 +1350,7 @@ void Project::readMapEvents(Map *map) {
1352 1350
             QString mapConstant = command.value(i++);
1353 1351
             if (mapConstantsToMapNames->contains(mapConstant)) {
1354 1352
                 warp->put("destination_map_name", mapConstantsToMapNames->value(mapConstant));
1355
-                warp->put("event_type", "warp");
1353
+                warp->put("event_type", EventType::Warp);
1356 1354
                 map->events["warp"].append(warp);
1357 1355
             } else {
1358 1356
                 qDebug() << QString("Destination map constant '%1' is invalid for warp").arg(mapConstant);
@@ -1383,7 +1381,7 @@ void Project::readMapEvents(Map *map) {
1383 1381
             //coord_unknown3
1384 1382
             //coord_unknown4
1385 1383
 
1386
-            coord->put("event_type", "trap");
1384
+            coord->put("event_type", EventType::CoordScript);
1387 1385
             map->events["trap"].append(coord);
1388 1386
         } else if (command.value(0) == "coord_weather_event") {
1389 1387
             Event *coord = new Event;
@@ -1393,7 +1391,7 @@ void Project::readMapEvents(Map *map) {
1393 1391
             coord->put("y", command.value(i++));
1394 1392
             coord->put("elevation", command.value(i++));
1395 1393
             coord->put("weather", command.value(i++));
1396
-            coord->put("event_type", "trap_weather");
1394
+            coord->put("event_type", EventType::CoordWeather);
1397 1395
             map->events["trap_weather"].append(coord);
1398 1396
         }
1399 1397
     }
@@ -1414,7 +1412,7 @@ void Project::readMapEvents(Map *map) {
1414 1412
             i++;
1415 1413
             bg->put("script_label", command.value(i++));
1416 1414
             //sign_unknown7
1417
-            bg->put("event_type", "sign");
1415
+            bg->put("event_type", EventType::Sign);
1418 1416
             map->events["sign"].append(bg);
1419 1417
         } else if (command.value(0) == "bg_hidden_item_event") {
1420 1418
             Event *bg = new Event;
@@ -1425,7 +1423,7 @@ void Project::readMapEvents(Map *map) {
1425 1423
             bg->put("elevation", command.value(i++));
1426 1424
             bg->put("item", command.value(i++));
1427 1425
             bg->put("flag", command.value(i++));
1428
-            bg->put("event_type", "event_hidden_item");
1426
+            bg->put("event_type", EventType::HiddenItem);
1429 1427
             map->events["event_hidden_item"].append(bg);
1430 1428
         } else if (command.value(0) == "bg_secret_base_event") {
1431 1429
             Event *bg = new Event;
@@ -1435,7 +1433,7 @@ 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");
1436
+            bg->put("event_type", EventType::SecretBase);
1439 1437
             map->events["event_secret_base"].append(bg);
1440 1438
         }
1441 1439
     }