Merge pull request #52 from huderlem/events

Events Editing
This commit is contained in:
yenatch 2018-07-07 15:11:38 -04:00 committed by GitHub
commit 10b6d3a0d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 537 additions and 191 deletions

View file

@ -1,4 +1,5 @@
#include "editor.h" #include "editor.h"
#include "event.h"
#include <QCheckBox> #include <QCheckBox>
#include <QPainter> #include <QPainter>
#include <QMouseEvent> #include <QMouseEvent>
@ -1297,15 +1298,10 @@ void Editor::selectMapEvent(DraggablePixmapItem *object, bool toggle) {
} }
} }
DraggablePixmapItem* Editor::addNewEvent() {
return addNewEvent("object");
}
DraggablePixmapItem* Editor::addNewEvent(QString event_type) { DraggablePixmapItem* Editor::addNewEvent(QString event_type) {
if (project && map) { if (project && map) {
Event *event = new Event; Event *event = Event::createNewEvent(event_type, map->name);
event->put("map_name", map->name); event->put("map_name", map->name);
event->put("event_type", event_type);
map->addEvent(event); map->addEvent(event);
project->loadEventPixmaps(map->getAllEvents()); project->loadEventPixmaps(map->getAllEvents());
DraggablePixmapItem *object = addMapEvent(event); DraggablePixmapItem *object = addMapEvent(event);
@ -1324,7 +1320,6 @@ void Editor::deleteEvent(Event *event) {
//updateSelectedObjects(); //updateSelectedObjects();
} }
// dunno how to detect bubbling. QMouseEvent::isAccepted seems to always be true // dunno how to detect bubbling. QMouseEvent::isAccepted seems to always be true
// check if selected_events changed instead. this has the side effect of deselecting // check if selected_events changed instead. this has the side effect of deselecting
// when you click on a selected event, since selected_events doesn't change. // when you click on a selected event, since selected_events doesn't change.

View file

@ -61,8 +61,8 @@ public:
DraggablePixmapItem *addMapEvent(Event *event); DraggablePixmapItem *addMapEvent(Event *event);
void selectMapEvent(DraggablePixmapItem *object); void selectMapEvent(DraggablePixmapItem *object);
void selectMapEvent(DraggablePixmapItem *object, bool toggle); void selectMapEvent(DraggablePixmapItem *object, bool toggle);
DraggablePixmapItem *addNewEvent();
DraggablePixmapItem *addNewEvent(QString event_type); DraggablePixmapItem *addNewEvent(QString event_type);
Event* createNewEvent(QString event_type);
void deleteEvent(Event *); void deleteEvent(Event *);
void updateSelectedEvents(); void updateSelectedEvents();
void redrawObject(DraggablePixmapItem *item); void redrawObject(DraggablePixmapItem *item);
@ -108,6 +108,13 @@ private:
void updateMirroredConnectionDirection(Connection*, QString); void updateMirroredConnectionDirection(Connection*, QString);
void updateMirroredConnectionMap(Connection*, QString); void updateMirroredConnectionMap(Connection*, QString);
void updateMirroredConnection(Connection*, QString, QString, bool isDelete = false); void updateMirroredConnection(Connection*, QString, QString, bool isDelete = false);
Event* createNewObjectEvent();
Event* createNewWarpEvent();
Event* createNewCoordScriptEvent();
Event* createNewCoordWeatherEvent();
Event* createNewSignEvent();
Event* createNewHiddenItemEvent();
Event* createNewSecretBaseEvent();
private slots: private slots:
void mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item); void mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item);
@ -166,7 +173,7 @@ public:
emit spriteChanged(event->pixmap); emit spriteChanged(event->pixmap);
} }
void bind(QComboBox *combo, QString key) { void bind(QComboBox *combo, QString key) {
connect(combo, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::activated), connect(combo, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentTextChanged),
this, [this, key](QString value){ this, [this, key](QString value){
this->event->put(key, value); this->event->put(key, value);
}); });

208
event.cpp
View file

@ -1,5 +1,213 @@
#include "event.h" #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() Event::Event()
{ {
} }
Event* Event::createNewEvent(QString event_type, QString map_name)
{
Event *event;
if (event_type == EventType::Object) {
event = createNewObjectEvent();
} else if (event_type == EventType::Warp) {
event = createNewWarpEvent(map_name);
} else if (event_type == EventType::CoordScript) {
event = createNewCoordScriptEvent();
} else if (event_type == EventType::CoordWeather) {
event = createNewCoordWeatherEvent();
} else if (event_type == EventType::Sign) {
event = createNewSignEvent();
} else if (event_type == EventType::HiddenItem) {
event = createNewHiddenItemEvent();
} else if (event_type == EventType::SecretBase) {
event = createNewSecretBaseEvent();
}
event->setX(0);
event->setY(0);
event->put("elevation", 3);
return event;
}
Event* Event::createNewObjectEvent()
{
Event *event = new Event;
event->put("event_group_type", "object_event_group");
event->put("event_type", EventType::Object);
event->put("sprite", "EVENT_OBJ_GFX_BOY_1");
event->put("behavior", "1");
event->put("radius_x", 0);
event->put("radius_y", 0);
event->put("script_label", "NULL");
event->put("event_flag", "0");
event->put("replacement", "0");
event->put("trainer_see_type", "0");
event->put("sight_radius_tree_id", 0);
return event;
}
Event* Event::createNewWarpEvent(QString map_name)
{
Event *event = new Event;
event->put("event_group_type", "warp_event_group");
event->put("event_type", EventType::Warp);
event->put("destination_warp", 0);
event->put("destination_map_name", map_name);
return event;
}
Event* Event::createNewCoordScriptEvent()
{
Event *event = new Event;
event->put("event_group_type", "coord_event_group");
event->put("event_type", EventType::CoordScript);
event->put("script_label", "NULL");
event->put("script_var", "VAR_TEMP_0");
event->put("script_var_value", "0");
return event;
}
Event* Event::createNewCoordWeatherEvent()
{
Event *event = new Event;
event->put("event_group_type", "coord_event_group");
event->put("event_type", EventType::CoordWeather);
event->put("weather", "COORD_EVENT_WEATHER_SUNNY");
return event;
}
Event* Event::createNewSignEvent()
{
Event *event = new Event;
event->put("event_group_type", "bg_event_group");
event->put("event_type", EventType::Sign);
event->put("player_facing_direction", "0");
event->put("script_label", "NULL");
return event;
}
Event* Event::createNewHiddenItemEvent()
{
Event *event = new Event;
event->put("event_group_type", "bg_event_group");
event->put("event_type", EventType::HiddenItem);
event->put("item", "ITEM_POTION");
event->put("flag", "FLAG_HIDDEN_ITEM_0");
return event;
}
Event* Event::createNewSecretBaseEvent()
{
Event *event = new Event;
event->put("event_group_type", "bg_event_group");
event->put("event_type", EventType::SecretBase);
event->put("secret_base_map", "SECRET_BASE_RED_CAVE2_1");
return event;
}
QString Event::buildObjectEventMacro(int item_index)
{
int radius_x = this->getInt("radius_x");
int radius_y = this->getInt("radius_y");
uint16_t x = this->getInt("x");
uint16_t y = this->getInt("y");
QString text = "";
text += QString("\tobject_event %1").arg(item_index + 1);
text += QString(", %1").arg(this->get("sprite"));
text += QString(", %1").arg(this->get("replacement"));
text += QString(", %1").arg(x);
text += QString(", %1").arg(y);
text += QString(", %1").arg(this->get("elevation"));
text += QString(", %1").arg(this->get("behavior"));
text += QString(", %1").arg(radius_x);
text += QString(", %1").arg(radius_y);
text += QString(", %1").arg(this->get("trainer_see_type"));
text += QString(", %1").arg(this->get("sight_radius_tree_id"));
text += QString(", %1").arg(this->get("script_label"));
text += QString(", %1").arg(this->get("event_flag"));
text += "\n";
return text;
}
QString Event::buildWarpEventMacro(QMap<QString, QString> *mapNamesToMapConstants)
{
QString text = "";
text += QString("\twarp_def %1").arg(this->get("x"));
text += QString(", %1").arg(this->get("y"));
text += QString(", %1").arg(this->get("elevation"));
text += QString(", %1").arg(this->get("destination_warp"));
text += QString(", %1").arg(mapNamesToMapConstants->value(this->get("destination_map_name")));
text += "\n";
return text;
}
QString Event::buildCoordScriptEventMacro()
{
QString text = "";
text += QString("\tcoord_event %1").arg(this->get("x"));
text += QString(", %1").arg(this->get("y"));
text += QString(", %1").arg(this->get("elevation"));
text += QString(", 0");
text += QString(", %1").arg(this->get("script_var"));
text += QString(", %1").arg(this->get("script_var_value"));
text += QString(", 0");
text += QString(", %1").arg(this->get("script_label"));
text += "\n";
return text;
}
QString Event::buildCoordWeatherEventMacro()
{
QString text = "";
text += QString("\tcoord_weather_event %1").arg(this->get("x"));
text += QString(", %1").arg(this->get("y"));
text += QString(", %1").arg(this->get("elevation"));
text += QString(", %1").arg(this->get("weather"));
text += "\n";
return text;
}
QString Event::buildSignEventMacro()
{
QString text = "";
text += QString("\tbg_event %1").arg(this->get("x"));
text += QString(", %1").arg(this->get("y"));
text += QString(", %1").arg(this->get("elevation"));
text += QString(", %1").arg(this->get("player_facing_direction"));
text += QString(", 0");
text += QString(", %1").arg(this->get("script_label"));
text += "\n";
return text;
}
QString Event::buildHiddenItemEventMacro()
{
QString text = "";
text += QString("\tbg_hidden_item_event %1").arg(this->get("x"));
text += QString(", %1").arg(this->get("y"));
text += QString(", %1").arg(this->get("elevation"));
text += QString(", %1").arg(this->get("item"));
text += QString(", %1").arg(this->get("flag"));
text += "\n";
return text;
}
QString Event::buildSecretBaseEventMacro()
{
QString text = "";
text += QString("\tbg_secret_base_event %1").arg(this->get("x"));
text += QString(", %1").arg(this->get("y"));
text += QString(", %1").arg(this->get("elevation"));
text += QString(", %1").arg(this->get("secret_base_map"));
text += "\n";
return text;
}

31
event.h
View file

@ -4,12 +4,24 @@
#include <QString> #include <QString>
#include <QPixmap> #include <QPixmap>
#include <QMap> #include <QMap>
#include <QDebug>
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 class Event
{ {
public: public:
Event(); Event();
public: public:
int x() { int x() {
return getInt("x"); return getInt("x");
@ -39,6 +51,23 @@ public:
values.insert(key, value); values.insert(key, value);
} }
static Event* createNewEvent(QString, QString);
static Event* createNewObjectEvent();
static Event* createNewWarpEvent(QString);
static Event* createNewCoordScriptEvent();
static Event* createNewCoordWeatherEvent();
static Event* createNewSignEvent();
static Event* createNewHiddenItemEvent();
static Event* createNewSecretBaseEvent();
QString buildObjectEventMacro(int);
QString buildWarpEventMacro(QMap<QString, QString>*);
QString buildCoordScriptEventMacro();
QString buildCoordWeatherEventMacro();
QString buildSignEventMacro();
QString buildHiddenItemEventMacro();
QString buildSecretBaseEventMacro();
QMap<QString, QString> values; QMap<QString, QString> values;
QPixmap pixmap; QPixmap pixmap;
}; };

View file

@ -24,6 +24,10 @@ MainWindow::MainWindow(QWidget *parent) :
QCoreApplication::setApplicationName("pretmap"); QCoreApplication::setApplicationName("pretmap");
ui->setupUi(this); 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())); new QShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Z), this, SLOT(redo()));
editor = new Editor(ui); editor = new Editor(ui);
@ -503,14 +507,12 @@ void MainWindow::on_actionRedo_triggered()
redo(); redo();
} }
void MainWindow::on_toolButton_newObject_clicked() void MainWindow::addNewEvent(QString event_type)
{ {
if (editor) { if (editor) {
DraggablePixmapItem *object = editor->addNewEvent(); DraggablePixmapItem *object = editor->addNewEvent(event_type);
if (object) { if (object) {
//if (editor->selected_events->length()) { editor->selectMapEvent(object, false);
editor->selectMapEvent(object, true);
//}
} }
updateSelectedObjects(); updateSelectedObjects();
} }
@ -554,12 +556,13 @@ void MainWindow::updateSelectedObjects() {
font.setCapitalization(QFont::Capitalize); font.setCapitalization(QFont::Capitalize);
frame->ui->label_name->setFont(font); frame->ui->label_name->setFont(font);
QString event_type = item->event->get("event_type"); QString event_type = item->event->get("event_type");
QString event_group_type = item->event->get("event_group_type");
QString map_name = item->event->get("map_name"); QString map_name = item->event->get("map_name");
frame->ui->label_name->setText( frame->ui->label_name->setText(
QString("%1 %2 %3") QString("%1: %2 %3")
.arg(editor->project->getMap(map_name)->events.value(event_group_type).indexOf(item->event) + 1)
.arg(map_name) .arg(map_name)
.arg(event_type) .arg(event_type)
.arg(editor->project->getMap(map_name)->events.value(event_type).indexOf(item->event) + 1)
); );
frame->ui->label_spritePixmap->setPixmap(item->event->pixmap); frame->ui->label_spritePixmap->setPixmap(item->event->pixmap);
@ -574,13 +577,13 @@ void MainWindow::updateSelectedObjects() {
field_labels["behavior"] = "Behavior"; field_labels["behavior"] = "Behavior";
field_labels["radius_x"] = "Movement Radius X"; field_labels["radius_x"] = "Movement Radius X";
field_labels["radius_y"] = "Movement Radius Y"; field_labels["radius_y"] = "Movement Radius Y";
field_labels["property"] = "Property"; field_labels["trainer_see_type"] = "Trainer See Type";
field_labels["sight_radius"] = "Sight Radius"; field_labels["sight_radius_tree_id"] = "Sight Radius / Berry Tree ID";
field_labels["destination_warp"] = "Destination Warp"; field_labels["destination_warp"] = "Destination Warp";
field_labels["destination_map_name"] = "Destination Map"; field_labels["destination_map_name"] = "Destination Map";
field_labels["script_var"] = "Var"; field_labels["script_var"] = "Var";
field_labels["script_var_value"] = "Var Value"; field_labels["script_var_value"] = "Var Value";
field_labels["type"] = "Type"; field_labels["player_facing_direction"] = "Player Facing Direction";
field_labels["item"] = "Item"; field_labels["item"] = "Item";
field_labels["item_unknown5"] = "Unknown 5"; field_labels["item_unknown5"] = "Unknown 5";
field_labels["item_unknown6"] = "Unknown 6"; field_labels["item_unknown6"] = "Unknown 6";
@ -590,7 +593,7 @@ void MainWindow::updateSelectedObjects() {
QStringList fields; QStringList fields;
if (event_type == "object") { if (event_type == EventType::Object) {
frame->ui->sprite->setVisible(true); frame->ui->sprite->setVisible(true);
frame->ui->comboBox_sprite->addItems(event_obj_gfx_constants.keys()); frame->ui->comboBox_sprite->addItems(event_obj_gfx_constants.keys());
@ -613,30 +616,30 @@ void MainWindow::updateSelectedObjects() {
fields << "script_label"; fields << "script_label";
fields << "event_flag"; fields << "event_flag";
fields << "replacement"; fields << "replacement";
fields << "property"; fields << "trainer_see_type";
fields << "sight_radius"; fields << "sight_radius_tree_id";
} }
else if (event_type == "warp") { else if (event_type == EventType::Warp) {
fields << "destination_warp"; fields << "destination_warp";
fields << "destination_map_name"; fields << "destination_map_name";
} }
else if (event_type == "trap") { else if (event_type == EventType::CoordScript) {
fields << "script_label"; fields << "script_label";
fields << "script_var"; fields << "script_var";
fields << "script_var_value"; fields << "script_var_value";
} }
else if (event_type == "trap_weather") { else if (event_type == EventType::CoordWeather) {
fields << "weather"; fields << "weather";
} }
else if (event_type == "sign") { else if (event_type == EventType::Sign) {
fields << "type"; fields << "player_facing_direction";
fields << "script_label"; fields << "script_label";
} }
else if (event_type == "event_hidden_item") { else if (event_type == EventType::HiddenItem) {
fields << "item"; fields << "item";
fields << "flag"; fields << "flag";
} }
else if (event_type == "event_secret_base") { else if (event_type == EventType::SecretBase) {
fields << "secret_base_map"; fields << "secret_base_map";
} }

View file

@ -56,10 +56,9 @@ private slots:
void on_actionRedo_triggered(); void on_actionRedo_triggered();
void on_toolButton_newObject_clicked();
void on_toolButton_deleteObject_clicked(); void on_toolButton_deleteObject_clicked();
void addNewEvent(QString);
void updateSelectedObjects(); void updateSelectedObjects();
void on_toolButton_Paint_clicked(); void on_toolButton_Paint_clicked();

View file

@ -60,7 +60,7 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>1</number>
</property> </property>
<property name="tabsClosable"> <property name="tabsClosable">
<bool>false</bool> <bool>false</bool>
@ -904,13 +904,7 @@
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<widget class="QToolButton" name="toolButton_newObject"> <widget class="NewEventToolButton" name="newEventToolButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>40</width> <width>40</width>
@ -918,7 +912,7 @@
</size> </size>
</property> </property>
<property name="text"> <property name="text">
<string>New</string> <string>New Object</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="resources/images.qrc"> <iconset resource="resources/images.qrc">
@ -1794,6 +1788,11 @@
<extends>QGraphicsView</extends> <extends>QGraphicsView</extends>
<header>graphicsview.h</header> <header>graphicsview.h</header>
</customwidget> </customwidget>
<customwidget>
<class>NewEventToolButton</class>
<extends>QToolButton</extends>
<header>neweventtoolbutton.h</header>
</customwidget>
</customwidgets> </customwidgets>
<resources> <resources>
<include location="resources/images.qrc"/> <include location="resources/images.qrc"/>

27
map.cpp
View file

@ -31,6 +31,26 @@ QString Map::mapConstantFromName(QString mapName) {
return constantName; return constantName;
} }
QString Map::objectEventsLabelFromName(QString mapName)
{
return QString("%1_EventObjects").arg(mapName);
}
QString Map::warpEventsLabelFromName(QString mapName)
{
return QString("%1_MapWarps").arg(mapName);
}
QString Map::coordEventsLabelFromName(QString mapName)
{
return QString("%1_MapCoordEvents").arg(mapName);
}
QString Map::bgEventsLabelFromName(QString mapName)
{
return QString("%1_MapBGEvents").arg(mapName);
}
int Map::getWidth() { int Map::getWidth() {
return layout->width.toInt(nullptr, 0); return layout->width.toInt(nullptr, 0);
} }
@ -733,11 +753,6 @@ QList<Event *> Map::getAllEvents() {
return all; return all;
} }
QList<Event *> Map::getEventsByType(QString type)
{
return events.value(type);
}
void Map::removeEvent(Event *event) { void Map::removeEvent(Event *event) {
for (QString key : events.keys()) { for (QString key : events.keys()) {
events[key].removeAll(event); events[key].removeAll(event);
@ -745,7 +760,7 @@ void Map::removeEvent(Event *event) {
} }
void Map::addEvent(Event *event) { void Map::addEvent(Event *event) {
events[event->get("event_type")].append(event); events[event->get("event_group_type")].append(event);
} }
bool Map::hasUnsavedChanges() { bool Map::hasUnsavedChanges() {

16
map.h
View file

@ -129,12 +129,16 @@ public:
public: public:
void setName(QString mapName); void setName(QString mapName);
static QString mapConstantFromName(QString mapName); static QString mapConstantFromName(QString mapName);
static QString objectEventsLabelFromName(QString mapName);
static QString warpEventsLabelFromName(QString mapName);
static QString coordEventsLabelFromName(QString mapName);
static QString bgEventsLabelFromName(QString mapName);
int getWidth(); int getWidth();
int getHeight(); int getHeight();
Tileset* getBlockTileset(int); Tileset* getBlockTileset(int);
int getBlockIndex(int layout_id); int getBlockIndex(int);
int getSelectedBlockIndex(int layout_id); int getSelectedBlockIndex(int);
int getDisplayedBlockIndex(int layout_id); int getDisplayedBlockIndex(int);
Metatile* getMetatile(int); Metatile* getMetatile(int);
QImage getMetatileImage(int); QImage getMetatileImage(int);
QImage getMetatileTile(int); QImage getMetatileTile(int);
@ -188,13 +192,7 @@ public:
void redo(); void redo();
void commit(); void commit();
QString object_events_label;
QString warps_label;
QString coord_events_label;
QString bg_events_label;
QList<Event*> getAllEvents(); QList<Event*> getAllEvents();
QList<Event*> getEventsByType(QString type);
void removeEvent(Event *event); void removeEvent(Event *event);
void addEvent(Event *event); void addEvent(Event *event);
QMap<QString, QList<Event*>> events; QMap<QString, QList<Event*>> events;

103
neweventtoolbutton.cpp Normal file
View 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
View 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

View file

@ -25,7 +25,8 @@ SOURCES += main.cpp\
editor.cpp \ editor.cpp \
objectpropertiesframe.cpp \ objectpropertiesframe.cpp \
graphicsview.cpp \ graphicsview.cpp \
parseutil.cpp parseutil.cpp \
neweventtoolbutton.cpp
HEADERS += mainwindow.h \ HEADERS += mainwindow.h \
project.h \ project.h \
@ -39,7 +40,8 @@ HEADERS += mainwindow.h \
editor.h \ editor.h \
objectpropertiesframe.h \ objectpropertiesframe.h \
graphicsview.h \ graphicsview.h \
parseutil.h parseutil.h \
neweventtoolbutton.h
FORMS += mainwindow.ui \ FORMS += mainwindow.ui \
objectpropertiesframe.ui objectpropertiesframe.ui

View file

@ -1152,17 +1152,17 @@ void Project::loadEventPixmaps(QList<Event*> objects) {
continue; continue;
} }
QString event_type = object->get("event_type"); 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); 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); 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); 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); 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")); int sprite_id = constants.value(object->get("sprite"));
QString info_label = pointers.value(sprite_id).replace("&", ""); QString info_label = pointers.value(sprite_id).replace("&", "");
@ -1178,117 +1178,74 @@ void Project::loadEventPixmaps(QList<Event*> objects) {
object->pixmap = pixmap; object->pixmap = pixmap;
} }
} }
} }
} }
} }
void Project::saveMapEvents(Map *map) { void Project::saveMapEvents(Map *map) {
QString path = root + QString("/data/maps/%1/events.inc").arg(map->name); QString path = root + QString("/data/maps/%1/events.inc").arg(map->name);
QString text = ""; QString text = "";
QString objectEventsLabel = "0x0";
QString warpEventsLabel = "0x0";
QString coordEventsLabel = "0x0";
QString bgEventsLabel = "0x0";
if (map->events["object"].length() > 0) { if (map->events["object_event_group"].length() > 0) {
text += QString("%1::\n").arg(map->object_events_label); objectEventsLabel = Map::objectEventsLabelFromName(map->name);
for (int i = 0; i < map->events["object"].length(); i++) { text += QString("%1::\n").arg(objectEventsLabel);
Event *object_event = map->events["object"].value(i); for (int i = 0; i < map->events["object_event_group"].length(); i++) {
int radius_x = object_event->getInt("radius_x"); Event *object_event = map->events["object_event_group"].value(i);
int radius_y = object_event->getInt("radius_y"); text += object_event->buildObjectEventMacro(i);
uint16_t x = object_event->getInt("x");
uint16_t y = object_event->getInt("y");
text += QString("\tobject_event %1").arg(i + 1);
text += QString(", %1").arg(object_event->get("sprite"));
text += QString(", %1").arg(object_event->get("replacement"));
text += QString(", %1").arg(x);
text += QString(", %1").arg(y);
text += QString(", %1").arg(object_event->get("elevation"));
text += QString(", %1").arg(object_event->get("behavior"));
text += QString(", %1").arg(radius_x);
text += QString(", %1").arg(radius_y);
text += QString(", %1").arg(object_event->get("property"));
text += QString(", %1").arg(object_event->get("sight_radius"));
text += QString(", %1").arg(object_event->get("script_label"));
text += QString(", %1").arg(object_event->get("event_flag"));
text += "\n";
} }
text += "\n"; text += "\n";
} }
if (map->events["warp"].length() > 0) { if (map->events["warp_event_group"].length() > 0) {
text += QString("%1::\n").arg(map->warps_label); warpEventsLabel = Map::warpEventsLabelFromName(map->name);
for (Event *warp : map->events["warp"]) { text += QString("%1::\n").arg(warpEventsLabel);
text += QString("\twarp_def %1").arg(warp->get("x")); for (Event *warp : map->events["warp_event_group"]) {
text += QString(", %1").arg(warp->get("y")); text += warp->buildWarpEventMacro(mapNamesToMapConstants);
text += QString(", %1").arg(warp->get("elevation"));
text += QString(", %1").arg(warp->get("destination_warp"));
text += QString(", %1").arg(mapNamesToMapConstants->value(warp->get("destination_map_name")));
text += "\n";
} }
text += "\n"; text += "\n";
} }
if (map->events["trap"].length() + map->events["trap_weather"].length() > 0) { if (map->events["coord_event_group"].length() > 0) {
text += QString("%1::\n").arg(map->coord_events_label); coordEventsLabel = Map::coordEventsLabelFromName(map->name);
for (Event *coords : map->events["trap"]) { text += QString("%1::\n").arg(coordEventsLabel);
text += QString("\tcoord_event %1").arg(coords->get("x")); for (Event *event : map->events["coord_event_group"]) {
text += QString(", %1").arg(coords->get("y")); QString event_type = event->get("event_type");
text += QString(", %1").arg(coords->get("elevation")); if (event_type == EventType::CoordScript) {
text += QString(", 0"); text += event->buildCoordScriptEventMacro();
text += QString(", %1").arg(coords->get("script_var")); } else if (event_type == EventType::CoordWeather) {
text += QString(", %1").arg(coords->get("script_var_value")); text += event->buildCoordWeatherEventMacro();
text += QString(", 0");
text += QString(", %1").arg(coords->get("script_label"));
text += "\n";
} }
for (Event *coords : map->events["trap_weather"]) {
text += QString("\tcoord_weather_event %1").arg(coords->get("x"));
text += QString(", %1").arg(coords->get("y"));
text += QString(", %1").arg(coords->get("elevation"));
text += QString(", %1").arg(coords->get("weather"));
text += "\n";
} }
text += "\n"; text += "\n";
} }
if (map->events["sign"].length() + if (map->events["bg_event_group"].length() > 0)
map->events["event_hidden_item"].length() +
map->events["event_secret_base"].length() > 0)
{ {
text += QString("%1::\n").arg(map->bg_events_label); bgEventsLabel = Map::bgEventsLabelFromName(map->name);
for (Event *sign : map->events["sign"]) { text += QString("%1::\n").arg(bgEventsLabel);
text += QString("\tbg_event %1").arg(sign->get("x")); for (Event *event : map->events["bg_event_group"]) {
text += QString(", %1").arg(sign->get("y")); QString event_type = event->get("event_type");
text += QString(", %1").arg(sign->get("elevation")); if (event_type == EventType::Sign) {
text += QString(", %1").arg(sign->get("type")); text += event->buildSignEventMacro();
text += QString(", 0"); } else if (event_type == EventType::HiddenItem) {
text += QString(", %1").arg(sign->get("script_label")); text += event->buildHiddenItemEventMacro();
text += "\n"; } else if (event_type == EventType::SecretBase) {
text += event->buildSecretBaseEventMacro();
} }
for (Event *item : map->events["event_hidden_item"]) {
text += QString("\tbg_hidden_item_event %1").arg(item->get("x"));
text += QString(", %1").arg(item->get("y"));
text += QString(", %1").arg(item->get("elevation"));
text += QString(", %1").arg(item->get("item"));
text += QString(", %1").arg(item->get("flag"));
text += "\n";
}
for (Event *item : map->events["event_secret_base"]) {
text += QString("\tbg_secret_base_event %1").arg(item->get("x"));
text += QString(", %1").arg(item->get("y"));
text += QString(", %1").arg(item->get("elevation"));
text += QString(", %1").arg(item->get("secret_base_map"));
text += "\n";
} }
text += "\n"; text += "\n";
} }
text += QString("%1::\n").arg(map->events_label); text += QString("%1::\n").arg(map->events_label);
text += QString("\tmap_events %1, %2, %3, %4\n") text += QString("\tmap_events %1, %2, %3, %4\n")
.arg(map->object_events_label) .arg(objectEventsLabel)
.arg(map->warps_label) .arg(warpEventsLabel)
.arg(map->coord_events_label) .arg(coordEventsLabel)
.arg(map->bg_events_label); .arg(bgEventsLabel);
saveTextFile(path, text); saveTextFile(path, text);
} }
@ -1306,13 +1263,13 @@ void Project::readMapEvents(Map *map) {
} }
QStringList *labels = getLabelValues(parseAsm(text), map->events_label); QStringList *labels = getLabelValues(parseAsm(text), map->events_label);
map->object_events_label = labels->value(0); QString objectEventsLabel = labels->value(0);
map->warps_label = labels->value(1); QString warpEventsLabel = labels->value(1);
map->coord_events_label = labels->value(2); QString coordEventsLabel = labels->value(2);
map->bg_events_label = labels->value(3); QString bgEventsLabel = labels->value(3);
QList<QStringList> *object_events = getLabelMacros(parseAsm(text), map->object_events_label); QList<QStringList> *object_events = getLabelMacros(parseAsm(text), objectEventsLabel);
map->events["object"].clear(); map->events["object_event_group"].clear();
for (QStringList command : *object_events) { for (QStringList command : *object_events) {
if (command.value(0) == "object_event") { if (command.value(0) == "object_event") {
Event *object = new Event; Event *object = new Event;
@ -1326,18 +1283,18 @@ void Project::readMapEvents(Map *map) {
object->put("behavior", command.value(i++)); object->put("behavior", command.value(i++));
object->put("radius_x", command.value(i++).toInt(nullptr, 0)); object->put("radius_x", command.value(i++).toInt(nullptr, 0));
object->put("radius_y", command.value(i++).toInt(nullptr, 0)); object->put("radius_y", command.value(i++).toInt(nullptr, 0));
object->put("property", command.value(i++)); object->put("trainer_see_type", command.value(i++));
object->put("sight_radius", command.value(i++)); object->put("sight_radius_tree_id", command.value(i++));
object->put("script_label", command.value(i++)); object->put("script_label", command.value(i++));
object->put("event_flag", command.value(i++)); object->put("event_flag", command.value(i++));
object->put("event_group_type", "object_event_group");
object->put("event_type", "object"); object->put("event_type", EventType::Object);
map->events["object"].append(object); map->events["object_event_group"].append(object);
} }
} }
QList<QStringList> *warps = getLabelMacros(parseAsm(text), map->warps_label); QList<QStringList> *warps = getLabelMacros(parseAsm(text), warpEventsLabel);
map->events["warp"].clear(); map->events["warp_event_group"].clear();
for (QStringList command : *warps) { for (QStringList command : *warps) {
if (command.value(0) == "warp_def") { if (command.value(0) == "warp_def") {
Event *warp = new Event; Event *warp = new Event;
@ -1352,17 +1309,17 @@ void Project::readMapEvents(Map *map) {
QString mapConstant = command.value(i++); QString mapConstant = command.value(i++);
if (mapConstantsToMapNames->contains(mapConstant)) { if (mapConstantsToMapNames->contains(mapConstant)) {
warp->put("destination_map_name", mapConstantsToMapNames->value(mapConstant)); warp->put("destination_map_name", mapConstantsToMapNames->value(mapConstant));
warp->put("event_type", "warp"); warp->put("event_group_type", "warp_event_group");
map->events["warp"].append(warp); warp->put("event_type", EventType::Warp);
map->events["warp_event_group"].append(warp);
} else { } else {
qDebug() << QString("Destination map constant '%1' is invalid for warp").arg(mapConstant); qDebug() << QString("Destination map constant '%1' is invalid for warp").arg(mapConstant);
} }
} }
} }
QList<QStringList> *coords = getLabelMacros(parseAsm(text), map->coord_events_label); QList<QStringList> *coords = getLabelMacros(parseAsm(text), coordEventsLabel);
map->events["trap"].clear(); map->events["coord_event_group"].clear();
map->events["trap_weather"].clear();
for (QStringList command : *coords) { for (QStringList command : *coords) {
if (command.value(0) == "coord_event") { if (command.value(0) == "coord_event") {
Event *coord = new Event; Event *coord = new Event;
@ -1383,8 +1340,9 @@ void Project::readMapEvents(Map *map) {
//coord_unknown3 //coord_unknown3
//coord_unknown4 //coord_unknown4
coord->put("event_type", "trap"); coord->put("event_group_type", "coord_event_group");
map->events["trap"].append(coord); coord->put("event_type", EventType::CoordScript);
map->events["coord_event_group"].append(coord);
} else if (command.value(0) == "coord_weather_event") { } else if (command.value(0) == "coord_weather_event") {
Event *coord = new Event; Event *coord = new Event;
coord->put("map_name", map->name); coord->put("map_name", map->name);
@ -1393,15 +1351,14 @@ void Project::readMapEvents(Map *map) {
coord->put("y", command.value(i++)); coord->put("y", command.value(i++));
coord->put("elevation", command.value(i++)); coord->put("elevation", command.value(i++));
coord->put("weather", command.value(i++)); coord->put("weather", command.value(i++));
coord->put("event_type", "trap_weather"); coord->put("event_group_type", "coord_event_group");
map->events["trap_weather"].append(coord); coord->put("event_type", EventType::CoordWeather);
map->events["coord_event_group"].append(coord);
} }
} }
QList<QStringList> *bgs = getLabelMacros(parseAsm(text), map->bg_events_label); QList<QStringList> *bgs = getLabelMacros(parseAsm(text), bgEventsLabel);
map->events["sign"].clear(); map->events["bg_event_group"].clear();
map->events["event_hidden_item"].clear();
map->events["event_secret_base"].clear();
for (QStringList command : *bgs) { for (QStringList command : *bgs) {
if (command.value(0) == "bg_event") { if (command.value(0) == "bg_event") {
Event *bg = new Event; Event *bg = new Event;
@ -1410,12 +1367,13 @@ void Project::readMapEvents(Map *map) {
bg->put("x", command.value(i++)); bg->put("x", command.value(i++));
bg->put("y", command.value(i++)); bg->put("y", command.value(i++));
bg->put("elevation", command.value(i++)); bg->put("elevation", command.value(i++));
bg->put("type", command.value(i++)); bg->put("player_facing_direction", command.value(i++));
i++; i++;
bg->put("script_label", command.value(i++)); bg->put("script_label", command.value(i++));
//sign_unknown7 //sign_unknown7
bg->put("event_type", "sign"); bg->put("event_group_type", "bg_event_group");
map->events["sign"].append(bg); bg->put("event_type", EventType::Sign);
map->events["bg_event_group"].append(bg);
} else if (command.value(0) == "bg_hidden_item_event") { } else if (command.value(0) == "bg_hidden_item_event") {
Event *bg = new Event; Event *bg = new Event;
bg->put("map_name", map->name); bg->put("map_name", map->name);
@ -1425,8 +1383,9 @@ void Project::readMapEvents(Map *map) {
bg->put("elevation", command.value(i++)); bg->put("elevation", command.value(i++));
bg->put("item", command.value(i++)); bg->put("item", command.value(i++));
bg->put("flag", command.value(i++)); bg->put("flag", command.value(i++));
bg->put("event_type", "event_hidden_item"); bg->put("event_group_type", "bg_event_group");
map->events["event_hidden_item"].append(bg); bg->put("event_type", EventType::HiddenItem);
map->events["bg_event_group"].append(bg);
} else if (command.value(0) == "bg_secret_base_event") { } else if (command.value(0) == "bg_secret_base_event") {
Event *bg = new Event; Event *bg = new Event;
bg->put("map_name", map->name); bg->put("map_name", map->name);
@ -1435,24 +1394,18 @@ void Project::readMapEvents(Map *map) {
bg->put("y", command.value(i++)); bg->put("y", command.value(i++));
bg->put("elevation", command.value(i++)); bg->put("elevation", command.value(i++));
bg->put("secret_base_map", command.value(i++)); bg->put("secret_base_map", command.value(i++));
bg->put("event_type", "event_secret_base"); bg->put("event_group_type", "bg_event_group");
map->events["event_secret_base"].append(bg); bg->put("event_type", EventType::SecretBase);
map->events["bg_event_group"].append(bg);
} }
} }
} }
void Project::setNewMapEvents(Map *map) { void Project::setNewMapEvents(Map *map) {
map->object_events_label = "0x0"; map->events["object_event_group"].clear();
map->warps_label = "0x0"; map->events["warp_event_group"].clear();
map->coord_events_label = "0x0"; map->events["coord_event_group"].clear();
map->bg_events_label = "0x0"; map->events["bg_event_group"].clear();
map->events["object"].clear();
map->events["warp"].clear();
map->events["trap"].clear();
map->events["trap_weather"].clear();
map->events["sign"].clear();
map->events["event_hidden_item"].clear();
map->events["event_secret_base"].clear();
} }
QStringList Project::readCArray(QString text, QString label) { QStringList Project::readCArray(QString text, QString label) {