Treat warp IDs as strings, stop deleting invalid warps
This commit is contained in:
parent
0e0da77c07
commit
8e6585bbb2
7 changed files with 61 additions and 45 deletions
|
@ -173,6 +173,7 @@ public:
|
|||
|
||||
int getEventIndex();
|
||||
|
||||
static QString eventGroupToString(Event::Group group);
|
||||
static QString eventTypeToString(Event::Type type);
|
||||
static Event::Type eventTypeFromString(QString type);
|
||||
|
||||
|
@ -340,12 +341,12 @@ public:
|
|||
void setDestinationMap(QString newDestinationMap) { this->destinationMap = newDestinationMap; }
|
||||
QString getDestinationMap() { return this->destinationMap; }
|
||||
|
||||
void setDestinationWarpID(int newDestinationWarpID) { this->destinationWarpID = newDestinationWarpID; }
|
||||
int getDestinationWarpID() { return this->destinationWarpID; }
|
||||
void setDestinationWarpID(QString newDestinationWarpID) { this->destinationWarpID = newDestinationWarpID; }
|
||||
QString getDestinationWarpID() { return this->destinationWarpID; }
|
||||
|
||||
private:
|
||||
QString destinationMap;
|
||||
int destinationWarpID = 0;
|
||||
QString destinationWarpID;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -219,6 +219,7 @@ private slots:
|
|||
void on_toolButton_deleteObject_clicked();
|
||||
|
||||
void addNewEvent(Event::Type type);
|
||||
void tryAddEventTab(QWidget * tab, Event::Group group);
|
||||
void displayEventTabs();
|
||||
void updateSelectedObjects();
|
||||
void updateObjects();
|
||||
|
|
|
@ -133,7 +133,7 @@ public:
|
|||
|
||||
public:
|
||||
NoScrollComboBox *combo_dest_map;
|
||||
NoScrollSpinBox *spinner_dest_warp;
|
||||
NoScrollComboBox *combo_dest_warp;
|
||||
|
||||
private:
|
||||
WarpEvent *warp;
|
||||
|
|
|
@ -61,6 +61,23 @@ void Event::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) {
|
||||
switch (type) {
|
||||
case Event::Type::Object:
|
||||
|
@ -324,8 +341,8 @@ bool CloneObjectEvent::loadFromJson(QJsonObject json, Project *project) {
|
|||
} else if (mapConstant == DYNAMIC_MAP_CONSTANT) {
|
||||
this->setTargetMap(DYNAMIC_MAP_NAME);
|
||||
} else {
|
||||
logError(QString("Destination map constant '%1' is invalid").arg(mapConstant));
|
||||
return false;
|
||||
logWarn(QString("Target Map constant '%1' is invalid. Using default '%2'.").arg(mapConstant).arg(DYNAMIC_MAP_CONSTANT));
|
||||
this->setTargetMap(DYNAMIC_MAP_NAME);
|
||||
}
|
||||
|
||||
this->readCustomValues(json);
|
||||
|
@ -425,7 +442,7 @@ bool WarpEvent::loadFromJson(QJsonObject json, Project *project) {
|
|||
this->setX(ParseUtil::jsonToInt(json["x"]));
|
||||
this->setY(ParseUtil::jsonToInt(json["y"]));
|
||||
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.
|
||||
QString mapConstant = ParseUtil::jsonToQString(json["dest_map"]);
|
||||
|
@ -434,8 +451,8 @@ bool WarpEvent::loadFromJson(QJsonObject json, Project *project) {
|
|||
} else if (mapConstant == DYNAMIC_MAP_CONSTANT) {
|
||||
this->setDestinationMap(DYNAMIC_MAP_NAME);
|
||||
} else {
|
||||
logError(QString("Destination map constant '%1' is invalid for warp").arg(mapConstant));
|
||||
return false;
|
||||
logWarn(QString("Destination Map constant '%1' is invalid. Using default '%2'.").arg(mapConstant).arg(DYNAMIC_MAP_CONSTANT));
|
||||
this->setDestinationMap(DYNAMIC_MAP_NAME);
|
||||
}
|
||||
|
||||
this->readCustomValues(json);
|
||||
|
@ -445,7 +462,7 @@ bool WarpEvent::loadFromJson(QJsonObject json, Project *project) {
|
|||
|
||||
void WarpEvent::setDefaultValues(Project *) {
|
||||
if (this->getMap()) this->setDestinationMap(this->getMap()->name);
|
||||
this->setDestinationWarpID(0);
|
||||
this->setDestinationWarpID("0");
|
||||
this->setElevation(0);
|
||||
}
|
||||
|
||||
|
|
|
@ -719,6 +719,10 @@ void MainWindow::refreshMapScene()
|
|||
}
|
||||
|
||||
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.
|
||||
if (!editor->project->mapNames.contains(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.
|
||||
event_id -= Event::getIndexOffset(event_group);
|
||||
int index = event_id - Event::getIndexOffset(event_group);
|
||||
QList<Event*> events = editor->map->events[event_group];
|
||||
if (event_id < events.length() && event_id >= 0) {
|
||||
Event *event = events.at(event_id);
|
||||
if (index < events.length() && index >= 0) {
|
||||
Event *event = events.at(index);
|
||||
for (DraggablePixmapItem *item : editor->getObjects()) {
|
||||
if (item->event == event) {
|
||||
editor->selected_events->clear();
|
||||
|
@ -748,6 +752,9 @@ void MainWindow::openWarpMap(QString map_name, int event_id, Event::Group event_
|
|||
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() {
|
||||
const QSignalBlocker blocker(ui->tabWidget_EventType);
|
||||
|
||||
ui->tabWidget_EventType->clear();
|
||||
|
||||
if (editor->map->events.value(Event::Group::Object).length())
|
||||
ui->tabWidget_EventType->addTab(eventTabObjectWidget, "Objects");
|
||||
|
||||
if (editor->map->events.value(Event::Group::Warp).length())
|
||||
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");
|
||||
tryAddEventTab(eventTabObjectWidget, Event::Group::Object);
|
||||
tryAddEventTab(eventTabWarpWidget, Event::Group::Warp);
|
||||
tryAddEventTab(eventTabTriggerWidget, Event::Group::Coord);
|
||||
tryAddEventTab(eventTabBGWidget, Event::Group::Bg);
|
||||
tryAddEventTab(eventTabHealspotWidget, Event::Group::Heal);
|
||||
}
|
||||
|
||||
void MainWindow::updateObjects() {
|
||||
|
|
|
@ -85,23 +85,18 @@ void DraggablePixmapItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *) {
|
|||
if (eventType == Event::Type::Warp) {
|
||||
WarpEvent *warp = dynamic_cast<WarpEvent *>(this->event);
|
||||
QString destMap = warp->getDestinationMap();
|
||||
if (destMap != DYNAMIC_MAP_NAME) {
|
||||
emit editor->warpEventDoubleClicked(destMap, warp->getDestinationWarpID(), Event::Group::Warp);
|
||||
}
|
||||
bool ok;
|
||||
int warpId = ParseUtil::gameStringToInt(warp->getDestinationWarpID(), &ok);
|
||||
if (ok) emit editor->warpEventDoubleClicked(destMap, warpId, Event::Group::Warp);
|
||||
}
|
||||
else if (eventType == Event::Type::CloneObject) {
|
||||
CloneObjectEvent *clone = dynamic_cast<CloneObjectEvent *>(this->event);
|
||||
QString destMap = clone->getTargetMap();
|
||||
if (destMap != DYNAMIC_MAP_NAME) {
|
||||
emit editor->warpEventDoubleClicked(destMap, clone->getTargetID(), Event::Group::Object);
|
||||
}
|
||||
emit editor->warpEventDoubleClicked(clone->getTargetMap(), clone->getTargetID(), Event::Group::Object);
|
||||
}
|
||||
else if (eventType == Event::Type::SecretBase) {
|
||||
SecretBaseEvent *base = dynamic_cast<SecretBaseEvent *>(this->event);
|
||||
QString baseId = base->getBaseID();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -507,9 +507,9 @@ void WarpFrame::setup() {
|
|||
|
||||
// desination warp id
|
||||
QFormLayout *l_form_dest_warp = new QFormLayout();
|
||||
this->spinner_dest_warp = new NoScrollSpinBox(this);
|
||||
this->spinner_dest_warp->setToolTip("The warp id on the destination map.");
|
||||
l_form_dest_warp->addRow("Destination Warp", this->spinner_dest_warp);
|
||||
this->combo_dest_warp = new NoScrollComboBox(this);
|
||||
this->combo_dest_warp->setToolTip("The warp id on the destination map.");
|
||||
l_form_dest_warp->addRow("Destination Warp", this->combo_dest_warp);
|
||||
this->layout_contents->addLayout(l_form_dest_warp);
|
||||
|
||||
// custom attributes
|
||||
|
@ -529,9 +529,9 @@ void WarpFrame::connectSignals() {
|
|||
});
|
||||
|
||||
// dest id
|
||||
this->spinner_dest_warp->disconnect();
|
||||
connect(this->spinner_dest_warp, QOverload<int>::of(&QSpinBox::valueChanged), [this](int value) {
|
||||
this->warp->setDestinationWarpID(value);
|
||||
this->combo_dest_warp->disconnect();
|
||||
connect(this->combo_dest_warp, &QComboBox::currentTextChanged, [this](const QString &text) {
|
||||
this->warp->setDestinationWarpID(text);
|
||||
this->warp->modify();
|
||||
});
|
||||
}
|
||||
|
@ -553,7 +553,7 @@ void WarpFrame::initialize() {
|
|||
}
|
||||
|
||||
// dest id
|
||||
this->spinner_dest_warp->setValue(this->warp->getDestinationWarpID());
|
||||
this->combo_dest_warp->setCurrentText(this->warp->getDestinationWarpID());
|
||||
}
|
||||
|
||||
void WarpFrame::populate(Project *project) {
|
||||
|
|
Loading…
Reference in a new issue