Support editing heal location respawns

This commit is contained in:
GriffinR 2020-03-20 13:41:40 -04:00
parent d365ebb664
commit 20b112de52
4 changed files with 27 additions and 10 deletions

View file

@ -87,14 +87,13 @@ Event* Event::createNewWarpEvent(QString map_name)
Event* Event::createNewHealLocationEvent(QString map_name) Event* Event::createNewHealLocationEvent(QString map_name)
{ {
Event *event = new Event; 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_group_type", "heal_event_group");
event->put("event_type", EventType::HealLocation); 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("id_name", map_name.replace(QRegularExpression("([a-z])([A-Z])"), "\\1_\\2").toUpper());
event->put("elevation", 3); event->put("elevation", 3);
if (projectConfig.getBaseGameVersion() == BaseGameVersion::pokefirered) { if (projectConfig.getBaseGameVersion() == BaseGameVersion::pokefirered) {
event->put("respawn_map", mapConstant); event->put("respawn_map", map_name);
event->put("respawn_npc", 1); event->put("respawn_npc", 1);
} }
return event; return event;

View file

@ -1,5 +1,6 @@
#include "heallocation.h" #include "heallocation.h"
#include "config.h" #include "config.h"
#include "map.h"
HealLocation::HealLocation(QString id, QString map, int i, uint16_t x, uint16_t y) 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"); hl.y = event->getU16("y");
if (projectConfig.getBaseGameVersion() == BaseGameVersion::pokefirered) { if (projectConfig.getBaseGameVersion() == BaseGameVersion::pokefirered) {
hl.respawnNPC = event->getU16("respawn_npc"); 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; return hl;
} }

View file

@ -1429,6 +1429,8 @@ void MainWindow::updateSelectedObjects() {
field_labels["weather"] = "Weather"; field_labels["weather"] = "Weather";
field_labels["flag"] = "Flag"; field_labels["flag"] = "Flag";
field_labels["secret_base_id"] = "Secret Base Id"; field_labels["secret_base_id"] = "Secret Base Id";
field_labels["respawn_map"] = "Respawn Map";
field_labels["respawn_npc"] = "Respawn NPC";
QStringList fields; QStringList fields;
@ -1491,8 +1493,13 @@ void MainWindow::updateSelectedObjects() {
// Hide elevation so users don't get impression that editing it is meaningful. // Hide elevation so users don't get impression that editing it is meaningful.
frame->ui->spinBox_z->setVisible(false); frame->ui->spinBox_z->setVisible(false);
frame->ui->label_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) { for (QString key : fields) {
QString value = item->event->get(key); QString value = item->event->get(key);
QWidget *widget = new QWidget(frame); QWidget *widget = new QWidget(frame);
@ -1504,10 +1511,9 @@ void MainWindow::updateSelectedObjects() {
NoScrollComboBox *combo; NoScrollComboBox *combo;
QCheckBox *check; QCheckBox *check;
// Some keys shouldn't use a combobox. This isn't very scalable if (spinKeys.contains(key)) {
if (key == "quantity") {
spin = new NoScrollSpinBox(widget); spin = new NoScrollSpinBox(widget);
} else if (key == "underfoot" || key == "in_connection") { } else if (checkKeys.contains(key)) {
check = new QCheckBox(widget); check = new QCheckBox(widget);
} else { } else {
combo = new NoScrollComboBox(widget); combo = new NoScrollComboBox(widget);
@ -1552,6 +1558,7 @@ void MainWindow::updateSelectedObjects() {
combo->addItems(*editor->project->itemNames); combo->addItems(*editor->project->itemNames);
} else if (key == "quantity") { } else if (key == "quantity") {
spin->setToolTip("The number of items received when the hidden item is picked up."); 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); spin->setMaximum(127);
} else if (key == "underfoot") { } else if (key == "underfoot") {
check->setToolTip("If checked, hidden item can only be picked up using the Itemfinder"); check->setToolTip("If checked, hidden item can only be picked up using the Itemfinder");
@ -1624,12 +1631,22 @@ void MainWindow::updateSelectedObjects() {
combo->setMinimumContentsLength(4); combo->setMinimumContentsLength(4);
} else if (key == "in_connection") { } else if (key == "in_connection") {
check->setToolTip("Check if object is positioned in the connection to another map."); 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 { } else {
combo->addItem(value); combo->addItem(value);
} }
// Keys using spin boxes // Keys using spin boxes
if (key == "quantity") { if (spinKeys.contains(key)) {
spin->setValue(value.toInt()); spin->setValue(value.toInt());
fl->addRow(new QLabel(field_labels[key], widget), spin); fl->addRow(new QLabel(field_labels[key], widget), spin);
@ -1640,7 +1657,7 @@ void MainWindow::updateSelectedObjects() {
item->event->put(key, value); item->event->put(key, value);
}); });
// Keys using check boxes // Keys using check boxes
} else if (key == "underfoot" || key == "in_connection") { } else if (checkKeys.contains(key)) {
check->setChecked(value.toInt()); check->setChecked(value.toInt());
fl->addRow(new QLabel(field_labels[key], widget), check); fl->addRow(new QLabel(field_labels[key], widget), check);

View file

@ -272,7 +272,7 @@ bool Project::loadMapData(Map* map) {
heal->put("event_group_type", "heal_event_group"); heal->put("event_group_type", "heal_event_group");
heal->put("event_type", EventType::HealLocation); heal->put("event_type", EventType::HealLocation);
if (projectConfig.getBaseGameVersion() == BaseGameVersion::pokefirered) { 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); heal->put("respawn_npc", loc.respawnNPC);
} }
map->events["heal_event_group"].append(heal); map->events["heal_event_group"].append(heal);