Add menu to 'add event' button
This commit is contained in:
parent
9c2cf84983
commit
76649ea867
11 changed files with 197 additions and 42 deletions
|
@ -1,4 +1,5 @@
|
|||
#include "editor.h"
|
||||
#include "event.h"
|
||||
#include <QCheckBox>
|
||||
#include <QPainter>
|
||||
#include <QMouseEvent>
|
||||
|
@ -1297,10 +1298,6 @@ void Editor::selectMapEvent(DraggablePixmapItem *object, bool toggle) {
|
|||
}
|
||||
}
|
||||
|
||||
DraggablePixmapItem* Editor::addNewEvent() {
|
||||
return addNewEvent("object");
|
||||
}
|
||||
|
||||
DraggablePixmapItem* Editor::addNewEvent(QString event_type) {
|
||||
if (project && map) {
|
||||
Event *event = new Event;
|
||||
|
|
1
editor.h
1
editor.h
|
@ -61,7 +61,6 @@ public:
|
|||
DraggablePixmapItem *addMapEvent(Event *event);
|
||||
void selectMapEvent(DraggablePixmapItem *object);
|
||||
void selectMapEvent(DraggablePixmapItem *object, bool toggle);
|
||||
DraggablePixmapItem *addNewEvent();
|
||||
DraggablePixmapItem *addNewEvent(QString event_type);
|
||||
void deleteEvent(Event *);
|
||||
void updateSelectedEvents();
|
||||
|
|
|
@ -1,5 +1,13 @@
|
|||
#include "event.h"
|
||||
|
||||
QString EventType::Object = "event_object";
|
||||
QString EventType::Warp = "event_warp";
|
||||
QString EventType::CoordScript = "event_trap";
|
||||
QString EventType::CoordWeather = "event_trap_weather";
|
||||
QString EventType::Sign = "event_sign";
|
||||
QString EventType::HiddenItem = "event_hidden_item";
|
||||
QString EventType::SecretBase = "event_secret_base";
|
||||
|
||||
Event::Event()
|
||||
{
|
||||
}
|
||||
|
|
13
event.h
13
event.h
|
@ -5,11 +5,22 @@
|
|||
#include <QPixmap>
|
||||
#include <QMap>
|
||||
|
||||
class EventType
|
||||
{
|
||||
public:
|
||||
static QString Object;
|
||||
static QString Warp;
|
||||
static QString CoordScript;
|
||||
static QString CoordWeather;
|
||||
static QString Sign;
|
||||
static QString HiddenItem;
|
||||
static QString SecretBase;
|
||||
};
|
||||
|
||||
class Event
|
||||
{
|
||||
public:
|
||||
Event();
|
||||
|
||||
public:
|
||||
int x() {
|
||||
return getInt("x");
|
||||
|
|
|
@ -24,6 +24,10 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
QCoreApplication::setApplicationName("pretmap");
|
||||
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->newEventToolButton->initButton();
|
||||
connect(ui->newEventToolButton, SIGNAL(newEventAdded(QString)), this, SLOT(addNewEvent(QString)));
|
||||
|
||||
new QShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Z), this, SLOT(redo()));
|
||||
|
||||
editor = new Editor(ui);
|
||||
|
@ -503,10 +507,10 @@ void MainWindow::on_actionRedo_triggered()
|
|||
redo();
|
||||
}
|
||||
|
||||
void MainWindow::on_toolButton_newObject_clicked()
|
||||
void MainWindow::addNewEvent(QString event_type)
|
||||
{
|
||||
if (editor) {
|
||||
DraggablePixmapItem *object = editor->addNewEvent();
|
||||
DraggablePixmapItem *object = editor->addNewEvent(event_type);
|
||||
if (object) {
|
||||
//if (editor->selected_events->length()) {
|
||||
editor->selectMapEvent(object, true);
|
||||
|
@ -590,7 +594,7 @@ void MainWindow::updateSelectedObjects() {
|
|||
|
||||
QStringList fields;
|
||||
|
||||
if (event_type == "object") {
|
||||
if (event_type == EventType::Object) {
|
||||
|
||||
frame->ui->sprite->setVisible(true);
|
||||
frame->ui->comboBox_sprite->addItems(event_obj_gfx_constants.keys());
|
||||
|
@ -616,27 +620,27 @@ void MainWindow::updateSelectedObjects() {
|
|||
fields << "property";
|
||||
fields << "sight_radius";
|
||||
}
|
||||
else if (event_type == "warp") {
|
||||
else if (event_type == EventType::Warp) {
|
||||
fields << "destination_warp";
|
||||
fields << "destination_map_name";
|
||||
}
|
||||
else if (event_type == "trap") {
|
||||
else if (event_type == EventType::CoordScript) {
|
||||
fields << "script_label";
|
||||
fields << "script_var";
|
||||
fields << "script_var_value";
|
||||
}
|
||||
else if (event_type == "trap_weather") {
|
||||
else if (event_type == EventType::CoordWeather) {
|
||||
fields << "weather";
|
||||
}
|
||||
else if (event_type == "sign") {
|
||||
else if (event_type == EventType::Sign) {
|
||||
fields << "type";
|
||||
fields << "script_label";
|
||||
}
|
||||
else if (event_type == "event_hidden_item") {
|
||||
else if (event_type == EventType::HiddenItem) {
|
||||
fields << "item";
|
||||
fields << "flag";
|
||||
}
|
||||
else if (event_type == "event_secret_base") {
|
||||
else if (event_type == EventType::SecretBase) {
|
||||
fields << "secret_base_map";
|
||||
}
|
||||
|
||||
|
|
|
@ -56,10 +56,9 @@ private slots:
|
|||
|
||||
void on_actionRedo_triggered();
|
||||
|
||||
void on_toolButton_newObject_clicked();
|
||||
|
||||
void on_toolButton_deleteObject_clicked();
|
||||
|
||||
void addNewEvent(QString);
|
||||
void updateSelectedObjects();
|
||||
|
||||
void on_toolButton_Paint_clicked();
|
||||
|
|
|
@ -60,7 +60,7 @@
|
|||
</sizepolicy>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="tabsClosable">
|
||||
<bool>false</bool>
|
||||
|
@ -904,13 +904,7 @@
|
|||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QToolButton" name="toolButton_newObject">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<widget class="NewEventToolButton" name="newEventToolButton">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>40</width>
|
||||
|
@ -918,7 +912,7 @@
|
|||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>New</string>
|
||||
<string>New Object</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="resources/images.qrc">
|
||||
|
@ -1794,6 +1788,11 @@
|
|||
<extends>QGraphicsView</extends>
|
||||
<header>graphicsview.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>NewEventToolButton</class>
|
||||
<extends>QToolButton</extends>
|
||||
<header>neweventtoolbutton.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="resources/images.qrc"/>
|
||||
|
|
103
neweventtoolbutton.cpp
Normal file
103
neweventtoolbutton.cpp
Normal file
|
@ -0,0 +1,103 @@
|
|||
#include "neweventtoolbutton.h"
|
||||
#include <QMenu>
|
||||
#include <QDebug>
|
||||
|
||||
// Custom QToolButton which has a context menu that expands to allow
|
||||
// selection of different types of map events.
|
||||
NewEventToolButton::NewEventToolButton(QWidget *parent) :
|
||||
QToolButton(parent)
|
||||
{
|
||||
setPopupMode(QToolButton::MenuButtonPopup);
|
||||
QObject::connect(this, SIGNAL(triggered(QAction*)),
|
||||
this, SLOT(setDefaultAction(QAction*)));
|
||||
}
|
||||
|
||||
void NewEventToolButton::initButton()
|
||||
{
|
||||
// Add a context menu to select different types of map events.
|
||||
this->newObjectAction = new QAction("New Object", this);
|
||||
this->newObjectAction->setIcon(QIcon(":/icons/add.ico"));
|
||||
connect(this->newObjectAction, SIGNAL(triggered(bool)), this, SLOT(newObject()));
|
||||
|
||||
this->newWarpAction = new QAction("New Warp", this);
|
||||
this->newWarpAction->setIcon(QIcon(":/icons/add.ico"));
|
||||
connect(this->newWarpAction, SIGNAL(triggered(bool)), this, SLOT(newWarp()));
|
||||
|
||||
this->newCoordScriptAction = new QAction("New Coord Script", this);
|
||||
this->newCoordScriptAction->setIcon(QIcon(":/icons/add.ico"));
|
||||
connect(this->newCoordScriptAction, SIGNAL(triggered(bool)), this, SLOT(newCoordScript()));
|
||||
|
||||
this->newCoordWeatherAction = new QAction("New Coord Weather", this);
|
||||
this->newCoordWeatherAction->setIcon(QIcon(":/icons/add.ico"));
|
||||
connect(this->newCoordWeatherAction, SIGNAL(triggered(bool)), this, SLOT(newCoordWeather()));
|
||||
|
||||
this->newSignAction = new QAction("New Sign", this);
|
||||
this->newSignAction->setIcon(QIcon(":/icons/add.ico"));
|
||||
connect(this->newSignAction, SIGNAL(triggered(bool)), this, SLOT(newSign()));
|
||||
|
||||
this->newHiddenItemAction = new QAction("New Hidden Item", this);
|
||||
this->newHiddenItemAction->setIcon(QIcon(":/icons/add.ico"));
|
||||
connect(this->newHiddenItemAction, SIGNAL(triggered(bool)), this, SLOT(newHiddenItem()));
|
||||
|
||||
this->newSecretBaseAction = new QAction("New Secret Base", this);
|
||||
this->newSecretBaseAction->setIcon(QIcon(":/icons/add.ico"));
|
||||
connect(this->newSecretBaseAction, SIGNAL(triggered(bool)), this, SLOT(newSecretBase()));
|
||||
|
||||
QMenu *alignMenu = new QMenu();
|
||||
alignMenu->addAction(this->newObjectAction);
|
||||
alignMenu->addAction(this->newWarpAction);
|
||||
alignMenu->addAction(this->newCoordScriptAction);
|
||||
alignMenu->addAction(this->newCoordWeatherAction);
|
||||
alignMenu->addAction(this->newSignAction);
|
||||
alignMenu->addAction(this->newHiddenItemAction);
|
||||
alignMenu->addAction(this->newSecretBaseAction);
|
||||
this->setMenu(alignMenu);
|
||||
this->setDefaultAction(this->newObjectAction);
|
||||
}
|
||||
|
||||
QString NewEventToolButton::getSelectedEventType()
|
||||
{
|
||||
return this->selectedEventType;
|
||||
}
|
||||
|
||||
void NewEventToolButton::newObject()
|
||||
{
|
||||
this->selectedEventType = EventType::Object;
|
||||
emit newEventAdded(this->selectedEventType);
|
||||
}
|
||||
|
||||
void NewEventToolButton::newWarp()
|
||||
{
|
||||
this->selectedEventType = EventType::Warp;
|
||||
emit newEventAdded(this->selectedEventType);
|
||||
}
|
||||
|
||||
void NewEventToolButton::newCoordScript()
|
||||
{
|
||||
this->selectedEventType = EventType::CoordScript;
|
||||
emit newEventAdded(this->selectedEventType);
|
||||
}
|
||||
|
||||
void NewEventToolButton::newCoordWeather()
|
||||
{
|
||||
this->selectedEventType = EventType::CoordWeather;
|
||||
emit newEventAdded(this->selectedEventType);
|
||||
}
|
||||
|
||||
void NewEventToolButton::newSign()
|
||||
{
|
||||
this->selectedEventType = EventType::Sign;
|
||||
emit newEventAdded(this->selectedEventType);
|
||||
}
|
||||
|
||||
void NewEventToolButton::newHiddenItem()
|
||||
{
|
||||
this->selectedEventType = EventType::HiddenItem;
|
||||
emit newEventAdded(this->selectedEventType);
|
||||
}
|
||||
|
||||
void NewEventToolButton::newSecretBase()
|
||||
{
|
||||
this->selectedEventType = EventType::SecretBase;
|
||||
emit newEventAdded(this->selectedEventType);
|
||||
}
|
35
neweventtoolbutton.h
Normal file
35
neweventtoolbutton.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
#ifndef NEWEVENTTOOLBUTTON_H
|
||||
#define NEWEVENTTOOLBUTTON_H
|
||||
|
||||
#include "event.h"
|
||||
#include <QToolButton>
|
||||
|
||||
class NewEventToolButton : public QToolButton
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit NewEventToolButton(QWidget *parent = 0);
|
||||
void initButton();
|
||||
QString getSelectedEventType();
|
||||
public slots:
|
||||
void newObject();
|
||||
void newWarp();
|
||||
void newCoordScript();
|
||||
void newCoordWeather();
|
||||
void newSign();
|
||||
void newHiddenItem();
|
||||
void newSecretBase();
|
||||
signals:
|
||||
void newEventAdded(QString);
|
||||
private:
|
||||
QString selectedEventType;
|
||||
QAction *newObjectAction;
|
||||
QAction *newWarpAction;
|
||||
QAction *newCoordScriptAction;
|
||||
QAction *newCoordWeatherAction;
|
||||
QAction *newSignAction;
|
||||
QAction *newHiddenItemAction;
|
||||
QAction *newSecretBaseAction;
|
||||
};
|
||||
|
||||
#endif // NEWEVENTTOOLBUTTON_H
|
|
@ -25,7 +25,8 @@ SOURCES += main.cpp\
|
|||
editor.cpp \
|
||||
objectpropertiesframe.cpp \
|
||||
graphicsview.cpp \
|
||||
parseutil.cpp
|
||||
parseutil.cpp \
|
||||
neweventtoolbutton.cpp
|
||||
|
||||
HEADERS += mainwindow.h \
|
||||
project.h \
|
||||
|
@ -39,7 +40,8 @@ HEADERS += mainwindow.h \
|
|||
editor.h \
|
||||
objectpropertiesframe.h \
|
||||
graphicsview.h \
|
||||
parseutil.h
|
||||
parseutil.h \
|
||||
neweventtoolbutton.h
|
||||
|
||||
FORMS += mainwindow.ui \
|
||||
objectpropertiesframe.ui
|
||||
|
|
26
project.cpp
26
project.cpp
|
@ -1152,17 +1152,17 @@ void Project::loadEventPixmaps(QList<Event*> objects) {
|
|||
continue;
|
||||
}
|
||||
QString event_type = object->get("event_type");
|
||||
if (event_type == "object") {
|
||||
if (event_type == EventType::Object) {
|
||||
object->pixmap = QPixmap(":/images/Entities_16x16.png").copy(0, 0, 16, 16);
|
||||
} else if (event_type == "warp") {
|
||||
} else if (event_type == EventType::Warp) {
|
||||
object->pixmap = QPixmap(":/images/Entities_16x16.png").copy(16, 0, 16, 16);
|
||||
} else if (event_type == "trap" || event_type == "trap_weather") {
|
||||
} else if (event_type == EventType::CoordScript || event_type == EventType::CoordWeather) {
|
||||
object->pixmap = QPixmap(":/images/Entities_16x16.png").copy(32, 0, 16, 16);
|
||||
} else if (event_type == "sign" || event_type == "event_hidden_item" || event_type == "event_secret_base") {
|
||||
} else if (event_type == EventType::Sign || event_type == EventType::HiddenItem || event_type == EventType::SecretBase) {
|
||||
object->pixmap = QPixmap(":/images/Entities_16x16.png").copy(48, 0, 16, 16);
|
||||
}
|
||||
|
||||
if (event_type == "object") {
|
||||
if (event_type == EventType::Object) {
|
||||
int sprite_id = constants.value(object->get("sprite"));
|
||||
|
||||
QString info_label = pointers.value(sprite_id).replace("&", "");
|
||||
|
@ -1178,10 +1178,8 @@ void Project::loadEventPixmaps(QList<Event*> objects) {
|
|||
object->pixmap = pixmap;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Project::saveMapEvents(Map *map) {
|
||||
|
@ -1331,7 +1329,7 @@ void Project::readMapEvents(Map *map) {
|
|||
object->put("script_label", command.value(i++));
|
||||
object->put("event_flag", command.value(i++));
|
||||
|
||||
object->put("event_type", "object");
|
||||
object->put("event_type", EventType::Object);
|
||||
map->events["object"].append(object);
|
||||
}
|
||||
}
|
||||
|
@ -1352,7 +1350,7 @@ void Project::readMapEvents(Map *map) {
|
|||
QString mapConstant = command.value(i++);
|
||||
if (mapConstantsToMapNames->contains(mapConstant)) {
|
||||
warp->put("destination_map_name", mapConstantsToMapNames->value(mapConstant));
|
||||
warp->put("event_type", "warp");
|
||||
warp->put("event_type", EventType::Warp);
|
||||
map->events["warp"].append(warp);
|
||||
} else {
|
||||
qDebug() << QString("Destination map constant '%1' is invalid for warp").arg(mapConstant);
|
||||
|
@ -1383,7 +1381,7 @@ void Project::readMapEvents(Map *map) {
|
|||
//coord_unknown3
|
||||
//coord_unknown4
|
||||
|
||||
coord->put("event_type", "trap");
|
||||
coord->put("event_type", EventType::CoordScript);
|
||||
map->events["trap"].append(coord);
|
||||
} else if (command.value(0) == "coord_weather_event") {
|
||||
Event *coord = new Event;
|
||||
|
@ -1393,7 +1391,7 @@ void Project::readMapEvents(Map *map) {
|
|||
coord->put("y", command.value(i++));
|
||||
coord->put("elevation", command.value(i++));
|
||||
coord->put("weather", command.value(i++));
|
||||
coord->put("event_type", "trap_weather");
|
||||
coord->put("event_type", EventType::CoordWeather);
|
||||
map->events["trap_weather"].append(coord);
|
||||
}
|
||||
}
|
||||
|
@ -1414,7 +1412,7 @@ void Project::readMapEvents(Map *map) {
|
|||
i++;
|
||||
bg->put("script_label", command.value(i++));
|
||||
//sign_unknown7
|
||||
bg->put("event_type", "sign");
|
||||
bg->put("event_type", EventType::Sign);
|
||||
map->events["sign"].append(bg);
|
||||
} else if (command.value(0) == "bg_hidden_item_event") {
|
||||
Event *bg = new Event;
|
||||
|
@ -1425,7 +1423,7 @@ void Project::readMapEvents(Map *map) {
|
|||
bg->put("elevation", command.value(i++));
|
||||
bg->put("item", command.value(i++));
|
||||
bg->put("flag", command.value(i++));
|
||||
bg->put("event_type", "event_hidden_item");
|
||||
bg->put("event_type", EventType::HiddenItem);
|
||||
map->events["event_hidden_item"].append(bg);
|
||||
} else if (command.value(0) == "bg_secret_base_event") {
|
||||
Event *bg = new Event;
|
||||
|
@ -1435,7 +1433,7 @@ void Project::readMapEvents(Map *map) {
|
|||
bg->put("y", command.value(i++));
|
||||
bg->put("elevation", command.value(i++));
|
||||
bg->put("secret_base_map", command.value(i++));
|
||||
bg->put("event_type", "event_secret_base");
|
||||
bg->put("event_type", EventType::SecretBase);
|
||||
map->events["event_secret_base"].append(bg);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue