Treat warp IDs as strings, stop deleting invalid warps

This commit is contained in:
GriffinR 2022-10-18 13:44:45 -04:00
parent 0e0da77c07
commit 8e6585bbb2
7 changed files with 61 additions and 45 deletions

View file

@ -173,6 +173,7 @@ public:
int getEventIndex(); int getEventIndex();
static QString eventGroupToString(Event::Group group);
static QString eventTypeToString(Event::Type type); static QString eventTypeToString(Event::Type type);
static Event::Type eventTypeFromString(QString type); static Event::Type eventTypeFromString(QString type);
@ -340,12 +341,12 @@ public:
void setDestinationMap(QString newDestinationMap) { this->destinationMap = newDestinationMap; } void setDestinationMap(QString newDestinationMap) { this->destinationMap = newDestinationMap; }
QString getDestinationMap() { return this->destinationMap; } QString getDestinationMap() { return this->destinationMap; }
void setDestinationWarpID(int newDestinationWarpID) { this->destinationWarpID = newDestinationWarpID; } void setDestinationWarpID(QString newDestinationWarpID) { this->destinationWarpID = newDestinationWarpID; }
int getDestinationWarpID() { return this->destinationWarpID; } QString getDestinationWarpID() { return this->destinationWarpID; }
private: private:
QString destinationMap; QString destinationMap;
int destinationWarpID = 0; QString destinationWarpID;
}; };

View file

@ -219,6 +219,7 @@ private slots:
void on_toolButton_deleteObject_clicked(); void on_toolButton_deleteObject_clicked();
void addNewEvent(Event::Type type); void addNewEvent(Event::Type type);
void tryAddEventTab(QWidget * tab, Event::Group group);
void displayEventTabs(); void displayEventTabs();
void updateSelectedObjects(); void updateSelectedObjects();
void updateObjects(); void updateObjects();

View file

@ -133,7 +133,7 @@ public:
public: public:
NoScrollComboBox *combo_dest_map; NoScrollComboBox *combo_dest_map;
NoScrollSpinBox *spinner_dest_warp; NoScrollComboBox *combo_dest_warp;
private: private:
WarpEvent *warp; WarpEvent *warp;

View file

@ -61,6 +61,23 @@ void Event::modify() {
this->map->modify(); this->map->modify();
} }
QString Event::eventGroupToString(Event::Group group) {
switch (group) {
case Event::Group::Object:
return "Object";
case Event::Group::Warp:
return "Warp";
case Event::Group::Coord:
return "Trigger";
case Event::Group::Bg:
return "BG";
case Event::Group::Heal:
return "Healspot";
default:
return "";
}
}
QString Event::eventTypeToString(Event::Type type) { QString Event::eventTypeToString(Event::Type type) {
switch (type) { switch (type) {
case Event::Type::Object: case Event::Type::Object:
@ -324,8 +341,8 @@ bool CloneObjectEvent::loadFromJson(QJsonObject json, Project *project) {
} else if (mapConstant == DYNAMIC_MAP_CONSTANT) { } else if (mapConstant == DYNAMIC_MAP_CONSTANT) {
this->setTargetMap(DYNAMIC_MAP_NAME); this->setTargetMap(DYNAMIC_MAP_NAME);
} else { } else {
logError(QString("Destination map constant '%1' is invalid").arg(mapConstant)); logWarn(QString("Target Map constant '%1' is invalid. Using default '%2'.").arg(mapConstant).arg(DYNAMIC_MAP_CONSTANT));
return false; this->setTargetMap(DYNAMIC_MAP_NAME);
} }
this->readCustomValues(json); this->readCustomValues(json);
@ -425,7 +442,7 @@ bool WarpEvent::loadFromJson(QJsonObject json, Project *project) {
this->setX(ParseUtil::jsonToInt(json["x"])); this->setX(ParseUtil::jsonToInt(json["x"]));
this->setY(ParseUtil::jsonToInt(json["y"])); this->setY(ParseUtil::jsonToInt(json["y"]));
this->setElevation(ParseUtil::jsonToInt(json["elevation"])); this->setElevation(ParseUtil::jsonToInt(json["elevation"]));
this->setDestinationWarpID(ParseUtil::jsonToInt(json["dest_warp_id"])); this->setDestinationWarpID(ParseUtil::jsonToQString(json["dest_warp_id"]));
// Ensure the warp destination map constant is valid before adding it to the warps. // Ensure the warp destination map constant is valid before adding it to the warps.
QString mapConstant = ParseUtil::jsonToQString(json["dest_map"]); QString mapConstant = ParseUtil::jsonToQString(json["dest_map"]);
@ -434,8 +451,8 @@ bool WarpEvent::loadFromJson(QJsonObject json, Project *project) {
} else if (mapConstant == DYNAMIC_MAP_CONSTANT) { } else if (mapConstant == DYNAMIC_MAP_CONSTANT) {
this->setDestinationMap(DYNAMIC_MAP_NAME); this->setDestinationMap(DYNAMIC_MAP_NAME);
} else { } else {
logError(QString("Destination map constant '%1' is invalid for warp").arg(mapConstant)); logWarn(QString("Destination Map constant '%1' is invalid. Using default '%2'.").arg(mapConstant).arg(DYNAMIC_MAP_CONSTANT));
return false; this->setDestinationMap(DYNAMIC_MAP_NAME);
} }
this->readCustomValues(json); this->readCustomValues(json);
@ -445,7 +462,7 @@ bool WarpEvent::loadFromJson(QJsonObject json, Project *project) {
void WarpEvent::setDefaultValues(Project *) { void WarpEvent::setDefaultValues(Project *) {
if (this->getMap()) this->setDestinationMap(this->getMap()->name); if (this->getMap()) this->setDestinationMap(this->getMap()->name);
this->setDestinationWarpID(0); this->setDestinationWarpID("0");
this->setElevation(0); this->setElevation(0);
} }

View file

@ -719,6 +719,10 @@ void MainWindow::refreshMapScene()
} }
void MainWindow::openWarpMap(QString map_name, int event_id, Event::Group event_group) { void MainWindow::openWarpMap(QString map_name, int event_id, Event::Group event_group) {
// Can't warp to dynamic maps
if (map_name == DYNAMIC_MAP_NAME)
return;
// Ensure valid destination map name. // Ensure valid destination map name.
if (!editor->project->mapNames.contains(map_name)) { if (!editor->project->mapNames.contains(map_name)) {
logError(QString("Invalid map name '%1'").arg(map_name)); logError(QString("Invalid map name '%1'").arg(map_name));
@ -737,10 +741,10 @@ void MainWindow::openWarpMap(QString map_name, int event_id, Event::Group event_
} }
// Select the target event. // Select the target event.
event_id -= Event::getIndexOffset(event_group); int index = event_id - Event::getIndexOffset(event_group);
QList<Event*> events = editor->map->events[event_group]; QList<Event*> events = editor->map->events[event_group];
if (event_id < events.length() && event_id >= 0) { if (index < events.length() && index >= 0) {
Event *event = events.at(event_id); Event *event = events.at(index);
for (DraggablePixmapItem *item : editor->getObjects()) { for (DraggablePixmapItem *item : editor->getObjects()) {
if (item->event == event) { if (item->event == event) {
editor->selected_events->clear(); editor->selected_events->clear();
@ -748,6 +752,9 @@ void MainWindow::openWarpMap(QString map_name, int event_id, Event::Group event_
editor->updateSelectedEvents(); editor->updateSelectedEvents();
} }
} }
} else {
// Can still warp to this map, but can't select the specified event
logWarn(QString("%1 %2 doesn't exist on map '%3'").arg(Event::eventGroupToString(event_group)).arg(event_id).arg(map_name));
} }
} }
@ -1884,25 +1891,20 @@ void MainWindow::addNewEvent(Event::Type type) {
} }
} }
void MainWindow::tryAddEventTab(QWidget * tab, Event::Group group) {
if (editor->map->events.value(group).length())
ui->tabWidget_EventType->addTab(tab, QString("%1s").arg(Event::eventGroupToString(group)));
}
void MainWindow::displayEventTabs() { void MainWindow::displayEventTabs() {
const QSignalBlocker blocker(ui->tabWidget_EventType); const QSignalBlocker blocker(ui->tabWidget_EventType);
ui->tabWidget_EventType->clear(); ui->tabWidget_EventType->clear();
tryAddEventTab(eventTabObjectWidget, Event::Group::Object);
if (editor->map->events.value(Event::Group::Object).length()) tryAddEventTab(eventTabWarpWidget, Event::Group::Warp);
ui->tabWidget_EventType->addTab(eventTabObjectWidget, "Objects"); tryAddEventTab(eventTabTriggerWidget, Event::Group::Coord);
tryAddEventTab(eventTabBGWidget, Event::Group::Bg);
if (editor->map->events.value(Event::Group::Warp).length()) tryAddEventTab(eventTabHealspotWidget, Event::Group::Heal);
ui->tabWidget_EventType->addTab(eventTabWarpWidget, "Warps");
if (editor->map->events.value(Event::Group::Coord).length())
ui->tabWidget_EventType->addTab(eventTabTriggerWidget, "Triggers");
if (editor->map->events.value(Event::Group::Bg).length())
ui->tabWidget_EventType->addTab(eventTabBGWidget, "BGs");
if (editor->map->events.value(Event::Group::Heal).length())
ui->tabWidget_EventType->addTab(eventTabHealspotWidget, "Healspots");
} }
void MainWindow::updateObjects() { void MainWindow::updateObjects() {

View file

@ -85,23 +85,18 @@ void DraggablePixmapItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *) {
if (eventType == Event::Type::Warp) { if (eventType == Event::Type::Warp) {
WarpEvent *warp = dynamic_cast<WarpEvent *>(this->event); WarpEvent *warp = dynamic_cast<WarpEvent *>(this->event);
QString destMap = warp->getDestinationMap(); QString destMap = warp->getDestinationMap();
if (destMap != DYNAMIC_MAP_NAME) { bool ok;
emit editor->warpEventDoubleClicked(destMap, warp->getDestinationWarpID(), Event::Group::Warp); int warpId = ParseUtil::gameStringToInt(warp->getDestinationWarpID(), &ok);
} if (ok) emit editor->warpEventDoubleClicked(destMap, warpId, Event::Group::Warp);
} }
else if (eventType == Event::Type::CloneObject) { else if (eventType == Event::Type::CloneObject) {
CloneObjectEvent *clone = dynamic_cast<CloneObjectEvent *>(this->event); CloneObjectEvent *clone = dynamic_cast<CloneObjectEvent *>(this->event);
QString destMap = clone->getTargetMap(); emit editor->warpEventDoubleClicked(clone->getTargetMap(), clone->getTargetID(), Event::Group::Object);
if (destMap != DYNAMIC_MAP_NAME) {
emit editor->warpEventDoubleClicked(destMap, clone->getTargetID(), Event::Group::Object);
}
} }
else if (eventType == Event::Type::SecretBase) { else if (eventType == Event::Type::SecretBase) {
SecretBaseEvent *base = dynamic_cast<SecretBaseEvent *>(this->event); SecretBaseEvent *base = dynamic_cast<SecretBaseEvent *>(this->event);
QString baseId = base->getBaseID(); QString baseId = base->getBaseID();
QString destMap = editor->project->mapConstantsToMapNames.value("MAP_" + baseId.left(baseId.lastIndexOf("_"))); QString destMap = editor->project->mapConstantsToMapNames.value("MAP_" + baseId.left(baseId.lastIndexOf("_")));
if (destMap != DYNAMIC_MAP_NAME) { emit editor->warpEventDoubleClicked(destMap, 0, Event::Group::Warp);
emit editor->warpEventDoubleClicked(destMap, 0, Event::Group::Warp);
}
} }
} }

View file

@ -507,9 +507,9 @@ void WarpFrame::setup() {
// desination warp id // desination warp id
QFormLayout *l_form_dest_warp = new QFormLayout(); QFormLayout *l_form_dest_warp = new QFormLayout();
this->spinner_dest_warp = new NoScrollSpinBox(this); this->combo_dest_warp = new NoScrollComboBox(this);
this->spinner_dest_warp->setToolTip("The warp id on the destination map."); this->combo_dest_warp->setToolTip("The warp id on the destination map.");
l_form_dest_warp->addRow("Destination Warp", this->spinner_dest_warp); l_form_dest_warp->addRow("Destination Warp", this->combo_dest_warp);
this->layout_contents->addLayout(l_form_dest_warp); this->layout_contents->addLayout(l_form_dest_warp);
// custom attributes // custom attributes
@ -529,9 +529,9 @@ void WarpFrame::connectSignals() {
}); });
// dest id // dest id
this->spinner_dest_warp->disconnect(); this->combo_dest_warp->disconnect();
connect(this->spinner_dest_warp, QOverload<int>::of(&QSpinBox::valueChanged), [this](int value) { connect(this->combo_dest_warp, &QComboBox::currentTextChanged, [this](const QString &text) {
this->warp->setDestinationWarpID(value); this->warp->setDestinationWarpID(text);
this->warp->modify(); this->warp->modify();
}); });
} }
@ -553,7 +553,7 @@ void WarpFrame::initialize() {
} }
// dest id // dest id
this->spinner_dest_warp->setValue(this->warp->getDestinationWarpID()); this->combo_dest_warp->setCurrentText(this->warp->getDestinationWarpID());
} }
void WarpFrame::populate(Project *project) { void WarpFrame::populate(Project *project) {