From 20b112de525d1760694cb52444dac438663ea22e Mon Sep 17 00:00:00 2001 From: GriffinR Date: Fri, 20 Mar 2020 13:41:40 -0400 Subject: [PATCH] Support editing heal location respawns --- src/core/event.cpp | 5 ++--- src/core/heallocation.cpp | 3 ++- src/mainwindow.cpp | 27 ++++++++++++++++++++++----- src/project.cpp | 2 +- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/core/event.cpp b/src/core/event.cpp index 4d08012d..8a0c4541 100644 --- a/src/core/event.cpp +++ b/src/core/event.cpp @@ -87,14 +87,13 @@ Event* Event::createNewWarpEvent(QString map_name) Event* Event::createNewHealLocationEvent(QString map_name) { Event *event = new Event; - QString mapConstant = QString(Map::mapConstantFromName(map_name)).remove(0,4); event->put("event_group_type", "heal_event_group"); event->put("event_type", EventType::HealLocation); - event->put("loc_name", mapConstant); + event->put("loc_name", QString(Map::mapConstantFromName(map_name)).remove(0,4)); event->put("id_name", map_name.replace(QRegularExpression("([a-z])([A-Z])"), "\\1_\\2").toUpper()); event->put("elevation", 3); if (projectConfig.getBaseGameVersion() == BaseGameVersion::pokefirered) { - event->put("respawn_map", mapConstant); + event->put("respawn_map", map_name); event->put("respawn_npc", 1); } return event; diff --git a/src/core/heallocation.cpp b/src/core/heallocation.cpp index ae4c1e91..3653443d 100644 --- a/src/core/heallocation.cpp +++ b/src/core/heallocation.cpp @@ -1,5 +1,6 @@ #include "heallocation.h" #include "config.h" +#include "map.h" HealLocation::HealLocation(QString id, QString map, int i, uint16_t x, uint16_t y) { @@ -38,7 +39,7 @@ HealLocation HealLocation::fromEvent(Event *event) hl.y = event->getU16("y"); if (projectConfig.getBaseGameVersion() == BaseGameVersion::pokefirered) { hl.respawnNPC = event->getU16("respawn_npc"); - hl.respawnMap = event->get("respawn_map"); + hl.respawnMap = Map::mapConstantFromName(event->get("respawn_map")).remove(0,4); } return hl; } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 436a1702..235ad23e 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1429,6 +1429,8 @@ void MainWindow::updateSelectedObjects() { field_labels["weather"] = "Weather"; field_labels["flag"] = "Flag"; field_labels["secret_base_id"] = "Secret Base Id"; + field_labels["respawn_map"] = "Respawn Map"; + field_labels["respawn_npc"] = "Respawn NPC"; QStringList fields; @@ -1491,8 +1493,13 @@ void MainWindow::updateSelectedObjects() { // Hide elevation so users don't get impression that editing it is meaningful. frame->ui->spinBox_z->setVisible(false); frame->ui->label_z->setVisible(false); + fields << "respawn_map"; + fields << "respawn_npc"; } + // Some keys shouldn't use a combobox + QStringList spinKeys = {"quantity", "respawn_npc"}; + QStringList checkKeys = {"underfoot", "in_connection"}; for (QString key : fields) { QString value = item->event->get(key); QWidget *widget = new QWidget(frame); @@ -1504,10 +1511,9 @@ void MainWindow::updateSelectedObjects() { NoScrollComboBox *combo; QCheckBox *check; - // Some keys shouldn't use a combobox. This isn't very scalable - if (key == "quantity") { + if (spinKeys.contains(key)) { spin = new NoScrollSpinBox(widget); - } else if (key == "underfoot" || key == "in_connection") { + } else if (checkKeys.contains(key)) { check = new QCheckBox(widget); } else { combo = new NoScrollComboBox(widget); @@ -1552,6 +1558,7 @@ void MainWindow::updateSelectedObjects() { combo->addItems(*editor->project->itemNames); } else if (key == "quantity") { spin->setToolTip("The number of items received when the hidden item is picked up."); + // Min 1 not needed. 0 is treated as a valid quantity and works as expected in-game. spin->setMaximum(127); } else if (key == "underfoot") { check->setToolTip("If checked, hidden item can only be picked up using the Itemfinder"); @@ -1624,12 +1631,22 @@ void MainWindow::updateSelectedObjects() { combo->setMinimumContentsLength(4); } else if (key == "in_connection") { check->setToolTip("Check if object is positioned in the connection to another map."); + } else if (key == "respawn_map") { + if (!editor->project->mapNames->contains(value)) { + combo->addItem(value); + } + combo->addItems(*editor->project->mapNames); + combo->setToolTip("The map where the player will respawn after whiteout."); + } else if (key == "respawn_npc") { + spin->setToolTip("event_object ID of the NPC the player interacts with upon respawning after whiteout."); + spin->setMinimum(1); + spin->setMaximum(126); } else { combo->addItem(value); } // Keys using spin boxes - if (key == "quantity") { + if (spinKeys.contains(key)) { spin->setValue(value.toInt()); fl->addRow(new QLabel(field_labels[key], widget), spin); @@ -1640,7 +1657,7 @@ void MainWindow::updateSelectedObjects() { item->event->put(key, value); }); // Keys using check boxes - } else if (key == "underfoot" || key == "in_connection") { + } else if (checkKeys.contains(key)) { check->setChecked(value.toInt()); fl->addRow(new QLabel(field_labels[key], widget), check); diff --git a/src/project.cpp b/src/project.cpp index 4b67f068..674850c8 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -272,7 +272,7 @@ bool Project::loadMapData(Map* map) { heal->put("event_group_type", "heal_event_group"); heal->put("event_type", EventType::HealLocation); if (projectConfig.getBaseGameVersion() == BaseGameVersion::pokefirered) { - heal->put("respawn_map", loc.respawnMap); + heal->put("respawn_map", mapConstantsToMapNames->value(QString("MAP_" + loc.respawnMap))); heal->put("respawn_npc", loc.respawnNPC); } map->events["heal_event_group"].append(heal);