Update map list when MAPSEC/layout is changed

This commit is contained in:
GriffinR 2025-03-14 18:53:18 -04:00
parent f4d4980aad
commit 1375572be1
7 changed files with 37 additions and 20 deletions

View File

@ -48,7 +48,7 @@ public:
static QString mapConstantFromName(const QString &name);
QString expectedConstantName() const { return Map::mapConstantFromName(m_name); }
void setLayout(Layout *layout) { m_layout = layout; }
void setLayout(Layout *layout);
Layout* layout() const { return m_layout; }
int getWidth() const;
@ -143,6 +143,7 @@ signals:
void openScriptRequested(QString label);
void connectionAdded(MapConnection*);
void connectionRemoved(MapConnection*);
void layoutChanged();
};
#endif // MAP_H

View File

@ -141,9 +141,7 @@ private:
void setNewBorderDimensionsBlockdata(int newWidth, int newHeight);
signals:
void layoutChanged(Layout *layout);
//void modified();
void layoutDimensionsChanged(const QSize &size);
void dimensionsChanged(const QSize &size);
void needsRedrawing();
};

View File

@ -186,7 +186,6 @@ private slots:
void copy();
void paste();
void onLayoutChanged(Layout *layout);
void onOpenConnectedMap(MapConnection*);
void onTilesetsSaved(QString, QString);
void onNewMapCreated(Map *newMap, const QString &groupName);
@ -383,6 +382,8 @@ private:
void refreshRecentProjectsMenu();
void rebuildMapList_Locations();
void rebuildMapList_Layouts();
void updateMapList();
void openMapListItem(const QModelIndex &index);
void onMapListTabChanged(int index);

View File

@ -47,6 +47,14 @@ Map::~Map() {
deleteConnections();
}
// Note: Map does not take ownership of layout
void Map::setLayout(Layout *layout) {
if (layout == m_layout)
return;
m_layout = layout;
emit layoutChanged();
}
// We don't enforce this for existing maps, but for creating new maps we need to formulaically generate a new MAP_NAME ID.
QString Map::mapConstantFromName(const QString &name) {
return projectConfig.getIdentifier(ProjectIdentifier::define_map_prefix) + Util::toDefineCase(name);

View File

@ -168,8 +168,7 @@ void Layout::setDimensions(int newWidth, int newHeight, bool setNewBlockdata, bo
Scripting::cb_MapResized(oldWidth, oldHeight, newWidth, newHeight);
}
emit layoutChanged(this);
emit layoutDimensionsChanged(QSize(getWidth(), getHeight()));
emit dimensionsChanged(QSize(getWidth(), getHeight()));
}
void Layout::adjustDimensions(QMargins margins, bool setNewBlockdata) {
@ -194,8 +193,7 @@ void Layout::adjustDimensions(QMargins margins, bool setNewBlockdata) {
this->width = newWidth;
this->height = newHeight;
emit layoutChanged(this);
emit layoutDimensionsChanged(QSize(getWidth(), getHeight()));
emit dimensionsChanged(QSize(getWidth(), getHeight()));
}
void Layout::setBorderDimensions(int newWidth, int newHeight, bool setNewBlockdata, bool enableScriptCallback) {
@ -211,8 +209,6 @@ void Layout::setBorderDimensions(int newWidth, int newHeight, bool setNewBlockda
if (enableScriptCallback && (oldWidth != newWidth || oldHeight != newHeight)) {
Scripting::cb_BorderResized(oldWidth, oldHeight, newWidth, newHeight);
}
emit layoutChanged(this);
}
void Layout::setNewDimensionsBlockdata(int newWidth, int newHeight) {

View File

@ -1204,7 +1204,7 @@ bool Editor::setLayout(QString layoutId) {
editGroup.addStack(&this->layout->editHistory);
map_ruler->setMapDimensions(QSize(this->layout->getWidth(), this->layout->getHeight()));
connect(this->layout, &Layout::layoutDimensionsChanged, map_ruler, &MapRuler::setMapDimensions);
connect(this->layout, &Layout::dimensionsChanged, map_ruler, &MapRuler::setMapDimensions);
ui->comboBox_PrimaryTileset->blockSignals(true);
ui->comboBox_SecondaryTileset->blockSignals(true);

View File

@ -926,7 +926,11 @@ bool MainWindow::setMap(QString map_name) {
connect(editor->map, &Map::modified, this, &MainWindow::markMapEdited, Qt::UniqueConnection);
connect(editor->layout, &Layout::layoutChanged, this, &MainWindow::onLayoutChanged, Qt::UniqueConnection);
// If the map's MAPSEC / layout changes, update the map's position in the map list.
// These are doing more work than necessary, rather than rebuilding the entire list they should find and relocate the appropriate row.
connect(editor->map, &Map::layoutChanged, this, &MainWindow::rebuildMapList_Layouts, Qt::UniqueConnection);
connect(editor->map->header(), &MapHeader::locationChanged, this, &MainWindow::rebuildMapList_Locations, Qt::UniqueConnection);
connect(editor->layout, &Layout::needsRedrawing, this, &MainWindow::redrawMapScene, Qt::UniqueConnection);
userConfig.recentMapOrLayout = map_name;
@ -1539,6 +1543,19 @@ void MainWindow::openMapListItem(const QModelIndex &index) {
if (toolbar) toolbar->setFilterLocked(false);
}
void MainWindow::rebuildMapList_Locations() {
this->mapLocationModel->deleteLater();
this->mapLocationModel = new MapLocationModel(this->editor->project);
this->locationListProxyModel->setSourceModel(this->mapLocationModel);
resetMapListFilters();
}
void MainWindow::rebuildMapList_Layouts() {
this->layoutTreeModel->deleteLater();
this->layoutTreeModel = new LayoutTreeModel(this->editor->project);
this->layoutListProxyModel->setSourceModel(this->layoutTreeModel);
resetMapListFilters();
}
void MainWindow::updateMapList() {
// Get the name of the open map/layout (or clear the relevant selection if there is none).
QString activeItemName;
@ -1583,9 +1600,9 @@ void MainWindow::save(bool currentOnly) {
if (!porymapConfig.shownInGameReloadMessage) {
// Show a one-time warning that the user may need to reload their map to see their new changes.
static const QString message = QStringLiteral("Reload your map in-game!\n\nIf your game is currently saved on a map you have edited, "
"the changes may not appear until you leave the map and return.");
InfoMessage::show(message, this);
InfoMessage::show(QStringLiteral("Reload your map in-game!\n\nIf your game is currently saved on a map you have edited, "
"the changes may not appear until you leave the map and return."),
this);
porymapConfig.shownInGameReloadMessage = true;
}
@ -2420,10 +2437,6 @@ void MainWindow::onOpenConnectedMap(MapConnection *connection) {
editor->setSelectedConnection(connection->findMirror());
}
void MainWindow::onLayoutChanged(Layout *) {
updateMapList();
}
void MainWindow::onMapLoaded(Map *map) {
connect(map, &Map::modified, [this, map] { this->markSpecificMapEdited(map); });
}