From ecce7d26f244dad572455732de713a77d26a9b54 Mon Sep 17 00:00:00 2001 From: Marcus Huderle Date: Sat, 7 Jul 2018 10:58:25 -0500 Subject: [PATCH] Add ability to add all map event types --- editor.cpp | 4 +- editor.h | 8 ++ event.cpp | 200 +++++++++++++++++++++++++++++++++++++++++++++++++ event.h | 18 +++++ mainwindow.cpp | 21 +++--- map.cpp | 7 +- map.h | 1 - project.cpp | 149 +++++++++++++----------------------- 8 files changed, 288 insertions(+), 120 deletions(-) diff --git a/editor.cpp b/editor.cpp index a68b618e..cd8f9d37 100755 --- a/editor.cpp +++ b/editor.cpp @@ -1300,9 +1300,8 @@ void Editor::selectMapEvent(DraggablePixmapItem *object, bool toggle) { DraggablePixmapItem* Editor::addNewEvent(QString event_type) { if (project && map) { - Event *event = new Event; + Event *event = Event::createNewEvent(event_type, map->name); event->put("map_name", map->name); - event->put("event_type", event_type); map->addEvent(event); project->loadEventPixmaps(map->getAllEvents()); DraggablePixmapItem *object = addMapEvent(event); @@ -1321,7 +1320,6 @@ void Editor::deleteEvent(Event *event) { //updateSelectedObjects(); } - // 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 // when you click on a selected event, since selected_events doesn't change. diff --git a/editor.h b/editor.h index 5065aac0..bc21584a 100755 --- a/editor.h +++ b/editor.h @@ -62,6 +62,7 @@ public: void selectMapEvent(DraggablePixmapItem *object); void selectMapEvent(DraggablePixmapItem *object, bool toggle); DraggablePixmapItem *addNewEvent(QString event_type); + Event* createNewEvent(QString event_type); void deleteEvent(Event *); void updateSelectedEvents(); void redrawObject(DraggablePixmapItem *item); @@ -107,6 +108,13 @@ private: void updateMirroredConnectionDirection(Connection*, QString); void updateMirroredConnectionMap(Connection*, QString); void updateMirroredConnection(Connection*, QString, QString, bool isDelete = false); + Event* createNewObjectEvent(); + Event* createNewWarpEvent(); + Event* createNewCoordScriptEvent(); + Event* createNewCoordWeatherEvent(); + Event* createNewSignEvent(); + Event* createNewHiddenItemEvent(); + Event* createNewSecretBaseEvent(); private slots: void mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item); diff --git a/event.cpp b/event.cpp index dcb0eaf7..6b47972e 100755 --- a/event.cpp +++ b/event.cpp @@ -11,3 +11,203 @@ QString EventType::SecretBase = "event_secret_base"; 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 *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; +} diff --git a/event.h b/event.h index 34e52829..03313d27 100755 --- a/event.h +++ b/event.h @@ -4,6 +4,7 @@ #include #include #include +#include class EventType { @@ -50,6 +51,23 @@ public: 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 buildCoordScriptEventMacro(); + QString buildCoordWeatherEventMacro(); + QString buildSignEventMacro(); + QString buildHiddenItemEventMacro(); + QString buildSecretBaseEventMacro(); + QMap values; QPixmap pixmap; }; diff --git a/mainwindow.cpp b/mainwindow.cpp index 3c728532..58f0e684 100755 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -512,9 +512,7 @@ void MainWindow::addNewEvent(QString event_type) if (editor) { DraggablePixmapItem *object = editor->addNewEvent(event_type); if (object) { - //if (editor->selected_events->length()) { - editor->selectMapEvent(object, true); - //} + editor->selectMapEvent(object, false); } updateSelectedObjects(); } @@ -558,12 +556,13 @@ void MainWindow::updateSelectedObjects() { font.setCapitalization(QFont::Capitalize); frame->ui->label_name->setFont(font); 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"); 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(event_type) - .arg(editor->project->getMap(map_name)->events.value(event_type).indexOf(item->event) + 1) ); frame->ui->label_spritePixmap->setPixmap(item->event->pixmap); @@ -578,13 +577,13 @@ void MainWindow::updateSelectedObjects() { field_labels["behavior"] = "Behavior"; field_labels["radius_x"] = "Movement Radius X"; field_labels["radius_y"] = "Movement Radius Y"; - field_labels["property"] = "Property"; - field_labels["sight_radius"] = "Sight Radius"; + field_labels["trainer_see_type"] = "Trainer See Type"; + field_labels["sight_radius_tree_id"] = "Sight Radius / Berry Tree ID"; field_labels["destination_warp"] = "Destination Warp"; field_labels["destination_map_name"] = "Destination Map"; field_labels["script_var"] = "Var"; 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_unknown5"] = "Unknown 5"; field_labels["item_unknown6"] = "Unknown 6"; @@ -617,8 +616,8 @@ void MainWindow::updateSelectedObjects() { fields << "script_label"; fields << "event_flag"; fields << "replacement"; - fields << "property"; - fields << "sight_radius"; + fields << "trainer_see_type"; + fields << "sight_radius_tree_id"; } else if (event_type == EventType::Warp) { fields << "destination_warp"; @@ -633,7 +632,7 @@ void MainWindow::updateSelectedObjects() { fields << "weather"; } else if (event_type == EventType::Sign) { - fields << "type"; + fields << "player_facing_direction"; fields << "script_label"; } else if (event_type == EventType::HiddenItem) { diff --git a/map.cpp b/map.cpp index 60867302..a9499b97 100755 --- a/map.cpp +++ b/map.cpp @@ -733,11 +733,6 @@ QList Map::getAllEvents() { return all; } -QList Map::getEventsByType(QString type) -{ - return events.value(type); -} - void Map::removeEvent(Event *event) { for (QString key : events.keys()) { events[key].removeAll(event); @@ -745,7 +740,7 @@ void Map::removeEvent(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() { diff --git a/map.h b/map.h index 2c6bafd8..88fa834f 100755 --- a/map.h +++ b/map.h @@ -194,7 +194,6 @@ public: QString bg_events_label; QList getAllEvents(); - QList getEventsByType(QString type); void removeEvent(Event *event); void addEvent(Event *event); QMap> events; diff --git a/project.cpp b/project.cpp index a0255578..5802198d 100755 --- a/project.cpp +++ b/project.cpp @@ -1186,97 +1186,48 @@ void Project::saveMapEvents(Map *map) { QString path = root + QString("/data/maps/%1/events.inc").arg(map->name); QString text = ""; - if (map->events["object"].length() > 0) { + if (map->events["object_event_group"].length() > 0) { text += QString("%1::\n").arg(map->object_events_label); - for (int i = 0; i < map->events["object"].length(); i++) { - Event *object_event = map->events["object"].value(i); - int radius_x = object_event->getInt("radius_x"); - int radius_y = object_event->getInt("radius_y"); - 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"; + for (int i = 0; i < map->events["object_event_group"].length(); i++) { + Event *object_event = map->events["object_event_group"].value(i); + text += object_event->buildObjectEventMacro(i); } text += "\n"; } - if (map->events["warp"].length() > 0) { + if (map->events["warp_event_group"].length() > 0) { text += QString("%1::\n").arg(map->warps_label); - for (Event *warp : map->events["warp"]) { - text += QString("\twarp_def %1").arg(warp->get("x")); - text += QString(", %1").arg(warp->get("y")); - 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"; + for (Event *warp : map->events["warp_event_group"]) { + text += warp->buildWarpEventMacro(mapNamesToMapConstants); } 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); - for (Event *coords : map->events["trap"]) { - text += QString("\tcoord_event %1").arg(coords->get("x")); - text += QString(", %1").arg(coords->get("y")); - text += QString(", %1").arg(coords->get("elevation")); - text += QString(", 0"); - text += QString(", %1").arg(coords->get("script_var")); - text += QString(", %1").arg(coords->get("script_var_value")); - 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"; + for (Event *event : map->events["coord_event_group"]) { + QString event_type = event->get("event_type"); + if (event_type == EventType::CoordScript) { + text += event->buildCoordScriptEventMacro(); + } else if (event_type == EventType::CoordWeather) { + text += event->buildCoordWeatherEventMacro(); + } } text += "\n"; } - if (map->events["sign"].length() + - map->events["event_hidden_item"].length() + - map->events["event_secret_base"].length() > 0) + if (map->events["bg_event_group"].length() > 0) { text += QString("%1::\n").arg(map->bg_events_label); - for (Event *sign : map->events["sign"]) { - text += QString("\tbg_event %1").arg(sign->get("x")); - text += QString(", %1").arg(sign->get("y")); - text += QString(", %1").arg(sign->get("elevation")); - text += QString(", %1").arg(sign->get("type")); - text += QString(", 0"); - text += QString(", %1").arg(sign->get("script_label")); - text += "\n"; - } - 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"; + for (Event *event : map->events["bg_event_group"]) { + QString event_type = event->get("event_type"); + if (event_type == EventType::Sign) { + text += event->buildSignEventMacro(); + } else if (event_type == EventType::HiddenItem) { + text += event->buildHiddenItemEventMacro(); + } else if (event_type == EventType::SecretBase) { + text += event->buildSecretBaseEventMacro(); + } } text += "\n"; } @@ -1310,7 +1261,7 @@ void Project::readMapEvents(Map *map) { map->bg_events_label = labels->value(3); QList *object_events = getLabelMacros(parseAsm(text), map->object_events_label); - map->events["object"].clear(); + map->events["object_event_group"].clear(); for (QStringList command : *object_events) { if (command.value(0) == "object_event") { Event *object = new Event; @@ -1324,18 +1275,18 @@ void Project::readMapEvents(Map *map) { object->put("behavior", command.value(i++)); object->put("radius_x", command.value(i++).toInt(nullptr, 0)); object->put("radius_y", command.value(i++).toInt(nullptr, 0)); - object->put("property", command.value(i++)); - object->put("sight_radius", command.value(i++)); + object->put("trainer_see_type", command.value(i++)); + object->put("sight_radius_tree_id", command.value(i++)); object->put("script_label", command.value(i++)); object->put("event_flag", command.value(i++)); - + object->put("event_group_type", "object_event_group"); object->put("event_type", EventType::Object); - map->events["object"].append(object); + map->events["object_event_group"].append(object); } } QList *warps = getLabelMacros(parseAsm(text), map->warps_label); - map->events["warp"].clear(); + map->events["warp_event_group"].clear(); for (QStringList command : *warps) { if (command.value(0) == "warp_def") { Event *warp = new Event; @@ -1350,8 +1301,9 @@ 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_group_type", "warp_event_group"); warp->put("event_type", EventType::Warp); - map->events["warp"].append(warp); + map->events["warp_event_group"].append(warp); } else { qDebug() << QString("Destination map constant '%1' is invalid for warp").arg(mapConstant); } @@ -1359,8 +1311,7 @@ void Project::readMapEvents(Map *map) { } QList *coords = getLabelMacros(parseAsm(text), map->coord_events_label); - map->events["trap"].clear(); - map->events["trap_weather"].clear(); + map->events["coord_event_group"].clear(); for (QStringList command : *coords) { if (command.value(0) == "coord_event") { Event *coord = new Event; @@ -1381,8 +1332,9 @@ void Project::readMapEvents(Map *map) { //coord_unknown3 //coord_unknown4 + coord->put("event_group_type", "coord_event_group"); coord->put("event_type", EventType::CoordScript); - map->events["trap"].append(coord); + map->events["coord_event_group"].append(coord); } else if (command.value(0) == "coord_weather_event") { Event *coord = new Event; coord->put("map_name", map->name); @@ -1391,15 +1343,14 @@ 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_group_type", "coord_event_group"); coord->put("event_type", EventType::CoordWeather); - map->events["trap_weather"].append(coord); + map->events["coord_event_group"].append(coord); } } QList *bgs = getLabelMacros(parseAsm(text), map->bg_events_label); - map->events["sign"].clear(); - map->events["event_hidden_item"].clear(); - map->events["event_secret_base"].clear(); + map->events["bg_event_group"].clear(); for (QStringList command : *bgs) { if (command.value(0) == "bg_event") { Event *bg = new Event; @@ -1408,12 +1359,13 @@ void Project::readMapEvents(Map *map) { bg->put("x", command.value(i++)); bg->put("y", command.value(i++)); bg->put("elevation", command.value(i++)); - bg->put("type", command.value(i++)); + bg->put("player_facing_direction", command.value(i++)); i++; bg->put("script_label", command.value(i++)); //sign_unknown7 + bg->put("event_group_type", "bg_event_group"); bg->put("event_type", EventType::Sign); - map->events["sign"].append(bg); + map->events["bg_event_group"].append(bg); } else if (command.value(0) == "bg_hidden_item_event") { Event *bg = new Event; bg->put("map_name", map->name); @@ -1423,8 +1375,9 @@ 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_group_type", "bg_event_group"); bg->put("event_type", EventType::HiddenItem); - map->events["event_hidden_item"].append(bg); + map->events["bg_event_group"].append(bg); } else if (command.value(0) == "bg_secret_base_event") { Event *bg = new Event; bg->put("map_name", map->name); @@ -1433,8 +1386,9 @@ 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_group_type", "bg_event_group"); bg->put("event_type", EventType::SecretBase); - map->events["event_secret_base"].append(bg); + map->events["bg_event_group"].append(bg); } } } @@ -1444,13 +1398,10 @@ void Project::setNewMapEvents(Map *map) { map->warps_label = "0x0"; map->coord_events_label = "0x0"; map->bg_events_label = "0x0"; - 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(); + map->events["object_event_group"].clear(); + map->events["warp_event_group"].clear(); + map->events["coord_event_group"].clear(); + map->events["bg_event_group"].clear(); } QStringList Project::readCArray(QString text, QString label) {