Allow warping by double-clicking clone objects

This commit is contained in:
GriffinR 2022-02-07 09:28:59 -05:00 committed by huderlem
parent b01581dc4d
commit b91914310e
5 changed files with 27 additions and 17 deletions

View file

@ -210,7 +210,7 @@ signals:
void selectedObjectsChanged();
void loadMapRequested(QString, QString);
void wildMonDataChanged();
void warpEventDoubleClicked(QString mapName, QString warpNum);
void warpEventDoubleClicked(QString, QString, QString);
void currentMetatilesSelectionChanged();
void mapRulerStatusChanged(const QString &);
void editedMapData();

View file

@ -212,7 +212,7 @@ private slots:
void on_action_Reload_Project_triggered();
void on_mapList_activated(const QModelIndex &index);
void on_action_Save_Project_triggered();
void openWarpMap(QString map_name, QString warp_num);
void openWarpMap(QString map_name, QString event_id, QString event_group);
void duplicate();
void setClipboardData(poryjson::Json::object);

View file

@ -692,22 +692,22 @@ void MainWindow::refreshMapScene()
on_horizontalSlider_MetatileZoom_valueChanged(ui->horizontalSlider_MetatileZoom->value());
}
void MainWindow::openWarpMap(QString map_name, QString warp_num) {
void MainWindow::openWarpMap(QString map_name, QString event_id, QString event_group) {
// Ensure valid destination map name.
if (!editor->project->mapNames.contains(map_name)) {
logError(QString("Invalid warp destination map name '%1'").arg(map_name));
logError(QString("Invalid map name '%1'").arg(map_name));
return;
}
// Ensure valid destination warp number.
// Ensure valid event number.
bool ok;
int warpNum = warp_num.toInt(&ok, 0);
int event_index = event_id.toInt(&ok, 0);
if (!ok) {
logError(QString("Invalid warp number '%1' for destination map '%2'").arg(warp_num).arg(map_name));
logError(QString("Invalid event number '%1' for map '%2'").arg(event_id).arg(map_name));
return;
}
// Open the destination map, and select the target warp event.
// Open the destination map.
if (!setMap(map_name, true)) {
QMessageBox msgBox(this);
QString errorMsg = QString("There was an error opening map %1. Please see %2 for full error details.\n\n%3")
@ -718,11 +718,14 @@ void MainWindow::openWarpMap(QString map_name, QString warp_num) {
return;
}
QList<Event*> warp_events = editor->map->events[EventGroup::Warp];
if (warp_events.length() > warpNum) {
Event *warp_event = warp_events.at(warpNum);
// Select the target event.
if (event_group != EventGroup::Warp && event_index)
event_index--;
QList<Event*> events = editor->map->events[event_group];
if (events.length() > event_index) {
Event *event = events.at(event_index);
for (DraggablePixmapItem *item : editor->getObjects()) {
if (item->event == warp_event) {
if (item->event == event) {
editor->selected_events->clear();
editor->selected_events->append(item);
editor->updateSelectedEvents();

View file

@ -102,17 +102,24 @@ void DraggablePixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *) {
}
void DraggablePixmapItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *) {
if (this->event->get("event_type") == EventType::Warp) {
QString eventType = this->event->get("event_type");
if (eventType == EventType::Warp) {
QString destMap = this->event->get("destination_map_name");
if (destMap != NONE_MAP_NAME) {
emit editor->warpEventDoubleClicked(this->event->get("destination_map_name"), this->event->get("destination_warp"));
emit editor->warpEventDoubleClicked(destMap, this->event->get("destination_warp"), EventGroup::Warp);
}
}
else if (this->event->get("event_type") == EventType::SecretBase) {
else if (eventType == EventType::CloneObject) {
QString destMap = this->event->get("target_map");
if (destMap != NONE_MAP_NAME) {
emit editor->warpEventDoubleClicked(destMap, this->event->get("target_local_id"), EventGroup::Object);
}
}
else if (eventType == EventType::SecretBase) {
QString baseId = this->event->get("secret_base_id");
QString destMap = editor->project->mapConstantsToMapNames.value("MAP_" + baseId.left(baseId.lastIndexOf("_")));
if (destMap != NONE_MAP_NAME) {
emit editor->warpEventDoubleClicked(destMap, "0");
emit editor->warpEventDoubleClicked(destMap, "0", EventGroup::Warp);
}
}
}

View file

@ -18,7 +18,7 @@ void NewEventToolButton::init()
this->newObjectAction->setIcon(QIcon(":/icons/add.ico"));
connect(this->newObjectAction, &QAction::triggered, this, &NewEventToolButton::newObject);
this->newCloneObjectAction = new QAction("New Object Clone", this);
this->newCloneObjectAction = new QAction("New Clone Object", this);
this->newCloneObjectAction->setIcon(QIcon(":/icons/add.ico"));
connect(this->newCloneObjectAction, &QAction::triggered, this, &NewEventToolButton::newCloneObject);