Browse Source

Add menu to 'add event' button

Marcus Huderle 5 years ago
parent
commit
76649ea867
11 changed files with 197 additions and 42 deletions
  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 View File

1
 #include "editor.h"
1
 #include "editor.h"
2
+#include "event.h"
2
 #include <QCheckBox>
3
 #include <QCheckBox>
3
 #include <QPainter>
4
 #include <QPainter>
4
 #include <QMouseEvent>
5
 #include <QMouseEvent>
1297
     }
1298
     }
1298
 }
1299
 }
1299
 
1300
 
1300
-DraggablePixmapItem* Editor::addNewEvent() {
1301
-    return addNewEvent("object");
1302
-}
1303
-
1304
 DraggablePixmapItem* Editor::addNewEvent(QString event_type) {
1301
 DraggablePixmapItem* Editor::addNewEvent(QString event_type) {
1305
     if (project && map) {
1302
     if (project && map) {
1306
         Event *event = new Event;
1303
         Event *event = new Event;

+ 0
- 1
editor.h View File

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

+ 8
- 0
event.cpp View File

1
 #include "event.h"
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
 Event::Event()
11
 Event::Event()
4
 {
12
 {
5
 }
13
 }

+ 12
- 1
event.h View File

5
 #include <QPixmap>
5
 #include <QPixmap>
6
 #include <QMap>
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
 class Event
20
 class Event
9
 {
21
 {
10
 public:
22
 public:
11
     Event();
23
     Event();
12
-
13
 public:
24
 public:
14
     int x() {
25
     int x() {
15
         return getInt("x");
26
         return getInt("x");

+ 13
- 9
mainwindow.cpp View File

24
     QCoreApplication::setApplicationName("pretmap");
24
     QCoreApplication::setApplicationName("pretmap");
25
 
25
 
26
     ui->setupUi(this);
26
     ui->setupUi(this);
27
+
28
+    ui->newEventToolButton->initButton();
29
+    connect(ui->newEventToolButton, SIGNAL(newEventAdded(QString)), this, SLOT(addNewEvent(QString)));
30
+
27
     new QShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Z), this, SLOT(redo()));
31
     new QShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Z), this, SLOT(redo()));
28
 
32
 
29
     editor = new Editor(ui);
33
     editor = new Editor(ui);
503
     redo();
507
     redo();
504
 }
508
 }
505
 
509
 
506
-void MainWindow::on_toolButton_newObject_clicked()
510
+void MainWindow::addNewEvent(QString event_type)
507
 {
511
 {
508
     if (editor) {
512
     if (editor) {
509
-        DraggablePixmapItem *object = editor->addNewEvent();
513
+        DraggablePixmapItem *object = editor->addNewEvent(event_type);
510
         if (object) {
514
         if (object) {
511
             //if (editor->selected_events->length()) {
515
             //if (editor->selected_events->length()) {
512
                 editor->selectMapEvent(object, true);
516
                 editor->selectMapEvent(object, true);
590
 
594
 
591
         QStringList fields;
595
         QStringList fields;
592
 
596
 
593
-        if (event_type == "object") {
597
+        if (event_type == EventType::Object) {
594
 
598
 
595
             frame->ui->sprite->setVisible(true);
599
             frame->ui->sprite->setVisible(true);
596
             frame->ui->comboBox_sprite->addItems(event_obj_gfx_constants.keys());
600
             frame->ui->comboBox_sprite->addItems(event_obj_gfx_constants.keys());
616
             fields << "property";
620
             fields << "property";
617
             fields << "sight_radius";
621
             fields << "sight_radius";
618
         }
622
         }
619
-        else if (event_type == "warp") {
623
+        else if (event_type == EventType::Warp) {
620
             fields << "destination_warp";
624
             fields << "destination_warp";
621
             fields << "destination_map_name";
625
             fields << "destination_map_name";
622
         }
626
         }
623
-        else if (event_type == "trap") {
627
+        else if (event_type == EventType::CoordScript) {
624
             fields << "script_label";
628
             fields << "script_label";
625
             fields << "script_var";
629
             fields << "script_var";
626
             fields << "script_var_value";
630
             fields << "script_var_value";
627
         }
631
         }
628
-        else if (event_type == "trap_weather") {
632
+        else if (event_type == EventType::CoordWeather) {
629
             fields << "weather";
633
             fields << "weather";
630
         }
634
         }
631
-        else if (event_type == "sign") {
635
+        else if (event_type == EventType::Sign) {
632
             fields << "type";
636
             fields << "type";
633
             fields << "script_label";
637
             fields << "script_label";
634
         }
638
         }
635
-        else if (event_type == "event_hidden_item") {
639
+        else if (event_type == EventType::HiddenItem) {
636
             fields << "item";
640
             fields << "item";
637
             fields << "flag";
641
             fields << "flag";
638
         }
642
         }
639
-        else if (event_type == "event_secret_base") {
643
+        else if (event_type == EventType::SecretBase) {
640
             fields << "secret_base_map";
644
             fields << "secret_base_map";
641
         }
645
         }
642
 
646
 

+ 1
- 2
mainwindow.h View File

56
 
56
 
57
     void on_actionRedo_triggered();
57
     void on_actionRedo_triggered();
58
 
58
 
59
-    void on_toolButton_newObject_clicked();
60
-
61
     void on_toolButton_deleteObject_clicked();
59
     void on_toolButton_deleteObject_clicked();
62
 
60
 
61
+    void addNewEvent(QString);
63
     void updateSelectedObjects();
62
     void updateSelectedObjects();
64
 
63
 
65
     void on_toolButton_Paint_clicked();
64
     void on_toolButton_Paint_clicked();

+ 8
- 9
mainwindow.ui View File

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

+ 103
- 0
neweventtoolbutton.cpp View File

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 View File

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 View File

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

+ 12
- 14
project.cpp View File

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